diff options
-rw-r--r-- | FastSPI_LED2.h | 44 | ||||
-rw-r--r-- | examples/Fast2Dev/Fast2Dev.ino | 4 | ||||
-rw-r--r-- | fastspi.h | 23 |
3 files changed, 66 insertions, 5 deletions
diff --git a/FastSPI_LED2.h b/FastSPI_LED2.h index 2a060a97..2201f99b 100644 --- a/FastSPI_LED2.h +++ b/FastSPI_LED2.h @@ -108,6 +108,50 @@ public: #endif }; + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// SM16716 definition - takes data/clock/select pin values (N.B. should take an SPI definition?) +// +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +template <uint8_t DATA_PIN, uint8_t CLOCK_PIN, uint8_t SELECT_PIN, uint8_t SPI_SPEED = 1> +class SM16716Controller : public CLEDController { + typedef SPIOutput<DATA_PIN, CLOCK_PIN, SPI_SPEED> SPI; + SPI mSPI; + OutputPin selectPin; +public: + SM16716Controller() : selectPin(SELECT_PIN) {} + + virtual void init() { + mSPI.setSelect(&selectPin); + mSPI.init(); + } + + virtual void showRGB(uint8_t *data, int nLeds) { + // Write out 50 zeros to the spi line (6 blocks of 8 followed by two single bit writes) + mSPI.writeBytesValue(0, 6); + mSPI.template writeBit<0>(0); + mSPI.template writeBit<0>(0); + + // Make sure the FLAG_START_BIT flag is set to ensure that an extra 1 bit is sent at the start + // of each triplet of bytes for rgb data + mSPI.template writeBytes3<FLAG_START_BIT>(data, nLeds * 3); + } + +#ifdef SUPPORT_ARGB + virtual void showARGB(uint8_t *data, int nLeds) { + mSPI.writeBytesValue(0, 6); + mSPI.template writeBit<0>(0); + mSPI.template writeBit<0>(0); + + // Make sure the FLAG_START_BIT flag is set to ensure that an extra 1 bit is sent at the start + // of each triplet of bytes for rgb data + mSPI.template writeBytes3<1 | FLAG_START_BIT>(data, nLeds * 4); + } +#endif +}; + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Clockless template instantiations diff --git a/examples/Fast2Dev/Fast2Dev.ino b/examples/Fast2Dev/Fast2Dev.ino index 52ec881b..3cf46ced 100644 --- a/examples/Fast2Dev/Fast2Dev.ino +++ b/examples/Fast2Dev/Fast2Dev.ino @@ -25,7 +25,9 @@ struct CRGB leds[NUM_LEDS]; // Hardware SPI - .652ms for an 86 led frame @8Mhz (3.1Mbps?), .913ms @4Mhz 1.434ms @2Mhz // Hardware SPIr2 - .539ms @8Mhz, .799 @4Mhz, 1.315ms @2Mhz // With the wait ordering reversed, .520ms at 8Mhz, .779ms @4Mhz, 1.3ms @2Mhz -LPD8806Controller<11, 13, 10> LED; +// LPD8806Controller<11, 13, 10> LED; +SM16716Controller<14, 13, 10> LED; + //LPD8806Controller<11, 13, 14> LED; // LPD8806Controller<2, 1, 0> LED; // teensy pins // LPD8806Controller<0, 4, 10> LED; @@ -65,6 +65,9 @@ public: static __attribute__((always_inline)) inline uint8_t adjust(uint8_t data) { return data; } }; +#define FLAG_START_BIT 0x80 +#define MASK_SKIP_BITS 0x7F + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Software SPI (aka bit-banging) support - with aggressive optimizations for when the clock and data pin are on the same port @@ -360,7 +363,10 @@ public: uint8_t *end = data + len; while(data != end) { - data += SKIP; + data += (MASK_SKIP_BITS & SKIP); + if(SKIP & FLAG_START_BIT) { + writeBit<0>(1, clockpin, datapin, datahi, datalo, clockhi, clocklo); + } writeByte(D::adjust(*data++), clockpin, datapin, datahi, datalo, clockhi, clocklo); writeByte(D::adjust(*data++), clockpin, datapin, datahi, datalo, clockhi, clocklo); writeByte(D::adjust(*data++), clockpin, datapin, datahi, datalo, clockhi, clocklo); @@ -376,7 +382,10 @@ public: uint8_t *end = data + len; while(data != end) { - data += SKIP; + data += (MASK_SKIP_BITS & SKIP); + if(SKIP & FLAG_START_BIT) { + writeBit<0>(1, datapin, datahi_clockhi, datalo_clockhi, datahi_clocklo, datalo_clocklo); + } writeByte(D::adjust(*data++), datapin, datahi_clockhi, datalo_clockhi, datahi_clocklo, datalo_clocklo); writeByte(D::adjust(*data++), datapin, datahi_clockhi, datalo_clockhi, datahi_clocklo, datalo_clocklo); writeByte(D::adjust(*data++), datapin, datahi_clockhi, datalo_clockhi, datahi_clocklo, datalo_clocklo); @@ -481,7 +490,7 @@ public: uint8_t *end = data + len; select(); while(data != end) { - data += SKIP; + data += (MASK_SKIP_BITS & SKIP); #if defined(__MK20DX128__) writeByte(D::adjust(*data++)); writeByte(D::adjust(*data++)); @@ -620,7 +629,13 @@ public: uint8_t *end = data + len; select(); while(data != end) { - data += SKIP; + data += (MASK_SKIP_BITS & SKIP); + if(SKIP & FLAG_START_BIT) { + if(_SPI_SPEED != 0) { + wait(); + } + writeBit<0>(1); + } #if defined(__MK20DX128__) writeByte(D::adjust(*data++)); writeByte(D::adjust(*data++)); |