LED drivers: add defines for PWM and LED control register counts (#22383)
This commit is contained in:
parent
0a94c2951f
commit
a27bc60703
|
@ -24,6 +24,9 @@
|
||||||
#define IS31FL3218_REG_UPDATE 0x16
|
#define IS31FL3218_REG_UPDATE 0x16
|
||||||
#define IS31FL3218_REG_RESET 0x17
|
#define IS31FL3218_REG_RESET 0x17
|
||||||
|
|
||||||
|
#define IS31FL3218_PWM_REGISTER_COUNT 18
|
||||||
|
#define IS31FL3218_LED_CONTROL_REGISTER_COUNT 3
|
||||||
|
|
||||||
#ifndef IS31FL3218_I2C_TIMEOUT
|
#ifndef IS31FL3218_I2C_TIMEOUT
|
||||||
# define IS31FL3218_I2C_TIMEOUT 100
|
# define IS31FL3218_I2C_TIMEOUT 100
|
||||||
#endif
|
#endif
|
||||||
|
@ -36,11 +39,11 @@
|
||||||
uint8_t g_twi_transfer_buffer[20];
|
uint8_t g_twi_transfer_buffer[20];
|
||||||
|
|
||||||
// IS31FL3218 has 18 PWM outputs and a fixed I2C address, so no chaining.
|
// IS31FL3218 has 18 PWM outputs and a fixed I2C address, so no chaining.
|
||||||
uint8_t g_pwm_buffer[18];
|
uint8_t g_pwm_buffer[IS31FL3218_PWM_REGISTER_COUNT];
|
||||||
bool g_pwm_buffer_update_required = false;
|
bool g_pwm_buffer_update_required = false;
|
||||||
|
|
||||||
uint8_t g_led_control_registers[3] = {0};
|
uint8_t g_led_control_registers[IS31FL3218_LED_CONTROL_REGISTER_COUNT] = {0};
|
||||||
bool g_led_control_registers_update_required = false;
|
bool g_led_control_registers_update_required = false;
|
||||||
|
|
||||||
void is31fl3218_write_register(uint8_t reg, uint8_t data) {
|
void is31fl3218_write_register(uint8_t reg, uint8_t data) {
|
||||||
g_twi_transfer_buffer[0] = reg;
|
g_twi_transfer_buffer[0] = reg;
|
||||||
|
@ -77,12 +80,12 @@ void is31fl3218_init(void) {
|
||||||
is31fl3218_write_register(IS31FL3218_REG_SHUTDOWN, 0x01);
|
is31fl3218_write_register(IS31FL3218_REG_SHUTDOWN, 0x01);
|
||||||
|
|
||||||
// Set all PWM values to zero
|
// Set all PWM values to zero
|
||||||
for (uint8_t i = 0; i < 18; i++) {
|
for (uint8_t i = 0; i < IS31FL3218_PWM_REGISTER_COUNT; i++) {
|
||||||
is31fl3218_write_register(IS31FL3218_REG_PWM + i, 0x00);
|
is31fl3218_write_register(IS31FL3218_REG_PWM + i, 0x00);
|
||||||
}
|
}
|
||||||
|
|
||||||
// turn off all LEDs in the LED control register
|
// turn off all LEDs in the LED control register
|
||||||
for (uint8_t i = 0; i < 3; i++) {
|
for (uint8_t i = 0; i < IS31FL3218_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||||
is31fl3218_write_register(IS31FL3218_REG_CONTROL + i, 0x00);
|
is31fl3218_write_register(IS31FL3218_REG_CONTROL + i, 0x00);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +145,7 @@ void is31fl3218_update_pwm_buffers(void) {
|
||||||
|
|
||||||
void is31fl3218_update_led_control_registers(void) {
|
void is31fl3218_update_led_control_registers(void) {
|
||||||
if (g_led_control_registers_update_required) {
|
if (g_led_control_registers_update_required) {
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < IS31FL3218_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||||
is31fl3218_write_register(IS31FL3218_REG_CONTROL + i, g_led_control_registers[i]);
|
is31fl3218_write_register(IS31FL3218_REG_CONTROL + i, g_led_control_registers[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
#define IS31FL3218_REG_UPDATE 0x16
|
#define IS31FL3218_REG_UPDATE 0x16
|
||||||
#define IS31FL3218_REG_RESET 0x17
|
#define IS31FL3218_REG_RESET 0x17
|
||||||
|
|
||||||
|
#define IS31FL3218_PWM_REGISTER_COUNT 18
|
||||||
|
#define IS31FL3218_LED_CONTROL_REGISTER_COUNT 3
|
||||||
|
|
||||||
#ifndef IS31FL3218_I2C_TIMEOUT
|
#ifndef IS31FL3218_I2C_TIMEOUT
|
||||||
# define IS31FL3218_I2C_TIMEOUT 100
|
# define IS31FL3218_I2C_TIMEOUT 100
|
||||||
#endif
|
#endif
|
||||||
|
@ -36,11 +39,11 @@
|
||||||
uint8_t g_twi_transfer_buffer[20];
|
uint8_t g_twi_transfer_buffer[20];
|
||||||
|
|
||||||
// IS31FL3218 has 18 PWM outputs and a fixed I2C address, so no chaining.
|
// IS31FL3218 has 18 PWM outputs and a fixed I2C address, so no chaining.
|
||||||
uint8_t g_pwm_buffer[18];
|
uint8_t g_pwm_buffer[IS31FL3218_PWM_REGISTER_COUNT];
|
||||||
bool g_pwm_buffer_update_required = false;
|
bool g_pwm_buffer_update_required = false;
|
||||||
|
|
||||||
uint8_t g_led_control_registers[3] = {0};
|
uint8_t g_led_control_registers[IS31FL3218_LED_CONTROL_REGISTER_COUNT] = {0};
|
||||||
bool g_led_control_registers_update_required = false;
|
bool g_led_control_registers_update_required = false;
|
||||||
|
|
||||||
void is31fl3218_write_register(uint8_t reg, uint8_t data) {
|
void is31fl3218_write_register(uint8_t reg, uint8_t data) {
|
||||||
g_twi_transfer_buffer[0] = reg;
|
g_twi_transfer_buffer[0] = reg;
|
||||||
|
@ -77,12 +80,12 @@ void is31fl3218_init(void) {
|
||||||
is31fl3218_write_register(IS31FL3218_REG_SHUTDOWN, 0x01);
|
is31fl3218_write_register(IS31FL3218_REG_SHUTDOWN, 0x01);
|
||||||
|
|
||||||
// Set all PWM values to zero
|
// Set all PWM values to zero
|
||||||
for (uint8_t i = 0; i < 18; i++) {
|
for (uint8_t i = 0; i < IS31FL3218_PWM_REGISTER_COUNT; i++) {
|
||||||
is31fl3218_write_register(IS31FL3218_REG_PWM + i, 0x00);
|
is31fl3218_write_register(IS31FL3218_REG_PWM + i, 0x00);
|
||||||
}
|
}
|
||||||
|
|
||||||
// turn off all LEDs in the LED control register
|
// turn off all LEDs in the LED control register
|
||||||
for (uint8_t i = 0; i < 3; i++) {
|
for (uint8_t i = 0; i < IS31FL3218_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||||
is31fl3218_write_register(IS31FL3218_REG_CONTROL + i, 0x00);
|
is31fl3218_write_register(IS31FL3218_REG_CONTROL + i, 0x00);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,7 +161,7 @@ void is31fl3218_update_pwm_buffers(void) {
|
||||||
|
|
||||||
void is31fl3218_update_led_control_registers(void) {
|
void is31fl3218_update_led_control_registers(void) {
|
||||||
if (g_led_control_registers_update_required) {
|
if (g_led_control_registers_update_required) {
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < IS31FL3218_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||||
is31fl3218_write_register(IS31FL3218_REG_CONTROL + i, g_led_control_registers[i]);
|
is31fl3218_write_register(IS31FL3218_REG_CONTROL + i, g_led_control_registers[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,9 @@
|
||||||
#define IS31FL3731_COMMANDREGISTER 0xFD
|
#define IS31FL3731_COMMANDREGISTER 0xFD
|
||||||
#define IS31FL3731_BANK_FUNCTIONREG 0x0B // helpfully called 'page nine'
|
#define IS31FL3731_BANK_FUNCTIONREG 0x0B // helpfully called 'page nine'
|
||||||
|
|
||||||
|
#define IS31FL3731_PWM_REGISTER_COUNT 144
|
||||||
|
#define IS31FL3731_LED_CONTROL_REGISTER_COUNT 18
|
||||||
|
|
||||||
#ifndef IS31FL3731_I2C_TIMEOUT
|
#ifndef IS31FL3731_I2C_TIMEOUT
|
||||||
# define IS31FL3731_I2C_TIMEOUT 100
|
# define IS31FL3731_I2C_TIMEOUT 100
|
||||||
#endif
|
#endif
|
||||||
|
@ -58,11 +61,11 @@ uint8_t g_twi_transfer_buffer[20];
|
||||||
// We could optimize this and take out the unused registers from these
|
// We could optimize this and take out the unused registers from these
|
||||||
// buffers and the transfers in is31fl3731_write_pwm_buffer() but it's
|
// buffers and the transfers in is31fl3731_write_pwm_buffer() but it's
|
||||||
// probably not worth the extra complexity.
|
// probably not worth the extra complexity.
|
||||||
uint8_t g_pwm_buffer[IS31FL3731_DRIVER_COUNT][144];
|
uint8_t g_pwm_buffer[IS31FL3731_DRIVER_COUNT][IS31FL3731_PWM_REGISTER_COUNT];
|
||||||
bool g_pwm_buffer_update_required[IS31FL3731_DRIVER_COUNT] = {false};
|
bool g_pwm_buffer_update_required[IS31FL3731_DRIVER_COUNT] = {false};
|
||||||
|
|
||||||
uint8_t g_led_control_registers[IS31FL3731_DRIVER_COUNT][18] = {0};
|
uint8_t g_led_control_registers[IS31FL3731_DRIVER_COUNT][IS31FL3731_LED_CONTROL_REGISTER_COUNT] = {0};
|
||||||
bool g_led_control_registers_update_required[IS31FL3731_DRIVER_COUNT] = {false};
|
bool g_led_control_registers_update_required[IS31FL3731_DRIVER_COUNT] = {false};
|
||||||
|
|
||||||
void is31fl3731_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
void is31fl3731_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
||||||
g_twi_transfer_buffer[0] = reg;
|
g_twi_transfer_buffer[0] = reg;
|
||||||
|
@ -86,7 +89,7 @@ void is31fl3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
|
||||||
// g_twi_transfer_buffer[] is 20 bytes
|
// g_twi_transfer_buffer[] is 20 bytes
|
||||||
|
|
||||||
// iterate over the pwm_buffer contents at 16 byte intervals
|
// iterate over the pwm_buffer contents at 16 byte intervals
|
||||||
for (int i = 0; i < 144; i += 16) {
|
for (int i = 0; i < IS31FL3731_PWM_REGISTER_COUNT; i += 16) {
|
||||||
// set the first register, e.g. 0x24, 0x34, 0x44, etc.
|
// set the first register, e.g. 0x24, 0x34, 0x44, etc.
|
||||||
g_twi_transfer_buffer[0] = 0x24 + i;
|
g_twi_transfer_buffer[0] = 0x24 + i;
|
||||||
// copy the data from i to i+15
|
// copy the data from i to i+15
|
||||||
|
@ -163,7 +166,7 @@ void is31fl3731_init(uint8_t addr) {
|
||||||
is31fl3731_write_register(addr, IS31FL3731_COMMANDREGISTER, 0);
|
is31fl3731_write_register(addr, IS31FL3731_COMMANDREGISTER, 0);
|
||||||
|
|
||||||
// turn off all LEDs in the LED control register
|
// turn off all LEDs in the LED control register
|
||||||
for (int i = 0x00; i <= 0x11; i++) {
|
for (int i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||||
is31fl3731_write_register(addr, i, 0x00);
|
is31fl3731_write_register(addr, i, 0x00);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,7 +238,7 @@ void is31fl3731_update_pwm_buffers(uint8_t addr, uint8_t index) {
|
||||||
|
|
||||||
void is31fl3731_update_led_control_registers(uint8_t addr, uint8_t index) {
|
void is31fl3731_update_led_control_registers(uint8_t addr, uint8_t index) {
|
||||||
if (g_led_control_registers_update_required[index]) {
|
if (g_led_control_registers_update_required[index]) {
|
||||||
for (int i = 0; i < 18; i++) {
|
for (int i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||||
is31fl3731_write_register(addr, i, g_led_control_registers[index][i]);
|
is31fl3731_write_register(addr, i, g_led_control_registers[index][i]);
|
||||||
}
|
}
|
||||||
g_led_control_registers_update_required[index] = false;
|
g_led_control_registers_update_required[index] = false;
|
||||||
|
|
|
@ -41,6 +41,9 @@
|
||||||
#define IS31FL3731_COMMANDREGISTER 0xFD
|
#define IS31FL3731_COMMANDREGISTER 0xFD
|
||||||
#define IS31FL3731_BANK_FUNCTIONREG 0x0B // helpfully called 'page nine'
|
#define IS31FL3731_BANK_FUNCTIONREG 0x0B // helpfully called 'page nine'
|
||||||
|
|
||||||
|
#define IS31FL3731_PWM_REGISTER_COUNT 144
|
||||||
|
#define IS31FL3731_LED_CONTROL_REGISTER_COUNT 18
|
||||||
|
|
||||||
#ifndef IS31FL3731_I2C_TIMEOUT
|
#ifndef IS31FL3731_I2C_TIMEOUT
|
||||||
# define IS31FL3731_I2C_TIMEOUT 100
|
# define IS31FL3731_I2C_TIMEOUT 100
|
||||||
#endif
|
#endif
|
||||||
|
@ -57,11 +60,11 @@ uint8_t g_twi_transfer_buffer[20];
|
||||||
// We could optimize this and take out the unused registers from these
|
// We could optimize this and take out the unused registers from these
|
||||||
// buffers and the transfers in is31fl3731_write_pwm_buffer() but it's
|
// buffers and the transfers in is31fl3731_write_pwm_buffer() but it's
|
||||||
// probably not worth the extra complexity.
|
// probably not worth the extra complexity.
|
||||||
uint8_t g_pwm_buffer[IS31FL3731_DRIVER_COUNT][144];
|
uint8_t g_pwm_buffer[IS31FL3731_DRIVER_COUNT][IS31FL3731_PWM_REGISTER_COUNT];
|
||||||
bool g_pwm_buffer_update_required[IS31FL3731_DRIVER_COUNT] = {false};
|
bool g_pwm_buffer_update_required[IS31FL3731_DRIVER_COUNT] = {false};
|
||||||
|
|
||||||
uint8_t g_led_control_registers[IS31FL3731_DRIVER_COUNT][18] = {0};
|
uint8_t g_led_control_registers[IS31FL3731_DRIVER_COUNT][IS31FL3731_LED_CONTROL_REGISTER_COUNT] = {0};
|
||||||
bool g_led_control_registers_update_required[IS31FL3731_DRIVER_COUNT] = {false};
|
bool g_led_control_registers_update_required[IS31FL3731_DRIVER_COUNT] = {false};
|
||||||
|
|
||||||
void is31fl3731_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
void is31fl3731_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
||||||
g_twi_transfer_buffer[0] = reg;
|
g_twi_transfer_buffer[0] = reg;
|
||||||
|
@ -83,7 +86,7 @@ void is31fl3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
|
||||||
// g_twi_transfer_buffer[] is 20 bytes
|
// g_twi_transfer_buffer[] is 20 bytes
|
||||||
|
|
||||||
// iterate over the pwm_buffer contents at 16 byte intervals
|
// iterate over the pwm_buffer contents at 16 byte intervals
|
||||||
for (int i = 0; i < 144; i += 16) {
|
for (int i = 0; i < IS31FL3731_PWM_REGISTER_COUNT; i += 16) {
|
||||||
// set the first register, e.g. 0x24, 0x34, 0x44, etc.
|
// set the first register, e.g. 0x24, 0x34, 0x44, etc.
|
||||||
g_twi_transfer_buffer[0] = 0x24 + i;
|
g_twi_transfer_buffer[0] = 0x24 + i;
|
||||||
// copy the data from i to i+15
|
// copy the data from i to i+15
|
||||||
|
@ -160,7 +163,7 @@ void is31fl3731_init(uint8_t addr) {
|
||||||
is31fl3731_write_register(addr, IS31FL3731_COMMANDREGISTER, 0);
|
is31fl3731_write_register(addr, IS31FL3731_COMMANDREGISTER, 0);
|
||||||
|
|
||||||
// turn off all LEDs in the LED control register
|
// turn off all LEDs in the LED control register
|
||||||
for (int i = 0x00; i <= 0x11; i++) {
|
for (int i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||||
is31fl3731_write_register(addr, i, 0x00);
|
is31fl3731_write_register(addr, i, 0x00);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,7 +250,7 @@ void is31fl3731_update_pwm_buffers(uint8_t addr, uint8_t index) {
|
||||||
|
|
||||||
void is31fl3731_update_led_control_registers(uint8_t addr, uint8_t index) {
|
void is31fl3731_update_led_control_registers(uint8_t addr, uint8_t index) {
|
||||||
if (g_led_control_registers_update_required[index]) {
|
if (g_led_control_registers_update_required[index]) {
|
||||||
for (int i = 0; i < 18; i++) {
|
for (int i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||||
is31fl3731_write_register(addr, i, g_led_control_registers[index][i]);
|
is31fl3731_write_register(addr, i, g_led_control_registers[index][i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,9 @@
|
||||||
#define IS31FL3733_REG_SWPULLUP 0x0F // PG3
|
#define IS31FL3733_REG_SWPULLUP 0x0F // PG3
|
||||||
#define IS31FL3733_REG_CSPULLUP 0x10 // PG3
|
#define IS31FL3733_REG_CSPULLUP 0x10 // PG3
|
||||||
|
|
||||||
|
#define IS31FL3733_PWM_REGISTER_COUNT 192
|
||||||
|
#define IS31FL3733_LED_CONTROL_REGISTER_COUNT 24
|
||||||
|
|
||||||
#ifndef IS31FL3733_I2C_TIMEOUT
|
#ifndef IS31FL3733_I2C_TIMEOUT
|
||||||
# define IS31FL3733_I2C_TIMEOUT 100
|
# define IS31FL3733_I2C_TIMEOUT 100
|
||||||
#endif
|
#endif
|
||||||
|
@ -85,11 +88,11 @@ uint8_t g_twi_transfer_buffer[20];
|
||||||
// We could optimize this and take out the unused registers from these
|
// We could optimize this and take out the unused registers from these
|
||||||
// buffers and the transfers in is31fl3733_write_pwm_buffer() but it's
|
// buffers and the transfers in is31fl3733_write_pwm_buffer() but it's
|
||||||
// probably not worth the extra complexity.
|
// probably not worth the extra complexity.
|
||||||
uint8_t g_pwm_buffer[IS31FL3733_DRIVER_COUNT][192];
|
uint8_t g_pwm_buffer[IS31FL3733_DRIVER_COUNT][IS31FL3733_PWM_REGISTER_COUNT];
|
||||||
bool g_pwm_buffer_update_required[IS31FL3733_DRIVER_COUNT] = {false};
|
bool g_pwm_buffer_update_required[IS31FL3733_DRIVER_COUNT] = {false};
|
||||||
|
|
||||||
uint8_t g_led_control_registers[IS31FL3733_DRIVER_COUNT][24] = {0};
|
uint8_t g_led_control_registers[IS31FL3733_DRIVER_COUNT][IS31FL3733_LED_CONTROL_REGISTER_COUNT] = {0};
|
||||||
bool g_led_control_registers_update_required[IS31FL3733_DRIVER_COUNT] = {false};
|
bool g_led_control_registers_update_required[IS31FL3733_DRIVER_COUNT] = {false};
|
||||||
|
|
||||||
bool is31fl3733_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
bool is31fl3733_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
||||||
// If the transaction fails function returns false.
|
// If the transaction fails function returns false.
|
||||||
|
@ -117,7 +120,7 @@ bool is31fl3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
|
||||||
// g_twi_transfer_buffer[] is 20 bytes
|
// g_twi_transfer_buffer[] is 20 bytes
|
||||||
|
|
||||||
// Iterate over the pwm_buffer contents at 16 byte intervals.
|
// Iterate over the pwm_buffer contents at 16 byte intervals.
|
||||||
for (int i = 0; i < 192; i += 16) {
|
for (int i = 0; i < IS31FL3733_PWM_REGISTER_COUNT; i += 16) {
|
||||||
g_twi_transfer_buffer[0] = i;
|
g_twi_transfer_buffer[0] = i;
|
||||||
// Copy the data from i to i+15.
|
// Copy the data from i to i+15.
|
||||||
// Device will auto-increment register for data after the first byte
|
// Device will auto-increment register for data after the first byte
|
||||||
|
@ -182,7 +185,7 @@ void is31fl3733_init(uint8_t addr, uint8_t sync) {
|
||||||
// Select PG0
|
// Select PG0
|
||||||
is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_LEDCONTROL);
|
is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_LEDCONTROL);
|
||||||
// Turn off all LEDs.
|
// Turn off all LEDs.
|
||||||
for (int i = 0x00; i <= 0x17; i++) {
|
for (int i = 0; i < IS31FL3733_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||||
is31fl3733_write_register(addr, i, 0x00);
|
is31fl3733_write_register(addr, i, 0x00);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,7 +196,7 @@ void is31fl3733_init(uint8_t addr, uint8_t sync) {
|
||||||
is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_PWM);
|
is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_PWM);
|
||||||
// Set PWM on all LEDs to 0
|
// Set PWM on all LEDs to 0
|
||||||
// No need to setup Breath registers to PWM as that is the default.
|
// No need to setup Breath registers to PWM as that is the default.
|
||||||
for (int i = 0x00; i <= 0xBF; i++) {
|
for (int i = 0; i < IS31FL3733_PWM_REGISTER_COUNT; i++) {
|
||||||
is31fl3733_write_register(addr, i, 0x00);
|
is31fl3733_write_register(addr, i, 0x00);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,7 +273,7 @@ void is31fl3733_update_led_control_registers(uint8_t addr, uint8_t index) {
|
||||||
// Firstly we need to unlock the command register and select PG0
|
// Firstly we need to unlock the command register and select PG0
|
||||||
is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER_WRITELOCK, 0xC5);
|
is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER_WRITELOCK, 0xC5);
|
||||||
is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_LEDCONTROL);
|
is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_LEDCONTROL);
|
||||||
for (int i = 0; i < 24; i++) {
|
for (int i = 0; i < IS31FL3733_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||||
is31fl3733_write_register(addr, i, g_led_control_registers[index][i]);
|
is31fl3733_write_register(addr, i, g_led_control_registers[index][i]);
|
||||||
}
|
}
|
||||||
g_led_control_registers_update_required[index] = false;
|
g_led_control_registers_update_required[index] = false;
|
||||||
|
|
|
@ -38,6 +38,9 @@
|
||||||
#define IS31FL3733_REG_SWPULLUP 0x0F // PG3
|
#define IS31FL3733_REG_SWPULLUP 0x0F // PG3
|
||||||
#define IS31FL3733_REG_CSPULLUP 0x10 // PG3
|
#define IS31FL3733_REG_CSPULLUP 0x10 // PG3
|
||||||
|
|
||||||
|
#define IS31FL3733_PWM_REGISTER_COUNT 192
|
||||||
|
#define IS31FL3733_LED_CONTROL_REGISTER_COUNT 24
|
||||||
|
|
||||||
#ifndef IS31FL3733_I2C_TIMEOUT
|
#ifndef IS31FL3733_I2C_TIMEOUT
|
||||||
# define IS31FL3733_I2C_TIMEOUT 100
|
# define IS31FL3733_I2C_TIMEOUT 100
|
||||||
#endif
|
#endif
|
||||||
|
@ -84,11 +87,11 @@ uint8_t g_twi_transfer_buffer[20];
|
||||||
// We could optimize this and take out the unused registers from these
|
// We could optimize this and take out the unused registers from these
|
||||||
// buffers and the transfers in is31fl3733_write_pwm_buffer() but it's
|
// buffers and the transfers in is31fl3733_write_pwm_buffer() but it's
|
||||||
// probably not worth the extra complexity.
|
// probably not worth the extra complexity.
|
||||||
uint8_t g_pwm_buffer[IS31FL3733_DRIVER_COUNT][192];
|
uint8_t g_pwm_buffer[IS31FL3733_DRIVER_COUNT][IS31FL3733_PWM_REGISTER_COUNT];
|
||||||
bool g_pwm_buffer_update_required[IS31FL3733_DRIVER_COUNT] = {false};
|
bool g_pwm_buffer_update_required[IS31FL3733_DRIVER_COUNT] = {false};
|
||||||
|
|
||||||
uint8_t g_led_control_registers[IS31FL3733_DRIVER_COUNT][24] = {0};
|
uint8_t g_led_control_registers[IS31FL3733_DRIVER_COUNT][IS31FL3733_LED_CONTROL_REGISTER_COUNT] = {0};
|
||||||
bool g_led_control_registers_update_required[IS31FL3733_DRIVER_COUNT] = {false};
|
bool g_led_control_registers_update_required[IS31FL3733_DRIVER_COUNT] = {false};
|
||||||
|
|
||||||
bool is31fl3733_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
bool is31fl3733_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
||||||
// If the transaction fails function returns false.
|
// If the transaction fails function returns false.
|
||||||
|
@ -116,7 +119,7 @@ bool is31fl3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
|
||||||
// g_twi_transfer_buffer[] is 20 bytes
|
// g_twi_transfer_buffer[] is 20 bytes
|
||||||
|
|
||||||
// Iterate over the pwm_buffer contents at 16 byte intervals.
|
// Iterate over the pwm_buffer contents at 16 byte intervals.
|
||||||
for (int i = 0; i < 192; i += 16) {
|
for (int i = 0; i < IS31FL3733_PWM_REGISTER_COUNT; i += 16) {
|
||||||
g_twi_transfer_buffer[0] = i;
|
g_twi_transfer_buffer[0] = i;
|
||||||
// Copy the data from i to i+15.
|
// Copy the data from i to i+15.
|
||||||
// Device will auto-increment register for data after the first byte
|
// Device will auto-increment register for data after the first byte
|
||||||
|
@ -181,7 +184,7 @@ void is31fl3733_init(uint8_t addr, uint8_t sync) {
|
||||||
// Select PG0
|
// Select PG0
|
||||||
is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_LEDCONTROL);
|
is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_LEDCONTROL);
|
||||||
// Turn off all LEDs.
|
// Turn off all LEDs.
|
||||||
for (int i = 0x00; i <= 0x17; i++) {
|
for (int i = 0; i < IS31FL3733_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||||
is31fl3733_write_register(addr, i, 0x00);
|
is31fl3733_write_register(addr, i, 0x00);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,7 +195,7 @@ void is31fl3733_init(uint8_t addr, uint8_t sync) {
|
||||||
is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_PWM);
|
is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_PWM);
|
||||||
// Set PWM on all LEDs to 0
|
// Set PWM on all LEDs to 0
|
||||||
// No need to setup Breath registers to PWM as that is the default.
|
// No need to setup Breath registers to PWM as that is the default.
|
||||||
for (int i = 0x00; i <= 0xBF; i++) {
|
for (int i = 0; i < IS31FL3733_PWM_REGISTER_COUNT; i++) {
|
||||||
is31fl3733_write_register(addr, i, 0x00);
|
is31fl3733_write_register(addr, i, 0x00);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,7 +288,7 @@ void is31fl3733_update_led_control_registers(uint8_t addr, uint8_t index) {
|
||||||
// Firstly we need to unlock the command register and select PG0
|
// Firstly we need to unlock the command register and select PG0
|
||||||
is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER_WRITELOCK, 0xC5);
|
is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER_WRITELOCK, 0xC5);
|
||||||
is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_LEDCONTROL);
|
is31fl3733_write_register(addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_LEDCONTROL);
|
||||||
for (int i = 0; i < 24; i++) {
|
for (int i = 0; i < IS31FL3733_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||||
is31fl3733_write_register(addr, i, g_led_control_registers[index][i]);
|
is31fl3733_write_register(addr, i, g_led_control_registers[index][i]);
|
||||||
}
|
}
|
||||||
g_led_control_registers_update_required[index] = false;
|
g_led_control_registers_update_required[index] = false;
|
||||||
|
|
|
@ -36,6 +36,9 @@
|
||||||
#define IS31FL3736_REG_SWPULLUP 0x0F // PG3
|
#define IS31FL3736_REG_SWPULLUP 0x0F // PG3
|
||||||
#define IS31FL3736_REG_CSPULLUP 0x10 // PG3
|
#define IS31FL3736_REG_CSPULLUP 0x10 // PG3
|
||||||
|
|
||||||
|
#define IS31FL3736_PWM_REGISTER_COUNT 192 // actually 96
|
||||||
|
#define IS31FL3736_LED_CONTROL_REGISTER_COUNT 24
|
||||||
|
|
||||||
#ifndef IS31FL3736_I2C_TIMEOUT
|
#ifndef IS31FL3736_I2C_TIMEOUT
|
||||||
# define IS31FL3736_I2C_TIMEOUT 100
|
# define IS31FL3736_I2C_TIMEOUT 100
|
||||||
#endif
|
#endif
|
||||||
|
@ -69,11 +72,11 @@ uint8_t g_twi_transfer_buffer[20];
|
||||||
// We could optimize this and take out the unused registers from these
|
// We could optimize this and take out the unused registers from these
|
||||||
// buffers and the transfers in is31fl3736_write_pwm_buffer() but it's
|
// buffers and the transfers in is31fl3736_write_pwm_buffer() but it's
|
||||||
// probably not worth the extra complexity.
|
// probably not worth the extra complexity.
|
||||||
uint8_t g_pwm_buffer[IS31FL3736_DRIVER_COUNT][192];
|
uint8_t g_pwm_buffer[IS31FL3736_DRIVER_COUNT][IS31FL3736_PWM_REGISTER_COUNT];
|
||||||
bool g_pwm_buffer_update_required[IS31FL3736_DRIVER_COUNT] = {false};
|
bool g_pwm_buffer_update_required[IS31FL3736_DRIVER_COUNT] = {false};
|
||||||
|
|
||||||
uint8_t g_led_control_registers[IS31FL3736_DRIVER_COUNT][24] = {0};
|
uint8_t g_led_control_registers[IS31FL3736_DRIVER_COUNT][IS31FL3736_LED_CONTROL_REGISTER_COUNT] = {0};
|
||||||
bool g_led_control_registers_update_required[IS31FL3736_DRIVER_COUNT] = {false};
|
bool g_led_control_registers_update_required[IS31FL3736_DRIVER_COUNT] = {false};
|
||||||
|
|
||||||
void is31fl3736_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
void is31fl3736_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
||||||
g_twi_transfer_buffer[0] = reg;
|
g_twi_transfer_buffer[0] = reg;
|
||||||
|
@ -95,7 +98,7 @@ void is31fl3736_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
|
||||||
// g_twi_transfer_buffer[] is 20 bytes
|
// g_twi_transfer_buffer[] is 20 bytes
|
||||||
|
|
||||||
// iterate over the pwm_buffer contents at 16 byte intervals
|
// iterate over the pwm_buffer contents at 16 byte intervals
|
||||||
for (int i = 0; i < 192; i += 16) {
|
for (int i = 0; i < IS31FL3736_PWM_REGISTER_COUNT; i += 16) {
|
||||||
g_twi_transfer_buffer[0] = i;
|
g_twi_transfer_buffer[0] = i;
|
||||||
// copy the data from i to i+15
|
// copy the data from i to i+15
|
||||||
// device will auto-increment register for data after the first byte
|
// device will auto-increment register for data after the first byte
|
||||||
|
@ -154,7 +157,7 @@ void is31fl3736_init(uint8_t addr) {
|
||||||
// Select PG0
|
// Select PG0
|
||||||
is31fl3736_write_register(addr, IS31FL3736_COMMANDREGISTER, IS31FL3736_PAGE_LEDCONTROL);
|
is31fl3736_write_register(addr, IS31FL3736_COMMANDREGISTER, IS31FL3736_PAGE_LEDCONTROL);
|
||||||
// Turn off all LEDs.
|
// Turn off all LEDs.
|
||||||
for (int i = 0x00; i <= 0x17; i++) {
|
for (int i = 0; i < IS31FL3736_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||||
is31fl3736_write_register(addr, i, 0x00);
|
is31fl3736_write_register(addr, i, 0x00);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +168,7 @@ void is31fl3736_init(uint8_t addr) {
|
||||||
is31fl3736_write_register(addr, IS31FL3736_COMMANDREGISTER, IS31FL3736_PAGE_PWM);
|
is31fl3736_write_register(addr, IS31FL3736_COMMANDREGISTER, IS31FL3736_PAGE_PWM);
|
||||||
// Set PWM on all LEDs to 0
|
// Set PWM on all LEDs to 0
|
||||||
// No need to setup Breath registers to PWM as that is the default.
|
// No need to setup Breath registers to PWM as that is the default.
|
||||||
for (int i = 0x00; i <= 0xBF; i++) {
|
for (int i = 0; i < IS31FL3736_PWM_REGISTER_COUNT; i++) {
|
||||||
is31fl3736_write_register(addr, i, 0x00);
|
is31fl3736_write_register(addr, i, 0x00);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,7 +247,7 @@ void is31fl3736_update_led_control_registers(uint8_t addr, uint8_t index) {
|
||||||
// Firstly we need to unlock the command register and select PG0
|
// Firstly we need to unlock the command register and select PG0
|
||||||
is31fl3736_write_register(addr, IS31FL3736_COMMANDREGISTER_WRITELOCK, 0xC5);
|
is31fl3736_write_register(addr, IS31FL3736_COMMANDREGISTER_WRITELOCK, 0xC5);
|
||||||
is31fl3736_write_register(addr, IS31FL3736_COMMANDREGISTER, IS31FL3736_PAGE_LEDCONTROL);
|
is31fl3736_write_register(addr, IS31FL3736_COMMANDREGISTER, IS31FL3736_PAGE_LEDCONTROL);
|
||||||
for (int i = 0; i < 24; i++) {
|
for (int i = 0; i < IS31FL3736_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||||
is31fl3736_write_register(addr, i, g_led_control_registers[index][i]);
|
is31fl3736_write_register(addr, i, g_led_control_registers[index][i]);
|
||||||
}
|
}
|
||||||
g_led_control_registers_update_required[index] = false;
|
g_led_control_registers_update_required[index] = false;
|
||||||
|
|
|
@ -36,6 +36,9 @@
|
||||||
#define IS31FL3736_REG_SWPULLUP 0x0F // PG3
|
#define IS31FL3736_REG_SWPULLUP 0x0F // PG3
|
||||||
#define IS31FL3736_REG_CSPULLUP 0x10 // PG3
|
#define IS31FL3736_REG_CSPULLUP 0x10 // PG3
|
||||||
|
|
||||||
|
#define IS31FL3736_PWM_REGISTER_COUNT 192 // actually 96
|
||||||
|
#define IS31FL3736_LED_CONTROL_REGISTER_COUNT 24
|
||||||
|
|
||||||
#ifndef IS31FL3736_I2C_TIMEOUT
|
#ifndef IS31FL3736_I2C_TIMEOUT
|
||||||
# define IS31FL3736_I2C_TIMEOUT 100
|
# define IS31FL3736_I2C_TIMEOUT 100
|
||||||
#endif
|
#endif
|
||||||
|
@ -69,11 +72,11 @@ uint8_t g_twi_transfer_buffer[20];
|
||||||
// We could optimize this and take out the unused registers from these
|
// We could optimize this and take out the unused registers from these
|
||||||
// buffers and the transfers in is31fl3736_write_pwm_buffer() but it's
|
// buffers and the transfers in is31fl3736_write_pwm_buffer() but it's
|
||||||
// probably not worth the extra complexity.
|
// probably not worth the extra complexity.
|
||||||
uint8_t g_pwm_buffer[IS31FL3736_DRIVER_COUNT][192];
|
uint8_t g_pwm_buffer[IS31FL3736_DRIVER_COUNT][IS31FL3736_PWM_REGISTER_COUNT];
|
||||||
bool g_pwm_buffer_update_required[IS31FL3736_DRIVER_COUNT] = {false};
|
bool g_pwm_buffer_update_required[IS31FL3736_DRIVER_COUNT] = {false};
|
||||||
|
|
||||||
uint8_t g_led_control_registers[IS31FL3736_DRIVER_COUNT][24] = {0};
|
uint8_t g_led_control_registers[IS31FL3736_DRIVER_COUNT][IS31FL3736_LED_CONTROL_REGISTER_COUNT] = {0};
|
||||||
bool g_led_control_registers_update_required[IS31FL3736_DRIVER_COUNT] = {false};
|
bool g_led_control_registers_update_required[IS31FL3736_DRIVER_COUNT] = {false};
|
||||||
|
|
||||||
void is31fl3736_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
void is31fl3736_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
||||||
g_twi_transfer_buffer[0] = reg;
|
g_twi_transfer_buffer[0] = reg;
|
||||||
|
@ -95,7 +98,7 @@ void is31fl3736_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
|
||||||
// g_twi_transfer_buffer[] is 20 bytes
|
// g_twi_transfer_buffer[] is 20 bytes
|
||||||
|
|
||||||
// iterate over the pwm_buffer contents at 16 byte intervals
|
// iterate over the pwm_buffer contents at 16 byte intervals
|
||||||
for (int i = 0; i < 192; i += 16) {
|
for (int i = 0; i < IS31FL3736_PWM_REGISTER_COUNT; i += 16) {
|
||||||
g_twi_transfer_buffer[0] = i;
|
g_twi_transfer_buffer[0] = i;
|
||||||
// copy the data from i to i+15
|
// copy the data from i to i+15
|
||||||
// device will auto-increment register for data after the first byte
|
// device will auto-increment register for data after the first byte
|
||||||
|
@ -154,7 +157,7 @@ void is31fl3736_init(uint8_t addr) {
|
||||||
// Select PG0
|
// Select PG0
|
||||||
is31fl3736_write_register(addr, IS31FL3736_COMMANDREGISTER, IS31FL3736_PAGE_LEDCONTROL);
|
is31fl3736_write_register(addr, IS31FL3736_COMMANDREGISTER, IS31FL3736_PAGE_LEDCONTROL);
|
||||||
// Turn off all LEDs.
|
// Turn off all LEDs.
|
||||||
for (int i = 0x00; i <= 0x17; i++) {
|
for (int i = 0; i < IS31FL3736_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||||
is31fl3736_write_register(addr, i, 0x00);
|
is31fl3736_write_register(addr, i, 0x00);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +168,7 @@ void is31fl3736_init(uint8_t addr) {
|
||||||
is31fl3736_write_register(addr, IS31FL3736_COMMANDREGISTER, IS31FL3736_PAGE_PWM);
|
is31fl3736_write_register(addr, IS31FL3736_COMMANDREGISTER, IS31FL3736_PAGE_PWM);
|
||||||
// Set PWM on all LEDs to 0
|
// Set PWM on all LEDs to 0
|
||||||
// No need to setup Breath registers to PWM as that is the default.
|
// No need to setup Breath registers to PWM as that is the default.
|
||||||
for (int i = 0x00; i <= 0xBF; i++) {
|
for (int i = 0; i < IS31FL3736_PWM_REGISTER_COUNT; i++) {
|
||||||
is31fl3736_write_register(addr, i, 0x00);
|
is31fl3736_write_register(addr, i, 0x00);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,7 +264,7 @@ void is31fl3736_update_led_control_registers(uint8_t addr, uint8_t index) {
|
||||||
// Firstly we need to unlock the command register and select PG0
|
// Firstly we need to unlock the command register and select PG0
|
||||||
is31fl3736_write_register(addr, IS31FL3736_COMMANDREGISTER_WRITELOCK, 0xC5);
|
is31fl3736_write_register(addr, IS31FL3736_COMMANDREGISTER_WRITELOCK, 0xC5);
|
||||||
is31fl3736_write_register(addr, IS31FL3736_COMMANDREGISTER, IS31FL3736_PAGE_LEDCONTROL);
|
is31fl3736_write_register(addr, IS31FL3736_COMMANDREGISTER, IS31FL3736_PAGE_LEDCONTROL);
|
||||||
for (int i = 0; i < 24; i++) {
|
for (int i = 0; i < IS31FL3736_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||||
is31fl3736_write_register(addr, i, g_led_control_registers[index][i]);
|
is31fl3736_write_register(addr, i, g_led_control_registers[index][i]);
|
||||||
}
|
}
|
||||||
g_led_control_registers_update_required[index] = false;
|
g_led_control_registers_update_required[index] = false;
|
||||||
|
|
|
@ -38,6 +38,9 @@
|
||||||
#define IS31FL3737_REG_SWPULLUP 0x0F // PG3
|
#define IS31FL3737_REG_SWPULLUP 0x0F // PG3
|
||||||
#define IS31FL3737_REG_CSPULLUP 0x10 // PG3
|
#define IS31FL3737_REG_CSPULLUP 0x10 // PG3
|
||||||
|
|
||||||
|
#define IS31FL3737_PWM_REGISTER_COUNT 192 // actually 144
|
||||||
|
#define IS31FL3737_LED_CONTROL_REGISTER_COUNT 24
|
||||||
|
|
||||||
#ifndef IS31FL3737_I2C_TIMEOUT
|
#ifndef IS31FL3737_I2C_TIMEOUT
|
||||||
# define IS31FL3737_I2C_TIMEOUT 100
|
# define IS31FL3737_I2C_TIMEOUT 100
|
||||||
#endif
|
#endif
|
||||||
|
@ -72,11 +75,11 @@ uint8_t g_twi_transfer_buffer[20];
|
||||||
// buffers and the transfers in is31fl3737_write_pwm_buffer() but it's
|
// buffers and the transfers in is31fl3737_write_pwm_buffer() but it's
|
||||||
// probably not worth the extra complexity.
|
// probably not worth the extra complexity.
|
||||||
|
|
||||||
uint8_t g_pwm_buffer[IS31FL3737_DRIVER_COUNT][192];
|
uint8_t g_pwm_buffer[IS31FL3737_DRIVER_COUNT][IS31FL3737_PWM_REGISTER_COUNT];
|
||||||
bool g_pwm_buffer_update_required[IS31FL3737_DRIVER_COUNT] = {false};
|
bool g_pwm_buffer_update_required[IS31FL3737_DRIVER_COUNT] = {false};
|
||||||
|
|
||||||
uint8_t g_led_control_registers[IS31FL3737_DRIVER_COUNT][24] = {0};
|
uint8_t g_led_control_registers[IS31FL3737_DRIVER_COUNT][IS31FL3737_LED_CONTROL_REGISTER_COUNT] = {0};
|
||||||
bool g_led_control_registers_update_required[IS31FL3737_DRIVER_COUNT] = {false};
|
bool g_led_control_registers_update_required[IS31FL3737_DRIVER_COUNT] = {false};
|
||||||
|
|
||||||
void is31fl3737_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
void is31fl3737_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
||||||
g_twi_transfer_buffer[0] = reg;
|
g_twi_transfer_buffer[0] = reg;
|
||||||
|
@ -98,7 +101,7 @@ void is31fl3737_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
|
||||||
// g_twi_transfer_buffer[] is 20 bytes
|
// g_twi_transfer_buffer[] is 20 bytes
|
||||||
|
|
||||||
// iterate over the pwm_buffer contents at 16 byte intervals
|
// iterate over the pwm_buffer contents at 16 byte intervals
|
||||||
for (int i = 0; i < 192; i += 16) {
|
for (int i = 0; i < IS31FL3737_PWM_REGISTER_COUNT; i += 16) {
|
||||||
g_twi_transfer_buffer[0] = i;
|
g_twi_transfer_buffer[0] = i;
|
||||||
// copy the data from i to i+15
|
// copy the data from i to i+15
|
||||||
// device will auto-increment register for data after the first byte
|
// device will auto-increment register for data after the first byte
|
||||||
|
@ -157,7 +160,7 @@ void is31fl3737_init(uint8_t addr) {
|
||||||
// Select PG0
|
// Select PG0
|
||||||
is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER, IS31FL3737_PAGE_LEDCONTROL);
|
is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER, IS31FL3737_PAGE_LEDCONTROL);
|
||||||
// Turn off all LEDs.
|
// Turn off all LEDs.
|
||||||
for (int i = 0x00; i <= 0x17; i++) {
|
for (int i = 0; i < IS31FL3737_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||||
is31fl3737_write_register(addr, i, 0x00);
|
is31fl3737_write_register(addr, i, 0x00);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,7 +171,7 @@ void is31fl3737_init(uint8_t addr) {
|
||||||
is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER, IS31FL3737_PAGE_PWM);
|
is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER, IS31FL3737_PAGE_PWM);
|
||||||
// Set PWM on all LEDs to 0
|
// Set PWM on all LEDs to 0
|
||||||
// No need to setup Breath registers to PWM as that is the default.
|
// No need to setup Breath registers to PWM as that is the default.
|
||||||
for (int i = 0x00; i <= 0xBF; i++) {
|
for (int i = 0; i < IS31FL3737_PWM_REGISTER_COUNT; i++) {
|
||||||
is31fl3737_write_register(addr, i, 0x00);
|
is31fl3737_write_register(addr, i, 0x00);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,7 +244,7 @@ void is31fl3737_update_led_control_registers(uint8_t addr, uint8_t index) {
|
||||||
// Firstly we need to unlock the command register and select PG0
|
// Firstly we need to unlock the command register and select PG0
|
||||||
is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER_WRITELOCK, 0xC5);
|
is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER_WRITELOCK, 0xC5);
|
||||||
is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER, IS31FL3737_PAGE_LEDCONTROL);
|
is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER, IS31FL3737_PAGE_LEDCONTROL);
|
||||||
for (int i = 0; i < 24; i++) {
|
for (int i = 0; i < IS31FL3737_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||||
is31fl3737_write_register(addr, i, g_led_control_registers[index][i]);
|
is31fl3737_write_register(addr, i, g_led_control_registers[index][i]);
|
||||||
}
|
}
|
||||||
g_led_control_registers_update_required[index] = false;
|
g_led_control_registers_update_required[index] = false;
|
||||||
|
|
|
@ -38,6 +38,9 @@
|
||||||
#define IS31FL3737_REG_SWPULLUP 0x0F // PG3
|
#define IS31FL3737_REG_SWPULLUP 0x0F // PG3
|
||||||
#define IS31FL3737_REG_CSPULLUP 0x10 // PG3
|
#define IS31FL3737_REG_CSPULLUP 0x10 // PG3
|
||||||
|
|
||||||
|
#define IS31FL3737_PWM_REGISTER_COUNT 192 // actually 144
|
||||||
|
#define IS31FL3737_LED_CONTROL_REGISTER_COUNT 24
|
||||||
|
|
||||||
#ifndef IS31FL3737_I2C_TIMEOUT
|
#ifndef IS31FL3737_I2C_TIMEOUT
|
||||||
# define IS31FL3737_I2C_TIMEOUT 100
|
# define IS31FL3737_I2C_TIMEOUT 100
|
||||||
#endif
|
#endif
|
||||||
|
@ -72,11 +75,11 @@ uint8_t g_twi_transfer_buffer[20];
|
||||||
// buffers and the transfers in is31fl3737_write_pwm_buffer() but it's
|
// buffers and the transfers in is31fl3737_write_pwm_buffer() but it's
|
||||||
// probably not worth the extra complexity.
|
// probably not worth the extra complexity.
|
||||||
|
|
||||||
uint8_t g_pwm_buffer[IS31FL3737_DRIVER_COUNT][192];
|
uint8_t g_pwm_buffer[IS31FL3737_DRIVER_COUNT][IS31FL3737_PWM_REGISTER_COUNT];
|
||||||
bool g_pwm_buffer_update_required[IS31FL3737_DRIVER_COUNT] = {false};
|
bool g_pwm_buffer_update_required[IS31FL3737_DRIVER_COUNT] = {false};
|
||||||
|
|
||||||
uint8_t g_led_control_registers[IS31FL3737_DRIVER_COUNT][24] = {0};
|
uint8_t g_led_control_registers[IS31FL3737_DRIVER_COUNT][IS31FL3737_LED_CONTROL_REGISTER_COUNT] = {0};
|
||||||
bool g_led_control_registers_update_required[IS31FL3737_DRIVER_COUNT] = {false};
|
bool g_led_control_registers_update_required[IS31FL3737_DRIVER_COUNT] = {false};
|
||||||
|
|
||||||
void is31fl3737_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
void is31fl3737_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
||||||
g_twi_transfer_buffer[0] = reg;
|
g_twi_transfer_buffer[0] = reg;
|
||||||
|
@ -98,7 +101,7 @@ void is31fl3737_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
|
||||||
// g_twi_transfer_buffer[] is 20 bytes
|
// g_twi_transfer_buffer[] is 20 bytes
|
||||||
|
|
||||||
// iterate over the pwm_buffer contents at 16 byte intervals
|
// iterate over the pwm_buffer contents at 16 byte intervals
|
||||||
for (int i = 0; i < 192; i += 16) {
|
for (int i = 0; i < IS31FL3737_PWM_REGISTER_COUNT; i += 16) {
|
||||||
g_twi_transfer_buffer[0] = i;
|
g_twi_transfer_buffer[0] = i;
|
||||||
// copy the data from i to i+15
|
// copy the data from i to i+15
|
||||||
// device will auto-increment register for data after the first byte
|
// device will auto-increment register for data after the first byte
|
||||||
|
@ -157,7 +160,7 @@ void is31fl3737_init(uint8_t addr) {
|
||||||
// Select PG0
|
// Select PG0
|
||||||
is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER, IS31FL3737_PAGE_LEDCONTROL);
|
is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER, IS31FL3737_PAGE_LEDCONTROL);
|
||||||
// Turn off all LEDs.
|
// Turn off all LEDs.
|
||||||
for (int i = 0x00; i <= 0x17; i++) {
|
for (int i = 0; i < IS31FL3737_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||||
is31fl3737_write_register(addr, i, 0x00);
|
is31fl3737_write_register(addr, i, 0x00);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,7 +171,7 @@ void is31fl3737_init(uint8_t addr) {
|
||||||
is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER, IS31FL3737_PAGE_PWM);
|
is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER, IS31FL3737_PAGE_PWM);
|
||||||
// Set PWM on all LEDs to 0
|
// Set PWM on all LEDs to 0
|
||||||
// No need to setup Breath registers to PWM as that is the default.
|
// No need to setup Breath registers to PWM as that is the default.
|
||||||
for (int i = 0x00; i <= 0xBF; i++) {
|
for (int i = 0; i < IS31FL3737_PWM_REGISTER_COUNT; i++) {
|
||||||
is31fl3737_write_register(addr, i, 0x00);
|
is31fl3737_write_register(addr, i, 0x00);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,7 +260,7 @@ void is31fl3737_update_led_control_registers(uint8_t addr, uint8_t index) {
|
||||||
// Firstly we need to unlock the command register and select PG0
|
// Firstly we need to unlock the command register and select PG0
|
||||||
is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER_WRITELOCK, 0xC5);
|
is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER_WRITELOCK, 0xC5);
|
||||||
is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER, IS31FL3737_PAGE_LEDCONTROL);
|
is31fl3737_write_register(addr, IS31FL3737_COMMANDREGISTER, IS31FL3737_PAGE_LEDCONTROL);
|
||||||
for (int i = 0; i < 24; i++) {
|
for (int i = 0; i < IS31FL3737_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||||
is31fl3737_write_register(addr, i, g_led_control_registers[index][i]);
|
is31fl3737_write_register(addr, i, g_led_control_registers[index][i]);
|
||||||
}
|
}
|
||||||
g_led_control_registers_update_required[index] = false;
|
g_led_control_registers_update_required[index] = false;
|
||||||
|
|
|
@ -40,6 +40,8 @@
|
||||||
#define IS31FL3741_REG_PWM_FREQUENCY 0x36 // PG4
|
#define IS31FL3741_REG_PWM_FREQUENCY 0x36 // PG4
|
||||||
#define IS31FL3741_REG_RESET 0x3F // PG4
|
#define IS31FL3741_REG_RESET 0x3F // PG4
|
||||||
|
|
||||||
|
#define IS31FL3741_PWM_REGISTER_COUNT 351
|
||||||
|
|
||||||
#ifndef IS31FL3741_I2C_TIMEOUT
|
#ifndef IS31FL3741_I2C_TIMEOUT
|
||||||
# define IS31FL3741_I2C_TIMEOUT 100
|
# define IS31FL3741_I2C_TIMEOUT 100
|
||||||
#endif
|
#endif
|
||||||
|
@ -68,8 +70,6 @@
|
||||||
# define IS31FL3741_GLOBALCURRENT 0xFF
|
# define IS31FL3741_GLOBALCURRENT 0xFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define IS31FL3741_MAX_LEDS 351
|
|
||||||
|
|
||||||
// Transfer buffer for TWITransmitData()
|
// Transfer buffer for TWITransmitData()
|
||||||
uint8_t g_twi_transfer_buffer[20] = {0xFF};
|
uint8_t g_twi_transfer_buffer[20] = {0xFF};
|
||||||
|
|
||||||
|
@ -79,11 +79,11 @@ uint8_t g_twi_transfer_buffer[20] = {0xFF};
|
||||||
// We could optimize this and take out the unused registers from these
|
// We could optimize this and take out the unused registers from these
|
||||||
// buffers and the transfers in is31fl3741_write_pwm_buffer() but it's
|
// buffers and the transfers in is31fl3741_write_pwm_buffer() but it's
|
||||||
// probably not worth the extra complexity.
|
// probably not worth the extra complexity.
|
||||||
uint8_t g_pwm_buffer[IS31FL3741_DRIVER_COUNT][IS31FL3741_MAX_LEDS];
|
uint8_t g_pwm_buffer[IS31FL3741_DRIVER_COUNT][IS31FL3741_PWM_REGISTER_COUNT];
|
||||||
bool g_pwm_buffer_update_required[IS31FL3741_DRIVER_COUNT] = {false};
|
bool g_pwm_buffer_update_required[IS31FL3741_DRIVER_COUNT] = {false};
|
||||||
bool g_scaling_registers_update_required[IS31FL3741_DRIVER_COUNT] = {false};
|
bool g_scaling_registers_update_required[IS31FL3741_DRIVER_COUNT] = {false};
|
||||||
|
|
||||||
uint8_t g_scaling_registers[IS31FL3741_DRIVER_COUNT][IS31FL3741_MAX_LEDS];
|
uint8_t g_scaling_registers[IS31FL3741_DRIVER_COUNT][IS31FL3741_PWM_REGISTER_COUNT];
|
||||||
|
|
||||||
void is31fl3741_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
void is31fl3741_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
||||||
g_twi_transfer_buffer[0] = reg;
|
g_twi_transfer_buffer[0] = reg;
|
||||||
|
|
|
@ -40,6 +40,8 @@
|
||||||
#define IS31FL3741_REG_PWM_FREQUENCY 0x36 // PG4
|
#define IS31FL3741_REG_PWM_FREQUENCY 0x36 // PG4
|
||||||
#define IS31FL3741_REG_RESET 0x3F // PG4
|
#define IS31FL3741_REG_RESET 0x3F // PG4
|
||||||
|
|
||||||
|
#define IS31FL3741_PWM_REGISTER_COUNT 351
|
||||||
|
|
||||||
#ifndef IS31FL3741_I2C_TIMEOUT
|
#ifndef IS31FL3741_I2C_TIMEOUT
|
||||||
# define IS31FL3741_I2C_TIMEOUT 100
|
# define IS31FL3741_I2C_TIMEOUT 100
|
||||||
#endif
|
#endif
|
||||||
|
@ -68,8 +70,6 @@
|
||||||
# define IS31FL3741_GLOBALCURRENT 0xFF
|
# define IS31FL3741_GLOBALCURRENT 0xFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define IS31FL3741_MAX_LEDS 351
|
|
||||||
|
|
||||||
// Transfer buffer for TWITransmitData()
|
// Transfer buffer for TWITransmitData()
|
||||||
uint8_t g_twi_transfer_buffer[20] = {0xFF};
|
uint8_t g_twi_transfer_buffer[20] = {0xFF};
|
||||||
|
|
||||||
|
@ -79,11 +79,11 @@ uint8_t g_twi_transfer_buffer[20] = {0xFF};
|
||||||
// We could optimize this and take out the unused registers from these
|
// We could optimize this and take out the unused registers from these
|
||||||
// buffers and the transfers in is31fl3741_write_pwm_buffer() but it's
|
// buffers and the transfers in is31fl3741_write_pwm_buffer() but it's
|
||||||
// probably not worth the extra complexity.
|
// probably not worth the extra complexity.
|
||||||
uint8_t g_pwm_buffer[IS31FL3741_DRIVER_COUNT][IS31FL3741_MAX_LEDS];
|
uint8_t g_pwm_buffer[IS31FL3741_DRIVER_COUNT][IS31FL3741_PWM_REGISTER_COUNT];
|
||||||
bool g_pwm_buffer_update_required[IS31FL3741_DRIVER_COUNT] = {false};
|
bool g_pwm_buffer_update_required[IS31FL3741_DRIVER_COUNT] = {false};
|
||||||
bool g_scaling_registers_update_required[IS31FL3741_DRIVER_COUNT] = {false};
|
bool g_scaling_registers_update_required[IS31FL3741_DRIVER_COUNT] = {false};
|
||||||
|
|
||||||
uint8_t g_scaling_registers[IS31FL3741_DRIVER_COUNT][IS31FL3741_MAX_LEDS];
|
uint8_t g_scaling_registers[IS31FL3741_DRIVER_COUNT][IS31FL3741_PWM_REGISTER_COUNT];
|
||||||
|
|
||||||
void is31fl3741_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
void is31fl3741_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
||||||
g_twi_transfer_buffer[0] = reg;
|
g_twi_transfer_buffer[0] = reg;
|
||||||
|
|
|
@ -17,6 +17,9 @@
|
||||||
#include "snled27351-simple.h"
|
#include "snled27351-simple.h"
|
||||||
#include "i2c_master.h"
|
#include "i2c_master.h"
|
||||||
|
|
||||||
|
#define SNLED27351_PWM_REGISTER_COUNT 192
|
||||||
|
#define SNLED27351_LED_CONTROL_REGISTER_COUNT 24
|
||||||
|
|
||||||
#ifndef SNLED27351_I2C_TIMEOUT
|
#ifndef SNLED27351_I2C_TIMEOUT
|
||||||
# define SNLED27351_I2C_TIMEOUT 100
|
# define SNLED27351_I2C_TIMEOUT 100
|
||||||
#endif
|
#endif
|
||||||
|
@ -43,11 +46,11 @@ uint8_t g_twi_transfer_buffer[20];
|
||||||
// We could optimize this and take out the unused registers from these
|
// We could optimize this and take out the unused registers from these
|
||||||
// buffers and the transfers in snled27351_write_pwm_buffer() but it's
|
// buffers and the transfers in snled27351_write_pwm_buffer() but it's
|
||||||
// probably not worth the extra complexity.
|
// probably not worth the extra complexity.
|
||||||
uint8_t g_pwm_buffer[SNLED27351_DRIVER_COUNT][192];
|
uint8_t g_pwm_buffer[SNLED27351_DRIVER_COUNT][SNLED27351_PWM_REGISTER_COUNT];
|
||||||
bool g_pwm_buffer_update_required[SNLED27351_DRIVER_COUNT] = {false};
|
bool g_pwm_buffer_update_required[SNLED27351_DRIVER_COUNT] = {false};
|
||||||
|
|
||||||
uint8_t g_led_control_registers[SNLED27351_DRIVER_COUNT][24] = {0};
|
uint8_t g_led_control_registers[SNLED27351_DRIVER_COUNT][SNLED27351_LED_CONTROL_REGISTER_COUNT] = {0};
|
||||||
bool g_led_control_registers_update_required[SNLED27351_DRIVER_COUNT] = {false};
|
bool g_led_control_registers_update_required[SNLED27351_DRIVER_COUNT] = {false};
|
||||||
|
|
||||||
bool snled27351_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
bool snled27351_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
||||||
// If the transaction fails function returns false.
|
// If the transaction fails function returns false.
|
||||||
|
@ -75,7 +78,7 @@ bool snled27351_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
|
||||||
// g_twi_transfer_buffer[] is 20 bytes
|
// g_twi_transfer_buffer[] is 20 bytes
|
||||||
|
|
||||||
// Iterate over the pwm_buffer contents at 16 byte intervals.
|
// Iterate over the pwm_buffer contents at 16 byte intervals.
|
||||||
for (int i = 0; i < 192; i += 16) {
|
for (int i = 0; i < SNLED27351_PWM_REGISTER_COUNT; i += 16) {
|
||||||
g_twi_transfer_buffer[0] = i;
|
g_twi_transfer_buffer[0] = i;
|
||||||
// Copy the data from i to i+15.
|
// Copy the data from i to i+15.
|
||||||
// Device will auto-increment register for data after the first byte
|
// Device will auto-increment register for data after the first byte
|
||||||
|
@ -224,7 +227,7 @@ void snled27351_update_pwm_buffers(uint8_t addr, uint8_t index) {
|
||||||
void snled27351_update_led_control_registers(uint8_t addr, uint8_t index) {
|
void snled27351_update_led_control_registers(uint8_t addr, uint8_t index) {
|
||||||
if (g_led_control_registers_update_required[index]) {
|
if (g_led_control_registers_update_required[index]) {
|
||||||
snled27351_write_register(addr, SNLED27351_REG_CONFIGURE_CMD_PAGE, SNLED27351_LED_CONTROL_PAGE);
|
snled27351_write_register(addr, SNLED27351_REG_CONFIGURE_CMD_PAGE, SNLED27351_LED_CONTROL_PAGE);
|
||||||
for (int i = 0; i < 24; i++) {
|
for (int i = 0; i < SNLED27351_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||||
snled27351_write_register(addr, i, g_led_control_registers[index][i]);
|
snled27351_write_register(addr, i, g_led_control_registers[index][i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,9 @@
|
||||||
#include "snled27351.h"
|
#include "snled27351.h"
|
||||||
#include "i2c_master.h"
|
#include "i2c_master.h"
|
||||||
|
|
||||||
|
#define SNLED27351_PWM_REGISTER_COUNT 192
|
||||||
|
#define SNLED27351_LED_CONTROL_REGISTER_COUNT 24
|
||||||
|
|
||||||
#ifndef SNLED27351_I2C_TIMEOUT
|
#ifndef SNLED27351_I2C_TIMEOUT
|
||||||
# define SNLED27351_I2C_TIMEOUT 100
|
# define SNLED27351_I2C_TIMEOUT 100
|
||||||
#endif
|
#endif
|
||||||
|
@ -43,11 +46,11 @@ uint8_t g_twi_transfer_buffer[65];
|
||||||
// We could optimize this and take out the unused registers from these
|
// We could optimize this and take out the unused registers from these
|
||||||
// buffers and the transfers in snled27351_write_pwm_buffer() but it's
|
// buffers and the transfers in snled27351_write_pwm_buffer() but it's
|
||||||
// probably not worth the extra complexity.
|
// probably not worth the extra complexity.
|
||||||
uint8_t g_pwm_buffer[SNLED27351_DRIVER_COUNT][192];
|
uint8_t g_pwm_buffer[SNLED27351_DRIVER_COUNT][SNLED27351_PWM_REGISTER_COUNT];
|
||||||
bool g_pwm_buffer_update_required[SNLED27351_DRIVER_COUNT] = {false};
|
bool g_pwm_buffer_update_required[SNLED27351_DRIVER_COUNT] = {false};
|
||||||
|
|
||||||
uint8_t g_led_control_registers[SNLED27351_DRIVER_COUNT][24] = {0};
|
uint8_t g_led_control_registers[SNLED27351_DRIVER_COUNT][SNLED27351_LED_CONTROL_REGISTER_COUNT] = {0};
|
||||||
bool g_led_control_registers_update_required[SNLED27351_DRIVER_COUNT] = {false};
|
bool g_led_control_registers_update_required[SNLED27351_DRIVER_COUNT] = {false};
|
||||||
|
|
||||||
bool snled27351_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
bool snled27351_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
||||||
// If the transaction fails function returns false.
|
// If the transaction fails function returns false.
|
||||||
|
@ -74,7 +77,7 @@ bool snled27351_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
|
||||||
// Transmit PWM registers in 3 transfers of 64 bytes.
|
// Transmit PWM registers in 3 transfers of 64 bytes.
|
||||||
|
|
||||||
// Iterate over the pwm_buffer contents at 64 byte intervals.
|
// Iterate over the pwm_buffer contents at 64 byte intervals.
|
||||||
for (uint8_t i = 0; i < 192; i += 64) {
|
for (uint8_t i = 0; i < SNLED27351_PWM_REGISTER_COUNT; i += 64) {
|
||||||
g_twi_transfer_buffer[0] = i;
|
g_twi_transfer_buffer[0] = i;
|
||||||
// Copy the data from i to i+63.
|
// Copy the data from i to i+63.
|
||||||
// Device will auto-increment register for data after the first byte
|
// Device will auto-increment register for data after the first byte
|
||||||
|
@ -239,7 +242,7 @@ void snled27351_update_pwm_buffers(uint8_t addr, uint8_t index) {
|
||||||
void snled27351_update_led_control_registers(uint8_t addr, uint8_t index) {
|
void snled27351_update_led_control_registers(uint8_t addr, uint8_t index) {
|
||||||
if (g_led_control_registers_update_required[index]) {
|
if (g_led_control_registers_update_required[index]) {
|
||||||
snled27351_write_register(addr, SNLED27351_REG_CONFIGURE_CMD_PAGE, SNLED27351_LED_CONTROL_PAGE);
|
snled27351_write_register(addr, SNLED27351_REG_CONFIGURE_CMD_PAGE, SNLED27351_LED_CONTROL_PAGE);
|
||||||
for (int i = 0; i < 24; i++) {
|
for (int i = 0; i < SNLED27351_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||||
snled27351_write_register(addr, i, g_led_control_registers[index][i]);
|
snled27351_write_register(addr, i, g_led_control_registers[index][i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,9 @@
|
||||||
#define IS31FL3733_REG_SWPULLUP 0x0F // PG3
|
#define IS31FL3733_REG_SWPULLUP 0x0F // PG3
|
||||||
#define IS31FL3733_REG_CSPULLUP 0x10 // PG3
|
#define IS31FL3733_REG_CSPULLUP 0x10 // PG3
|
||||||
|
|
||||||
|
#define IS31FL3733_PWM_REGISTER_COUNT 192
|
||||||
|
#define IS31FL3733_LED_CONTROL_REGISTER_COUNT 24
|
||||||
|
|
||||||
#ifndef IS31FL3733_I2C_TIMEOUT
|
#ifndef IS31FL3733_I2C_TIMEOUT
|
||||||
# define IS31FL3733_I2C_TIMEOUT 100
|
# define IS31FL3733_I2C_TIMEOUT 100
|
||||||
#endif
|
#endif
|
||||||
|
@ -82,11 +85,11 @@ uint8_t g_twi_transfer_buffer[20];
|
||||||
// We could optimize this and take out the unused registers from these
|
// We could optimize this and take out the unused registers from these
|
||||||
// buffers and the transfers in is31fl3733_write_pwm_buffer() but it's
|
// buffers and the transfers in is31fl3733_write_pwm_buffer() but it's
|
||||||
// probably not worth the extra complexity.
|
// probably not worth the extra complexity.
|
||||||
uint8_t g_pwm_buffer[IS31FL3733_DRIVER_COUNT][192];
|
uint8_t g_pwm_buffer[IS31FL3733_DRIVER_COUNT][IS31FL3733_PWM_REGISTER_COUNT];
|
||||||
bool g_pwm_buffer_update_required[IS31FL3733_DRIVER_COUNT] = {false};
|
bool g_pwm_buffer_update_required[IS31FL3733_DRIVER_COUNT] = {false};
|
||||||
|
|
||||||
uint8_t g_led_control_registers[IS31FL3733_DRIVER_COUNT][24] = {{0}, {0}};
|
uint8_t g_led_control_registers[IS31FL3733_DRIVER_COUNT][IS31FL3733_LED_CONTROL_REGISTER_COUNT] = {0};
|
||||||
bool g_led_control_registers_update_required[IS31FL3733_DRIVER_COUNT] = {false};
|
bool g_led_control_registers_update_required[IS31FL3733_DRIVER_COUNT] = {false};
|
||||||
|
|
||||||
bool is31fl3733_write_register(uint8_t index, uint8_t addr, uint8_t reg, uint8_t data) {
|
bool is31fl3733_write_register(uint8_t index, uint8_t addr, uint8_t reg, uint8_t data) {
|
||||||
// If the transaction fails function returns false.
|
// If the transaction fails function returns false.
|
||||||
|
@ -114,7 +117,7 @@ bool is31fl3733_write_pwm_buffer(uint8_t index, uint8_t addr, uint8_t *pwm_buffe
|
||||||
// g_twi_transfer_buffer[] is 20 bytes
|
// g_twi_transfer_buffer[] is 20 bytes
|
||||||
|
|
||||||
// Iterate over the pwm_buffer contents at 16 byte intervals.
|
// Iterate over the pwm_buffer contents at 16 byte intervals.
|
||||||
for (int i = 0; i < 192; i += 16) {
|
for (int i = 0; i < IS31FL3733_PWM_REGISTER_COUNT; i += 16) {
|
||||||
g_twi_transfer_buffer[0] = i;
|
g_twi_transfer_buffer[0] = i;
|
||||||
// Copy the data from i to i+15.
|
// Copy the data from i to i+15.
|
||||||
// Device will auto-increment register for data after the first byte
|
// Device will auto-increment register for data after the first byte
|
||||||
|
@ -169,7 +172,7 @@ void is31fl3733_init(uint8_t bus, uint8_t addr, uint8_t sync) {
|
||||||
// Select PG0
|
// Select PG0
|
||||||
is31fl3733_write_register(bus, addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_LEDCONTROL);
|
is31fl3733_write_register(bus, addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_LEDCONTROL);
|
||||||
// Turn off all LEDs.
|
// Turn off all LEDs.
|
||||||
for (int i = 0x00; i <= 0x17; i++) {
|
for (int i = 0; i < IS31FL3733_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||||
is31fl3733_write_register(bus, addr, i, 0x00);
|
is31fl3733_write_register(bus, addr, i, 0x00);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,7 +183,7 @@ void is31fl3733_init(uint8_t bus, uint8_t addr, uint8_t sync) {
|
||||||
is31fl3733_write_register(bus, addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_PWM);
|
is31fl3733_write_register(bus, addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_PWM);
|
||||||
// Set PWM on all LEDs to 0
|
// Set PWM on all LEDs to 0
|
||||||
// No need to setup Breath registers to PWM as that is the default.
|
// No need to setup Breath registers to PWM as that is the default.
|
||||||
for (int i = 0x00; i <= 0xBF; i++) {
|
for (int i = 0; i < IS31FL3733_PWM_REGISTER_COUNT; i++) {
|
||||||
is31fl3733_write_register(bus, addr, i, 0x00);
|
is31fl3733_write_register(bus, addr, i, 0x00);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,7 +276,7 @@ void is31fl3733_update_led_control_registers(uint8_t addr, uint8_t index) {
|
||||||
// Firstly we need to unlock the command register and select PG0
|
// Firstly we need to unlock the command register and select PG0
|
||||||
is31fl3733_write_register(index, addr, IS31FL3733_COMMANDREGISTER_WRITELOCK, 0xC5);
|
is31fl3733_write_register(index, addr, IS31FL3733_COMMANDREGISTER_WRITELOCK, 0xC5);
|
||||||
is31fl3733_write_register(index, addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_LEDCONTROL);
|
is31fl3733_write_register(index, addr, IS31FL3733_COMMANDREGISTER, IS31FL3733_PAGE_LEDCONTROL);
|
||||||
for (int i = 0; i < 24; i++) {
|
for (int i = 0; i < IS31FL3733_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||||
is31fl3733_write_register(index, addr, i, g_led_control_registers[index][i]);
|
is31fl3733_write_register(index, addr, i, g_led_control_registers[index][i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue