Merge remote-tracking branch 'origin/develop' into xap
This commit is contained in:
commit
eb8bfcb505
54 changed files with 1292 additions and 1349 deletions
|
|
@ -32,6 +32,19 @@
|
|||
# define IS31FL3731_I2C_PERSISTENCE 0
|
||||
#endif
|
||||
|
||||
const uint8_t i2c_addresses[IS31FL3731_DRIVER_COUNT] = {
|
||||
IS31FL3731_I2C_ADDRESS_1,
|
||||
#ifdef IS31FL3731_I2C_ADDRESS_2
|
||||
IS31FL3731_I2C_ADDRESS_2,
|
||||
# ifdef IS31FL3731_I2C_ADDRESS_3
|
||||
IS31FL3731_I2C_ADDRESS_3,
|
||||
# ifdef IS31FL3731_I2C_ADDRESS_4
|
||||
IS31FL3731_I2C_ADDRESS_4,
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
};
|
||||
|
||||
// These buffers match the IS31FL3731 PWM registers 0x24-0xB3.
|
||||
// Storing them like this is optimal for I2C transfers to the registers.
|
||||
// We could optimize this and take out the unused registers from these
|
||||
|
|
@ -43,21 +56,21 @@ bool g_pwm_buffer_update_required[IS31FL3731_DRIVER_COUNT] = {false};
|
|||
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};
|
||||
|
||||
void is31fl3731_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
||||
void is31fl3731_write_register(uint8_t index, uint8_t reg, uint8_t data) {
|
||||
#if IS31FL3731_I2C_PERSISTENCE > 0
|
||||
for (uint8_t i = 0; i < IS31FL3731_I2C_PERSISTENCE; i++) {
|
||||
if (i2c_write_register(addr << 1, reg, &data, 1, IS31FL3731_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
if (i2c_write_register(i2c_addresses[index] << 1, reg, &data, 1, IS31FL3731_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
}
|
||||
#else
|
||||
i2c_write_register(addr << 1, reg, &data, 1, IS31FL3731_I2C_TIMEOUT);
|
||||
i2c_write_register(i2c_addresses[index] << 1, reg, &data, 1, IS31FL3731_I2C_TIMEOUT);
|
||||
#endif
|
||||
}
|
||||
|
||||
void is31fl3731_select_page(uint8_t addr, uint8_t page) {
|
||||
is31fl3731_write_register(addr, IS31FL3731_REG_COMMAND, page);
|
||||
void is31fl3731_select_page(uint8_t index, uint8_t page) {
|
||||
is31fl3731_write_register(index, IS31FL3731_REG_COMMAND, page);
|
||||
}
|
||||
|
||||
void is31fl3731_write_pwm_buffer(uint8_t addr, uint8_t index) {
|
||||
void is31fl3731_write_pwm_buffer(uint8_t index) {
|
||||
// Assumes page 0 is already selected.
|
||||
// Transmit PWM registers in 9 transfers of 16 bytes.
|
||||
|
||||
|
|
@ -65,10 +78,10 @@ void is31fl3731_write_pwm_buffer(uint8_t addr, uint8_t index) {
|
|||
for (uint8_t i = 0; i < IS31FL3731_PWM_REGISTER_COUNT; i += 16) {
|
||||
#if IS31FL3731_I2C_PERSISTENCE > 0
|
||||
for (uint8_t j = 0; j < IS31FL3731_I2C_PERSISTENCE; j++) {
|
||||
if (i2c_write_register(addr << 1, IS31FL3731_FRAME_REG_PWM + i, g_pwm_buffer[index] + i, 16, IS31FL3731_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
if (i2c_write_register(i2c_addresses[index] << 1, IS31FL3731_FRAME_REG_PWM + i, g_pwm_buffer[index] + i, 16, IS31FL3731_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
}
|
||||
#else
|
||||
i2c_write_register(addr << 1, IS31FL3731_FRAME_REG_PWM + i, g_pwm_buffer[index] + i, 16, IS31FL3731_I2C_TIMEOUT);
|
||||
i2c_write_register(i2c_addresses[index] << 1, IS31FL3731_FRAME_REG_PWM + i, g_pwm_buffer[index] + i, 16, IS31FL3731_I2C_TIMEOUT);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
@ -76,83 +89,69 @@ void is31fl3731_write_pwm_buffer(uint8_t addr, uint8_t index) {
|
|||
void is31fl3731_init_drivers(void) {
|
||||
i2c_init();
|
||||
|
||||
is31fl3731_init(IS31FL3731_I2C_ADDRESS_1);
|
||||
#if defined(IS31FL3731_I2C_ADDRESS_2)
|
||||
is31fl3731_init(IS31FL3731_I2C_ADDRESS_2);
|
||||
# if defined(IS31FL3731_I2C_ADDRESS_3)
|
||||
is31fl3731_init(IS31FL3731_I2C_ADDRESS_3);
|
||||
# if defined(IS31FL3731_I2C_ADDRESS_4)
|
||||
is31fl3731_init(IS31FL3731_I2C_ADDRESS_4);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
for (uint8_t i = 0; i < IS31FL3731_DRIVER_COUNT; i++) {
|
||||
is31fl3731_init(i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < IS31FL3731_LED_COUNT; i++) {
|
||||
is31fl3731_set_led_control_register(i, true);
|
||||
}
|
||||
|
||||
is31fl3731_update_led_control_registers(IS31FL3731_I2C_ADDRESS_1, 0);
|
||||
#if defined(IS31FL3731_I2C_ADDRESS_2)
|
||||
is31fl3731_update_led_control_registers(IS31FL3731_I2C_ADDRESS_2, 1);
|
||||
# if defined(IS31FL3731_I2C_ADDRESS_3)
|
||||
is31fl3731_update_led_control_registers(IS31FL3731_I2C_ADDRESS_3, 2);
|
||||
# if defined(IS31FL3731_I2C_ADDRESS_4)
|
||||
is31fl3731_update_led_control_registers(IS31FL3731_I2C_ADDRESS_4, 3);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
for (uint8_t i = 0; i < IS31FL3731_DRIVER_COUNT; i++) {
|
||||
is31fl3731_update_led_control_registers(i);
|
||||
}
|
||||
}
|
||||
|
||||
void is31fl3731_init(uint8_t addr) {
|
||||
void is31fl3731_init(uint8_t index) {
|
||||
// In order to avoid the LEDs being driven with garbage data
|
||||
// in the LED driver's PWM registers, first enable software shutdown,
|
||||
// then set up the mode and other settings, clear the PWM registers,
|
||||
// then disable software shutdown.
|
||||
|
||||
is31fl3731_select_page(addr, IS31FL3731_COMMAND_FUNCTION);
|
||||
is31fl3731_select_page(index, IS31FL3731_COMMAND_FUNCTION);
|
||||
|
||||
// enable software shutdown
|
||||
is31fl3731_write_register(addr, IS31FL3731_FUNCTION_REG_SHUTDOWN, 0x00);
|
||||
is31fl3731_write_register(index, IS31FL3731_FUNCTION_REG_SHUTDOWN, 0x00);
|
||||
#ifdef IS31FL3731_DEGHOST // set to enable de-ghosting of the array
|
||||
is31fl3731_write_register(addr, IS31FL3731_FUNCTION_REG_GHOST_IMAGE_PREVENTION, IS31FL3731_GHOST_IMAGE_PREVENTION_GEN);
|
||||
is31fl3731_write_register(index, IS31FL3731_FUNCTION_REG_GHOST_IMAGE_PREVENTION, IS31FL3731_GHOST_IMAGE_PREVENTION_GEN);
|
||||
#endif
|
||||
|
||||
// this delay was copied from other drivers, might not be needed
|
||||
wait_ms(10);
|
||||
|
||||
// picture mode
|
||||
is31fl3731_write_register(addr, IS31FL3731_FUNCTION_REG_CONFIG, IS31FL3731_CONFIG_MODE_PICTURE);
|
||||
is31fl3731_write_register(index, IS31FL3731_FUNCTION_REG_CONFIG, IS31FL3731_CONFIG_MODE_PICTURE);
|
||||
// display frame 0
|
||||
is31fl3731_write_register(addr, IS31FL3731_FUNCTION_REG_PICTURE_DISPLAY, 0x00);
|
||||
is31fl3731_write_register(index, IS31FL3731_FUNCTION_REG_PICTURE_DISPLAY, 0x00);
|
||||
// audio sync off
|
||||
is31fl3731_write_register(addr, IS31FL3731_FUNCTION_REG_AUDIO_SYNC, 0x00);
|
||||
is31fl3731_write_register(index, IS31FL3731_FUNCTION_REG_AUDIO_SYNC, 0x00);
|
||||
|
||||
is31fl3731_select_page(addr, IS31FL3731_COMMAND_FRAME_1);
|
||||
is31fl3731_select_page(index, IS31FL3731_COMMAND_FRAME_1);
|
||||
|
||||
// turn off all LEDs in the LED control register
|
||||
for (uint8_t i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||
is31fl3731_write_register(addr, IS31FL3731_FRAME_REG_LED_CONTROL + i, 0x00);
|
||||
is31fl3731_write_register(index, IS31FL3731_FRAME_REG_LED_CONTROL + i, 0x00);
|
||||
}
|
||||
|
||||
// turn off all LEDs in the blink control register (not really needed)
|
||||
for (uint8_t i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||
is31fl3731_write_register(addr, IS31FL3731_FRAME_REG_BLINK_CONTROL + i, 0x00);
|
||||
is31fl3731_write_register(index, IS31FL3731_FRAME_REG_BLINK_CONTROL + i, 0x00);
|
||||
}
|
||||
|
||||
// set PWM on all LEDs to 0
|
||||
for (uint8_t i = 0; i < IS31FL3731_PWM_REGISTER_COUNT; i++) {
|
||||
is31fl3731_write_register(addr, IS31FL3731_FRAME_REG_PWM + i, 0x00);
|
||||
is31fl3731_write_register(index, IS31FL3731_FRAME_REG_PWM + i, 0x00);
|
||||
}
|
||||
|
||||
is31fl3731_select_page(addr, IS31FL3731_COMMAND_FUNCTION);
|
||||
is31fl3731_select_page(index, IS31FL3731_COMMAND_FUNCTION);
|
||||
|
||||
// disable software shutdown
|
||||
is31fl3731_write_register(addr, IS31FL3731_FUNCTION_REG_SHUTDOWN, 0x01);
|
||||
is31fl3731_write_register(index, IS31FL3731_FUNCTION_REG_SHUTDOWN, 0x01);
|
||||
|
||||
// select page 0 and leave it selected.
|
||||
// most usage after initialization is just writing PWM buffers in page 0
|
||||
// as there's not much point in double-buffering
|
||||
is31fl3731_select_page(addr, IS31FL3731_COMMAND_FRAME_1);
|
||||
is31fl3731_select_page(index, IS31FL3731_COMMAND_FRAME_1);
|
||||
}
|
||||
|
||||
void is31fl3731_set_value(int index, uint8_t value) {
|
||||
|
|
@ -192,18 +191,18 @@ void is31fl3731_set_led_control_register(uint8_t index, bool value) {
|
|||
g_led_control_registers_update_required[led.driver] = true;
|
||||
}
|
||||
|
||||
void is31fl3731_update_pwm_buffers(uint8_t addr, uint8_t index) {
|
||||
void is31fl3731_update_pwm_buffers(uint8_t index) {
|
||||
if (g_pwm_buffer_update_required[index]) {
|
||||
is31fl3731_write_pwm_buffer(addr, index);
|
||||
is31fl3731_write_pwm_buffer(index);
|
||||
|
||||
g_pwm_buffer_update_required[index] = false;
|
||||
}
|
||||
}
|
||||
|
||||
void is31fl3731_update_led_control_registers(uint8_t addr, uint8_t index) {
|
||||
void is31fl3731_update_led_control_registers(uint8_t index) {
|
||||
if (g_led_control_registers_update_required[index]) {
|
||||
for (uint8_t i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||
is31fl3731_write_register(addr, i, g_led_control_registers[index][i]);
|
||||
is31fl3731_write_register(index, i, g_led_control_registers[index][i]);
|
||||
}
|
||||
|
||||
g_led_control_registers_update_required[index] = false;
|
||||
|
|
@ -211,14 +210,7 @@ void is31fl3731_update_led_control_registers(uint8_t addr, uint8_t index) {
|
|||
}
|
||||
|
||||
void is31fl3731_flush(void) {
|
||||
is31fl3731_update_pwm_buffers(IS31FL3731_I2C_ADDRESS_1, 0);
|
||||
#if defined(IS31FL3731_I2C_ADDRESS_2)
|
||||
is31fl3731_update_pwm_buffers(IS31FL3731_I2C_ADDRESS_2, 1);
|
||||
# if defined(IS31FL3731_I2C_ADDRESS_3)
|
||||
is31fl3731_update_pwm_buffers(IS31FL3731_I2C_ADDRESS_3, 2);
|
||||
# if defined(IS31FL3731_I2C_ADDRESS_4)
|
||||
is31fl3731_update_pwm_buffers(IS31FL3731_I2C_ADDRESS_4, 3);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
for (uint8_t i = 0; i < IS31FL3731_DRIVER_COUNT; i++) {
|
||||
is31fl3731_update_pwm_buffers(i);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,9 +105,9 @@ typedef struct is31fl3731_led_t {
|
|||
extern const is31fl3731_led_t PROGMEM g_is31fl3731_leds[IS31FL3731_LED_COUNT];
|
||||
|
||||
void is31fl3731_init_drivers(void);
|
||||
void is31fl3731_init(uint8_t addr);
|
||||
void is31fl3731_write_register(uint8_t addr, uint8_t reg, uint8_t data);
|
||||
void is31fl3731_select_page(uint8_t addr, uint8_t page);
|
||||
void is31fl3731_init(uint8_t index);
|
||||
void is31fl3731_write_register(uint8_t index, uint8_t reg, uint8_t data);
|
||||
void is31fl3731_select_page(uint8_t index, uint8_t page);
|
||||
|
||||
void is31fl3731_set_value(int index, uint8_t value);
|
||||
void is31fl3731_set_value_all(uint8_t value);
|
||||
|
|
@ -118,8 +118,8 @@ void is31fl3731_set_led_control_register(uint8_t index, bool value);
|
|||
// (eg. from a timer interrupt).
|
||||
// Call this while idle (in between matrix scans).
|
||||
// If the buffer is dirty, it will update the driver with the buffer.
|
||||
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_pwm_buffers(uint8_t index);
|
||||
void is31fl3731_update_led_control_registers(uint8_t index);
|
||||
|
||||
void is31fl3731_flush(void);
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,19 @@
|
|||
# define IS31FL3731_I2C_PERSISTENCE 0
|
||||
#endif
|
||||
|
||||
const uint8_t i2c_addresses[IS31FL3731_DRIVER_COUNT] = {
|
||||
IS31FL3731_I2C_ADDRESS_1,
|
||||
#ifdef IS31FL3731_I2C_ADDRESS_2
|
||||
IS31FL3731_I2C_ADDRESS_2,
|
||||
# ifdef IS31FL3731_I2C_ADDRESS_3
|
||||
IS31FL3731_I2C_ADDRESS_3,
|
||||
# ifdef IS31FL3731_I2C_ADDRESS_4
|
||||
IS31FL3731_I2C_ADDRESS_4,
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
};
|
||||
|
||||
// These buffers match the IS31FL3731 PWM registers 0x24-0xB3.
|
||||
// Storing them like this is optimal for I2C transfers to the registers.
|
||||
// We could optimize this and take out the unused registers from these
|
||||
|
|
@ -42,21 +55,21 @@ bool g_pwm_buffer_update_required[IS31FL3731_DRIVER_COUNT] = {false};
|
|||
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};
|
||||
|
||||
void is31fl3731_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
||||
void is31fl3731_write_register(uint8_t index, uint8_t reg, uint8_t data) {
|
||||
#if IS31FL3731_I2C_PERSISTENCE > 0
|
||||
for (uint8_t i = 0; i < IS31FL3731_I2C_PERSISTENCE; i++) {
|
||||
if (i2c_write_register(addr << 1, reg, &data, 1, IS31FL3731_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
if (i2c_write_register(i2c_addresses[index] << 1, reg, &data, 1, IS31FL3731_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
}
|
||||
#else
|
||||
i2c_write_register(addr << 1, reg, &data, 1, IS31FL3731_I2C_TIMEOUT);
|
||||
i2c_write_register(i2c_addresses[index] << 1, reg, &data, 1, IS31FL3731_I2C_TIMEOUT);
|
||||
#endif
|
||||
}
|
||||
|
||||
void is31fl3731_select_page(uint8_t addr, uint8_t page) {
|
||||
is31fl3731_write_register(addr, IS31FL3731_REG_COMMAND, page);
|
||||
void is31fl3731_select_page(uint8_t index, uint8_t page) {
|
||||
is31fl3731_write_register(index, IS31FL3731_REG_COMMAND, page);
|
||||
}
|
||||
|
||||
void is31fl3731_write_pwm_buffer(uint8_t addr, uint8_t index) {
|
||||
void is31fl3731_write_pwm_buffer(uint8_t index) {
|
||||
// Assumes page 0 is already selected.
|
||||
// Transmit PWM registers in 9 transfers of 16 bytes.
|
||||
|
||||
|
|
@ -64,10 +77,10 @@ void is31fl3731_write_pwm_buffer(uint8_t addr, uint8_t index) {
|
|||
for (uint8_t i = 0; i < IS31FL3731_PWM_REGISTER_COUNT; i += 16) {
|
||||
#if IS31FL3731_I2C_PERSISTENCE > 0
|
||||
for (uint8_t j = 0; j < IS31FL3731_I2C_PERSISTENCE; j++) {
|
||||
if (i2c_write_register(addr << 1, IS31FL3731_FRAME_REG_PWM + i, g_pwm_buffer[index] + i, 16, IS31FL3731_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
if (i2c_write_register(i2c_addresses[index] << 1, IS31FL3731_FRAME_REG_PWM + i, g_pwm_buffer[index] + i, 16, IS31FL3731_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
}
|
||||
#else
|
||||
i2c_write_register(addr << 1, IS31FL3731_FRAME_REG_PWM + i, g_pwm_buffer[index] + i, 16, IS31FL3731_I2C_TIMEOUT);
|
||||
i2c_write_register(i2c_addresses[index] << 1, IS31FL3731_FRAME_REG_PWM + i, g_pwm_buffer[index] + i, 16, IS31FL3731_I2C_TIMEOUT);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
@ -75,83 +88,69 @@ void is31fl3731_write_pwm_buffer(uint8_t addr, uint8_t index) {
|
|||
void is31fl3731_init_drivers(void) {
|
||||
i2c_init();
|
||||
|
||||
is31fl3731_init(IS31FL3731_I2C_ADDRESS_1);
|
||||
#if defined(IS31FL3731_I2C_ADDRESS_2)
|
||||
is31fl3731_init(IS31FL3731_I2C_ADDRESS_2);
|
||||
# if defined(IS31FL3731_I2C_ADDRESS_3)
|
||||
is31fl3731_init(IS31FL3731_I2C_ADDRESS_3);
|
||||
# if defined(IS31FL3731_I2C_ADDRESS_4)
|
||||
is31fl3731_init(IS31FL3731_I2C_ADDRESS_4);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
for (uint8_t i = 0; i < IS31FL3731_DRIVER_COUNT; i++) {
|
||||
is31fl3731_init(i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < IS31FL3731_LED_COUNT; i++) {
|
||||
is31fl3731_set_led_control_register(i, true, true, true);
|
||||
}
|
||||
|
||||
is31fl3731_update_led_control_registers(IS31FL3731_I2C_ADDRESS_1, 0);
|
||||
#if defined(IS31FL3731_I2C_ADDRESS_2)
|
||||
is31fl3731_update_led_control_registers(IS31FL3731_I2C_ADDRESS_2, 1);
|
||||
# if defined(IS31FL3731_I2C_ADDRESS_3)
|
||||
is31fl3731_update_led_control_registers(IS31FL3731_I2C_ADDRESS_3, 2);
|
||||
# if defined(IS31FL3731_I2C_ADDRESS_4)
|
||||
is31fl3731_update_led_control_registers(IS31FL3731_I2C_ADDRESS_4, 3);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
for (uint8_t i = 0; i < IS31FL3731_DRIVER_COUNT; i++) {
|
||||
is31fl3731_update_led_control_registers(i);
|
||||
}
|
||||
}
|
||||
|
||||
void is31fl3731_init(uint8_t addr) {
|
||||
void is31fl3731_init(uint8_t index) {
|
||||
// In order to avoid the LEDs being driven with garbage data
|
||||
// in the LED driver's PWM registers, first enable software shutdown,
|
||||
// then set up the mode and other settings, clear the PWM registers,
|
||||
// then disable software shutdown.
|
||||
|
||||
is31fl3731_select_page(addr, IS31FL3731_COMMAND_FUNCTION);
|
||||
is31fl3731_select_page(index, IS31FL3731_COMMAND_FUNCTION);
|
||||
|
||||
// enable software shutdown
|
||||
is31fl3731_write_register(addr, IS31FL3731_FUNCTION_REG_SHUTDOWN, 0x00);
|
||||
is31fl3731_write_register(index, IS31FL3731_FUNCTION_REG_SHUTDOWN, 0x00);
|
||||
#ifdef IS31FL3731_DEGHOST // set to enable de-ghosting of the array
|
||||
is31fl3731_write_register(addr, IS31FL3731_FUNCTION_REG_GHOST_IMAGE_PREVENTION, IS31FL3731_GHOST_IMAGE_PREVENTION_GEN);
|
||||
is31fl3731_write_register(index, IS31FL3731_FUNCTION_REG_GHOST_IMAGE_PREVENTION, IS31FL3731_GHOST_IMAGE_PREVENTION_GEN);
|
||||
#endif
|
||||
|
||||
// this delay was copied from other drivers, might not be needed
|
||||
wait_ms(10);
|
||||
|
||||
// picture mode
|
||||
is31fl3731_write_register(addr, IS31FL3731_FUNCTION_REG_CONFIG, IS31FL3731_CONFIG_MODE_PICTURE);
|
||||
is31fl3731_write_register(index, IS31FL3731_FUNCTION_REG_CONFIG, IS31FL3731_CONFIG_MODE_PICTURE);
|
||||
// display frame 0
|
||||
is31fl3731_write_register(addr, IS31FL3731_FUNCTION_REG_PICTURE_DISPLAY, 0x00);
|
||||
is31fl3731_write_register(index, IS31FL3731_FUNCTION_REG_PICTURE_DISPLAY, 0x00);
|
||||
// audio sync off
|
||||
is31fl3731_write_register(addr, IS31FL3731_FUNCTION_REG_AUDIO_SYNC, 0x00);
|
||||
is31fl3731_write_register(index, IS31FL3731_FUNCTION_REG_AUDIO_SYNC, 0x00);
|
||||
|
||||
is31fl3731_select_page(addr, IS31FL3731_COMMAND_FRAME_1);
|
||||
is31fl3731_select_page(index, IS31FL3731_COMMAND_FRAME_1);
|
||||
|
||||
// turn off all LEDs in the LED control register
|
||||
for (uint8_t i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||
is31fl3731_write_register(addr, IS31FL3731_FRAME_REG_LED_CONTROL + i, 0x00);
|
||||
is31fl3731_write_register(index, IS31FL3731_FRAME_REG_LED_CONTROL + i, 0x00);
|
||||
}
|
||||
|
||||
// turn off all LEDs in the blink control register (not really needed)
|
||||
for (uint8_t i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||
is31fl3731_write_register(addr, IS31FL3731_FRAME_REG_BLINK_CONTROL + i, 0x00);
|
||||
is31fl3731_write_register(index, IS31FL3731_FRAME_REG_BLINK_CONTROL + i, 0x00);
|
||||
}
|
||||
|
||||
// set PWM on all LEDs to 0
|
||||
for (uint8_t i = 0; i < IS31FL3731_PWM_REGISTER_COUNT; i++) {
|
||||
is31fl3731_write_register(addr, IS31FL3731_FRAME_REG_PWM + i, 0x00);
|
||||
is31fl3731_write_register(index, IS31FL3731_FRAME_REG_PWM + i, 0x00);
|
||||
}
|
||||
|
||||
is31fl3731_select_page(addr, IS31FL3731_COMMAND_FUNCTION);
|
||||
is31fl3731_select_page(index, IS31FL3731_COMMAND_FUNCTION);
|
||||
|
||||
// disable software shutdown
|
||||
is31fl3731_write_register(addr, IS31FL3731_FUNCTION_REG_SHUTDOWN, 0x01);
|
||||
is31fl3731_write_register(index, IS31FL3731_FUNCTION_REG_SHUTDOWN, 0x01);
|
||||
|
||||
// select page 0 and leave it selected.
|
||||
// most usage after initialization is just writing PWM buffers in page 0
|
||||
// as there's not much point in double-buffering
|
||||
is31fl3731_select_page(addr, IS31FL3731_COMMAND_FRAME_1);
|
||||
is31fl3731_select_page(index, IS31FL3731_COMMAND_FRAME_1);
|
||||
}
|
||||
|
||||
void is31fl3731_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
|
||||
|
|
@ -207,18 +206,18 @@ void is31fl3731_set_led_control_register(uint8_t index, bool red, bool green, bo
|
|||
g_led_control_registers_update_required[led.driver] = true;
|
||||
}
|
||||
|
||||
void is31fl3731_update_pwm_buffers(uint8_t addr, uint8_t index) {
|
||||
void is31fl3731_update_pwm_buffers(uint8_t index) {
|
||||
if (g_pwm_buffer_update_required[index]) {
|
||||
is31fl3731_write_pwm_buffer(addr, index);
|
||||
is31fl3731_write_pwm_buffer(index);
|
||||
|
||||
g_pwm_buffer_update_required[index] = false;
|
||||
}
|
||||
}
|
||||
|
||||
void is31fl3731_update_led_control_registers(uint8_t addr, uint8_t index) {
|
||||
void is31fl3731_update_led_control_registers(uint8_t index) {
|
||||
if (g_led_control_registers_update_required[index]) {
|
||||
for (uint8_t i = 0; i < IS31FL3731_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||
is31fl3731_write_register(addr, i, g_led_control_registers[index][i]);
|
||||
is31fl3731_write_register(index, i, g_led_control_registers[index][i]);
|
||||
}
|
||||
|
||||
g_led_control_registers_update_required[index] = false;
|
||||
|
|
@ -226,14 +225,7 @@ void is31fl3731_update_led_control_registers(uint8_t addr, uint8_t index) {
|
|||
}
|
||||
|
||||
void is31fl3731_flush(void) {
|
||||
is31fl3731_update_pwm_buffers(IS31FL3731_I2C_ADDRESS_1, 0);
|
||||
#if defined(IS31FL3731_I2C_ADDRESS_2)
|
||||
is31fl3731_update_pwm_buffers(IS31FL3731_I2C_ADDRESS_2, 1);
|
||||
# if defined(IS31FL3731_I2C_ADDRESS_3)
|
||||
is31fl3731_update_pwm_buffers(IS31FL3731_I2C_ADDRESS_3, 2);
|
||||
# if defined(IS31FL3731_I2C_ADDRESS_4)
|
||||
is31fl3731_update_pwm_buffers(IS31FL3731_I2C_ADDRESS_4, 3);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
for (uint8_t i = 0; i < IS31FL3731_DRIVER_COUNT; i++) {
|
||||
is31fl3731_update_pwm_buffers(i);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,9 +106,9 @@ typedef struct is31fl3731_led_t {
|
|||
extern const is31fl3731_led_t PROGMEM g_is31fl3731_leds[IS31FL3731_LED_COUNT];
|
||||
|
||||
void is31fl3731_init_drivers(void);
|
||||
void is31fl3731_init(uint8_t addr);
|
||||
void is31fl3731_write_register(uint8_t addr, uint8_t reg, uint8_t data);
|
||||
void is31fl3731_select_page(uint8_t addr, uint8_t page);
|
||||
void is31fl3731_init(uint8_t index);
|
||||
void is31fl3731_write_register(uint8_t index, uint8_t reg, uint8_t data);
|
||||
void is31fl3731_select_page(uint8_t index, uint8_t page);
|
||||
|
||||
void is31fl3731_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
|
||||
void is31fl3731_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
|
||||
|
|
@ -119,8 +119,8 @@ void is31fl3731_set_led_control_register(uint8_t index, bool red, bool green, bo
|
|||
// (eg. from a timer interrupt).
|
||||
// Call this while idle (in between matrix scans).
|
||||
// If the buffer is dirty, it will update the driver with the buffer.
|
||||
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_pwm_buffers(uint8_t index);
|
||||
void is31fl3731_update_led_control_registers(uint8_t index);
|
||||
|
||||
void is31fl3731_flush(void);
|
||||
|
||||
|
|
|
|||
|
|
@ -62,6 +62,32 @@
|
|||
# define IS31FL3733_SYNC_4 IS31FL3733_SYNC_NONE
|
||||
#endif
|
||||
|
||||
const uint8_t i2c_addresses[IS31FL3733_DRIVER_COUNT] = {
|
||||
IS31FL3733_I2C_ADDRESS_1,
|
||||
#ifdef IS31FL3733_I2C_ADDRESS_2
|
||||
IS31FL3733_I2C_ADDRESS_2,
|
||||
# ifdef IS31FL3733_I2C_ADDRESS_3
|
||||
IS31FL3733_I2C_ADDRESS_3,
|
||||
# ifdef IS31FL3733_I2C_ADDRESS_4
|
||||
IS31FL3733_I2C_ADDRESS_4,
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
};
|
||||
|
||||
const uint8_t driver_sync[IS31FL3733_DRIVER_COUNT] = {
|
||||
IS31FL3733_SYNC_1,
|
||||
#ifdef IS31FL3733_I2C_ADDRESS_2
|
||||
IS31FL3733_SYNC_2,
|
||||
# ifdef IS31FL3733_I2C_ADDRESS_3
|
||||
IS31FL3733_SYNC_3,
|
||||
# ifdef IS31FL3733_I2C_ADDRESS_4
|
||||
IS31FL3733_SYNC_4,
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
};
|
||||
|
||||
// These buffers match the IS31FL3733 PWM registers.
|
||||
// The control buffers match the page 0 LED On/Off registers.
|
||||
// Storing them like this is optimal for I2C transfers to the registers.
|
||||
|
|
@ -74,22 +100,22 @@ bool g_pwm_buffer_update_required[IS31FL3733_DRIVER_COUNT] = {false};
|
|||
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};
|
||||
|
||||
void is31fl3733_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
||||
void is31fl3733_write_register(uint8_t index, uint8_t reg, uint8_t data) {
|
||||
#if IS31FL3733_I2C_PERSISTENCE > 0
|
||||
for (uint8_t i = 0; i < IS31FL3733_I2C_PERSISTENCE; i++) {
|
||||
if (i2c_write_register(addr << 1, reg, &data, 1, IS31FL3733_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
if (i2c_write_register(i2c_addresses[index] << 1, reg, &data, 1, IS31FL3733_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
}
|
||||
#else
|
||||
i2c_write_register(addr << 1, reg, &data, 1, IS31FL3733_I2C_TIMEOUT);
|
||||
i2c_write_register(i2c_addresses[index] << 1, reg, &data, 1, IS31FL3733_I2C_TIMEOUT);
|
||||
#endif
|
||||
}
|
||||
|
||||
void is31fl3733_select_page(uint8_t addr, uint8_t page) {
|
||||
is31fl3733_write_register(addr, IS31FL3733_REG_COMMAND_WRITE_LOCK, IS31FL3733_COMMAND_WRITE_LOCK_MAGIC);
|
||||
is31fl3733_write_register(addr, IS31FL3733_REG_COMMAND, page);
|
||||
void is31fl3733_select_page(uint8_t index, uint8_t page) {
|
||||
is31fl3733_write_register(index, IS31FL3733_REG_COMMAND_WRITE_LOCK, IS31FL3733_COMMAND_WRITE_LOCK_MAGIC);
|
||||
is31fl3733_write_register(index, IS31FL3733_REG_COMMAND, page);
|
||||
}
|
||||
|
||||
void is31fl3733_write_pwm_buffer(uint8_t addr, uint8_t index) {
|
||||
void is31fl3733_write_pwm_buffer(uint8_t index) {
|
||||
// Assumes page 1 is already selected.
|
||||
// Transmit PWM registers in 12 transfers of 16 bytes.
|
||||
|
||||
|
|
@ -97,10 +123,10 @@ void is31fl3733_write_pwm_buffer(uint8_t addr, uint8_t index) {
|
|||
for (uint8_t i = 0; i < IS31FL3733_PWM_REGISTER_COUNT; i += 16) {
|
||||
#if IS31FL3733_I2C_PERSISTENCE > 0
|
||||
for (uint8_t j = 0; j < IS31FL3733_I2C_PERSISTENCE; j++) {
|
||||
if (i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3733_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
if (i2c_write_register(i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3733_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
}
|
||||
#else
|
||||
i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3733_I2C_TIMEOUT);
|
||||
i2c_write_register(i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3733_I2C_TIMEOUT);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
@ -108,65 +134,52 @@ void is31fl3733_write_pwm_buffer(uint8_t addr, uint8_t index) {
|
|||
void is31fl3733_init_drivers(void) {
|
||||
i2c_init();
|
||||
|
||||
is31fl3733_init(IS31FL3733_I2C_ADDRESS_1, IS31FL3733_SYNC_1);
|
||||
#if defined(IS31FL3733_I2C_ADDRESS_2)
|
||||
is31fl3733_init(IS31FL3733_I2C_ADDRESS_2, IS31FL3733_SYNC_2);
|
||||
# if defined(IS31FL3733_I2C_ADDRESS_3)
|
||||
is31fl3733_init(IS31FL3733_I2C_ADDRESS_3, IS31FL3733_SYNC_3);
|
||||
# if defined(IS31FL3733_I2C_ADDRESS_4)
|
||||
is31fl3733_init(IS31FL3733_I2C_ADDRESS_4, IS31FL3733_SYNC_4);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
for (uint8_t i = 0; i < IS31FL3733_DRIVER_COUNT; i++) {
|
||||
is31fl3733_init(i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < IS31FL3733_LED_COUNT; i++) {
|
||||
is31fl3733_set_led_control_register(i, true);
|
||||
}
|
||||
|
||||
is31fl3733_update_led_control_registers(IS31FL3733_I2C_ADDRESS_1, 0);
|
||||
#if defined(IS31FL3733_I2C_ADDRESS_2)
|
||||
is31fl3733_update_led_control_registers(IS31FL3733_I2C_ADDRESS_2, 1);
|
||||
# if defined(IS31FL3733_I2C_ADDRESS_3)
|
||||
is31fl3733_update_led_control_registers(IS31FL3733_I2C_ADDRESS_3, 2);
|
||||
# if defined(IS31FL3733_I2C_ADDRESS_4)
|
||||
is31fl3733_update_led_control_registers(IS31FL3733_I2C_ADDRESS_4, 3);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
for (uint8_t i = 0; i < IS31FL3733_DRIVER_COUNT; i++) {
|
||||
is31fl3733_update_led_control_registers(i);
|
||||
}
|
||||
}
|
||||
|
||||
void is31fl3733_init(uint8_t addr, uint8_t sync) {
|
||||
void is31fl3733_init(uint8_t index) {
|
||||
// In order to avoid the LEDs being driven with garbage data
|
||||
// in the LED driver's PWM registers, shutdown is enabled last.
|
||||
// Set up the mode and other settings, clear the PWM registers,
|
||||
// then disable software shutdown.
|
||||
// Sync is passed so set it according to the datasheet.
|
||||
|
||||
is31fl3733_select_page(addr, IS31FL3733_COMMAND_LED_CONTROL);
|
||||
is31fl3733_select_page(index, IS31FL3733_COMMAND_LED_CONTROL);
|
||||
|
||||
// Turn off all LEDs.
|
||||
for (uint8_t i = 0; i < IS31FL3733_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||
is31fl3733_write_register(addr, i, 0x00);
|
||||
is31fl3733_write_register(index, i, 0x00);
|
||||
}
|
||||
|
||||
is31fl3733_select_page(addr, IS31FL3733_COMMAND_PWM);
|
||||
is31fl3733_select_page(index, IS31FL3733_COMMAND_PWM);
|
||||
|
||||
// Set PWM on all LEDs to 0
|
||||
// No need to setup Breath registers to PWM as that is the default.
|
||||
for (uint8_t i = 0; i < IS31FL3733_PWM_REGISTER_COUNT; i++) {
|
||||
is31fl3733_write_register(addr, i, 0x00);
|
||||
is31fl3733_write_register(index, i, 0x00);
|
||||
}
|
||||
|
||||
is31fl3733_select_page(addr, IS31FL3733_COMMAND_FUNCTION);
|
||||
is31fl3733_select_page(index, IS31FL3733_COMMAND_FUNCTION);
|
||||
|
||||
uint8_t sync = driver_sync[index];
|
||||
|
||||
// Set de-ghost pull-up resistors (SWx)
|
||||
is31fl3733_write_register(addr, IS31FL3733_FUNCTION_REG_SW_PULLUP, IS31FL3733_SW_PULLUP);
|
||||
is31fl3733_write_register(index, IS31FL3733_FUNCTION_REG_SW_PULLUP, IS31FL3733_SW_PULLUP);
|
||||
// Set de-ghost pull-down resistors (CSx)
|
||||
is31fl3733_write_register(addr, IS31FL3733_FUNCTION_REG_CS_PULLDOWN, IS31FL3733_CS_PULLDOWN);
|
||||
is31fl3733_write_register(index, IS31FL3733_FUNCTION_REG_CS_PULLDOWN, IS31FL3733_CS_PULLDOWN);
|
||||
// Set global current to maximum.
|
||||
is31fl3733_write_register(addr, IS31FL3733_FUNCTION_REG_GLOBAL_CURRENT, IS31FL3733_GLOBAL_CURRENT);
|
||||
is31fl3733_write_register(index, IS31FL3733_FUNCTION_REG_GLOBAL_CURRENT, IS31FL3733_GLOBAL_CURRENT);
|
||||
// Disable software shutdown.
|
||||
is31fl3733_write_register(addr, IS31FL3733_FUNCTION_REG_CONFIGURATION, ((sync & 0b11) << 6) | ((IS31FL3733_PWM_FREQUENCY & 0b111) << 3) | 0x01);
|
||||
is31fl3733_write_register(index, IS31FL3733_FUNCTION_REG_CONFIGURATION, ((sync & 0b11) << 6) | ((IS31FL3733_PWM_FREQUENCY & 0b111) << 3) | 0x01);
|
||||
|
||||
// Wait 10ms to ensure the device has woken up.
|
||||
wait_ms(10);
|
||||
|
|
@ -209,22 +222,22 @@ void is31fl3733_set_led_control_register(uint8_t index, bool value) {
|
|||
g_led_control_registers_update_required[led.driver] = true;
|
||||
}
|
||||
|
||||
void is31fl3733_update_pwm_buffers(uint8_t addr, uint8_t index) {
|
||||
void is31fl3733_update_pwm_buffers(uint8_t index) {
|
||||
if (g_pwm_buffer_update_required[index]) {
|
||||
is31fl3733_select_page(addr, IS31FL3733_COMMAND_PWM);
|
||||
is31fl3733_select_page(index, IS31FL3733_COMMAND_PWM);
|
||||
|
||||
is31fl3733_write_pwm_buffer(addr, index);
|
||||
is31fl3733_write_pwm_buffer(index);
|
||||
|
||||
g_pwm_buffer_update_required[index] = false;
|
||||
}
|
||||
}
|
||||
|
||||
void is31fl3733_update_led_control_registers(uint8_t addr, uint8_t index) {
|
||||
void is31fl3733_update_led_control_registers(uint8_t index) {
|
||||
if (g_led_control_registers_update_required[index]) {
|
||||
is31fl3733_select_page(addr, IS31FL3733_COMMAND_LED_CONTROL);
|
||||
is31fl3733_select_page(index, IS31FL3733_COMMAND_LED_CONTROL);
|
||||
|
||||
for (uint8_t i = 0; i < IS31FL3733_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||
is31fl3733_write_register(addr, i, g_led_control_registers[index][i]);
|
||||
is31fl3733_write_register(index, i, g_led_control_registers[index][i]);
|
||||
}
|
||||
|
||||
g_led_control_registers_update_required[index] = false;
|
||||
|
|
@ -232,14 +245,7 @@ void is31fl3733_update_led_control_registers(uint8_t addr, uint8_t index) {
|
|||
}
|
||||
|
||||
void is31fl3733_flush(void) {
|
||||
is31fl3733_update_pwm_buffers(IS31FL3733_I2C_ADDRESS_1, 0);
|
||||
#if defined(IS31FL3733_I2C_ADDRESS_2)
|
||||
is31fl3733_update_pwm_buffers(IS31FL3733_I2C_ADDRESS_2, 1);
|
||||
# if defined(IS31FL3733_I2C_ADDRESS_3)
|
||||
is31fl3733_update_pwm_buffers(IS31FL3733_I2C_ADDRESS_3, 2);
|
||||
# if defined(IS31FL3733_I2C_ADDRESS_4)
|
||||
is31fl3733_update_pwm_buffers(IS31FL3733_I2C_ADDRESS_4, 3);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
for (uint8_t i = 0; i < IS31FL3733_DRIVER_COUNT; i++) {
|
||||
is31fl3733_update_pwm_buffers(i);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,9 +115,9 @@ typedef struct is31fl3733_led_t {
|
|||
extern const is31fl3733_led_t PROGMEM g_is31fl3733_leds[IS31FL3733_LED_COUNT];
|
||||
|
||||
void is31fl3733_init_drivers(void);
|
||||
void is31fl3733_init(uint8_t addr, uint8_t sync);
|
||||
void is31fl3733_write_register(uint8_t addr, uint8_t reg, uint8_t data);
|
||||
void is31fl3733_select_page(uint8_t addr, uint8_t page);
|
||||
void is31fl3733_init(uint8_t index);
|
||||
void is31fl3733_write_register(uint8_t index, uint8_t reg, uint8_t data);
|
||||
void is31fl3733_select_page(uint8_t index, uint8_t page);
|
||||
|
||||
void is31fl3733_set_value(int index, uint8_t value);
|
||||
void is31fl3733_set_value_all(uint8_t value);
|
||||
|
|
@ -128,8 +128,8 @@ void is31fl3733_set_led_control_register(uint8_t index, bool value);
|
|||
// (eg. from a timer interrupt).
|
||||
// Call this while idle (in between matrix scans).
|
||||
// If the buffer is dirty, it will update the driver with the buffer.
|
||||
void is31fl3733_update_pwm_buffers(uint8_t addr, uint8_t index);
|
||||
void is31fl3733_update_led_control_registers(uint8_t addr, uint8_t index);
|
||||
void is31fl3733_update_pwm_buffers(uint8_t index);
|
||||
void is31fl3733_update_led_control_registers(uint8_t index);
|
||||
|
||||
void is31fl3733_flush(void);
|
||||
|
||||
|
|
|
|||
|
|
@ -61,6 +61,32 @@
|
|||
# define IS31FL3733_SYNC_4 IS31FL3733_SYNC_NONE
|
||||
#endif
|
||||
|
||||
const uint8_t i2c_addresses[IS31FL3733_DRIVER_COUNT] = {
|
||||
IS31FL3733_I2C_ADDRESS_1,
|
||||
#ifdef IS31FL3733_I2C_ADDRESS_2
|
||||
IS31FL3733_I2C_ADDRESS_2,
|
||||
# ifdef IS31FL3733_I2C_ADDRESS_3
|
||||
IS31FL3733_I2C_ADDRESS_3,
|
||||
# ifdef IS31FL3733_I2C_ADDRESS_4
|
||||
IS31FL3733_I2C_ADDRESS_4,
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
};
|
||||
|
||||
const uint8_t driver_sync[IS31FL3733_DRIVER_COUNT] = {
|
||||
IS31FL3733_SYNC_1,
|
||||
#ifdef IS31FL3733_I2C_ADDRESS_2
|
||||
IS31FL3733_SYNC_2,
|
||||
# ifdef IS31FL3733_I2C_ADDRESS_3
|
||||
IS31FL3733_SYNC_3,
|
||||
# ifdef IS31FL3733_I2C_ADDRESS_4
|
||||
IS31FL3733_SYNC_4,
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
};
|
||||
|
||||
// These buffers match the IS31FL3733 PWM registers.
|
||||
// The control buffers match the page 0 LED On/Off registers.
|
||||
// Storing them like this is optimal for I2C transfers to the registers.
|
||||
|
|
@ -73,22 +99,22 @@ bool g_pwm_buffer_update_required[IS31FL3733_DRIVER_COUNT] = {false};
|
|||
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};
|
||||
|
||||
void is31fl3733_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
||||
void is31fl3733_write_register(uint8_t index, uint8_t reg, uint8_t data) {
|
||||
#if IS31FL3733_I2C_PERSISTENCE > 0
|
||||
for (uint8_t i = 0; i < IS31FL3733_I2C_PERSISTENCE; i++) {
|
||||
if (i2c_write_register(addr << 1, reg, &data, 1, IS31FL3733_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
if (i2c_write_register(i2c_addresses[index] << 1, reg, &data, 1, IS31FL3733_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
}
|
||||
#else
|
||||
i2c_write_register(addr << 1, reg, &data, 1, IS31FL3733_I2C_TIMEOUT);
|
||||
i2c_write_register(i2c_addresses[index] << 1, reg, &data, 1, IS31FL3733_I2C_TIMEOUT);
|
||||
#endif
|
||||
}
|
||||
|
||||
void is31fl3733_select_page(uint8_t addr, uint8_t page) {
|
||||
is31fl3733_write_register(addr, IS31FL3733_REG_COMMAND_WRITE_LOCK, IS31FL3733_COMMAND_WRITE_LOCK_MAGIC);
|
||||
is31fl3733_write_register(addr, IS31FL3733_REG_COMMAND, page);
|
||||
void is31fl3733_select_page(uint8_t index, uint8_t page) {
|
||||
is31fl3733_write_register(index, IS31FL3733_REG_COMMAND_WRITE_LOCK, IS31FL3733_COMMAND_WRITE_LOCK_MAGIC);
|
||||
is31fl3733_write_register(index, IS31FL3733_REG_COMMAND, page);
|
||||
}
|
||||
|
||||
void is31fl3733_write_pwm_buffer(uint8_t addr, uint8_t index) {
|
||||
void is31fl3733_write_pwm_buffer(uint8_t index) {
|
||||
// Assumes page 1 is already selected.
|
||||
// Transmit PWM registers in 12 transfers of 16 bytes.
|
||||
|
||||
|
|
@ -96,10 +122,10 @@ void is31fl3733_write_pwm_buffer(uint8_t addr, uint8_t index) {
|
|||
for (uint8_t i = 0; i < IS31FL3733_PWM_REGISTER_COUNT; i += 16) {
|
||||
#if IS31FL3733_I2C_PERSISTENCE > 0
|
||||
for (uint8_t j = 0; j < IS31FL3733_I2C_PERSISTENCE; j++) {
|
||||
if (i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3733_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
if (i2c_write_register(i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3733_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
}
|
||||
#else
|
||||
i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3733_I2C_TIMEOUT);
|
||||
i2c_write_register(i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3733_I2C_TIMEOUT);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
@ -107,65 +133,52 @@ void is31fl3733_write_pwm_buffer(uint8_t addr, uint8_t index) {
|
|||
void is31fl3733_init_drivers(void) {
|
||||
i2c_init();
|
||||
|
||||
is31fl3733_init(IS31FL3733_I2C_ADDRESS_1, IS31FL3733_SYNC_1);
|
||||
#if defined(IS31FL3733_I2C_ADDRESS_2)
|
||||
is31fl3733_init(IS31FL3733_I2C_ADDRESS_2, IS31FL3733_SYNC_2);
|
||||
# if defined(IS31FL3733_I2C_ADDRESS_3)
|
||||
is31fl3733_init(IS31FL3733_I2C_ADDRESS_3, IS31FL3733_SYNC_3);
|
||||
# if defined(IS31FL3733_I2C_ADDRESS_4)
|
||||
is31fl3733_init(IS31FL3733_I2C_ADDRESS_4, IS31FL3733_SYNC_4);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
for (uint8_t i = 0; i < IS31FL3733_DRIVER_COUNT; i++) {
|
||||
is31fl3733_init(i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < IS31FL3733_LED_COUNT; i++) {
|
||||
is31fl3733_set_led_control_register(i, true, true, true);
|
||||
}
|
||||
|
||||
is31fl3733_update_led_control_registers(IS31FL3733_I2C_ADDRESS_1, 0);
|
||||
#if defined(IS31FL3733_I2C_ADDRESS_2)
|
||||
is31fl3733_update_led_control_registers(IS31FL3733_I2C_ADDRESS_2, 1);
|
||||
# if defined(IS31FL3733_I2C_ADDRESS_3)
|
||||
is31fl3733_update_led_control_registers(IS31FL3733_I2C_ADDRESS_3, 2);
|
||||
# if defined(IS31FL3733_I2C_ADDRESS_4)
|
||||
is31fl3733_update_led_control_registers(IS31FL3733_I2C_ADDRESS_4, 3);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
for (uint8_t i = 0; i < IS31FL3733_DRIVER_COUNT; i++) {
|
||||
is31fl3733_update_led_control_registers(i);
|
||||
}
|
||||
}
|
||||
|
||||
void is31fl3733_init(uint8_t addr, uint8_t sync) {
|
||||
void is31fl3733_init(uint8_t index) {
|
||||
// In order to avoid the LEDs being driven with garbage data
|
||||
// in the LED driver's PWM registers, shutdown is enabled last.
|
||||
// Set up the mode and other settings, clear the PWM registers,
|
||||
// then disable software shutdown.
|
||||
// Sync is passed so set it according to the datasheet.
|
||||
|
||||
is31fl3733_select_page(addr, IS31FL3733_COMMAND_LED_CONTROL);
|
||||
is31fl3733_select_page(index, IS31FL3733_COMMAND_LED_CONTROL);
|
||||
|
||||
// Turn off all LEDs.
|
||||
for (uint8_t i = 0; i < IS31FL3733_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||
is31fl3733_write_register(addr, i, 0x00);
|
||||
is31fl3733_write_register(index, i, 0x00);
|
||||
}
|
||||
|
||||
is31fl3733_select_page(addr, IS31FL3733_COMMAND_PWM);
|
||||
is31fl3733_select_page(index, IS31FL3733_COMMAND_PWM);
|
||||
|
||||
// Set PWM on all LEDs to 0
|
||||
// No need to setup Breath registers to PWM as that is the default.
|
||||
for (uint8_t i = 0; i < IS31FL3733_PWM_REGISTER_COUNT; i++) {
|
||||
is31fl3733_write_register(addr, i, 0x00);
|
||||
is31fl3733_write_register(index, i, 0x00);
|
||||
}
|
||||
|
||||
is31fl3733_select_page(addr, IS31FL3733_COMMAND_FUNCTION);
|
||||
is31fl3733_select_page(index, IS31FL3733_COMMAND_FUNCTION);
|
||||
|
||||
uint8_t sync = driver_sync[index];
|
||||
|
||||
// Set de-ghost pull-up resistors (SWx)
|
||||
is31fl3733_write_register(addr, IS31FL3733_FUNCTION_REG_SW_PULLUP, IS31FL3733_SW_PULLUP);
|
||||
is31fl3733_write_register(index, IS31FL3733_FUNCTION_REG_SW_PULLUP, IS31FL3733_SW_PULLUP);
|
||||
// Set de-ghost pull-down resistors (CSx)
|
||||
is31fl3733_write_register(addr, IS31FL3733_FUNCTION_REG_CS_PULLDOWN, IS31FL3733_CS_PULLDOWN);
|
||||
is31fl3733_write_register(index, IS31FL3733_FUNCTION_REG_CS_PULLDOWN, IS31FL3733_CS_PULLDOWN);
|
||||
// Set global current to maximum.
|
||||
is31fl3733_write_register(addr, IS31FL3733_FUNCTION_REG_GLOBAL_CURRENT, IS31FL3733_GLOBAL_CURRENT);
|
||||
is31fl3733_write_register(index, IS31FL3733_FUNCTION_REG_GLOBAL_CURRENT, IS31FL3733_GLOBAL_CURRENT);
|
||||
// Disable software shutdown.
|
||||
is31fl3733_write_register(addr, IS31FL3733_FUNCTION_REG_CONFIGURATION, ((sync & 0b11) << 6) | ((IS31FL3733_PWM_FREQUENCY & 0b111) << 3) | 0x01);
|
||||
is31fl3733_write_register(index, IS31FL3733_FUNCTION_REG_CONFIGURATION, ((sync & 0b11) << 6) | ((IS31FL3733_PWM_FREQUENCY & 0b111) << 3) | 0x01);
|
||||
|
||||
// Wait 10ms to ensure the device has woken up.
|
||||
wait_ms(10);
|
||||
|
|
@ -224,22 +237,22 @@ void is31fl3733_set_led_control_register(uint8_t index, bool red, bool green, bo
|
|||
g_led_control_registers_update_required[led.driver] = true;
|
||||
}
|
||||
|
||||
void is31fl3733_update_pwm_buffers(uint8_t addr, uint8_t index) {
|
||||
void is31fl3733_update_pwm_buffers(uint8_t index) {
|
||||
if (g_pwm_buffer_update_required[index]) {
|
||||
is31fl3733_select_page(addr, IS31FL3733_COMMAND_PWM);
|
||||
is31fl3733_select_page(index, IS31FL3733_COMMAND_PWM);
|
||||
|
||||
is31fl3733_write_pwm_buffer(addr, index);
|
||||
is31fl3733_write_pwm_buffer(index);
|
||||
|
||||
g_pwm_buffer_update_required[index] = false;
|
||||
}
|
||||
}
|
||||
|
||||
void is31fl3733_update_led_control_registers(uint8_t addr, uint8_t index) {
|
||||
void is31fl3733_update_led_control_registers(uint8_t index) {
|
||||
if (g_led_control_registers_update_required[index]) {
|
||||
is31fl3733_select_page(addr, IS31FL3733_COMMAND_LED_CONTROL);
|
||||
is31fl3733_select_page(index, IS31FL3733_COMMAND_LED_CONTROL);
|
||||
|
||||
for (uint8_t i = 0; i < IS31FL3733_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||
is31fl3733_write_register(addr, i, g_led_control_registers[index][i]);
|
||||
is31fl3733_write_register(index, i, g_led_control_registers[index][i]);
|
||||
}
|
||||
|
||||
g_led_control_registers_update_required[index] = false;
|
||||
|
|
@ -247,14 +260,7 @@ void is31fl3733_update_led_control_registers(uint8_t addr, uint8_t index) {
|
|||
}
|
||||
|
||||
void is31fl3733_flush(void) {
|
||||
is31fl3733_update_pwm_buffers(IS31FL3733_I2C_ADDRESS_1, 0);
|
||||
#if defined(IS31FL3733_I2C_ADDRESS_2)
|
||||
is31fl3733_update_pwm_buffers(IS31FL3733_I2C_ADDRESS_2, 1);
|
||||
# if defined(IS31FL3733_I2C_ADDRESS_3)
|
||||
is31fl3733_update_pwm_buffers(IS31FL3733_I2C_ADDRESS_3, 2);
|
||||
# if defined(IS31FL3733_I2C_ADDRESS_4)
|
||||
is31fl3733_update_pwm_buffers(IS31FL3733_I2C_ADDRESS_4, 3);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
for (uint8_t i = 0; i < IS31FL3733_DRIVER_COUNT; i++) {
|
||||
is31fl3733_update_pwm_buffers(i);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -140,9 +140,9 @@ typedef struct is31fl3733_led_t {
|
|||
extern const is31fl3733_led_t PROGMEM g_is31fl3733_leds[IS31FL3733_LED_COUNT];
|
||||
|
||||
void is31fl3733_init_drivers(void);
|
||||
void is31fl3733_init(uint8_t addr, uint8_t sync);
|
||||
void is31fl3733_write_register(uint8_t addr, uint8_t reg, uint8_t data);
|
||||
void is31fl3733_select_page(uint8_t addr, uint8_t page);
|
||||
void is31fl3733_init(uint8_t index);
|
||||
void is31fl3733_write_register(uint8_t index, uint8_t reg, uint8_t data);
|
||||
void is31fl3733_select_page(uint8_t index, uint8_t page);
|
||||
|
||||
void is31fl3733_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
|
||||
void is31fl3733_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
|
||||
|
|
@ -153,8 +153,8 @@ void is31fl3733_set_led_control_register(uint8_t index, bool red, bool green, bo
|
|||
// (eg. from a timer interrupt).
|
||||
// Call this while idle (in between matrix scans).
|
||||
// If the buffer is dirty, it will update the driver with the buffer.
|
||||
void is31fl3733_update_pwm_buffers(uint8_t addr, uint8_t index);
|
||||
void is31fl3733_update_led_control_registers(uint8_t addr, uint8_t index);
|
||||
void is31fl3733_update_pwm_buffers(uint8_t index);
|
||||
void is31fl3733_update_led_control_registers(uint8_t index);
|
||||
|
||||
void is31fl3733_flush(void);
|
||||
|
||||
|
|
|
|||
|
|
@ -46,6 +46,19 @@
|
|||
# define IS31FL3736_GLOBAL_CURRENT 0xFF
|
||||
#endif
|
||||
|
||||
const uint8_t i2c_addresses[IS31FL3736_DRIVER_COUNT] = {
|
||||
IS31FL3736_I2C_ADDRESS_1,
|
||||
#ifdef IS31FL3736_I2C_ADDRESS_2
|
||||
IS31FL3736_I2C_ADDRESS_2,
|
||||
# ifdef IS31FL3736_I2C_ADDRESS_3
|
||||
IS31FL3736_I2C_ADDRESS_3,
|
||||
# ifdef IS31FL3736_I2C_ADDRESS_4
|
||||
IS31FL3736_I2C_ADDRESS_4,
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
};
|
||||
|
||||
// These buffers match the IS31FL3736 PWM registers.
|
||||
// The control buffers match the page 0 LED On/Off registers.
|
||||
// Storing them like this is optimal for I2C transfers to the registers.
|
||||
|
|
@ -58,22 +71,22 @@ bool g_pwm_buffer_update_required[IS31FL3736_DRIVER_COUNT] = {false};
|
|||
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};
|
||||
|
||||
void is31fl3736_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
||||
void is31fl3736_write_register(uint8_t index, uint8_t reg, uint8_t data) {
|
||||
#if IS31FL3736_I2C_PERSISTENCE > 0
|
||||
for (uint8_t i = 0; i < IS31FL3736_I2C_PERSISTENCE; i++) {
|
||||
if (i2c_write_register(addr << 1, reg, &data, 1, IS31FL3736_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
if (i2c_write_register(i2c_addresses[index] << 1, reg, &data, 1, IS31FL3736_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
}
|
||||
#else
|
||||
i2c_write_register(addr << 1, reg, &data, 1, IS31FL3736_I2C_TIMEOUT);
|
||||
i2c_write_register(i2c_addresses[index] << 1, reg, &data, 1, IS31FL3736_I2C_TIMEOUT);
|
||||
#endif
|
||||
}
|
||||
|
||||
void is31fl3736_select_page(uint8_t addr, uint8_t page) {
|
||||
is31fl3736_write_register(addr, IS31FL3736_REG_COMMAND_WRITE_LOCK, IS31FL3736_COMMAND_WRITE_LOCK_MAGIC);
|
||||
is31fl3736_write_register(addr, IS31FL3736_REG_COMMAND, page);
|
||||
void is31fl3736_select_page(uint8_t index, uint8_t page) {
|
||||
is31fl3736_write_register(index, IS31FL3736_REG_COMMAND_WRITE_LOCK, IS31FL3736_COMMAND_WRITE_LOCK_MAGIC);
|
||||
is31fl3736_write_register(index, IS31FL3736_REG_COMMAND, page);
|
||||
}
|
||||
|
||||
void is31fl3736_write_pwm_buffer(uint8_t addr, uint8_t index) {
|
||||
void is31fl3736_write_pwm_buffer(uint8_t index) {
|
||||
// Assumes page 1 is already selected.
|
||||
// Transmit PWM registers in 12 transfers of 16 bytes.
|
||||
|
||||
|
|
@ -81,10 +94,10 @@ void is31fl3736_write_pwm_buffer(uint8_t addr, uint8_t index) {
|
|||
for (uint8_t i = 0; i < IS31FL3736_PWM_REGISTER_COUNT; i += 16) {
|
||||
#if IS31FL3736_I2C_PERSISTENCE > 0
|
||||
for (uint8_t j = 0; j < IS31FL3736_I2C_PERSISTENCE; j++) {
|
||||
if (i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3736_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
if (i2c_write_register(i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3736_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
}
|
||||
#else
|
||||
i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3736_I2C_TIMEOUT);
|
||||
i2c_write_register(i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3736_I2C_TIMEOUT);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
@ -92,64 +105,50 @@ void is31fl3736_write_pwm_buffer(uint8_t addr, uint8_t index) {
|
|||
void is31fl3736_init_drivers(void) {
|
||||
i2c_init();
|
||||
|
||||
is31fl3736_init(IS31FL3736_I2C_ADDRESS_1);
|
||||
#if defined(IS31FL3736_I2C_ADDRESS_2)
|
||||
is31fl3736_init(IS31FL3736_I2C_ADDRESS_2);
|
||||
# if defined(IS31FL3736_I2C_ADDRESS_3)
|
||||
is31fl3736_init(IS31FL3736_I2C_ADDRESS_3);
|
||||
# if defined(IS31FL3736_I2C_ADDRESS_4)
|
||||
is31fl3736_init(IS31FL3736_I2C_ADDRESS_4);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
for (uint8_t i = 0; i < IS31FL3736_DRIVER_COUNT; i++) {
|
||||
is31fl3736_init(i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < IS31FL3736_LED_COUNT; i++) {
|
||||
is31fl3736_set_led_control_register(i, true);
|
||||
}
|
||||
|
||||
is31fl3736_update_led_control_registers(IS31FL3736_I2C_ADDRESS_1, 0);
|
||||
#if defined(IS31FL3736_I2C_ADDRESS_2)
|
||||
is31fl3736_update_led_control_registers(IS31FL3736_I2C_ADDRESS_2, 1);
|
||||
# if defined(IS31FL3736_I2C_ADDRESS_3)
|
||||
is31fl3736_update_led_control_registers(IS31FL3736_I2C_ADDRESS_3, 2);
|
||||
# if defined(IS31FL3736_I2C_ADDRESS_4)
|
||||
is31fl3736_update_led_control_registers(IS31FL3736_I2C_ADDRESS_4, 3);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
for (uint8_t i = 0; i < IS31FL3736_DRIVER_COUNT; i++) {
|
||||
is31fl3736_update_led_control_registers(i);
|
||||
}
|
||||
}
|
||||
|
||||
void is31fl3736_init(uint8_t addr) {
|
||||
void is31fl3736_init(uint8_t index) {
|
||||
// In order to avoid the LEDs being driven with garbage data
|
||||
// in the LED driver's PWM registers, shutdown is enabled last.
|
||||
// Set up the mode and other settings, clear the PWM registers,
|
||||
// then disable software shutdown.
|
||||
|
||||
is31fl3736_select_page(addr, IS31FL3736_COMMAND_LED_CONTROL);
|
||||
is31fl3736_select_page(index, IS31FL3736_COMMAND_LED_CONTROL);
|
||||
|
||||
// Turn off all LEDs.
|
||||
for (uint8_t i = 0; i < IS31FL3736_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||
is31fl3736_write_register(addr, i, 0x00);
|
||||
is31fl3736_write_register(index, i, 0x00);
|
||||
}
|
||||
|
||||
is31fl3736_select_page(addr, IS31FL3736_COMMAND_PWM);
|
||||
is31fl3736_select_page(index, IS31FL3736_COMMAND_PWM);
|
||||
|
||||
// Set PWM on all LEDs to 0
|
||||
// No need to setup Breath registers to PWM as that is the default.
|
||||
for (uint8_t i = 0; i < IS31FL3736_PWM_REGISTER_COUNT; i++) {
|
||||
is31fl3736_write_register(addr, i, 0x00);
|
||||
is31fl3736_write_register(index, i, 0x00);
|
||||
}
|
||||
|
||||
is31fl3736_select_page(addr, IS31FL3736_COMMAND_FUNCTION);
|
||||
is31fl3736_select_page(index, IS31FL3736_COMMAND_FUNCTION);
|
||||
|
||||
// Set de-ghost pull-up resistors (SWx)
|
||||
is31fl3736_write_register(addr, IS31FL3736_FUNCTION_REG_SW_PULLUP, IS31FL3736_SW_PULLUP);
|
||||
is31fl3736_write_register(index, IS31FL3736_FUNCTION_REG_SW_PULLUP, IS31FL3736_SW_PULLUP);
|
||||
// Set de-ghost pull-down resistors (CSx)
|
||||
is31fl3736_write_register(addr, IS31FL3736_FUNCTION_REG_CS_PULLDOWN, IS31FL3736_CS_PULLDOWN);
|
||||
is31fl3736_write_register(index, IS31FL3736_FUNCTION_REG_CS_PULLDOWN, IS31FL3736_CS_PULLDOWN);
|
||||
// Set global current to maximum.
|
||||
is31fl3736_write_register(addr, IS31FL3736_FUNCTION_REG_GLOBAL_CURRENT, IS31FL3736_GLOBAL_CURRENT);
|
||||
is31fl3736_write_register(index, IS31FL3736_FUNCTION_REG_GLOBAL_CURRENT, IS31FL3736_GLOBAL_CURRENT);
|
||||
// Disable software shutdown.
|
||||
is31fl3736_write_register(addr, IS31FL3736_FUNCTION_REG_CONFIGURATION, ((IS31FL3736_PWM_FREQUENCY & 0b111) << 3) | 0x01);
|
||||
is31fl3736_write_register(index, IS31FL3736_FUNCTION_REG_CONFIGURATION, ((IS31FL3736_PWM_FREQUENCY & 0b111) << 3) | 0x01);
|
||||
|
||||
// Wait 10ms to ensure the device has woken up.
|
||||
wait_ms(10);
|
||||
|
|
@ -198,22 +197,22 @@ void is31fl3736_set_led_control_register(uint8_t index, bool value) {
|
|||
g_led_control_registers_update_required[led.driver] = true;
|
||||
}
|
||||
|
||||
void is31fl3736_update_pwm_buffers(uint8_t addr, uint8_t index) {
|
||||
void is31fl3736_update_pwm_buffers(uint8_t index) {
|
||||
if (g_pwm_buffer_update_required[index]) {
|
||||
is31fl3736_select_page(addr, IS31FL3736_COMMAND_PWM);
|
||||
is31fl3736_select_page(index, IS31FL3736_COMMAND_PWM);
|
||||
|
||||
is31fl3736_write_pwm_buffer(addr, index);
|
||||
is31fl3736_write_pwm_buffer(index);
|
||||
|
||||
g_pwm_buffer_update_required[index] = false;
|
||||
}
|
||||
}
|
||||
|
||||
void is31fl3736_update_led_control_registers(uint8_t addr, uint8_t index) {
|
||||
void is31fl3736_update_led_control_registers(uint8_t index) {
|
||||
if (g_led_control_registers_update_required[index]) {
|
||||
is31fl3736_select_page(addr, IS31FL3736_COMMAND_LED_CONTROL);
|
||||
is31fl3736_select_page(index, IS31FL3736_COMMAND_LED_CONTROL);
|
||||
|
||||
for (uint8_t i = 0; i < IS31FL3736_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||
is31fl3736_write_register(addr, i, g_led_control_registers[index][i]);
|
||||
is31fl3736_write_register(index, i, g_led_control_registers[index][i]);
|
||||
}
|
||||
|
||||
g_led_control_registers_update_required[index] = false;
|
||||
|
|
@ -221,14 +220,7 @@ void is31fl3736_update_led_control_registers(uint8_t addr, uint8_t index) {
|
|||
}
|
||||
|
||||
void is31fl3736_flush(void) {
|
||||
is31fl3736_update_pwm_buffers(IS31FL3736_I2C_ADDRESS_1, 0);
|
||||
#if defined(IS31FL3736_I2C_ADDRESS_2)
|
||||
is31fl3736_update_pwm_buffers(IS31FL3736_I2C_ADDRESS_2, 1);
|
||||
# if defined(IS31FL3736_I2C_ADDRESS_3)
|
||||
is31fl3736_update_pwm_buffers(IS31FL3736_I2C_ADDRESS_3, 2);
|
||||
# if defined(IS31FL3736_I2C_ADDRESS_4)
|
||||
is31fl3736_update_pwm_buffers(IS31FL3736_I2C_ADDRESS_4, 3);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
for (uint8_t i = 0; i < IS31FL3736_DRIVER_COUNT; i++) {
|
||||
is31fl3736_update_pwm_buffers(i);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -110,9 +110,9 @@ typedef struct is31fl3736_led_t {
|
|||
extern const is31fl3736_led_t PROGMEM g_is31fl3736_leds[IS31FL3736_LED_COUNT];
|
||||
|
||||
void is31fl3736_init_drivers(void);
|
||||
void is31fl3736_init(uint8_t addr);
|
||||
void is31fl3736_write_register(uint8_t addr, uint8_t reg, uint8_t data);
|
||||
void is31fl3736_select_page(uint8_t addr, uint8_t page);
|
||||
void is31fl3736_init(uint8_t index);
|
||||
void is31fl3736_write_register(uint8_t index, uint8_t reg, uint8_t data);
|
||||
void is31fl3736_select_page(uint8_t index, uint8_t page);
|
||||
|
||||
void is31fl3736_set_value(int index, uint8_t value);
|
||||
void is31fl3736_set_value_all(uint8_t value);
|
||||
|
|
@ -123,8 +123,8 @@ void is31fl3736_set_led_control_register(uint8_t index, bool value);
|
|||
// (eg. from a timer interrupt).
|
||||
// Call this while idle (in between matrix scans).
|
||||
// If the buffer is dirty, it will update the driver with the buffer.
|
||||
void is31fl3736_update_pwm_buffers(uint8_t addr, uint8_t index);
|
||||
void is31fl3736_update_led_control_registers(uint8_t addr, uint8_t index);
|
||||
void is31fl3736_update_pwm_buffers(uint8_t index);
|
||||
void is31fl3736_update_led_control_registers(uint8_t index);
|
||||
|
||||
void is31fl3736_flush(void);
|
||||
|
||||
|
|
|
|||
|
|
@ -46,6 +46,19 @@
|
|||
# define IS31FL3736_GLOBAL_CURRENT 0xFF
|
||||
#endif
|
||||
|
||||
const uint8_t i2c_addresses[IS31FL3736_DRIVER_COUNT] = {
|
||||
IS31FL3736_I2C_ADDRESS_1,
|
||||
#ifdef IS31FL3736_I2C_ADDRESS_2
|
||||
IS31FL3736_I2C_ADDRESS_2,
|
||||
# ifdef IS31FL3736_I2C_ADDRESS_3
|
||||
IS31FL3736_I2C_ADDRESS_3,
|
||||
# ifdef IS31FL3736_I2C_ADDRESS_4
|
||||
IS31FL3736_I2C_ADDRESS_4,
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
};
|
||||
|
||||
// These buffers match the IS31FL3736 PWM registers.
|
||||
// The control buffers match the page 0 LED On/Off registers.
|
||||
// Storing them like this is optimal for I2C transfers to the registers.
|
||||
|
|
@ -58,22 +71,22 @@ bool g_pwm_buffer_update_required[IS31FL3736_DRIVER_COUNT] = {false};
|
|||
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};
|
||||
|
||||
void is31fl3736_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
||||
void is31fl3736_write_register(uint8_t index, uint8_t reg, uint8_t data) {
|
||||
#if IS31FL3736_I2C_PERSISTENCE > 0
|
||||
for (uint8_t i = 0; i < IS31FL3736_I2C_PERSISTENCE; i++) {
|
||||
if (i2c_write_register(addr << 1, reg, &data, 1, IS31FL3736_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
if (i2c_write_register(i2c_addresses[index] << 1, reg, &data, 1, IS31FL3736_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
}
|
||||
#else
|
||||
i2c_write_register(addr << 1, reg, &data, 1, IS31FL3736_I2C_TIMEOUT);
|
||||
i2c_write_register(i2c_addresses[index] << 1, reg, &data, 1, IS31FL3736_I2C_TIMEOUT);
|
||||
#endif
|
||||
}
|
||||
|
||||
void is31fl3736_select_page(uint8_t addr, uint8_t page) {
|
||||
is31fl3736_write_register(addr, IS31FL3736_REG_COMMAND_WRITE_LOCK, IS31FL3736_COMMAND_WRITE_LOCK_MAGIC);
|
||||
is31fl3736_write_register(addr, IS31FL3736_REG_COMMAND, page);
|
||||
void is31fl3736_select_page(uint8_t index, uint8_t page) {
|
||||
is31fl3736_write_register(index, IS31FL3736_REG_COMMAND_WRITE_LOCK, IS31FL3736_COMMAND_WRITE_LOCK_MAGIC);
|
||||
is31fl3736_write_register(index, IS31FL3736_REG_COMMAND, page);
|
||||
}
|
||||
|
||||
void is31fl3736_write_pwm_buffer(uint8_t addr, uint8_t index) {
|
||||
void is31fl3736_write_pwm_buffer(uint8_t index) {
|
||||
// Assumes page 1 is already selected.
|
||||
// Transmit PWM registers in 12 transfers of 16 bytes.
|
||||
|
||||
|
|
@ -81,10 +94,10 @@ void is31fl3736_write_pwm_buffer(uint8_t addr, uint8_t index) {
|
|||
for (uint8_t i = 0; i < IS31FL3736_PWM_REGISTER_COUNT; i += 16) {
|
||||
#if IS31FL3736_I2C_PERSISTENCE > 0
|
||||
for (uint8_t j = 0; j < IS31FL3736_I2C_PERSISTENCE; j++) {
|
||||
if (i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3736_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
if (i2c_write_register(i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3736_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
}
|
||||
#else
|
||||
i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3736_I2C_TIMEOUT);
|
||||
i2c_write_register(i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3736_I2C_TIMEOUT);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
@ -92,64 +105,50 @@ void is31fl3736_write_pwm_buffer(uint8_t addr, uint8_t index) {
|
|||
void is31fl3736_init_drivers(void) {
|
||||
i2c_init();
|
||||
|
||||
is31fl3736_init(IS31FL3736_I2C_ADDRESS_1);
|
||||
#if defined(IS31FL3736_I2C_ADDRESS_2)
|
||||
is31fl3736_init(IS31FL3736_I2C_ADDRESS_2);
|
||||
# if defined(IS31FL3736_I2C_ADDRESS_3)
|
||||
is31fl3736_init(IS31FL3736_I2C_ADDRESS_3);
|
||||
# if defined(IS31FL3736_I2C_ADDRESS_4)
|
||||
is31fl3736_init(IS31FL3736_I2C_ADDRESS_4);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
for (uint8_t i = 0; i < IS31FL3736_DRIVER_COUNT; i++) {
|
||||
is31fl3736_init(i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < IS31FL3736_LED_COUNT; i++) {
|
||||
is31fl3736_set_led_control_register(i, true, true, true);
|
||||
}
|
||||
|
||||
is31fl3736_update_led_control_registers(IS31FL3736_I2C_ADDRESS_1, 0);
|
||||
#if defined(IS31FL3736_I2C_ADDRESS_2)
|
||||
is31fl3736_update_led_control_registers(IS31FL3736_I2C_ADDRESS_2, 1);
|
||||
# if defined(IS31FL3736_I2C_ADDRESS_3)
|
||||
is31fl3736_update_led_control_registers(IS31FL3736_I2C_ADDRESS_3, 2);
|
||||
# if defined(IS31FL3736_I2C_ADDRESS_4)
|
||||
is31fl3736_update_led_control_registers(IS31FL3736_I2C_ADDRESS_4, 3);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
for (uint8_t i = 0; i < IS31FL3736_DRIVER_COUNT; i++) {
|
||||
is31fl3736_update_led_control_registers(i);
|
||||
}
|
||||
}
|
||||
|
||||
void is31fl3736_init(uint8_t addr) {
|
||||
void is31fl3736_init(uint8_t index) {
|
||||
// In order to avoid the LEDs being driven with garbage data
|
||||
// in the LED driver's PWM registers, shutdown is enabled last.
|
||||
// Set up the mode and other settings, clear the PWM registers,
|
||||
// then disable software shutdown.
|
||||
|
||||
is31fl3736_select_page(addr, IS31FL3736_COMMAND_LED_CONTROL);
|
||||
is31fl3736_select_page(index, IS31FL3736_COMMAND_LED_CONTROL);
|
||||
|
||||
// Turn off all LEDs.
|
||||
for (uint8_t i = 0; i < IS31FL3736_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||
is31fl3736_write_register(addr, i, 0x00);
|
||||
is31fl3736_write_register(index, i, 0x00);
|
||||
}
|
||||
|
||||
is31fl3736_select_page(addr, IS31FL3736_COMMAND_PWM);
|
||||
is31fl3736_select_page(index, IS31FL3736_COMMAND_PWM);
|
||||
|
||||
// Set PWM on all LEDs to 0
|
||||
// No need to setup Breath registers to PWM as that is the default.
|
||||
for (uint8_t i = 0; i < IS31FL3736_PWM_REGISTER_COUNT; i++) {
|
||||
is31fl3736_write_register(addr, i, 0x00);
|
||||
is31fl3736_write_register(index, i, 0x00);
|
||||
}
|
||||
|
||||
is31fl3736_select_page(addr, IS31FL3736_COMMAND_FUNCTION);
|
||||
is31fl3736_select_page(index, IS31FL3736_COMMAND_FUNCTION);
|
||||
|
||||
// Set de-ghost pull-up resistors (SWx)
|
||||
is31fl3736_write_register(addr, IS31FL3736_FUNCTION_REG_SW_PULLUP, IS31FL3736_SW_PULLUP);
|
||||
is31fl3736_write_register(index, IS31FL3736_FUNCTION_REG_SW_PULLUP, IS31FL3736_SW_PULLUP);
|
||||
// Set de-ghost pull-down resistors (CSx)
|
||||
is31fl3736_write_register(addr, IS31FL3736_FUNCTION_REG_CS_PULLDOWN, IS31FL3736_CS_PULLDOWN);
|
||||
is31fl3736_write_register(index, IS31FL3736_FUNCTION_REG_CS_PULLDOWN, IS31FL3736_CS_PULLDOWN);
|
||||
// Set global current to maximum.
|
||||
is31fl3736_write_register(addr, IS31FL3736_FUNCTION_REG_GLOBAL_CURRENT, IS31FL3736_GLOBAL_CURRENT);
|
||||
is31fl3736_write_register(index, IS31FL3736_FUNCTION_REG_GLOBAL_CURRENT, IS31FL3736_GLOBAL_CURRENT);
|
||||
// Disable software shutdown.
|
||||
is31fl3736_write_register(addr, IS31FL3736_FUNCTION_REG_CONFIGURATION, ((IS31FL3736_PWM_FREQUENCY & 0b111) << 3) | 0x01);
|
||||
is31fl3736_write_register(index, IS31FL3736_FUNCTION_REG_CONFIGURATION, ((IS31FL3736_PWM_FREQUENCY & 0b111) << 3) | 0x01);
|
||||
|
||||
// Wait 10ms to ensure the device has woken up.
|
||||
wait_ms(10);
|
||||
|
|
@ -215,22 +214,22 @@ void is31fl3736_set_led_control_register(uint8_t index, bool red, bool green, bo
|
|||
g_led_control_registers_update_required[led.driver] = true;
|
||||
}
|
||||
|
||||
void is31fl3736_update_pwm_buffers(uint8_t addr, uint8_t index) {
|
||||
void is31fl3736_update_pwm_buffers(uint8_t index) {
|
||||
if (g_pwm_buffer_update_required[index]) {
|
||||
is31fl3736_select_page(addr, IS31FL3736_COMMAND_PWM);
|
||||
is31fl3736_select_page(index, IS31FL3736_COMMAND_PWM);
|
||||
|
||||
is31fl3736_write_pwm_buffer(addr, index);
|
||||
is31fl3736_write_pwm_buffer(index);
|
||||
|
||||
g_pwm_buffer_update_required[index] = false;
|
||||
}
|
||||
}
|
||||
|
||||
void is31fl3736_update_led_control_registers(uint8_t addr, uint8_t index) {
|
||||
void is31fl3736_update_led_control_registers(uint8_t index) {
|
||||
if (g_led_control_registers_update_required[index]) {
|
||||
is31fl3736_select_page(addr, IS31FL3736_COMMAND_LED_CONTROL);
|
||||
is31fl3736_select_page(index, IS31FL3736_COMMAND_LED_CONTROL);
|
||||
|
||||
for (uint8_t i = 0; i < IS31FL3736_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||
is31fl3736_write_register(addr, i, g_led_control_registers[index][i]);
|
||||
is31fl3736_write_register(index, i, g_led_control_registers[index][i]);
|
||||
}
|
||||
|
||||
g_led_control_registers_update_required[index] = false;
|
||||
|
|
@ -238,14 +237,7 @@ void is31fl3736_update_led_control_registers(uint8_t addr, uint8_t index) {
|
|||
}
|
||||
|
||||
void is31fl3736_flush(void) {
|
||||
is31fl3736_update_pwm_buffers(IS31FL3736_I2C_ADDRESS_1, 0);
|
||||
#if defined(IS31FL3736_I2C_ADDRESS_2)
|
||||
is31fl3736_update_pwm_buffers(IS31FL3736_I2C_ADDRESS_2, 1);
|
||||
# if defined(IS31FL3736_I2C_ADDRESS_3)
|
||||
is31fl3736_update_pwm_buffers(IS31FL3736_I2C_ADDRESS_3, 2);
|
||||
# if defined(IS31FL3736_I2C_ADDRESS_4)
|
||||
is31fl3736_update_pwm_buffers(IS31FL3736_I2C_ADDRESS_4, 3);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
for (uint8_t i = 0; i < IS31FL3736_DRIVER_COUNT; i++) {
|
||||
is31fl3736_update_pwm_buffers(i);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,9 +124,9 @@ typedef struct is31fl3736_led_t {
|
|||
extern const is31fl3736_led_t PROGMEM g_is31fl3736_leds[IS31FL3736_LED_COUNT];
|
||||
|
||||
void is31fl3736_init_drivers(void);
|
||||
void is31fl3736_init(uint8_t addr);
|
||||
void is31fl3736_write_register(uint8_t addr, uint8_t reg, uint8_t data);
|
||||
void is31fl3736_select_page(uint8_t addr, uint8_t page);
|
||||
void is31fl3736_init(uint8_t index);
|
||||
void is31fl3736_write_register(uint8_t index, uint8_t reg, uint8_t data);
|
||||
void is31fl3736_select_page(uint8_t index, uint8_t page);
|
||||
|
||||
void is31fl3736_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
|
||||
void is31fl3736_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
|
||||
|
|
@ -137,8 +137,8 @@ void is31fl3736_set_led_control_register(uint8_t index, bool red, bool green, bo
|
|||
// (eg. from a timer interrupt).
|
||||
// Call this while idle (in between matrix scans).
|
||||
// If the buffer is dirty, it will update the driver with the buffer.
|
||||
void is31fl3736_update_pwm_buffers(uint8_t addr, uint8_t index);
|
||||
void is31fl3736_update_led_control_registers(uint8_t addr, uint8_t index);
|
||||
void is31fl3736_update_pwm_buffers(uint8_t index);
|
||||
void is31fl3736_update_led_control_registers(uint8_t index);
|
||||
|
||||
void is31fl3736_flush(void);
|
||||
|
||||
|
|
|
|||
|
|
@ -48,6 +48,19 @@
|
|||
# define IS31FL3737_GLOBAL_CURRENT 0xFF
|
||||
#endif
|
||||
|
||||
const uint8_t i2c_addresses[IS31FL3737_DRIVER_COUNT] = {
|
||||
IS31FL3737_I2C_ADDRESS_1,
|
||||
#ifdef IS31FL3737_I2C_ADDRESS_2
|
||||
IS31FL3737_I2C_ADDRESS_2,
|
||||
# ifdef IS31FL3737_I2C_ADDRESS_3
|
||||
IS31FL3737_I2C_ADDRESS_3,
|
||||
# ifdef IS31FL3737_I2C_ADDRESS_4
|
||||
IS31FL3737_I2C_ADDRESS_4,
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
};
|
||||
|
||||
// These buffers match the IS31FL3737 PWM registers.
|
||||
// The control buffers match the page 0 LED On/Off registers.
|
||||
// Storing them like this is optimal for I2C transfers to the registers.
|
||||
|
|
@ -61,22 +74,22 @@ bool g_pwm_buffer_update_required[IS31FL3737_DRIVER_COUNT] = {false};
|
|||
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};
|
||||
|
||||
void is31fl3737_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
||||
void is31fl3737_write_register(uint8_t index, uint8_t reg, uint8_t data) {
|
||||
#if IS31FL3737_I2C_PERSISTENCE > 0
|
||||
for (uint8_t i = 0; i < IS31FL3737_I2C_PERSISTENCE; i++) {
|
||||
if (i2c_write_register(addr << 1, reg, &data, 1, IS31FL3737_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
if (i2c_write_register(i2c_addresses[index] << 1, reg, &data, 1, IS31FL3737_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
}
|
||||
#else
|
||||
i2c_write_register(addr << 1, reg, &data, 1, IS31FL3737_I2C_TIMEOUT);
|
||||
i2c_write_register(i2c_addresses[index] << 1, reg, &data, 1, IS31FL3737_I2C_TIMEOUT);
|
||||
#endif
|
||||
}
|
||||
|
||||
void is31fl3737_select_page(uint8_t addr, uint8_t page) {
|
||||
is31fl3737_write_register(addr, IS31FL3737_REG_COMMAND_WRITE_LOCK, IS31FL3737_COMMAND_WRITE_LOCK_MAGIC);
|
||||
is31fl3737_write_register(addr, IS31FL3737_REG_COMMAND, page);
|
||||
void is31fl3737_select_page(uint8_t index, uint8_t page) {
|
||||
is31fl3737_write_register(index, IS31FL3737_REG_COMMAND_WRITE_LOCK, IS31FL3737_COMMAND_WRITE_LOCK_MAGIC);
|
||||
is31fl3737_write_register(index, IS31FL3737_REG_COMMAND, page);
|
||||
}
|
||||
|
||||
void is31fl3737_write_pwm_buffer(uint8_t addr, uint8_t index) {
|
||||
void is31fl3737_write_pwm_buffer(uint8_t index) {
|
||||
// Assumes page 1 is already selected.
|
||||
// Transmit PWM registers in 12 transfers of 16 bytes.
|
||||
|
||||
|
|
@ -84,10 +97,10 @@ void is31fl3737_write_pwm_buffer(uint8_t addr, uint8_t index) {
|
|||
for (uint8_t i = 0; i < IS31FL3737_PWM_REGISTER_COUNT; i += 16) {
|
||||
#if IS31FL3737_I2C_PERSISTENCE > 0
|
||||
for (uint8_t j = 0; j < IS31FL3737_I2C_PERSISTENCE; j++) {
|
||||
if (i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3737_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
if (i2c_write_register(i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3737_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
}
|
||||
#else
|
||||
i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3737_I2C_TIMEOUT);
|
||||
i2c_write_register(i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3737_I2C_TIMEOUT);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
@ -95,64 +108,50 @@ void is31fl3737_write_pwm_buffer(uint8_t addr, uint8_t index) {
|
|||
void is31fl3737_init_drivers(void) {
|
||||
i2c_init();
|
||||
|
||||
is31fl3737_init(IS31FL3737_I2C_ADDRESS_1);
|
||||
#if defined(IS31FL3737_I2C_ADDRESS_2)
|
||||
is31fl3737_init(IS31FL3737_I2C_ADDRESS_2);
|
||||
# if defined(IS31FL3737_I2C_ADDRESS_3)
|
||||
is31fl3737_init(IS31FL3737_I2C_ADDRESS_3);
|
||||
# if defined(IS31FL3737_I2C_ADDRESS_4)
|
||||
is31fl3737_init(IS31FL3737_I2C_ADDRESS_4);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
for (uint8_t i = 0; i < IS31FL3737_DRIVER_COUNT; i++) {
|
||||
is31fl3737_init(i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < IS31FL3737_LED_COUNT; i++) {
|
||||
is31fl3737_set_led_control_register(i, true);
|
||||
}
|
||||
|
||||
is31fl3737_update_led_control_registers(IS31FL3737_I2C_ADDRESS_1, 0);
|
||||
#if defined(IS31FL3737_I2C_ADDRESS_2)
|
||||
is31fl3737_update_led_control_registers(IS31FL3737_I2C_ADDRESS_2, 1);
|
||||
# if defined(IS31FL3737_I2C_ADDRESS_3)
|
||||
is31fl3737_update_led_control_registers(IS31FL3737_I2C_ADDRESS_3, 2);
|
||||
# if defined(IS31FL3737_I2C_ADDRESS_4)
|
||||
is31fl3737_update_led_control_registers(IS31FL3737_I2C_ADDRESS_4, 3);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
for (uint8_t i = 0; i < IS31FL3737_DRIVER_COUNT; i++) {
|
||||
is31fl3737_update_led_control_registers(i);
|
||||
}
|
||||
}
|
||||
|
||||
void is31fl3737_init(uint8_t addr) {
|
||||
void is31fl3737_init(uint8_t index) {
|
||||
// In order to avoid the LEDs being driven with garbage data
|
||||
// in the LED driver's PWM registers, shutdown is enabled last.
|
||||
// Set up the mode and other settings, clear the PWM registers,
|
||||
// then disable software shutdown.
|
||||
|
||||
is31fl3737_select_page(addr, IS31FL3737_COMMAND_LED_CONTROL);
|
||||
is31fl3737_select_page(index, IS31FL3737_COMMAND_LED_CONTROL);
|
||||
|
||||
// Turn off all LEDs.
|
||||
for (uint8_t i = 0; i < IS31FL3737_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||
is31fl3737_write_register(addr, i, 0x00);
|
||||
is31fl3737_write_register(index, i, 0x00);
|
||||
}
|
||||
|
||||
is31fl3737_select_page(addr, IS31FL3737_COMMAND_PWM);
|
||||
is31fl3737_select_page(index, IS31FL3737_COMMAND_PWM);
|
||||
|
||||
// Set PWM on all LEDs to 0
|
||||
// No need to setup Breath registers to PWM as that is the default.
|
||||
for (uint8_t i = 0; i < IS31FL3737_PWM_REGISTER_COUNT; i++) {
|
||||
is31fl3737_write_register(addr, i, 0x00);
|
||||
is31fl3737_write_register(index, i, 0x00);
|
||||
}
|
||||
|
||||
is31fl3737_select_page(addr, IS31FL3737_COMMAND_FUNCTION);
|
||||
is31fl3737_select_page(index, IS31FL3737_COMMAND_FUNCTION);
|
||||
|
||||
// Set de-ghost pull-up resistors (SWx)
|
||||
is31fl3737_write_register(addr, IS31FL3737_FUNCTION_REG_SW_PULLUP, IS31FL3737_SW_PULLUP);
|
||||
is31fl3737_write_register(index, IS31FL3737_FUNCTION_REG_SW_PULLUP, IS31FL3737_SW_PULLUP);
|
||||
// Set de-ghost pull-down resistors (CSx)
|
||||
is31fl3737_write_register(addr, IS31FL3737_FUNCTION_REG_CS_PULLDOWN, IS31FL3737_CS_PULLDOWN);
|
||||
is31fl3737_write_register(index, IS31FL3737_FUNCTION_REG_CS_PULLDOWN, IS31FL3737_CS_PULLDOWN);
|
||||
// Set global current to maximum.
|
||||
is31fl3737_write_register(addr, IS31FL3737_FUNCTION_REG_GLOBAL_CURRENT, IS31FL3737_GLOBAL_CURRENT);
|
||||
is31fl3737_write_register(index, IS31FL3737_FUNCTION_REG_GLOBAL_CURRENT, IS31FL3737_GLOBAL_CURRENT);
|
||||
// Disable software shutdown.
|
||||
is31fl3737_write_register(addr, IS31FL3737_FUNCTION_REG_CONFIGURATION, ((IS31FL3737_PWM_FREQUENCY & 0b111) << 3) | 0x01);
|
||||
is31fl3737_write_register(index, IS31FL3737_FUNCTION_REG_CONFIGURATION, ((IS31FL3737_PWM_FREQUENCY & 0b111) << 3) | 0x01);
|
||||
|
||||
// Wait 10ms to ensure the device has woken up.
|
||||
wait_ms(10);
|
||||
|
|
@ -195,22 +194,22 @@ void is31fl3737_set_led_control_register(uint8_t index, bool value) {
|
|||
g_led_control_registers_update_required[led.driver] = true;
|
||||
}
|
||||
|
||||
void is31fl3737_update_pwm_buffers(uint8_t addr, uint8_t index) {
|
||||
void is31fl3737_update_pwm_buffers(uint8_t index) {
|
||||
if (g_pwm_buffer_update_required[index]) {
|
||||
is31fl3737_select_page(addr, IS31FL3737_COMMAND_PWM);
|
||||
is31fl3737_select_page(index, IS31FL3737_COMMAND_PWM);
|
||||
|
||||
is31fl3737_write_pwm_buffer(addr, index);
|
||||
is31fl3737_write_pwm_buffer(index);
|
||||
|
||||
g_pwm_buffer_update_required[index] = false;
|
||||
}
|
||||
}
|
||||
|
||||
void is31fl3737_update_led_control_registers(uint8_t addr, uint8_t index) {
|
||||
void is31fl3737_update_led_control_registers(uint8_t index) {
|
||||
if (g_led_control_registers_update_required[index]) {
|
||||
is31fl3737_select_page(addr, IS31FL3737_COMMAND_LED_CONTROL);
|
||||
is31fl3737_select_page(index, IS31FL3737_COMMAND_LED_CONTROL);
|
||||
|
||||
for (uint8_t i = 0; i < IS31FL3737_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||
is31fl3737_write_register(addr, i, g_led_control_registers[index][i]);
|
||||
is31fl3737_write_register(index, i, g_led_control_registers[index][i]);
|
||||
}
|
||||
|
||||
g_led_control_registers_update_required[index] = false;
|
||||
|
|
@ -218,14 +217,7 @@ void is31fl3737_update_led_control_registers(uint8_t addr, uint8_t index) {
|
|||
}
|
||||
|
||||
void is31fl3737_flush(void) {
|
||||
is31fl3737_update_pwm_buffers(IS31FL3737_I2C_ADDRESS_1, 0);
|
||||
#if defined(IS31FL3737_I2C_ADDRESS_2)
|
||||
is31fl3737_update_pwm_buffers(IS31FL3737_I2C_ADDRESS_2, 1);
|
||||
# if defined(IS31FL3737_I2C_ADDRESS_3)
|
||||
is31fl3737_update_pwm_buffers(IS31FL3737_I2C_ADDRESS_3, 2);
|
||||
# if defined(IS31FL3737_I2C_ADDRESS_4)
|
||||
is31fl3737_update_pwm_buffers(IS31FL3737_I2C_ADDRESS_4, 3);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
for (uint8_t i = 0; i < IS31FL3737_DRIVER_COUNT; i++) {
|
||||
is31fl3737_update_pwm_buffers(i);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,9 +100,9 @@ typedef struct is31fl3737_led_t {
|
|||
extern const is31fl3737_led_t PROGMEM g_is31fl3737_leds[IS31FL3737_LED_COUNT];
|
||||
|
||||
void is31fl3737_init_drivers(void);
|
||||
void is31fl3737_init(uint8_t addr);
|
||||
void is31fl3737_write_register(uint8_t addr, uint8_t reg, uint8_t data);
|
||||
void is31fl3737_select_page(uint8_t addr, uint8_t page);
|
||||
void is31fl3737_init(uint8_t index);
|
||||
void is31fl3737_write_register(uint8_t index, uint8_t reg, uint8_t data);
|
||||
void is31fl3737_select_page(uint8_t index, uint8_t page);
|
||||
|
||||
void is31fl3737_set_value(int index, uint8_t value);
|
||||
void is31fl3737_set_value_all(uint8_t value);
|
||||
|
|
@ -113,8 +113,8 @@ void is31fl3737_set_led_control_register(uint8_t index, bool value);
|
|||
// (eg. from a timer interrupt).
|
||||
// Call this while idle (in between matrix scans).
|
||||
// If the buffer is dirty, it will update the driver with the buffer.
|
||||
void is31fl3737_update_pwm_buffers(uint8_t addr, uint8_t index);
|
||||
void is31fl3737_update_led_control_registers(uint8_t addr, uint8_t index);
|
||||
void is31fl3737_update_pwm_buffers(uint8_t index);
|
||||
void is31fl3737_update_led_control_registers(uint8_t index);
|
||||
|
||||
void is31fl3737_flush(void);
|
||||
|
||||
|
|
|
|||
|
|
@ -48,6 +48,19 @@
|
|||
# define IS31FL3737_GLOBAL_CURRENT 0xFF
|
||||
#endif
|
||||
|
||||
const uint8_t i2c_addresses[IS31FL3737_DRIVER_COUNT] = {
|
||||
IS31FL3737_I2C_ADDRESS_1,
|
||||
#ifdef IS31FL3737_I2C_ADDRESS_2
|
||||
IS31FL3737_I2C_ADDRESS_2,
|
||||
# ifdef IS31FL3737_I2C_ADDRESS_3
|
||||
IS31FL3737_I2C_ADDRESS_3,
|
||||
# ifdef IS31FL3737_I2C_ADDRESS_4
|
||||
IS31FL3737_I2C_ADDRESS_4,
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
};
|
||||
|
||||
// These buffers match the IS31FL3737 PWM registers.
|
||||
// The control buffers match the page 0 LED On/Off registers.
|
||||
// Storing them like this is optimal for I2C transfers to the registers.
|
||||
|
|
@ -61,22 +74,22 @@ bool g_pwm_buffer_update_required[IS31FL3737_DRIVER_COUNT] = {false};
|
|||
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};
|
||||
|
||||
void is31fl3737_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
||||
void is31fl3737_write_register(uint8_t index, uint8_t reg, uint8_t data) {
|
||||
#if IS31FL3737_I2C_PERSISTENCE > 0
|
||||
for (uint8_t i = 0; i < IS31FL3737_I2C_PERSISTENCE; i++) {
|
||||
if (i2c_write_register(addr << 1, reg, &data, 1, IS31FL3737_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
if (i2c_write_register(i2c_addresses[index] << 1, reg, &data, 1, IS31FL3737_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
}
|
||||
#else
|
||||
i2c_write_register(addr << 1, reg, &data, 1, IS31FL3737_I2C_TIMEOUT);
|
||||
i2c_write_register(i2c_addresses[index] << 1, reg, &data, 1, IS31FL3737_I2C_TIMEOUT);
|
||||
#endif
|
||||
}
|
||||
|
||||
void is31fl3737_select_page(uint8_t addr, uint8_t page) {
|
||||
is31fl3737_write_register(addr, IS31FL3737_REG_COMMAND_WRITE_LOCK, IS31FL3737_COMMAND_WRITE_LOCK_MAGIC);
|
||||
is31fl3737_write_register(addr, IS31FL3737_REG_COMMAND, page);
|
||||
void is31fl3737_select_page(uint8_t index, uint8_t page) {
|
||||
is31fl3737_write_register(index, IS31FL3737_REG_COMMAND_WRITE_LOCK, IS31FL3737_COMMAND_WRITE_LOCK_MAGIC);
|
||||
is31fl3737_write_register(index, IS31FL3737_REG_COMMAND, page);
|
||||
}
|
||||
|
||||
void is31fl3737_write_pwm_buffer(uint8_t addr, uint8_t index) {
|
||||
void is31fl3737_write_pwm_buffer(uint8_t index) {
|
||||
// Assumes page 1 is already selected.
|
||||
// Transmit PWM registers in 12 transfers of 16 bytes.
|
||||
|
||||
|
|
@ -84,10 +97,10 @@ void is31fl3737_write_pwm_buffer(uint8_t addr, uint8_t index) {
|
|||
for (uint8_t i = 0; i < IS31FL3737_PWM_REGISTER_COUNT; i += 16) {
|
||||
#if IS31FL3737_I2C_PERSISTENCE > 0
|
||||
for (uint8_t j = 0; j < IS31FL3737_I2C_PERSISTENCE; j++) {
|
||||
if (i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3737_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
if (i2c_write_register(i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3737_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
}
|
||||
#else
|
||||
i2c_write_register(addr << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3737_I2C_TIMEOUT);
|
||||
i2c_write_register(i2c_addresses[index] << 1, i, g_pwm_buffer[index] + i, 16, IS31FL3737_I2C_TIMEOUT);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
@ -95,64 +108,50 @@ void is31fl3737_write_pwm_buffer(uint8_t addr, uint8_t index) {
|
|||
void is31fl3737_init_drivers(void) {
|
||||
i2c_init();
|
||||
|
||||
is31fl3737_init(IS31FL3737_I2C_ADDRESS_1);
|
||||
#if defined(IS31FL3737_I2C_ADDRESS_2)
|
||||
is31fl3737_init(IS31FL3737_I2C_ADDRESS_2);
|
||||
# if defined(IS31FL3737_I2C_ADDRESS_3)
|
||||
is31fl3737_init(IS31FL3737_I2C_ADDRESS_3);
|
||||
# if defined(IS31FL3737_I2C_ADDRESS_4)
|
||||
is31fl3737_init(IS31FL3737_I2C_ADDRESS_4);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
for (uint8_t i = 0; i < IS31FL3737_DRIVER_COUNT; i++) {
|
||||
is31fl3737_init(i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < IS31FL3737_LED_COUNT; i++) {
|
||||
is31fl3737_set_led_control_register(i, true, true, true);
|
||||
}
|
||||
|
||||
is31fl3737_update_led_control_registers(IS31FL3737_I2C_ADDRESS_1, 0);
|
||||
#if defined(IS31FL3737_I2C_ADDRESS_2)
|
||||
is31fl3737_update_led_control_registers(IS31FL3737_I2C_ADDRESS_2, 1);
|
||||
# if defined(IS31FL3737_I2C_ADDRESS_3)
|
||||
is31fl3737_update_led_control_registers(IS31FL3737_I2C_ADDRESS_3, 2);
|
||||
# if defined(IS31FL3737_I2C_ADDRESS_4)
|
||||
is31fl3737_update_led_control_registers(IS31FL3737_I2C_ADDRESS_4, 3);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
for (uint8_t i = 0; i < IS31FL3737_DRIVER_COUNT; i++) {
|
||||
is31fl3737_update_led_control_registers(i);
|
||||
}
|
||||
}
|
||||
|
||||
void is31fl3737_init(uint8_t addr) {
|
||||
void is31fl3737_init(uint8_t index) {
|
||||
// In order to avoid the LEDs being driven with garbage data
|
||||
// in the LED driver's PWM registers, shutdown is enabled last.
|
||||
// Set up the mode and other settings, clear the PWM registers,
|
||||
// then disable software shutdown.
|
||||
|
||||
is31fl3737_select_page(addr, IS31FL3737_COMMAND_LED_CONTROL);
|
||||
is31fl3737_select_page(index, IS31FL3737_COMMAND_LED_CONTROL);
|
||||
|
||||
// Turn off all LEDs.
|
||||
for (uint8_t i = 0; i < IS31FL3737_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||
is31fl3737_write_register(addr, i, 0x00);
|
||||
is31fl3737_write_register(index, i, 0x00);
|
||||
}
|
||||
|
||||
is31fl3737_select_page(addr, IS31FL3737_COMMAND_PWM);
|
||||
is31fl3737_select_page(index, IS31FL3737_COMMAND_PWM);
|
||||
|
||||
// Set PWM on all LEDs to 0
|
||||
// No need to setup Breath registers to PWM as that is the default.
|
||||
for (uint8_t i = 0; i < IS31FL3737_PWM_REGISTER_COUNT; i++) {
|
||||
is31fl3737_write_register(addr, i, 0x00);
|
||||
is31fl3737_write_register(index, i, 0x00);
|
||||
}
|
||||
|
||||
is31fl3737_select_page(addr, IS31FL3737_COMMAND_FUNCTION);
|
||||
is31fl3737_select_page(index, IS31FL3737_COMMAND_FUNCTION);
|
||||
|
||||
// Set de-ghost pull-up resistors (SWx)
|
||||
is31fl3737_write_register(addr, IS31FL3737_FUNCTION_REG_SW_PULLUP, IS31FL3737_SW_PULLUP);
|
||||
is31fl3737_write_register(index, IS31FL3737_FUNCTION_REG_SW_PULLUP, IS31FL3737_SW_PULLUP);
|
||||
// Set de-ghost pull-down resistors (CSx)
|
||||
is31fl3737_write_register(addr, IS31FL3737_FUNCTION_REG_CS_PULLDOWN, IS31FL3737_CS_PULLDOWN);
|
||||
is31fl3737_write_register(index, IS31FL3737_FUNCTION_REG_CS_PULLDOWN, IS31FL3737_CS_PULLDOWN);
|
||||
// Set global current to maximum.
|
||||
is31fl3737_write_register(addr, IS31FL3737_FUNCTION_REG_GLOBAL_CURRENT, IS31FL3737_GLOBAL_CURRENT);
|
||||
is31fl3737_write_register(index, IS31FL3737_FUNCTION_REG_GLOBAL_CURRENT, IS31FL3737_GLOBAL_CURRENT);
|
||||
// Disable software shutdown.
|
||||
is31fl3737_write_register(addr, IS31FL3737_FUNCTION_REG_CONFIGURATION, ((IS31FL3737_PWM_FREQUENCY & 0b111) << 3) | 0x01);
|
||||
is31fl3737_write_register(index, IS31FL3737_FUNCTION_REG_CONFIGURATION, ((IS31FL3737_PWM_FREQUENCY & 0b111) << 3) | 0x01);
|
||||
|
||||
// Wait 10ms to ensure the device has woken up.
|
||||
wait_ms(10);
|
||||
|
|
@ -211,22 +210,22 @@ void is31fl3737_set_led_control_register(uint8_t index, bool red, bool green, bo
|
|||
g_led_control_registers_update_required[led.driver] = true;
|
||||
}
|
||||
|
||||
void is31fl3737_update_pwm_buffers(uint8_t addr, uint8_t index) {
|
||||
void is31fl3737_update_pwm_buffers(uint8_t index) {
|
||||
if (g_pwm_buffer_update_required[index]) {
|
||||
is31fl3737_select_page(addr, IS31FL3737_COMMAND_PWM);
|
||||
is31fl3737_select_page(index, IS31FL3737_COMMAND_PWM);
|
||||
|
||||
is31fl3737_write_pwm_buffer(addr, index);
|
||||
is31fl3737_write_pwm_buffer(index);
|
||||
|
||||
g_pwm_buffer_update_required[index] = false;
|
||||
}
|
||||
}
|
||||
|
||||
void is31fl3737_update_led_control_registers(uint8_t addr, uint8_t index) {
|
||||
void is31fl3737_update_led_control_registers(uint8_t index) {
|
||||
if (g_led_control_registers_update_required[index]) {
|
||||
is31fl3737_select_page(addr, IS31FL3737_COMMAND_LED_CONTROL);
|
||||
is31fl3737_select_page(index, IS31FL3737_COMMAND_LED_CONTROL);
|
||||
|
||||
for (uint8_t i = 0; i < IS31FL3737_LED_CONTROL_REGISTER_COUNT; i++) {
|
||||
is31fl3737_write_register(addr, i, g_led_control_registers[index][i]);
|
||||
is31fl3737_write_register(index, i, g_led_control_registers[index][i]);
|
||||
}
|
||||
|
||||
g_led_control_registers_update_required[index] = false;
|
||||
|
|
@ -234,14 +233,7 @@ void is31fl3737_update_led_control_registers(uint8_t addr, uint8_t index) {
|
|||
}
|
||||
|
||||
void is31fl3737_flush(void) {
|
||||
is31fl3737_update_pwm_buffers(IS31FL3737_I2C_ADDRESS_1, 0);
|
||||
#if defined(IS31FL3737_I2C_ADDRESS_2)
|
||||
is31fl3737_update_pwm_buffers(IS31FL3737_I2C_ADDRESS_2, 1);
|
||||
# if defined(IS31FL3737_I2C_ADDRESS_3)
|
||||
is31fl3737_update_pwm_buffers(IS31FL3737_I2C_ADDRESS_3, 2);
|
||||
# if defined(IS31FL3737_I2C_ADDRESS_4)
|
||||
is31fl3737_update_pwm_buffers(IS31FL3737_I2C_ADDRESS_4, 3);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
for (uint8_t i = 0; i < IS31FL3737_DRIVER_COUNT; i++) {
|
||||
is31fl3737_update_pwm_buffers(i);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,9 +117,9 @@ typedef struct is31fl3737_led_t {
|
|||
extern const is31fl3737_led_t PROGMEM g_is31fl3737_leds[IS31FL3737_LED_COUNT];
|
||||
|
||||
void is31fl3737_init_drivers(void);
|
||||
void is31fl3737_init(uint8_t addr);
|
||||
void is31fl3737_write_register(uint8_t addr, uint8_t reg, uint8_t data);
|
||||
void is31fl3737_select_page(uint8_t addr, uint8_t page);
|
||||
void is31fl3737_init(uint8_t index);
|
||||
void is31fl3737_write_register(uint8_t index, uint8_t reg, uint8_t data);
|
||||
void is31fl3737_select_page(uint8_t index, uint8_t page);
|
||||
|
||||
void is31fl3737_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
|
||||
void is31fl3737_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
|
||||
|
|
@ -130,8 +130,8 @@ void is31fl3737_set_led_control_register(uint8_t index, bool red, bool green, bo
|
|||
// (eg. from a timer interrupt).
|
||||
// Call this while idle (in between matrix scans).
|
||||
// If the buffer is dirty, it will update the driver with the buffer.
|
||||
void is31fl3737_update_pwm_buffers(uint8_t addr, uint8_t index);
|
||||
void is31fl3737_update_led_control_registers(uint8_t addr, uint8_t index);
|
||||
void is31fl3737_update_pwm_buffers(uint8_t index);
|
||||
void is31fl3737_update_led_control_registers(uint8_t index);
|
||||
|
||||
void is31fl3737_flush(void);
|
||||
|
||||
|
|
|
|||
|
|
@ -52,6 +52,19 @@
|
|||
# define IS31FL3741_GLOBAL_CURRENT 0xFF
|
||||
#endif
|
||||
|
||||
const uint8_t i2c_addresses[IS31FL3741_DRIVER_COUNT] = {
|
||||
IS31FL3741_I2C_ADDRESS_1,
|
||||
#ifdef IS31FL3741_I2C_ADDRESS_2
|
||||
IS31FL3741_I2C_ADDRESS_2,
|
||||
# ifdef IS31FL3741_I2C_ADDRESS_3
|
||||
IS31FL3741_I2C_ADDRESS_3,
|
||||
# ifdef IS31FL3741_I2C_ADDRESS_4
|
||||
IS31FL3741_I2C_ADDRESS_4,
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
};
|
||||
|
||||
// These buffers match the IS31FL3741 and IS31FL3741A PWM registers.
|
||||
// The scaling buffers match the page 2 and 3 LED On/Off registers.
|
||||
// Storing them like this is optimal for I2C transfers to the registers.
|
||||
|
|
@ -64,98 +77,84 @@ bool g_scaling_registers_update_required[IS31FL3741_DRIVER_COUNT] = {false};
|
|||
|
||||
uint8_t g_scaling_registers[IS31FL3741_DRIVER_COUNT][IS31FL3741_SCALING_REGISTER_COUNT];
|
||||
|
||||
void is31fl3741_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
||||
void is31fl3741_write_register(uint8_t index, uint8_t reg, uint8_t data) {
|
||||
#if IS31FL3741_I2C_PERSISTENCE > 0
|
||||
for (uint8_t i = 0; i < IS31FL3741_I2C_PERSISTENCE; i++) {
|
||||
if (i2c_write_register(addr << 1, reg, &data, 1, IS31FL3741_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
if (i2c_write_register(i2c_addresses[index] << 1, reg, &data, 1, IS31FL3741_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
}
|
||||
#else
|
||||
i2c_write_register(addr << 1, reg, &data, 1, IS31FL3741_I2C_TIMEOUT);
|
||||
i2c_write_register(i2c_addresses[index] << 1, reg, &data, 1, IS31FL3741_I2C_TIMEOUT);
|
||||
#endif
|
||||
}
|
||||
|
||||
void is31fl3741_select_page(uint8_t addr, uint8_t page) {
|
||||
is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND_WRITE_LOCK, IS31FL3741_COMMAND_WRITE_LOCK_MAGIC);
|
||||
is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND, page);
|
||||
void is31fl3741_select_page(uint8_t index, uint8_t page) {
|
||||
is31fl3741_write_register(index, IS31FL3741_REG_COMMAND_WRITE_LOCK, IS31FL3741_COMMAND_WRITE_LOCK_MAGIC);
|
||||
is31fl3741_write_register(index, IS31FL3741_REG_COMMAND, page);
|
||||
}
|
||||
|
||||
void is31fl3741_write_pwm_buffer(uint8_t addr, uint8_t index) {
|
||||
void is31fl3741_write_pwm_buffer(uint8_t index) {
|
||||
// Assume page 0 is already selected
|
||||
|
||||
for (uint16_t i = 0; i < 342; i += 18) {
|
||||
if (i == 180) {
|
||||
is31fl3741_select_page(addr, IS31FL3741_COMMAND_PWM_1);
|
||||
is31fl3741_select_page(index, IS31FL3741_COMMAND_PWM_1);
|
||||
}
|
||||
|
||||
#if IS31FL3741_I2C_PERSISTENCE > 0
|
||||
for (uint8_t j = 0; j < IS31FL3741_I2C_PERSISTENCE; j++) {
|
||||
if (i2c_write_register(addr << 1, i % 180, g_pwm_buffer[index] + i, 18, IS31FL3741_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
if (i2c_write_register(i2c_addresses[index] << 1, i % 180, g_pwm_buffer[index] + i, 18, IS31FL3741_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
}
|
||||
#else
|
||||
i2c_write_register(addr << 1, i % 180, g_pwm_buffer[index] + i, 18, IS31FL3741_I2C_TIMEOUT);
|
||||
i2c_write_register(i2c_addresses[index] << 1, i % 180, g_pwm_buffer[index] + i, 18, IS31FL3741_I2C_TIMEOUT);
|
||||
#endif
|
||||
}
|
||||
|
||||
// transfer the left cause the total number is 351
|
||||
#if IS31FL3741_I2C_PERSISTENCE > 0
|
||||
for (uint8_t i = 0; i < IS31FL3741_I2C_PERSISTENCE; i++) {
|
||||
if (i2c_write_register(addr << 1, 162, g_pwm_buffer[index] + 342, 9, IS31FL3741_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
if (i2c_write_register(i2c_addresses[index] << 1, 162, g_pwm_buffer[index] + 342, 9, IS31FL3741_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
}
|
||||
#else
|
||||
i2c_write_register(addr << 1, 162, g_pwm_buffer[index] + 342, 9, IS31FL3741_I2C_TIMEOUT);
|
||||
i2c_write_register(i2c_addresses[index] << 1, 162, g_pwm_buffer[index] + 342, 9, IS31FL3741_I2C_TIMEOUT);
|
||||
#endif
|
||||
}
|
||||
|
||||
void is31fl3741_init_drivers(void) {
|
||||
i2c_init();
|
||||
|
||||
is31fl3741_init(IS31FL3741_I2C_ADDRESS_1);
|
||||
#if defined(IS31FL3741_I2C_ADDRESS_2)
|
||||
is31fl3741_init(IS31FL3741_I2C_ADDRESS_2);
|
||||
# if defined(IS31FL3741_I2C_ADDRESS_3)
|
||||
is31fl3741_init(IS31FL3741_I2C_ADDRESS_3);
|
||||
# if defined(IS31FL3741_I2C_ADDRESS_4)
|
||||
is31fl3741_init(IS31FL3741_I2C_ADDRESS_4);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
for (uint8_t i = 0; i < IS31FL3741_DRIVER_COUNT; i++) {
|
||||
is31fl3741_init(i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < IS31FL3741_LED_COUNT; i++) {
|
||||
is31fl3741_set_led_control_register(i, true);
|
||||
}
|
||||
|
||||
is31fl3741_update_led_control_registers(IS31FL3741_I2C_ADDRESS_1, 0);
|
||||
#if defined(IS31FL3741_I2C_ADDRESS_2)
|
||||
is31fl3741_update_led_control_registers(IS31FL3741_I2C_ADDRESS_2, 1);
|
||||
# if defined(IS31FL3741_I2C_ADDRESS_3)
|
||||
is31fl3741_update_led_control_registers(IS31FL3741_I2C_ADDRESS_3, 2);
|
||||
# if defined(IS31FL3741_I2C_ADDRESS_4)
|
||||
is31fl3741_update_led_control_registers(IS31FL3741_I2C_ADDRESS_4, 3);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
for (uint8_t i = 0; i < IS31FL3741_DRIVER_COUNT; i++) {
|
||||
is31fl3741_update_led_control_registers(i);
|
||||
}
|
||||
}
|
||||
|
||||
void is31fl3741_init(uint8_t addr) {
|
||||
void is31fl3741_init(uint8_t index) {
|
||||
// In order to avoid the LEDs being driven with garbage data
|
||||
// in the LED driver's PWM registers, shutdown is enabled last.
|
||||
// Set up the mode and other settings, clear the PWM registers,
|
||||
// then disable software shutdown.
|
||||
// Unlock the command register.
|
||||
|
||||
is31fl3741_select_page(addr, IS31FL3741_COMMAND_FUNCTION);
|
||||
is31fl3741_select_page(index, IS31FL3741_COMMAND_FUNCTION);
|
||||
|
||||
// Set to Normal operation
|
||||
is31fl3741_write_register(addr, IS31FL3741_FUNCTION_REG_CONFIGURATION, IS31FL3741_CONFIGURATION);
|
||||
is31fl3741_write_register(index, IS31FL3741_FUNCTION_REG_CONFIGURATION, IS31FL3741_CONFIGURATION);
|
||||
|
||||
// Set Golbal Current Control Register
|
||||
is31fl3741_write_register(addr, IS31FL3741_FUNCTION_REG_GLOBAL_CURRENT, IS31FL3741_GLOBAL_CURRENT);
|
||||
is31fl3741_write_register(index, IS31FL3741_FUNCTION_REG_GLOBAL_CURRENT, IS31FL3741_GLOBAL_CURRENT);
|
||||
// Set Pull up & Down for SWx CSy
|
||||
is31fl3741_write_register(addr, IS31FL3741_FUNCTION_REG_PULLDOWNUP, ((IS31FL3741_CS_PULLDOWN << 4) | IS31FL3741_SW_PULLUP));
|
||||
is31fl3741_write_register(index, IS31FL3741_FUNCTION_REG_PULLDOWNUP, ((IS31FL3741_CS_PULLDOWN << 4) | IS31FL3741_SW_PULLUP));
|
||||
// Set PWM frequency
|
||||
is31fl3741_write_register(addr, IS31FL3741_FUNCTION_REG_PWM_FREQUENCY, (IS31FL3741_PWM_FREQUENCY & 0b1111));
|
||||
is31fl3741_write_register(index, IS31FL3741_FUNCTION_REG_PWM_FREQUENCY, (IS31FL3741_PWM_FREQUENCY & 0b1111));
|
||||
|
||||
// is31fl3741_update_led_scaling_registers(addr, 0xFF, 0xFF, 0xFF);
|
||||
// is31fl3741_update_led_scaling_registers(index, 0xFF, 0xFF, 0xFF);
|
||||
|
||||
// Wait 10ms to ensure the device has woken up.
|
||||
wait_ms(10);
|
||||
|
|
@ -195,11 +194,11 @@ void is31fl3741_set_led_control_register(uint8_t index, bool value) {
|
|||
g_scaling_registers_update_required[led.driver] = true;
|
||||
}
|
||||
|
||||
void is31fl3741_update_pwm_buffers(uint8_t addr, uint8_t index) {
|
||||
void is31fl3741_update_pwm_buffers(uint8_t index) {
|
||||
if (g_pwm_buffer_update_required[index]) {
|
||||
is31fl3741_select_page(addr, IS31FL3741_COMMAND_PWM_0);
|
||||
is31fl3741_select_page(index, IS31FL3741_COMMAND_PWM_0);
|
||||
|
||||
is31fl3741_write_pwm_buffer(addr, index);
|
||||
is31fl3741_write_pwm_buffer(index);
|
||||
|
||||
g_pwm_buffer_update_required[index] = false;
|
||||
}
|
||||
|
|
@ -210,20 +209,20 @@ void is31fl3741_set_pwm_buffer(const is31fl3741_led_t *pled, uint8_t value) {
|
|||
g_pwm_buffer_update_required[pled->driver] = true;
|
||||
}
|
||||
|
||||
void is31fl3741_update_led_control_registers(uint8_t addr, uint8_t index) {
|
||||
void is31fl3741_update_led_control_registers(uint8_t index) {
|
||||
if (g_scaling_registers_update_required[index]) {
|
||||
is31fl3741_select_page(addr, IS31FL3741_COMMAND_SCALING_0);
|
||||
is31fl3741_select_page(index, IS31FL3741_COMMAND_SCALING_0);
|
||||
|
||||
// CS1_SW1 to CS30_SW6 are on page 2
|
||||
for (int i = CS1_SW1; i <= CS30_SW6; ++i) {
|
||||
is31fl3741_write_register(addr, i, g_scaling_registers[index][i]);
|
||||
is31fl3741_write_register(index, i, g_scaling_registers[index][i]);
|
||||
}
|
||||
|
||||
is31fl3741_select_page(addr, IS31FL3741_COMMAND_SCALING_1);
|
||||
is31fl3741_select_page(index, IS31FL3741_COMMAND_SCALING_1);
|
||||
|
||||
// CS1_SW7 to CS39_SW9 are on page 3
|
||||
for (int i = CS1_SW7; i <= CS39_SW9; ++i) {
|
||||
is31fl3741_write_register(addr, i - CS1_SW7, g_scaling_registers[index][i]);
|
||||
is31fl3741_write_register(index, i - CS1_SW7, g_scaling_registers[index][i]);
|
||||
}
|
||||
|
||||
g_scaling_registers_update_required[index] = false;
|
||||
|
|
@ -236,14 +235,7 @@ void is31fl3741_set_scaling_registers(const is31fl3741_led_t *pled, uint8_t valu
|
|||
}
|
||||
|
||||
void is31fl3741_flush(void) {
|
||||
is31fl3741_update_pwm_buffers(IS31FL3741_I2C_ADDRESS_1, 0);
|
||||
#if defined(IS31FL3741_I2C_ADDRESS_2)
|
||||
is31fl3741_update_pwm_buffers(IS31FL3741_I2C_ADDRESS_2, 1);
|
||||
# if defined(IS31FL3741_I2C_ADDRESS_3)
|
||||
is31fl3741_update_pwm_buffers(IS31FL3741_I2C_ADDRESS_3, 2);
|
||||
# if defined(IS31FL3741_I2C_ADDRESS_4)
|
||||
is31fl3741_update_pwm_buffers(IS31FL3741_I2C_ADDRESS_4, 3);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
for (uint8_t i = 0; i < IS31FL3741_DRIVER_COUNT; i++) {
|
||||
is31fl3741_update_pwm_buffers(i);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,9 +102,9 @@ typedef struct is31fl3741_led_t {
|
|||
extern const is31fl3741_led_t PROGMEM g_is31fl3741_leds[IS31FL3741_LED_COUNT];
|
||||
|
||||
void is31fl3741_init_drivers(void);
|
||||
void is31fl3741_init(uint8_t addr);
|
||||
void is31fl3741_write_register(uint8_t addr, uint8_t reg, uint8_t data);
|
||||
void is31fl3741_select_page(uint8_t addr, uint8_t page);
|
||||
void is31fl3741_init(uint8_t index);
|
||||
void is31fl3741_write_register(uint8_t index, uint8_t reg, uint8_t data);
|
||||
void is31fl3741_select_page(uint8_t index, uint8_t page);
|
||||
|
||||
void is31fl3741_set_value(int index, uint8_t value);
|
||||
void is31fl3741_set_value_all(uint8_t value);
|
||||
|
|
@ -115,8 +115,8 @@ void is31fl3741_set_led_control_register(uint8_t index, bool value);
|
|||
// (eg. from a timer interrupt).
|
||||
// Call this while idle (in between matrix scans).
|
||||
// If the buffer is dirty, it will update the driver with the buffer.
|
||||
void is31fl3741_update_pwm_buffers(uint8_t addr, uint8_t index);
|
||||
void is31fl3741_update_led_control_registers(uint8_t addr, uint8_t index);
|
||||
void is31fl3741_update_pwm_buffers(uint8_t index);
|
||||
void is31fl3741_update_led_control_registers(uint8_t index);
|
||||
void is31fl3741_set_scaling_registers(const is31fl3741_led_t *pled, uint8_t value);
|
||||
|
||||
void is31fl3741_set_pwm_buffer(const is31fl3741_led_t *pled, uint8_t value);
|
||||
|
|
|
|||
|
|
@ -52,6 +52,19 @@
|
|||
# define IS31FL3741_GLOBAL_CURRENT 0xFF
|
||||
#endif
|
||||
|
||||
const uint8_t i2c_addresses[IS31FL3741_DRIVER_COUNT] = {
|
||||
IS31FL3741_I2C_ADDRESS_1,
|
||||
#ifdef IS31FL3741_I2C_ADDRESS_2
|
||||
IS31FL3741_I2C_ADDRESS_2,
|
||||
# ifdef IS31FL3741_I2C_ADDRESS_3
|
||||
IS31FL3741_I2C_ADDRESS_3,
|
||||
# ifdef IS31FL3741_I2C_ADDRESS_4
|
||||
IS31FL3741_I2C_ADDRESS_4,
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
};
|
||||
|
||||
// These buffers match the IS31FL3741 and IS31FL3741A PWM registers.
|
||||
// The scaling buffers match the page 2 and 3 LED On/Off registers.
|
||||
// Storing them like this is optimal for I2C transfers to the registers.
|
||||
|
|
@ -64,98 +77,84 @@ bool g_scaling_registers_update_required[IS31FL3741_DRIVER_COUNT] = {false};
|
|||
|
||||
uint8_t g_scaling_registers[IS31FL3741_DRIVER_COUNT][IS31FL3741_SCALING_REGISTER_COUNT];
|
||||
|
||||
void is31fl3741_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
||||
void is31fl3741_write_register(uint8_t index, uint8_t reg, uint8_t data) {
|
||||
#if IS31FL3741_I2C_PERSISTENCE > 0
|
||||
for (uint8_t i = 0; i < IS31FL3741_I2C_PERSISTENCE; i++) {
|
||||
if (i2c_write_register(addr << 1, reg, &data, 1, IS31FL3741_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
if (i2c_write_register(i2c_addresses[index] << 1, reg, &data, 1, IS31FL3741_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
}
|
||||
#else
|
||||
i2c_write_register(addr << 1, reg, &data, 1, IS31FL3741_I2C_TIMEOUT);
|
||||
i2c_write_register(i2c_addresses[index] << 1, reg, &data, 1, IS31FL3741_I2C_TIMEOUT);
|
||||
#endif
|
||||
}
|
||||
|
||||
void is31fl3741_select_page(uint8_t addr, uint8_t page) {
|
||||
is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND_WRITE_LOCK, IS31FL3741_COMMAND_WRITE_LOCK_MAGIC);
|
||||
is31fl3741_write_register(addr, IS31FL3741_REG_COMMAND, page);
|
||||
void is31fl3741_select_page(uint8_t index, uint8_t page) {
|
||||
is31fl3741_write_register(index, IS31FL3741_REG_COMMAND_WRITE_LOCK, IS31FL3741_COMMAND_WRITE_LOCK_MAGIC);
|
||||
is31fl3741_write_register(index, IS31FL3741_REG_COMMAND, page);
|
||||
}
|
||||
|
||||
void is31fl3741_write_pwm_buffer(uint8_t addr, uint8_t index) {
|
||||
void is31fl3741_write_pwm_buffer(uint8_t index) {
|
||||
// Assume page 0 is already selected
|
||||
|
||||
for (uint16_t i = 0; i < 342; i += 18) {
|
||||
if (i == 180) {
|
||||
is31fl3741_select_page(addr, IS31FL3741_COMMAND_PWM_1);
|
||||
is31fl3741_select_page(index, IS31FL3741_COMMAND_PWM_1);
|
||||
}
|
||||
|
||||
#if IS31FL3741_I2C_PERSISTENCE > 0
|
||||
for (uint8_t j = 0; j < IS31FL3741_I2C_PERSISTENCE; j++) {
|
||||
if (i2c_write_register(addr << 1, i % 180, g_pwm_buffer[index] + i, 18, IS31FL3741_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
if (i2c_write_register(i2c_addresses[index] << 1, i % 180, g_pwm_buffer[index] + i, 18, IS31FL3741_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
}
|
||||
#else
|
||||
i2c_write_register(addr << 1, i % 180, g_pwm_buffer[index] + i, 18, IS31FL3741_I2C_TIMEOUT);
|
||||
i2c_write_register(i2c_addresses[index] << 1, i % 180, g_pwm_buffer[index] + i, 18, IS31FL3741_I2C_TIMEOUT);
|
||||
#endif
|
||||
}
|
||||
|
||||
// transfer the left cause the total number is 351
|
||||
#if IS31FL3741_I2C_PERSISTENCE > 0
|
||||
for (uint8_t i = 0; i < IS31FL3741_I2C_PERSISTENCE; i++) {
|
||||
if (i2c_write_register(addr << 1, 162, g_pwm_buffer[index] + 342, 9, IS31FL3741_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
if (i2c_write_register(i2c_addresses[index] << 1, 162, g_pwm_buffer[index] + 342, 9, IS31FL3741_I2C_TIMEOUT) == I2C_STATUS_SUCCESS) break;
|
||||
}
|
||||
#else
|
||||
i2c_write_register(addr << 1, 162, g_pwm_buffer[index] + 342, 9, IS31FL3741_I2C_TIMEOUT);
|
||||
i2c_write_register(i2c_addresses[index] << 1, 162, g_pwm_buffer[index] + 342, 9, IS31FL3741_I2C_TIMEOUT);
|
||||
#endif
|
||||
}
|
||||
|
||||
void is31fl3741_init_drivers(void) {
|
||||
i2c_init();
|
||||
|
||||
is31fl3741_init(IS31FL3741_I2C_ADDRESS_1);
|
||||
#if defined(IS31FL3741_I2C_ADDRESS_2)
|
||||
is31fl3741_init(IS31FL3741_I2C_ADDRESS_2);
|
||||
# if defined(IS31FL3741_I2C_ADDRESS_3)
|
||||
is31fl3741_init(IS31FL3741_I2C_ADDRESS_3);
|
||||
# if defined(IS31FL3741_I2C_ADDRESS_4)
|
||||
is31fl3741_init(IS31FL3741_I2C_ADDRESS_4);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
for (uint8_t i = 0; i < IS31FL3741_DRIVER_COUNT; i++) {
|
||||
is31fl3741_init(i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < IS31FL3741_LED_COUNT; i++) {
|
||||
is31fl3741_set_led_control_register(i, true, true, true);
|
||||
}
|
||||
|
||||
is31fl3741_update_led_control_registers(IS31FL3741_I2C_ADDRESS_1, 0);
|
||||
#if defined(IS31FL3741_I2C_ADDRESS_2)
|
||||
is31fl3741_update_led_control_registers(IS31FL3741_I2C_ADDRESS_2, 1);
|
||||
# if defined(IS31FL3741_I2C_ADDRESS_3)
|
||||
is31fl3741_update_led_control_registers(IS31FL3741_I2C_ADDRESS_3, 2);
|
||||
# if defined(IS31FL3741_I2C_ADDRESS_4)
|
||||
is31fl3741_update_led_control_registers(IS31FL3741_I2C_ADDRESS_4, 3);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
for (uint8_t i = 0; i < IS31FL3741_DRIVER_COUNT; i++) {
|
||||
is31fl3741_update_led_control_registers(i);
|
||||
}
|
||||
}
|
||||
|
||||
void is31fl3741_init(uint8_t addr) {
|
||||
void is31fl3741_init(uint8_t index) {
|
||||
// In order to avoid the LEDs being driven with garbage data
|
||||
// in the LED driver's PWM registers, shutdown is enabled last.
|
||||
// Set up the mode and other settings, clear the PWM registers,
|
||||
// then disable software shutdown.
|
||||
// Unlock the command register.
|
||||
|
||||
is31fl3741_select_page(addr, IS31FL3741_COMMAND_FUNCTION);
|
||||
is31fl3741_select_page(index, IS31FL3741_COMMAND_FUNCTION);
|
||||
|
||||
// Set to Normal operation
|
||||
is31fl3741_write_register(addr, IS31FL3741_FUNCTION_REG_CONFIGURATION, IS31FL3741_CONFIGURATION);
|
||||
is31fl3741_write_register(index, IS31FL3741_FUNCTION_REG_CONFIGURATION, IS31FL3741_CONFIGURATION);
|
||||
|
||||
// Set Golbal Current Control Register
|
||||
is31fl3741_write_register(addr, IS31FL3741_FUNCTION_REG_GLOBAL_CURRENT, IS31FL3741_GLOBAL_CURRENT);
|
||||
is31fl3741_write_register(index, IS31FL3741_FUNCTION_REG_GLOBAL_CURRENT, IS31FL3741_GLOBAL_CURRENT);
|
||||
// Set Pull up & Down for SWx CSy
|
||||
is31fl3741_write_register(addr, IS31FL3741_FUNCTION_REG_PULLDOWNUP, ((IS31FL3741_CS_PULLDOWN << 4) | IS31FL3741_SW_PULLUP));
|
||||
is31fl3741_write_register(index, IS31FL3741_FUNCTION_REG_PULLDOWNUP, ((IS31FL3741_CS_PULLDOWN << 4) | IS31FL3741_SW_PULLUP));
|
||||
// Set PWM frequency
|
||||
is31fl3741_write_register(addr, IS31FL3741_FUNCTION_REG_PWM_FREQUENCY, (IS31FL3741_PWM_FREQUENCY & 0b1111));
|
||||
is31fl3741_write_register(index, IS31FL3741_FUNCTION_REG_PWM_FREQUENCY, (IS31FL3741_PWM_FREQUENCY & 0b1111));
|
||||
|
||||
// is31fl3741_update_led_scaling_registers(addr, 0xFF, 0xFF, 0xFF);
|
||||
// is31fl3741_update_led_scaling_registers(index, 0xFF, 0xFF, 0xFF);
|
||||
|
||||
// Wait 10ms to ensure the device has woken up.
|
||||
wait_ms(10);
|
||||
|
|
@ -209,11 +208,11 @@ void is31fl3741_set_led_control_register(uint8_t index, bool red, bool green, bo
|
|||
g_scaling_registers_update_required[led.driver] = true;
|
||||
}
|
||||
|
||||
void is31fl3741_update_pwm_buffers(uint8_t addr, uint8_t index) {
|
||||
void is31fl3741_update_pwm_buffers(uint8_t index) {
|
||||
if (g_pwm_buffer_update_required[index]) {
|
||||
is31fl3741_select_page(addr, IS31FL3741_COMMAND_PWM_0);
|
||||
is31fl3741_select_page(index, IS31FL3741_COMMAND_PWM_0);
|
||||
|
||||
is31fl3741_write_pwm_buffer(addr, index);
|
||||
is31fl3741_write_pwm_buffer(index);
|
||||
|
||||
g_pwm_buffer_update_required[index] = false;
|
||||
}
|
||||
|
|
@ -226,20 +225,20 @@ void is31fl3741_set_pwm_buffer(const is31fl3741_led_t *pled, uint8_t red, uint8_
|
|||
g_pwm_buffer_update_required[pled->driver] = true;
|
||||
}
|
||||
|
||||
void is31fl3741_update_led_control_registers(uint8_t addr, uint8_t index) {
|
||||
void is31fl3741_update_led_control_registers(uint8_t index) {
|
||||
if (g_scaling_registers_update_required[index]) {
|
||||
is31fl3741_select_page(addr, IS31FL3741_COMMAND_SCALING_0);
|
||||
is31fl3741_select_page(index, IS31FL3741_COMMAND_SCALING_0);
|
||||
|
||||
// CS1_SW1 to CS30_SW6 are on page 2
|
||||
for (int i = CS1_SW1; i <= CS30_SW6; ++i) {
|
||||
is31fl3741_write_register(addr, i, g_scaling_registers[index][i]);
|
||||
is31fl3741_write_register(index, i, g_scaling_registers[index][i]);
|
||||
}
|
||||
|
||||
is31fl3741_select_page(addr, IS31FL3741_COMMAND_SCALING_1);
|
||||
is31fl3741_select_page(index, IS31FL3741_COMMAND_SCALING_1);
|
||||
|
||||
// CS1_SW7 to CS39_SW9 are on page 3
|
||||
for (int i = CS1_SW7; i <= CS39_SW9; ++i) {
|
||||
is31fl3741_write_register(addr, i - CS1_SW7, g_scaling_registers[index][i]);
|
||||
is31fl3741_write_register(index, i - CS1_SW7, g_scaling_registers[index][i]);
|
||||
}
|
||||
|
||||
g_scaling_registers_update_required[index] = false;
|
||||
|
|
@ -254,14 +253,7 @@ void is31fl3741_set_scaling_registers(const is31fl3741_led_t *pled, uint8_t red,
|
|||
}
|
||||
|
||||
void is31fl3741_flush(void) {
|
||||
is31fl3741_update_pwm_buffers(IS31FL3741_I2C_ADDRESS_1, 0);
|
||||
#if defined(IS31FL3741_I2C_ADDRESS_2)
|
||||
is31fl3741_update_pwm_buffers(IS31FL3741_I2C_ADDRESS_2, 1);
|
||||
# if defined(IS31FL3741_I2C_ADDRESS_3)
|
||||
is31fl3741_update_pwm_buffers(IS31FL3741_I2C_ADDRESS_3, 2);
|
||||
# if defined(IS31FL3741_I2C_ADDRESS_4)
|
||||
is31fl3741_update_pwm_buffers(IS31FL3741_I2C_ADDRESS_4, 3);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
for (uint8_t i = 0; i < IS31FL3741_DRIVER_COUNT; i++) {
|
||||
is31fl3741_update_pwm_buffers(i);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,9 +119,9 @@ typedef struct is31fl3741_led_t {
|
|||
extern const is31fl3741_led_t PROGMEM g_is31fl3741_leds[IS31FL3741_LED_COUNT];
|
||||
|
||||
void is31fl3741_init_drivers(void);
|
||||
void is31fl3741_init(uint8_t addr);
|
||||
void is31fl3741_write_register(uint8_t addr, uint8_t reg, uint8_t data);
|
||||
void is31fl3741_select_page(uint8_t addr, uint8_t page);
|
||||
void is31fl3741_init(uint8_t index);
|
||||
void is31fl3741_write_register(uint8_t index, uint8_t reg, uint8_t data);
|
||||
void is31fl3741_select_page(uint8_t index, uint8_t page);
|
||||
|
||||
void is31fl3741_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
|
||||
void is31fl3741_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
|
||||
|
|
@ -132,8 +132,8 @@ void is31fl3741_set_led_control_register(uint8_t index, bool red, bool green, bo
|
|||
// (eg. from a timer interrupt).
|
||||
// Call this while idle (in between matrix scans).
|
||||
// If the buffer is dirty, it will update the driver with the buffer.
|
||||
void is31fl3741_update_pwm_buffers(uint8_t addr, uint8_t index);
|
||||
void is31fl3741_update_led_control_registers(uint8_t addr, uint8_t index);
|
||||
void is31fl3741_update_pwm_buffers(uint8_t index);
|
||||
void is31fl3741_update_led_control_registers(uint8_t index);
|
||||
void is31fl3741_set_scaling_registers(const is31fl3741_led_t *pled, uint8_t red, uint8_t green, uint8_t blue);
|
||||
|
||||
void is31fl3741_set_pwm_buffer(const is31fl3741_led_t *pled, uint8_t red, uint8_t green, uint8_t blue);
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue