From fe1c3fc835c026af1a0280b6a795c73a67a901e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Mart=C3=ADnez?= <58857054+elpekenin@users.noreply.github.com> Date: Sun, 11 Jan 2026 02:00:36 +0100 Subject: [PATCH] [Bugfix] WS2812 indexing in split boards (#25407) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * initial * oops * Update quantum/rgb_matrix/rgb_matrix.c Co-authored-by: フィルターペーパー <76888457+filterpaper@users.noreply.github.com> --------- Co-authored-by: フィルターペーパー <76888457+filterpaper@users.noreply.github.com> --- quantum/rgb_matrix/rgb_matrix.c | 22 +++++++++++++++++++--- quantum/rgb_matrix/rgb_matrix.h | 8 ++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/quantum/rgb_matrix/rgb_matrix.c b/quantum/rgb_matrix/rgb_matrix.c index 97ae6a3c76..e2b268efa7 100644 --- a/quantum/rgb_matrix/rgb_matrix.c +++ b/quantum/rgb_matrix/rgb_matrix.c @@ -158,15 +158,31 @@ void rgb_matrix_update_pwm_buffers(void) { __attribute__((weak)) int rgb_matrix_led_index(int index) { #if defined(RGB_MATRIX_SPLIT) - if (!is_keyboard_left() && index >= k_rgb_matrix_split[0]) { - return index - k_rgb_matrix_split[0]; + const bool index_in_left_side = index < k_rgb_matrix_split[0]; + + if (is_keyboard_left()) { + if (index_in_left_side) { + return index; + } + return -1; } + + if (index_in_left_side) { + return -1; + } + + return index - k_rgb_matrix_split[0]; #endif return index; } void rgb_matrix_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { - rgb_matrix_driver.set_color(rgb_matrix_led_index(index), red, green, blue); + const int led_index = rgb_matrix_led_index(index); + if (led_index < 0) { + return; + } + + rgb_matrix_driver.set_color(led_index, red, green, blue); } void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { diff --git a/quantum/rgb_matrix/rgb_matrix.h b/quantum/rgb_matrix/rgb_matrix.h index f800679b46..f49ad04ace 100644 --- a/quantum/rgb_matrix/rgb_matrix.h +++ b/quantum/rgb_matrix/rgb_matrix.h @@ -151,6 +151,14 @@ void eeconfig_force_flush_rgb_matrix(void); uint8_t rgb_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i); uint8_t rgb_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i); +/** + * @brief Convert an index to the addressing used by underlying driver + * + * @param index Logical index of the LED we want to work on + * + * @return Resolved index to be used on the driver + * @retval < 0 Error (eg: trying to address a LED on the other half of a split board) + */ int rgb_matrix_led_index(int index); void rgb_matrix_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);