Subversion Repositories Code-Repo

Rev

Rev 270 | Go to most recent revision | Blame | Compare with Previous | 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(LED_VALUES *values) {
    uint8_t buffer[17];

    buffer[0] = TLC59116_AUTO_INCR_ALL | TLC59116_REG_PWM0; // Register Select
    buffer[1] = values->w[0];
    buffer[2] = values->w[1];
    buffer[3] = values->w[2];
    buffer[4] = values->w[3];
    buffer[5] = values->w[4];
    buffer[6] = values->w[5];
    buffer[7] = values->w[6];
    buffer[8] = values->w[7];
    buffer[9] = values->w[8];
    buffer[10] = values->w[9];
    buffer[11] = values->w[10];
    buffer[12] = values->w[11];
    buffer[13] = values->w[12];
    buffer[14] = values->w[13];
    buffer[15] = values->w[14];
    buffer[16] = values->w[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);
}