diff options
author | Nick Brassel <nick@tzarc.org> | 2023-08-29 21:24:43 +1000 |
---|---|---|
committer | Nick Brassel <nick@tzarc.org> | 2023-08-29 21:24:43 +1000 |
commit | 31a91add168c956655ace8ec4cf9750db1e2cfc6 (patch) | |
tree | 12cea9b5f8e769f9611a31cbaede9537edad71cc /drivers/led/issi/is31fl3218.c | |
parent | f07490bc092e365ba03dc685b3fc30ad0bf0b752 (diff) | |
parent | edaf8a87ef3164f8986b0a8eb171d4879b45414c (diff) |
Merge branch 'develop'
Diffstat (limited to 'drivers/led/issi/is31fl3218.c')
-rw-r--r-- | drivers/led/issi/is31fl3218.c | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/drivers/led/issi/is31fl3218.c b/drivers/led/issi/is31fl3218.c index c2300ebe89..970e9a0be9 100644 --- a/drivers/led/issi/is31fl3218.c +++ b/drivers/led/issi/is31fl3218.c @@ -37,58 +37,61 @@ uint8_t g_twi_transfer_buffer[20]; uint8_t g_pwm_buffer[18]; bool g_pwm_buffer_update_required = false; -void IS31FL3218_write_register(uint8_t reg, uint8_t data) { +void is31fl3218_write_register(uint8_t reg, uint8_t data) { g_twi_transfer_buffer[0] = reg; g_twi_transfer_buffer[1] = data; i2c_transmit(ISSI_ADDRESS, g_twi_transfer_buffer, 2, ISSI_TIMEOUT); } -void IS31FL3218_write_pwm_buffer(uint8_t *pwm_buffer) { +void is31fl3218_write_pwm_buffer(uint8_t *pwm_buffer) { g_twi_transfer_buffer[0] = ISSI_REG_PWM; memcpy(g_twi_transfer_buffer + 1, pwm_buffer, 18); i2c_transmit(ISSI_ADDRESS, g_twi_transfer_buffer, 19, ISSI_TIMEOUT); } -void IS31FL3218_init(void) { +void is31fl3218_init(void) { // In case we ever want to reinitialize (?) - IS31FL3218_write_register(ISSI_REG_RESET, 0x00); + is31fl3218_write_register(ISSI_REG_RESET, 0x00); // Turn off software shutdown - IS31FL3218_write_register(ISSI_REG_SHUTDOWN, 0x01); + is31fl3218_write_register(ISSI_REG_SHUTDOWN, 0x01); // Set all PWM values to zero for (uint8_t i = 0; i < 18; i++) { - IS31FL3218_write_register(ISSI_REG_PWM + i, 0x00); + is31fl3218_write_register(ISSI_REG_PWM + i, 0x00); } // Enable all channels for (uint8_t i = 0; i < 3; i++) { - IS31FL3218_write_register(ISSI_REG_CONTROL + i, 0b00111111); + is31fl3218_write_register(ISSI_REG_CONTROL + i, 0b00111111); } // Load PWM registers and LED Control register data - IS31FL3218_write_register(ISSI_REG_UPDATE, 0x01); + is31fl3218_write_register(ISSI_REG_UPDATE, 0x01); } -void IS31FL3218_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { +void is31fl3218_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { + if (g_pwm_buffer[index * 3 + 0] == red && g_pwm_buffer[index * 3 + 1] == green && g_pwm_buffer[index * 3 + 2] == blue) { + return; + } g_pwm_buffer[index * 3 + 0] = red; g_pwm_buffer[index * 3 + 1] = green; g_pwm_buffer[index * 3 + 2] = blue; g_pwm_buffer_update_required = true; } -void IS31FL3218_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { +void is31fl3218_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { for (int i = 0; i < 6; i++) { - IS31FL3218_set_color(i, red, green, blue); + is31fl3218_set_color(i, red, green, blue); } } -void IS31FL3218_update_pwm_buffers(void) { +void is31fl3218_update_pwm_buffers(void) { if (g_pwm_buffer_update_required) { - IS31FL3218_write_pwm_buffer(g_pwm_buffer); + is31fl3218_write_pwm_buffer(g_pwm_buffer); // Load PWM registers and LED Control register data - IS31FL3218_write_register(ISSI_REG_UPDATE, 0x01); + is31fl3218_write_register(ISSI_REG_UPDATE, 0x01); } g_pwm_buffer_update_required = false; } |