diff options
author | danielgarcia@gmail.com <danielgarcia@gmail.com@4ad4ec5c-605d-bd5c-5796-512c9b60011b> | 2013-05-31 12:01:42 +0400 |
---|---|---|
committer | danielgarcia@gmail.com <danielgarcia@gmail.com@4ad4ec5c-605d-bd5c-5796-512c9b60011b> | 2013-05-31 12:01:42 +0400 |
commit | 38fc7c315e29885fa74dc2ca27114c90a8f77d1b (patch) | |
tree | a968c593218dfd44721fa02666b7bbb15124c088 /chipsets.h | |
parent | d0100fc2a3f45aed7316411e11eafc868ae0a33c (diff) |
Expand the test case a little bit. Fix LPD8806 showColor. Add a separate mechanism to set global brightness. Some other tweaks/cleanups
Diffstat (limited to 'chipsets.h')
-rw-r--r-- | chipsets.h | 51 |
1 files changed, 30 insertions, 21 deletions
@@ -9,11 +9,7 @@ // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -#ifdef SPI_DATA -template <uint8_t DATA_PIN = SPI_DATA, uint8_t CLOCK_PIN = SPI_CLOCK, EOrder RGB_ORDER = RGB, uint8_t SPI_SPEED = DATA_RATE_MHZ(24) > -#else template <uint8_t DATA_PIN, uint8_t CLOCK_PIN, EOrder RGB_ORDER = RGB, uint8_t SPI_SPEED = DATA_RATE_MHZ(24) > -#endif class LPD8806Controller : public CLEDController { typedef SPIOutput<DATA_PIN, CLOCK_PIN, SPI_SPEED> SPI; @@ -50,21 +46,27 @@ public: } virtual void clearLeds(int nLeds) { - checkClear(nLeds); - mSPI.writeBytesValue(0x80, nLeds * 3); + mSPI.select(); + mSPI.writeBytesValueRaw(0x80, nLeds * 3); + mSPI.writeBytesValueRaw(0, ((nLeds*3+63)>>6)); + mSPI.release(); } virtual void showColor(const struct CRGB & data, int nLeds, uint8_t scale = 255) { - checkClear(nLeds); mSPI.select(); - while(nLeds--) { - mSPI.writeByte(data[RGB_BYTE0(RGB_ORDER)]); - mSPI.writeByte(data[RGB_BYTE1(RGB_ORDER)]); - mSPI.writeByte(data[RGB_BYTE2(RGB_ORDER)]); + uint8_t a = 0x80 | (scale8(data[RGB_BYTE0(RGB_ORDER)], scale) >> 1); + uint8_t b = 0x80 | (scale8(data[RGB_BYTE1(RGB_ORDER)], scale) >> 1); + uint8_t c = 0x80 | (scale8(data[RGB_BYTE2(RGB_ORDER)], scale) >> 1); + int iLeds = 0; + + while(iLeds++ < nLeds) { + mSPI.writeByte(a); + mSPI.writeByte(b); + mSPI.writeByte(c); } + // latch in the world - mSPI.writeBytesValueRaw(0, ((nLeds+63)>>6)); - mSPI.waitFully(); + mSPI.writeBytesValueRaw(0, ((nLeds*3+63)>>6)); mSPI.release(); } @@ -109,10 +111,14 @@ public: virtual void showColor(const struct CRGB & data, int nLeds, uint8_t scale = 255) { mWaitDelay.wait(); mSPI.select(); + uint8_t a = scale8(data[RGB_BYTE0(RGB_ORDER)], scale); + uint8_t b = scale8(data[RGB_BYTE1(RGB_ORDER)], scale); + uint8_t c = scale8(data[RGB_BYTE2(RGB_ORDER)], scale); + while(nLeds--) { - mSPI.writeByte(data[RGB_BYTE0(RGB_ORDER)]); - mSPI.writeByte(data[RGB_BYTE1(RGB_ORDER)]); - mSPI.writeByte(data[RGB_BYTE2(RGB_ORDER)]); + mSPI.writeByte(a); + mSPI.writeByte(b); + mSPI.writeByte(c); } mSPI.waitFully(); mSPI.release(); @@ -165,7 +171,6 @@ public: virtual void clearLeds(int nLeds) { mSPI.select(); - writeHeader(); while(nLeds--) { mSPI.template writeBit<0>(1); mSPI.writeByte(0); @@ -174,16 +179,20 @@ public: } mSPI.waitFully(); mSPI.release(); + writeHeader(); } virtual void showColor(const struct CRGB & data, int nLeds, uint8_t scale = 255) { mSPI.select(); - writeHeader(); + uint8_t a = scale8(data[RGB_BYTE0(RGB_ORDER)], scale); + uint8_t b = scale8(data[RGB_BYTE1(RGB_ORDER)], scale); + uint8_t c = scale8(data[RGB_BYTE2(RGB_ORDER)], scale); + while(nLeds--) { mSPI.template writeBit<0>(1); - mSPI.writeByte(data[RGB_BYTE0(RGB_ORDER)]); - mSPI.writeByte(data[RGB_BYTE1(RGB_ORDER)]); - mSPI.writeByte(data[RGB_BYTE2(RGB_ORDER)]); + mSPI.writeByte(a); + mSPI.writeByte(b); + mSPI.writeByte(c); } writeHeader(); mSPI.release(); |