Pavel S / TLC59116

Fork of TLC59116 by Sille Van Landschoot

Files at this revision

API Documentation at this revision

Comitter:
sillevl
Date:
Thu Dec 03 07:57:50 2015 +0000
Child:
1:c285b2c57b2e
Commit message:
initial commit

Changed in this revision

TLC59116.cpp Show annotated file Show diff for this revision Revisions of this file
TLC59116.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TLC59116.cpp	Thu Dec 03 07:57:50 2015 +0000
@@ -0,0 +1,53 @@
+#include "TLC59116.h"
+
+
+TLC59116::TLC59116(PinName sda, PinName scl, int _address): i2c(sda, scl), address(_address)
+{
+    // oscillator set to normal mode 
+    enable();
+    // enable individual brightness and group dimming
+    setOutputState(0xFF,0xFF,0xFF,0xFF);
+}
+
+void TLC59116::enable()
+{
+    // should readout register state first
+    setRegister(0,0);
+}
+
+void TLC59116::disable()
+{
+    // should readout register state first
+    setRegister(0,1 << 4);
+}
+
+void TLC59116::setOutputState(int ledout0, int ledout1, int ledout2, int ledout3)
+{
+    setRegister(0x14,ledout0);
+    setRegister(0x15,ledout1);
+    setRegister(0x16,ledout2);
+    setRegister(0x17,ledout3);
+}
+
+void TLC59116::setChannel(int led, float brightness)
+{
+    char data[] = {NO_AUTO_INCREMENT + 0x02 + led, brightness * 255.0};
+    i2c.write(address, data, 2);
+}
+
+
+void TLC59116::setBrightness(float brightness)
+{
+    setRegister(GRPPWM, brightness * 255.0);
+}
+
+void TLC59116::setRegister(int reg, int value)
+{
+    char data[] = {NO_AUTO_INCREMENT + reg, value};
+    i2c.write(address, data, 2);
+}
+
+void TLC59116::setRegisters(int reg, char* value, int length, int mode)
+{
+    // not implemented yet
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TLC59116.h	Thu Dec 03 07:57:50 2015 +0000
@@ -0,0 +1,34 @@
+#pragma once
+
+#include "mbed.h"
+
+class TLC59116{
+    public:
+    TLC59116(PinName sda, PinName scl, int address);
+    
+    void setBrightness(float brightness);
+    void setChannel(int channel, float brightness);
+    void enable();
+    void disable();
+    
+    protected:
+    int address;
+    I2C i2c;
+    
+    void setOutputState(int ledout0, int ledout1, int ledout2, int ledout3);
+    
+    private:
+    void setRegister(int reg, int value);
+    void setRegisters(int reg, char* value, int length, int mode = AUTO_INCREMENT_ALL_REGISTERS);
+    
+    static const int AUTO_INCREMENT_ALL_REGISTERS = 0x80;
+    static const int AUTO_INCREMENT_BRIGHTNESS = 0xA0;
+    static const int AUTO_INCREMENT_CONTROL = 0xC0;
+    static const int AUTO_INCREMENT_BRIGHTNESS_CONTROL = 0xE0;
+    static const int NO_AUTO_INCREMENT = 0x00;
+    
+    static const int GRPPWM = 0x12;
+    static const int LEDOUT0 = 0x014;
+
+    
+};
\ No newline at end of file