TLC5940 library which supports SWSPI, has API to specify grayscale PWM period and has API like Arduino library.
Fork of TLC5940 by
Diff: TLC5940.cpp
- Revision:
- 3:2c0af5f5fa13
- Parent:
- 2:b411648dfe54
- Child:
- 5:c35b2b62f2f3
--- a/TLC5940.cpp Tue Oct 13 12:20:23 2015 +0000 +++ b/TLC5940.cpp Sat Oct 17 01:36:58 2015 +0000 @@ -1,20 +1,17 @@ #include "TLC5940.h" -#define GSCLK_PERIOD 5 -TLC5940::TLC5940(PinName mosi, PinName miso, PinName sck, PinName xlat, PinName blank, PinName gsclk): - _spi(SWSPI(mosi, miso, sck)), - _gsclk(PwmOut(gsclk)), - _sclk(DigitalOut(sck)), - _xlat(DigitalOut(xlat)), - _blank(DigitalOut(blank)), - _t(Ticker()) +TLC5940::TLC5940(PinName mosi, PinName miso, PinName sck, PinName xlat, PinName blank, PinName gsclk, + int gspwmcycle_us, bool gspwmcycle_repeat): + _spi(mosi, miso, sck), + _gsclk(gsclk), + _xlat(xlat), + _blank(blank), + _gspwmcycle_us(gspwmcycle_us), + _gspwmcycle_repeat(gspwmcycle_repeat) { _spi.format(12,0); _spi.frequency(30000000); - - // Turn off GSCLK - _gsclk.write(0.0f); - _gsclk.period_us(GSCLK_PERIOD); + _gsclk.period_us(gspwmcycle_us / 4096); // Reset to 0 for(int i = 0; i < 16; i++) @@ -42,14 +39,18 @@ _spi.write(gs_data[i]); } + _blank.write(1); _xlat.write(1); _xlat.write(0); + _blank.write(0); } void TLC5940::run() { + if (_gspwmcycle_repeat) { + _t.attach_us(this, &TLC5940::refresh, _gspwmcycle_us); + } _gsclk.write(0.5f); - _t.attach_us(this, &TLC5940::refresh, GSCLK_PERIOD*4096); } void TLC5940::refresh()