diff options
author | Daniel Garcia <danielgarcia@gmail.com> | 2014-02-19 10:00:56 +0400 |
---|---|---|
committer | Daniel Garcia <danielgarcia@gmail.com> | 2014-02-19 10:00:56 +0400 |
commit | e393d6996476a5032cc2cc1e4a27da9843c7f602 (patch) | |
tree | c7a15a90086ffa67d41c5612fa3b295580ac390e | |
parent | 4ff103d94afcc33afc389dcd31537f15b98ae64a (diff) |
Fixing regular AVR build, flipping all AVR code over to using the clockless_trinket code. Dithering and RGB brightness control for everyone
-rw-r--r-- | chipsets.h | 39 | ||||
-rw-r--r-- | clockless.h | 2 | ||||
-rw-r--r-- | clockless_arm_sam.h | 48 | ||||
-rw-r--r-- | clockless_trinket.h | 10 | ||||
-rw-r--r-- | lib8tion.h | 6 |
5 files changed, 61 insertions, 44 deletions
@@ -297,49 +297,49 @@ public: // We want to force all avr's to use the Trinket controller when running at 8Mhz, because even the 328's at 8Mhz // need the more tightly defined timeframes. -#if (defined(LIB8_ATTINY) || defined(FASTLED_AVR)) && (F_CPU == 8000000) // 125ns/clock +#if defined(FASTLED_AVR) && (F_CPU == 8000000) // 125ns/clock // WS2811@8Mhz 2 clocks, 5 clocks, 3 clocks template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB> -class WS2811Controller800Khz : public ClocklessController_Trinket<DATA_PIN, 2, 5, 3, RGB_ORDER> {}; +class WS2811Controller800Khz : public ClocklessController<DATA_PIN, 2, 5, 3, RGB_ORDER> {}; template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB> -class WS2811Controller400Khz : public ClocklessController_Trinket<DATA_PIN, 4, 10, 6, RGB_ORDER> {}; +class WS2811Controller400Khz : public ClocklessController<DATA_PIN, 4, 10, 6, RGB_ORDER> {}; template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB> -class UCS1903Controller400Khz : public ClocklessController_Trinket<DATA_PIN, 4, 12, 4, RGB_ORDER> {}; +class UCS1903Controller400Khz : public ClocklessController<DATA_PIN, 4, 12, 4, RGB_ORDER> {}; template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB> -class UCS1903BController800Khz : public ClocklessController_Trinket<DATA_PIN, 2, 4, 4, RGB_ORDER> {}; +class UCS1903BController800Khz : public ClocklessController<DATA_PIN, 2, 4, 4, RGB_ORDER> {}; template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB> -class TM1809Controller800Khz : public ClocklessController_Trinket<DATA_PIN, 2, 5, 3, RGB_ORDER> {}; +class TM1809Controller800Khz : public ClocklessController<DATA_PIN, 2, 5, 3, RGB_ORDER> {}; template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB> -class TM1803Controller400Khz : public ClocklessController_Trinket<DATA_PIN, 6, 6, 6, RGB_ORDER> {}; +class TM1803Controller400Khz : public ClocklessController<DATA_PIN, 6, 6, 6, RGB_ORDER> {}; template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB> -class TM1829Controller800Khz : public ClocklessController_Trinket<DATA_PIN, 2, 5, 3, RGB_ORDER> {}; +class TM1829Controller800Khz : public ClocklessController<DATA_PIN, 2, 5, 3, RGB_ORDER> {}; template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB> -class GW6205Controller400Khz : public ClocklessController_Trinket<DATA_PIN, 6, 7, 6, RGB_ORDER> {}; +class GW6205Controller400Khz : public ClocklessController<DATA_PIN, 6, 7, 6, RGB_ORDER> {}; template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB> -class GW6205Controller800Khz : public ClocklessController_Trinket<DATA_PIN, 2, 4, 4, RGB_ORDER> {}; +class GW6205Controller800Khz : public ClocklessController<DATA_PIN, 2, 4, 4, RGB_ORDER> {}; -#elif defined(LIB8_ATTINY) && (F_CPU == 16000000) // 62.5ns/clock +#elif defined(FASTLED_AVR) && (F_CPU == 16000000) // 62.5ns/clock // WS2811@16Mhz 4 clocks, 10 clocks, 6 clocks template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB> -class WS2811Controller800Khz : public ClocklessController_Trinket<DATA_PIN, 4, 10, 6, RGB_ORDER> {}; +class WS2811Controller800Khz : public ClocklessController<DATA_PIN, 4, 10, 6, RGB_ORDER> {}; template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB> -class WS2811Controller400Khz : public ClocklessController_Trinket<DATA_PIN, 8, 20, 12, RGB_ORDER> {}; +class WS2811Controller400Khz : public ClocklessController<DATA_PIN, 8, 20, 12, RGB_ORDER> {}; template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB> -class UCS1903Controller400Khz : public ClocklessController_Trinket<DATA_PIN, 8, 24, 8, RGB_ORDER> {}; +class UCS1903Controller400Khz : public ClocklessController<DATA_PIN, 8, 24, 8, RGB_ORDER> {}; template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB> -class UCS1903BController800Khz : public ClocklessController_Trinket<DATA_PIN, 4, 8, 8, RGB_ORDER> {}; +class UCS1903BController800Khz : public ClocklessController<DATA_PIN, 4, 8, 8, RGB_ORDER> {}; template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB> class TM1809Controller800Khz : public ClocklessController<DATA_PIN, 4, 10, 6, RGB_ORDER> {}; @@ -347,6 +347,15 @@ class TM1809Controller800Khz : public ClocklessController<DATA_PIN, 4, 10, 6, RG template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB> class TM1803Controller400Khz : public ClocklessController<DATA_PIN, 12, 12, 12, RGB_ORDER> {}; +template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB> +class TM1829Controller800Khz : public ClocklessController<DATA_PIN, 4, 10, 6, RGB_ORDER> {}; + +template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB> +class GW6205Controller400Khz : public ClocklessController<DATA_PIN, 12, 14, 12, RGB_ORDER> {}; + +template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB> +class GW6205Controller800Khz : public ClocklessController<DATA_PIN, 4, 8, 8, RGB_ORDER> {}; + #else // GW6205@400khz - 800ns, 800ns, 800ns template <uint8_t DATA_PIN, EOrder RGB_ORDER = RGB> diff --git a/clockless.h b/clockless.h index 65fe18e4..b3fabbc5 100644 --- a/clockless.h +++ b/clockless.h @@ -18,7 +18,7 @@ #define SET_LO FLIP ? FastPin<DATA_PIN>::fastset(port, hi) : FastPin<DATA_PIN>::fastset(port, lo); #define SET_HI FLIP ? FastPin<DATA_PIN>::fastset(port, lo) : FastPin<DATA_PIN>::fastset(port, hi); -#include "clockless_avr.h" +// #include "clockless_avr.h" #include "clockless_trinket.h" #include "clockless_arm_k20.h" #include "clockless_arm_sam.h" diff --git a/clockless_arm_sam.h b/clockless_arm_sam.h index 7eb37698..3ce29bcb 100644 --- a/clockless_arm_sam.h +++ b/clockless_arm_sam.h @@ -6,6 +6,13 @@ #if defined(__SAM3X8E__) +#define TOTAL ( (T1+2) + (T2+2) + (T3+2) ) +#define T1_MARK (TOTAL - (T1+2)) +#define T2_MARK (T1_MARK - (T2+2)) + +#define SCALE(S,V) scale8_video(S,V) +// #define SCALE(S,V) scale8(S,V) + template <uint8_t DATA_PIN, int T1, int T2, int T3, EOrder RGB_ORDER = RGB, bool FLIP = false, int WAIT_TIME = 50> class ClocklessController : public CLEDController { typedef typename FastPinBB<DATA_PIN>::port_ptr_t data_ptr_t; @@ -29,12 +36,12 @@ public: virtual void showColor(const struct CRGB & data, int nLeds, CRGB scale = CRGB::White) { mWait.wait(); cli(); - SysClockSaver savedClock(T1 + T2 + T3); + SysClockSaver savedClock(TOTAL); showRGBInternal<0, false>(nLeds, scale, (const byte*)&data); // Adjust the timer - long microsTaken = CLKS_TO_MICROS((long)nLeds * 8 * (T1 + T2 + T3)); + long microsTaken = CLKS_TO_MICROS((long)nLeds * 8 * (TOTAL)); long millisTaken = (microsTaken / 1000); savedClock.restore(); do { TimeTick_Increment(); } while(--millisTaken > 0); @@ -45,17 +52,17 @@ public: virtual void show(const struct CRGB *rgbdata, int nLeds, CRGB scale = CRGB::White) { mWait.wait(); cli(); - SysClockSaver savedClock(T1 + T2 + T3); + SysClockSaver savedClock(TOTAL); - Serial.print("Scale is "); - Serial.print(scale.raw[0]); Serial.print(" "); - Serial.print(scale.raw[1]); Serial.print(" "); - Serial.print(scale.raw[2]); Serial.println(" "); + // Serial.print("Scale is "); + // Serial.print(scale.raw[0]); Serial.print(" "); + // Serial.print(scale.raw[1]); Serial.print(" "); + // Serial.print(scale.raw[2]); Serial.println(" "); // FastPinBB<DATA_PIN>::hi(); delay(1); FastPinBB<DATA_PIN>::lo(); showRGBInternal<0, true>(nLeds, scale, (const byte*)rgbdata); // Adjust the timer - long microsTaken = CLKS_TO_MICROS((long)nLeds * 8 * (T1 + T2 + T3)); + long microsTaken = CLKS_TO_MICROS((long)nLeds * 8 * (TOTAL)); long millisTaken = (microsTaken / 1000); savedClock.restore(); do { TimeTick_Increment(); } while(--millisTaken > 0); @@ -67,12 +74,12 @@ public: virtual void show(const struct CARGB *rgbdata, int nLeds, CRGB scale = CRGB::White) { mWait.wait(); cli(); - SysClockSaver savedClock(T1 + T2 + T3); + SysClockSaver savedClock(TOTAL); showRGBInternal<1, true>(nLeds, scale, (const byte*)rgbdata); // Adjust the timer - long microsTaken = CLKS_TO_MICROS((long)nLeds * 8 * (T1 + T2 + T3)); + long microsTaken = CLKS_TO_MICROS((long)nLeds * 8 * (TOTAL)); long millisTaken = (microsTaken / 1000); savedClock.restore(); do { TimeTick_Increment(); } while(--millisTaken > 0); @@ -126,10 +133,7 @@ public: //#define AT_MARK(X) delayclocks_until<T1_MARK>(_VAL); X; //#define AT_END(X) delayclocks_until<T2_MARK>(_VAL); X; -#define TOTAL (T1 + T2 + T3) -#define T1_MARK (TOTAL - T1) -#define T2_MARK (T1_MARK - T2) template<int MARK> __attribute__((always_inline)) static inline void delayclocks_until(register byte b) { __asm__ __volatile__ ( " sub %0, %0, %1\n" @@ -172,7 +176,7 @@ public: // dither if(DITHER && b) b = qadd8(b, D[B0]); // now scale - b = scale8(b, scale.raw[B0]); + b = SCALE(b, scale.raw[B0]); // Setup and start the clock _LOAD = TOTAL; @@ -199,13 +203,13 @@ public: AT_BIT_START(*port = 1); if(b& 0x80) {} else { AT_MARK(*port = 0); } + b = ADVANCE ? data[SKIP + B1] : rgbdata[SKIP + B1]; AT_END(*port = 0); - b = ADVANCE ? data[SKIP + B1] : rgbdata[SKIP + B1]; // dither if(DITHER && b) b = qadd8(b, D[B1]); // now scale - b = scale8(b, scale.raw[B1]); + b = SCALE(b, scale.raw[B1]); for(register uint32_t i = 7; i > 0; i--) { AT_BIT_START(*port = 1); @@ -216,13 +220,13 @@ public: AT_BIT_START(*port = 1); if(b& 0x80) {} else { AT_MARK(*port = 0); } + b = ADVANCE ? data[SKIP + B2] : rgbdata[SKIP + B2]; AT_END(*port = 0); - b = ADVANCE ? data[SKIP + B2] : rgbdata[SKIP + B2]; // dither if(DITHER && b) b = qadd8(b, D[B2]); // now scale - b = scale8(b, scale.raw[B2]); + b = SCALE(b, scale.raw[B2]); for(register uint32_t i = 7; i > 0; i--) { AT_BIT_START(*port = 1); @@ -233,16 +237,14 @@ public: AT_BIT_START(*port = 1); if(b& 0x80) {} else { AT_MARK(*port = 0); } - AT_END(*port = 0); - - // We have some extra time between rgb pixels, prep - // the next byte and cycle the dither adjustments data += (3 + SKIP); b = ADVANCE ? data[SKIP + B0] : rgbdata[SKIP + B0]; + AT_END(*port = 0); + // dither if(DITHER && b) b = qadd8(b, D[B0]); // now scale - b = scale8(b, scale.raw[B0]); + b = SCALE(b, scale.raw[B0]); }; // Save the D values for cycling through next time diff --git a/clockless_trinket.h b/clockless_trinket.h index 52831296..fe628aa6 100644 --- a/clockless_trinket.h +++ b/clockless_trinket.h @@ -6,7 +6,7 @@ #include "delay.h" #include <avr/interrupt.h> // for cli/se definitions -#if defined(LIB8_ATTINY) +#if defined(FASTLED_AVR) // Scaling macro choice #ifndef TRINKET_SCALE @@ -32,6 +32,12 @@ template<int CYCLES> __attribute__((always_inline)) inline void _dc(register uin template<> __attribute__((always_inline)) inline void _dc<0>(register uint8_t & loopvar) {} template<> __attribute__((always_inline)) inline void _dc<1>(register uint8_t & loopvar) {asm __volatile__("cp r0,r0":::);} template<> __attribute__((always_inline)) inline void _dc<2>(register uint8_t & loopvar) {asm __volatile__("rjmp .+0":::);} +template<> __attribute__((always_inline)) inline void _dc<3>(register uint8_t & loopvar) { _dc<2>(loopvar); _dc<1>(loopvar); } +template<> __attribute__((always_inline)) inline void _dc<4>(register uint8_t & loopvar) { _dc<2>(loopvar); _dc<2>(loopvar); } +template<> __attribute__((always_inline)) inline void _dc<5>(register uint8_t & loopvar) { _dc<2>(loopvar); _dc<3>(loopvar); } +template<> __attribute__((always_inline)) inline void _dc<6>(register uint8_t & loopvar) { _dc<2>(loopvar); _dc<2>(loopvar); _dc<2>(loopvar);} +template<> __attribute__((always_inline)) inline void _dc<7>(register uint8_t & loopvar) { _dc<4>(loopvar); _dc<3>(loopvar); } +template<> __attribute__((always_inline)) inline void _dc<8>(register uint8_t & loopvar) { _dc<4>(loopvar); _dc<4>(loopvar); } #define D1(ADJ) _dc<T1-(1+ADJ)>(loopvar); #define D2(ADJ) _dc<T2-(1+ADJ)>(loopvar); @@ -46,7 +52,7 @@ template<> __attribute__((always_inline)) inline void _dc<2>(register uint8_t & ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// template <uint8_t DATA_PIN, int T1, int T2, int T3, EOrder RGB_ORDER = RGB, int WAIT_TIME = 50> -class ClocklessController_Trinket : public CLEDController { +class ClocklessController : public CLEDController { typedef typename FastPin<DATA_PIN>::port_ptr_t data_ptr_t; typedef typename FastPin<DATA_PIN>::port_t data_t; @@ -470,9 +470,9 @@ LIB8STATIC uint8_t scale8_video( uint8_t i, fract8 scale) "mov %[j], r1\n\t" "clr __zero_reg__\n\t" "cpse %[i], r1\n\t" - "addi %[j], 1\n\t" - : "+a" (j) - : "a" (i), "a" (scale) + "subi %[j], 0xFF\n\t" + : [j] "+a" (j) + : [i] "a" (i), [scale] "a" (scale) : "r0", "r1"); return j; |