Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FastLED/FastLED.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Garcia <danielgarcia@gmail.com>2015-01-15 21:37:51 +0300
committerDaniel Garcia <danielgarcia@gmail.com>2015-01-15 21:37:51 +0300
commitb4bbd5ca60ffd6a8c35ee191a0d510f41e6c52b9 (patch)
treedd7d1073c835a1e83ba78aea851df77a6be79a8d
parentea921d7762b0ed4a13c0939d62c7b52c289b6bf6 (diff)
Attempt at a fix for #121 - base the cycle for a pin on the port that the pin is attached to, vs. the arbitrary pin numbers used by arduino.
-rw-r--r--platforms/avr/clockless_trinket.h16
-rw-r--r--platforms/avr/fastpin_avr.h7
2 files changed, 9 insertions, 14 deletions
diff --git a/platforms/avr/clockless_trinket.h b/platforms/avr/clockless_trinket.h
index 5a9a96c6..07b56ca0 100644
--- a/platforms/avr/clockless_trinket.h
+++ b/platforms/avr/clockless_trinket.h
@@ -51,9 +51,9 @@ template<> __attribute__((always_inline)) inline void _dc<8>(register uint8_t &
template<> __attribute__((always_inline)) inline void _dc<9>(register uint8_t & loopvar) { _dc<5>(loopvar); _dc<4>(loopvar); }
template<> __attribute__((always_inline)) inline void _dc<10>(register uint8_t & loopvar) { _dc<6>(loopvar); _dc<4>(loopvar); }
-#define D1(ADJ) _dc<T1-(AVR_PIN_CYCLES(DATA_PIN)+ADJ)>(loopvar);
-#define D2(ADJ) _dc<T2-(AVR_PIN_CYCLES(DATA_PIN)+ADJ)>(loopvar);
-#define D3(ADJ) (T3-(AVR_PIN_CYCLES(DATA_PIN)+ADJ)>0) ? _dc<T3-(AVR_PIN_CYCLES(DATA_PIN)+ADJ)>(loopvar) : _dc<0>(loopvar);
+#define D1(ADJ) _dc<T1-(2+ADJ)>(loopvar); if(AVR_PIN_CYCLES(DATA_PIN)==1) _dc<1>(loopvar);
+#define D2(ADJ) _dc<T2-(2+ADJ)>(loopvar); if(AVR_PIN_CYCLES(DATA_PIN)==1) _dc<1>(loopvar);
+#define D3(ADJ) (T3-(2+ADJ)>0) ? _dc<T3-(2+ADJ)>(loopvar) : _dc<0>(loopvar); if(AVR_PIN_CYCLES(DATA_PIN)==1) _dc<1>(loopvar);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
@@ -116,7 +116,7 @@ protected:
// roughly 9.6 cycles per pixel, which is 0.6us/pixel at 16MHz
// microsTaken += nLeds * 0.6 * CLKS_TO_MICROS(16);
microsTaken += scale16by8(nLeds,(0.6 * 256) + 1) * CLKS_TO_MICROS(16);
-
+
// if less than 1000us, there is NO timer impact,
// this is because the ONE interrupt that might come in while interrupts
// are disabled is queued up, and it will be serviced as soon as
@@ -124,22 +124,22 @@ protected:
// This actually should technically also account for the runtime of the
// interrupt handler itself, but we're just not going to worry about that.
if( microsTaken > 1000) {
-
+
// Since up to one timer tick will be queued, we don't need
// to adjust the MS_COUNTER for that one.
microsTaken -= 1000;
-
+
// Now convert microseconds to 256ths of a second, approximately like this:
// 250ths = (us/4)
// 256ths = 250ths * (263/256);
uint16_t x256ths = microsTaken >> 2;
x256ths += scale16by8(x256ths,7);
-
+
x256ths += gTimeErrorAccum256ths;
MS_COUNTER += (x256ths >> 8);
gTimeErrorAccum256ths = x256ths & 0xFF;
}
-
+
#if 0
// For pixel counts of 30 and under at 16Mhz, no correction is necessary.
// For pixel counts of 15 and under at 8Mhz, no correction is necessary.
diff --git a/platforms/avr/fastpin_avr.h b/platforms/avr/fastpin_avr.h
index fdae2598..4a7c0942 100644
--- a/platforms/avr/fastpin_avr.h
+++ b/platforms/avr/fastpin_avr.h
@@ -8,12 +8,7 @@
#else
-#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
-#define AVR_PIN_CYCLES(_PIN) (((_PIN >= 62 ) || (_PIN>=42 && _PIN<=49) || (_PIN>=14 && _PIN <=17) || (_PIN>=6 && _PIN <=9)) ? 2 : 1)
-#else
-#define AVR_PIN_CYCLES(_PIN) ((_PIN >= 24) ? 2 : 1)
-#endif
-
+#define AVR_PIN_CYCLES(_PIN) ((((int)FastPin<_PIN>::port())-0x20 < 64) ? 1 : 2)
/// Class definition for a Pin where we know the port registers at compile time for said pin. This allows us to make
/// a lot of optimizations, as the inlined hi/lo methods will devolve to a single io register write/bitset.