From 222d22d09e9f9cc48320b4c34d6e8f9e839309d6 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Wed, 15 Sep 2021 10:07:08 -0700 Subject: [PATCH] [Bug] Fix IS31fl3741 driver to accept 1 or 2 addresses (#14451) Co-authored-by: Joel Challis --- drivers/led/issi/is31fl3741.c | 20 ++++++++++---------- drivers/led/issi/is31fl3741.h | 4 ++-- keyboards/kbdfans/boop65/rgb/config.h | 13 ++++++------- quantum/rgb_matrix/rgb_matrix_drivers.c | 7 ++++++- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/drivers/led/issi/is31fl3741.c b/drivers/led/issi/is31fl3741.c index 1b533c9b6a69..24a273514ed9 100644 --- a/drivers/led/issi/is31fl3741.c +++ b/drivers/led/issi/is31fl3741.c @@ -73,7 +73,7 @@ uint8_t g_twi_transfer_buffer[20] = {0xFF}; // buffers and the transfers in IS31FL3741_write_pwm_buffer() but it's // probably not worth the extra complexity. uint8_t g_pwm_buffer[DRIVER_COUNT][ISSI_MAX_LEDS]; -bool g_pwm_buffer_update_required = false; +bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false}; bool g_scaling_registers_update_required[DRIVER_COUNT] = {false}; uint8_t g_scaling_registers[DRIVER_COUNT][ISSI_MAX_LEDS]; @@ -169,10 +169,10 @@ void IS31FL3741_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { if (index >= 0 && index < DRIVER_LED_TOTAL) { is31_led led = g_is31_leds[index]; - g_pwm_buffer[led.driver][led.r] = red; - g_pwm_buffer[led.driver][led.g] = green; - g_pwm_buffer[led.driver][led.b] = blue; - g_pwm_buffer_update_required = true; + g_pwm_buffer[led.driver][led.r] = red; + g_pwm_buffer[led.driver][led.g] = green; + g_pwm_buffer[led.driver][led.b] = blue; + g_pwm_buffer_update_required[led.driver] = true; } } @@ -206,12 +206,12 @@ 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 addr1, uint8_t addr2) { - if (g_pwm_buffer_update_required) { - IS31FL3741_write_pwm_buffer(addr1, g_pwm_buffer[0]); +void IS31FL3741_update_pwm_buffers(uint8_t addr, uint8_t index) { + if (g_pwm_buffer_update_required[index]) { + IS31FL3741_write_pwm_buffer(addr, g_pwm_buffer[index]); } - g_pwm_buffer_update_required = false; + g_pwm_buffer_update_required[index] = false; } void IS31FL3741_set_pwm_buffer(const is31_led *pled, uint8_t red, uint8_t green, uint8_t blue) { @@ -219,7 +219,7 @@ void IS31FL3741_set_pwm_buffer(const is31_led *pled, uint8_t red, uint8_t green, g_pwm_buffer[pled->driver][pled->g] = green; g_pwm_buffer[pled->driver][pled->b] = blue; - g_pwm_buffer_update_required = true; + g_pwm_buffer_update_required[pled->driver] = true; } void IS31FL3741_update_led_control_registers(uint8_t addr, uint8_t index) { diff --git a/drivers/led/issi/is31fl3741.h b/drivers/led/issi/is31fl3741.h index cea6761ca882..163a0352338a 100644 --- a/drivers/led/issi/is31fl3741.h +++ b/drivers/led/issi/is31fl3741.h @@ -45,8 +45,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 addr1, uint8_t addr2); -void IS31FL3741_update_led_control_registers(uint8_t addr1, uint8_t addr2); +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_set_scaling_registers(const is31_led *pled, uint8_t red, uint8_t green, uint8_t blue); void IS31FL3741_set_pwm_buffer(const is31_led *pled, uint8_t red, uint8_t green, uint8_t blue); diff --git a/keyboards/kbdfans/boop65/rgb/config.h b/keyboards/kbdfans/boop65/rgb/config.h index 1236b6bfbedc..71db0f8b57de 100644 --- a/keyboards/kbdfans/boop65/rgb/config.h +++ b/keyboards/kbdfans/boop65/rgb/config.h @@ -52,12 +52,11 @@ # define RGB_MATRIX_MAXIMUM_BRIGHTNESS 200 // limits maximum brightness of LEDs to 200 out of 255. If not defined maximum brightness is set to 255 # define RGB_MATRIX_STARTUP_VAL RGB_MATRIX_MAXIMUM_BRIGHTNESS // Sets the default brightness value, if none has been set # define RGB_MATRIX_STARTUP_MODE RGB_MATRIX_CYCLE_ALL -# define DRIVER_ADDR_1 0b0110000 -# define DRIVER_ADDR_2 0b0110000 -# define DRIVER_COUNT 1 -# define DRIVER_1_LED_TOTAL 83 -# define DRIVER_LED_TOTAL DRIVER_1_LED_TOTAL -# define DRIVER_INDICATOR_LED_TOTAL 0 +# define DRIVER_ADDR_1 0b0110000 +# define DRIVER_COUNT 1 +# define DRIVER_1_LED_TOTAL 83 +# define DRIVER_LED_TOTAL DRIVER_1_LED_TOTAL +# define DRIVER_INDICATOR_LED_TOTAL 0 #endif -#define VIA_EEPROM_LAYOUT_OPTIONS_SIZE 2 +#define VIA_EEPROM_LAYOUT_OPTIONS_SIZE 2 \ No newline at end of file diff --git a/quantum/rgb_matrix/rgb_matrix_drivers.c b/quantum/rgb_matrix/rgb_matrix_drivers.c index bfaedaa4a07d..2cec162e22cd 100644 --- a/quantum/rgb_matrix/rgb_matrix_drivers.c +++ b/quantum/rgb_matrix/rgb_matrix_drivers.c @@ -172,7 +172,12 @@ const rgb_matrix_driver_t rgb_matrix_driver = { .set_color_all = IS31FL3737_set_color_all, }; # else -static void flush(void) { IS31FL3741_update_pwm_buffers(DRIVER_ADDR_1, DRIVER_ADDR_2); } +static void flush(void) { + IS31FL3741_update_pwm_buffers(DRIVER_ADDR_1, 0); +# if defined(DRIVER_ADDR_2) && (DRIVER_ADDR_2 != DRIVER_ADDR_1) // provides backward compatibility + IS31FL3741_update_pwm_buffers(DRIVER_ADDR_2, 1); +# endif +} const rgb_matrix_driver_t rgb_matrix_driver = { .init = init,