Subversion Repositories Code-Repo

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

#include "defines.h"
#include "TLC59116.h"
#include "I2C2.h"

void TLC59116_Init(void) {
    uint8_t buffer[25];

    buffer[0] = TLC59116_AUTO_INCR_ALL | 0x00; // Register Select
    buffer[1] = TLC59116_AUTO_INCR_ALL | 0x00; // MODE1
    buffer[2] = 0x00;   // MODE2
    buffer[3] = 0x00;   // PWM0
    buffer[4] = 0x00;   // PWM1
    buffer[5] = 0x00;   // PWM2
    buffer[6] = 0x00;   // PWM3
    buffer[7] = 0x00;   // PWM4
    buffer[8] = 0x00;   // PWM5
    buffer[9] = 0x00;   // PWM6
    buffer[10] = 0x00;  // PWM7
    buffer[11] = 0x00;  // PWM8
    buffer[12] = 0x00;  // PWM9
    buffer[13] = 0x00;  // PWM10
    buffer[14] = 0x00;  // PWM11
    buffer[15] = 0x00;  // PWM12
    buffer[16] = 0x00;  // PWM13
    buffer[17] = 0x00;  // PWM14
    buffer[18] = 0x00;  // PWM15
    buffer[19] = 0xFF;  // GRPPWM (maximum brightness)
    buffer[20] = 0x00;  // GRPFREQ (not used)
    buffer[21] = 0xFF;  // LEDOUT0 (brightness and group dimming enabled)
    buffer[22] = 0xFF;  // LEDOUT1
    buffer[23] = 0xFF;  // LEDOUT2
    buffer[24] = 0xFF;  // LEDOUT3

    I2C2_Master_Send(TLC59116_ADDR, 25, buffer);
    uint8_t result;
    do {
        result = I2C2_Get_Status();
    } while (!result);
}

void TLC59116_Write(uint8_t led, uint8_t brightness) {
    uint8_t buffer[2];

    buffer[0] = led + 0x02;    // Register Select
    buffer[1] = brightness;

    I2C2_Master_Send(TLC59116_ADDR, 2, buffer);
    uint8_t result;
    do {
        result = I2C2_Get_Status();
    } while (!result);
}

void TLC59116_Write_All(uint8_t *values) {
    uint8_t buffer[17];
    uint8_t i;

    buffer[0] = buffer[0] = TLC59116_AUTO_INCR_ALL | TLC59116_REG_PWM0; // Register Select
    buffer[1] = values[0];
    buffer[2] = values[1];
    buffer[3] = values[2];
    buffer[4] = values[3];
    buffer[5] = values[4];
    buffer[6] = values[5];
    buffer[7] = values[6];
    buffer[8] = values[7];
    buffer[9] = values[8];
    buffer[10] = values[9];
    buffer[11] = values[10];
    buffer[12] = values[11];
    buffer[13] = values[12];
    buffer[14] = values[13];
    buffer[15] = values[14];
    buffer[16] = values[15];

    I2C2_Master_Send(TLC59116_ADDR, 17, buffer);
    uint8_t result;
    do {
        result = I2C2_Get_Status();
    } while (!result);
}

void TLC59116_Write_BC(uint8_t brightness) {
    uint8_t buffer[2];

    buffer[0] = TLC59116_REG_GRPPWM;    // Register Select
    buffer[1] = brightness;

    I2C2_Master_Send(TLC59116_ADDR, 2, buffer);
    uint8_t result;
    do {
        result = I2C2_Get_Status();
    } while (!result);
}