Skip to content

[Bug] RGBLED_SPLIT causes indexing overwflow #25883

@muteso

Description

@muteso

Describe the Bug

Greetings! Initially i'm just tried to find out how to turn on only one onboard led (i mean soldered directly in microcontroller) on right half of split keyboard when some nondefault layer is active regardless to which half is plugged in with usb cable. And there is no any working (as i described above) solution was found by me finally.

During my research i've tried a lot of combinations of #define and functions, and found something useful (as i thought):

// config.h

#ifdef RGBLIGHT_ENABLE
#   define WS2812_DI_PIN 16
#   define RGBLIGHT_LED_COUNT 2
// #   define RGBLED_SPLIT { 1, 1 }
// #   define SPLIT_LED_STATE_ENABLE
// #   define SPLIT_LAYER_STATE_ENABLE
#endif
// keymap.c

#ifdef RGBLIGHT_ENABLE
layer_state_t layer_state_set_user(layer_state_t state) {
    if (!layer_state_cmp(state, 0)) {   
        rgblight_sethsv_at(128, 255, 70, 1); // cyan with lowered brightness
    } else {
        rgblight_sethsv_at(0,   0,   0,  1); // off
    };
    return state;
} 
#endif

... but all of this didn't work as explained (or as i understood) in docs - 1-indexed led never turned on in all combinations of #define and "targeting" (with _at-suffix) rgblight-functions. After this failure i've tried other one combination - uncommented #define RGBLED_SPLIT { 1, 1 } and rgblight_sethsv_noeeprom(128, 255, 70) - and some progress at last - both leds were on. Then i've tried to debug what is happening underneath, cus something strange is happening if #define RGBLED_SPLIT { 1, 1 } was commented again - only one led was on on "active" half of keyboard (i mean half which is plugged in with usb cable).

And i've found some bug here when #define RGBLED_SPLIT is included - as clipping borders of leds "chain" is redifining by this macro, in a lot of rgblight-function (except rgblight_sethsv_noeeprom, which uses effect borders, but it's really doesn't matter here) when you try to access 0-indexed led you will get overflowed uint8_t (255 in my case) from rgblight_led_index on right half of keyboard which finally (on drivers level) have to point to "garbage" or nonallocated data. But even if i use rgblight_sethsv_noeeprom instead of rgblight_sethsv_at there is always both leds on regardless overflowing (0 and 1 is mutated to 255 and 0 accordingly).

Please help me find out what is happening - i may admit that i miss something but overflowing looks buggy anyway.

Keyboard Used

silakka54/vial (modified latest version - 1.4.0)

Link to product page (if applicable)

https://github.com/Squalius-cephalus/silakka54

Operating System

qmk+vial

qmk doctor Output

Ψ QMK Doctor is checking your environment.
Ψ CLI version: 1.2.0
Ψ QMK home: /home/sam/projects/vial-qmk
Ψ Detected Linux (WSL, Ubuntu 22.04.1 LTS).
Ψ Userspace enabled: False
Ψ Git branch: vial
⚠ Git has unstashed/uncommitted changes.
⚠ The official repository does not seem to be configured as git remote "upstream".
Ψ CLI installed in virtualenv.
⚠ Issues encountered while checking dependencies.
Ψ Found arm-none-eabi-gcc version 15.2.0
Ψ Successfully compiled using arm-none-eabi-gcc
Ψ Successfully tested arm-none-eabi-binutils using arm-none-eabi-size
Ψ Found avr-gcc version 15.2.0
Ψ Successfully compiled using avr-gcc
Ψ Successfully tested avr-binutils using avr-size
⚠ Unknown version for avrdude
⚠ Unknown version for dfu-programmer
⚠ Unknown version for dfu-util
Ψ Submodules are up to date.
Ψ Submodule status:
Ψ - lib/chibios: 2025-05-15 08:25:11 +0000 --  (8bd61b8043)
Ψ - lib/chibios-contrib: 2025-01-08 21:03:31 +0100 --  (3ac181e4)
Ψ - lib/googletest: 2021-06-11 06:37:43 -0700 --  (e2239ee6)
Ψ - lib/lufa: 2022-08-26 12:09:55 +1000 --  (549b97320)
Ψ - lib/vusb: 2022-06-13 09:18:17 +1000 --  (819dbc1)
Ψ - lib/printf: 2022-06-29 23:59:58 +0300 --  (c2e3b4e)
Ψ - lib/pico-sdk: 2025-04-20 21:24:29 +1000 --  (d0c5cac)
Ψ - lib/lvgl: 2022-04-11 04:44:53 -0600 --  (e19410f8)
Ψ QMK is ready to go, but minor problems were found

Is AutoHotKey / Karabiner installed

  • AutoHotKey (Windows)
  • Karabiner (macOS)

Other keyboard-related software installed

vial framework

Additional Context

Keyboard if flashed with two versions of firmware - left (common) and right (with #define MASTER_RIGHT) for each half of keyboard.
Microcontroller is used by keyboard - RP2040-Zero.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions