16-channel I2C constant current LED sink driver
Fork of TLC59116 by
TLC59116.cpp@2:daabe2fe9b1d, 2017-08-22 (annotated)
- Committer:
- pilotak
- Date:
- Tue Aug 22 10:56:36 2017 +0000
- Revision:
- 2:daabe2fe9b1d
- Parent:
- 1:c285b2c57b2e
fix the mbed::NonCopyable thing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sillevl | 0:52a1996ad711 | 1 | #include "TLC59116.h" |
sillevl | 0:52a1996ad711 | 2 | |
pilotak | 2:daabe2fe9b1d | 3 | TLC59116::TLC59116(I2C &i2c_obj, int _address) |
pilotak | 2:daabe2fe9b1d | 4 | : |
pilotak | 2:daabe2fe9b1d | 5 | i2c_p(NULL), |
pilotak | 2:daabe2fe9b1d | 6 | i2c(i2c_obj), |
pilotak | 2:daabe2fe9b1d | 7 | address(_address) |
sillevl | 1:c285b2c57b2e | 8 | { |
sillevl | 1:c285b2c57b2e | 9 | initialize(); |
sillevl | 1:c285b2c57b2e | 10 | } |
sillevl | 0:52a1996ad711 | 11 | |
pilotak | 2:daabe2fe9b1d | 12 | TLC59116::TLC59116(PinName sda, PinName scl, int _address) |
pilotak | 2:daabe2fe9b1d | 13 | : |
pilotak | 2:daabe2fe9b1d | 14 | i2c_p(new I2C(sda, scl)), |
pilotak | 2:daabe2fe9b1d | 15 | i2c(*i2c_p), |
pilotak | 2:daabe2fe9b1d | 16 | address(_address) |
sillevl | 0:52a1996ad711 | 17 | { |
sillevl | 1:c285b2c57b2e | 18 | initialize(); |
sillevl | 1:c285b2c57b2e | 19 | } |
sillevl | 1:c285b2c57b2e | 20 | |
sillevl | 1:c285b2c57b2e | 21 | void TLC59116::initialize() |
sillevl | 1:c285b2c57b2e | 22 | { |
sillevl | 0:52a1996ad711 | 23 | // oscillator set to normal mode |
sillevl | 0:52a1996ad711 | 24 | enable(); |
sillevl | 0:52a1996ad711 | 25 | // enable individual brightness and group dimming |
sillevl | 0:52a1996ad711 | 26 | setOutputState(0xFF,0xFF,0xFF,0xFF); |
sillevl | 0:52a1996ad711 | 27 | } |
sillevl | 0:52a1996ad711 | 28 | |
sillevl | 0:52a1996ad711 | 29 | void TLC59116::enable() |
sillevl | 0:52a1996ad711 | 30 | { |
sillevl | 0:52a1996ad711 | 31 | // should readout register state first |
sillevl | 0:52a1996ad711 | 32 | setRegister(0,0); |
sillevl | 0:52a1996ad711 | 33 | } |
sillevl | 0:52a1996ad711 | 34 | |
sillevl | 0:52a1996ad711 | 35 | void TLC59116::disable() |
sillevl | 0:52a1996ad711 | 36 | { |
sillevl | 0:52a1996ad711 | 37 | // should readout register state first |
sillevl | 0:52a1996ad711 | 38 | setRegister(0,1 << 4); |
sillevl | 0:52a1996ad711 | 39 | } |
sillevl | 0:52a1996ad711 | 40 | |
sillevl | 0:52a1996ad711 | 41 | void TLC59116::setOutputState(int ledout0, int ledout1, int ledout2, int ledout3) |
sillevl | 0:52a1996ad711 | 42 | { |
sillevl | 0:52a1996ad711 | 43 | setRegister(0x14,ledout0); |
sillevl | 0:52a1996ad711 | 44 | setRegister(0x15,ledout1); |
sillevl | 0:52a1996ad711 | 45 | setRegister(0x16,ledout2); |
sillevl | 0:52a1996ad711 | 46 | setRegister(0x17,ledout3); |
sillevl | 0:52a1996ad711 | 47 | } |
sillevl | 0:52a1996ad711 | 48 | |
sillevl | 0:52a1996ad711 | 49 | void TLC59116::setChannel(int led, float brightness) |
sillevl | 0:52a1996ad711 | 50 | { |
sillevl | 0:52a1996ad711 | 51 | char data[] = {NO_AUTO_INCREMENT + 0x02 + led, brightness * 255.0}; |
sillevl | 0:52a1996ad711 | 52 | i2c.write(address, data, 2); |
sillevl | 0:52a1996ad711 | 53 | } |
sillevl | 0:52a1996ad711 | 54 | |
sillevl | 0:52a1996ad711 | 55 | |
sillevl | 0:52a1996ad711 | 56 | void TLC59116::setBrightness(float brightness) |
sillevl | 0:52a1996ad711 | 57 | { |
sillevl | 0:52a1996ad711 | 58 | setRegister(GRPPWM, brightness * 255.0); |
sillevl | 0:52a1996ad711 | 59 | } |
sillevl | 0:52a1996ad711 | 60 | |
sillevl | 0:52a1996ad711 | 61 | void TLC59116::setRegister(int reg, int value) |
sillevl | 0:52a1996ad711 | 62 | { |
sillevl | 0:52a1996ad711 | 63 | char data[] = {NO_AUTO_INCREMENT + reg, value}; |
sillevl | 0:52a1996ad711 | 64 | i2c.write(address, data, 2); |
sillevl | 0:52a1996ad711 | 65 | } |
sillevl | 0:52a1996ad711 | 66 | |
sillevl | 0:52a1996ad711 | 67 | void TLC59116::setRegisters(int reg, char* value, int length, int mode) |
sillevl | 0:52a1996ad711 | 68 | { |
sillevl | 0:52a1996ad711 | 69 | // not implemented yet |
sillevl | 0:52a1996ad711 | 70 | } |