RGB LED Driver demo

Dependents:   NJU6063_HelloWorld

NJU6063.cpp

Committer:
og
Date:
2015-12-26
Revision:
0:0283db13b7f1
Child:
1:bbc915c814da

File content as of revision 0:0283db13b7f1:

#include "NJU6063.h"

NJU6063::NJU6063( PinName sda, PinName scl, PinName rst)
    : _i2c(sda, scl), _rst(rst)
{
}

void NJU6063::reset(void)
{
    wait_ms(100);
    _rst = 0;
    wait_ms(100);
    _rst = 1;
}

void NJU6063::set_multi_device(uint8_t n)
{
    char data[3];
    data[0] = 0x00; // Initial chip addres
    data[1] = 0x0d; // multi device address
    for (uint8_t i=1; i<=n; i++) {
        data[2] = i;
        _i2c.write(NJU6063_SLAVE, data, 3);
    }
}
void NJU6063::init(uint8_t chip_addr, uint8_t d)
{
    char data[3];
    data[0] = chip_addr;
    data[1] = 0x00;
    data[2] = d;
    _i2c.write(NJU6063_SLAVE, data, 3);
}

void NJU6063::set_iled(uint8_t chip_addr, uint8_t d1, uint8_t d2, uint8_t d3)
{
    char data[3];
    data[0] = chip_addr;
    data[1] = 0x01;
    data[2] = (0x03&d1) | (0x03&d2)<<2 | (0x03&d3) <<4;
    _i2c.write(NJU6063_SLAVE, data, 3);
}

void NJU6063::set_pwm(uint8_t chip_addr, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t loop, uint8_t son)
{
    char data[7];
    data[0] = chip_addr;
    data[1] = 0x02;
    data[2] = d1;
    data[3] = d2;
    data[4] = d3;
    data[5] = loop;
    data[6] = son;
    _i2c.write(NJU6063_SLAVE, data, 7);
}
void NJU6063::dim_start(uint8_t chip_addr)
{
    char data[3];
    data[0] = chip_addr;
    data[1] = 0x07; // reg addres
    data[2] = 0x01; // start
    _i2c.write(NJU6063_SLAVE, data, 3);
}

uint8_t NJU6063::check_dim(void)
{
    uint8_t ACK;
    char data[3];
    data[0] = 0xff;
    data[1] = 0x0b;
    data[2] = 0x00;
    do {
        ACK = _i2c.write(NJU6063_SLAVE, data, 3);
    } while(!ACK);
    return(ACK);
}