From ec9754a50c64930ae013078ae6bb13d0016ecefa Mon Sep 17 00:00:00 2001 From: N M Date: Tue, 21 Mar 2023 00:10:12 -0700 Subject: [PATCH 1/2] Fixed split keyboard issue where custom LED indicators could activate incorrect LEDs (#20203) Changed `rgb_matrix_indicators_advanced` to restrict the RGB index range to the split keyboard's left or right range. Added `RGB_MATRIX_USE_LIMITS_ITER` macro to reduce code duplication in handling split keyboard RGB index range. --- quantum/rgb_matrix/rgb_matrix.c | 9 +-------- quantum/rgb_matrix/rgb_matrix.h | 16 +++++++++------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/quantum/rgb_matrix/rgb_matrix.c b/quantum/rgb_matrix/rgb_matrix.c index bbb706da6980..1f3912cf7e0c 100644 --- a/quantum/rgb_matrix/rgb_matrix.c +++ b/quantum/rgb_matrix/rgb_matrix.c @@ -459,14 +459,7 @@ void rgb_matrix_indicators_advanced(effect_params_t *params) { * and not sure which would be better. Otherwise, this should be called from * rgb_task_render, right before the iter++ line. */ -#if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < RGB_MATRIX_LED_COUNT - uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * (params->iter - 1); - uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT; - if (max > RGB_MATRIX_LED_COUNT) max = RGB_MATRIX_LED_COUNT; -#else - uint8_t min = 0; - uint8_t max = RGB_MATRIX_LED_COUNT; -#endif + RGB_MATRIX_USE_LIMITS_ITER(min, max, params->iter - 1); rgb_matrix_indicators_advanced_kb(min, max); } diff --git a/quantum/rgb_matrix/rgb_matrix.h b/quantum/rgb_matrix/rgb_matrix.h index 62078f6e60c4..346da43c0844 100644 --- a/quantum/rgb_matrix/rgb_matrix.h +++ b/quantum/rgb_matrix/rgb_matrix.h @@ -52,34 +52,36 @@ #if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < RGB_MATRIX_LED_COUNT # if defined(RGB_MATRIX_SPLIT) -# define RGB_MATRIX_USE_LIMITS(min, max) \ - uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * params->iter; \ +# define RGB_MATRIX_USE_LIMITS_ITER(min, max, iter) \ + uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * (iter); \ uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT; \ if (max > RGB_MATRIX_LED_COUNT) max = RGB_MATRIX_LED_COUNT; \ uint8_t k_rgb_matrix_split[2] = RGB_MATRIX_SPLIT; \ if (is_keyboard_left() && (max > k_rgb_matrix_split[0])) max = k_rgb_matrix_split[0]; \ if (!(is_keyboard_left()) && (min < k_rgb_matrix_split[0])) min = k_rgb_matrix_split[0]; # else -# define RGB_MATRIX_USE_LIMITS(min, max) \ - uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * params->iter; \ +# define RGB_MATRIX_USE_LIMITS_ITER(min, max, iter) \ + uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * (iter); \ uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT; \ if (max > RGB_MATRIX_LED_COUNT) max = RGB_MATRIX_LED_COUNT; # endif #else # if defined(RGB_MATRIX_SPLIT) -# define RGB_MATRIX_USE_LIMITS(min, max) \ +# define RGB_MATRIX_USE_LIMITS_ITER(min, max, iter) \ uint8_t min = 0; \ uint8_t max = RGB_MATRIX_LED_COUNT; \ const uint8_t k_rgb_matrix_split[2] = RGB_MATRIX_SPLIT; \ if (is_keyboard_left() && (max > k_rgb_matrix_split[0])) max = k_rgb_matrix_split[0]; \ if (!(is_keyboard_left()) && (min < k_rgb_matrix_split[0])) min = k_rgb_matrix_split[0]; # else -# define RGB_MATRIX_USE_LIMITS(min, max) \ - uint8_t min = 0; \ +# define RGB_MATRIX_USE_LIMITS_ITER(min, max, iter) \ + uint8_t min = 0; \ uint8_t max = RGB_MATRIX_LED_COUNT; # endif #endif +#define RGB_MATRIX_USE_LIMITS(min, max) RGB_MATRIX_USE_LIMITS_ITER(min, max, params->iter) + #define RGB_MATRIX_INDICATOR_SET_COLOR(i, r, g, b) \ if (i >= led_min && i < led_max) { \ rgb_matrix_set_color(i, r, g, b); \ From 9db0b0d079208169e4af337a1ffd5b33d2615924 Mon Sep 17 00:00:00 2001 From: N M Date: Tue, 21 Mar 2023 00:40:52 -0700 Subject: [PATCH 2/2] Fixed formatting from ec9754a5. --- quantum/rgb_matrix/rgb_matrix.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/quantum/rgb_matrix/rgb_matrix.h b/quantum/rgb_matrix/rgb_matrix.h index 346da43c0844..6b373d0bcdfe 100644 --- a/quantum/rgb_matrix/rgb_matrix.h +++ b/quantum/rgb_matrix/rgb_matrix.h @@ -60,9 +60,9 @@ if (is_keyboard_left() && (max > k_rgb_matrix_split[0])) max = k_rgb_matrix_split[0]; \ if (!(is_keyboard_left()) && (min < k_rgb_matrix_split[0])) min = k_rgb_matrix_split[0]; # else -# define RGB_MATRIX_USE_LIMITS_ITER(min, max, iter) \ - uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * (iter); \ - uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT; \ +# define RGB_MATRIX_USE_LIMITS_ITER(min, max, iter) \ + uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * (iter); \ + uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT; \ if (max > RGB_MATRIX_LED_COUNT) max = RGB_MATRIX_LED_COUNT; # endif #else