TLC5940 library which supports SWSPI, has API to specify grayscale PWM period and has API like Arduino library.

Fork of TLC5940 by Stefan Nielsen

Committer:
deton
Date:
Sun Oct 18 12:06:51 2015 +0000
Revision:
6:04354724a9c6
Parent:
5:c35b2b62f2f3
Avoid unexpected refresh in flush() for use of GS PWM as blink.; Otherwise, blink period varies.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Julepalme 0:bdf7a64b89a7 1 #ifndef TLC5940_H_
Julepalme 0:bdf7a64b89a7 2 #define TLC5940_H_
Julepalme 0:bdf7a64b89a7 3
Julepalme 0:bdf7a64b89a7 4 #include "mbed.h"
Julepalme 0:bdf7a64b89a7 5
deton 5:c35b2b62f2f3 6 template<typename T>
Julepalme 0:bdf7a64b89a7 7 class TLC5940 {
Julepalme 0:bdf7a64b89a7 8 private:
deton 5:c35b2b62f2f3 9 T _spi;
deton 1:b188393f5b49 10 PwmOut _gsclk;
deton 1:b188393f5b49 11 DigitalOut _xlat;
deton 3:2c0af5f5fa13 12 DigitalOut _blank;
deton 1:b188393f5b49 13 Ticker _t;
deton 3:2c0af5f5fa13 14 int _gspwmcycle_us;
deton 3:2c0af5f5fa13 15 bool _gspwmcycle_repeat;
deton 1:b188393f5b49 16 uint16_t gs_data[16];
Julepalme 0:bdf7a64b89a7 17 public:
deton 3:2c0af5f5fa13 18 /**
deton 3:2c0af5f5fa13 19 * Constructor.
deton 3:2c0af5f5fa13 20 * @param mosi -> SIN
deton 3:2c0af5f5fa13 21 * @param miso -> (not connect to TLC5940)
deton 3:2c0af5f5fa13 22 * @param sck -> SCLK
deton 3:2c0af5f5fa13 23 * @param xlat -> XLAT
deton 3:2c0af5f5fa13 24 * @param blank -> BLANK
deton 3:2c0af5f5fa13 25 * @param gsclk -> GSCLK
deton 3:2c0af5f5fa13 26 * @param gspwmcycle_us grayscale PWM cycle in [us]. consists of 4096 pulses.
deton 3:2c0af5f5fa13 27 * @param gspwmcycle_repeat repeat grayscale PWM cycle or not.
deton 3:2c0af5f5fa13 28 * If true, send BLANK pulse after each grayscale PWM cycle using Ticker.
deton 3:2c0af5f5fa13 29 */
deton 3:2c0af5f5fa13 30 TLC5940(PinName mosi, PinName miso, PinName sck, PinName xlat, PinName blank, PinName gsclk,
deton 3:2c0af5f5fa13 31 int gspwmcycle_us = 20480, bool gspwmcycle_repeat = true);
deton 1:b188393f5b49 32 void set(int channel, uint16_t brightness);
Julepalme 0:bdf7a64b89a7 33 void flush();
Julepalme 0:bdf7a64b89a7 34 void run();
deton 4:fc83415fa28c 35 void refresh();
Julepalme 0:bdf7a64b89a7 36 };
Julepalme 0:bdf7a64b89a7 37
Julepalme 0:bdf7a64b89a7 38 #endif /* TLC5940_H_ */