Repository navigation
fix(underglow): turn on with USB power from boot when AUTO_OFF_USB is set - #3555
Open
akira-toriyama wants to merge 1 commit into
Open
akira-toriyama wants to merge 1 commit into
akira-toriyama wants to merge 1 commit into
Conversation
… set With CONFIG_ZMK_RGB_UNDERGLOW_AUTO_OFF_USB the underglow never came on by itself. zmk_rgb_underglow_init() read zmk_usb_is_powered() before zmk_usb_init() had run (CONFIG_APPLICATION_INIT_PRIORITY against ZMK_USB_INIT_PRIORITY, 96), so it read "not powered" and stayed off, and rgb_underglow_auto_state() started with is_awake = true, so the first connection event, the only one a keyboard booted on USB gets, counted as a wake while awake and did nothing. Only a disconnect acted, and the off it saved was restored at the next boot. The underglow now follows USB power from boot. The first evaluation runs from the settings commit handler, after zmk_usb_init() and the saved state, with the sleep state set as after an automatic off, so that it and every later USB event take the same path; without CONFIG_SETTINGS it runs at the end of init and the connection event turns the underglow on. The saved on/off is not restored with this option, since an automatic off writes it too. On an nRF52840 split peripheral with a WS2812 strip (zmk 4dd95d7), the underglow stayed off when booted on USB, when booted on battery and then plugged in, and when rebooted on USB; with this change it is on in all three cases and goes off when the cable is pulled. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
CONFIG_ZMK_RGB_UNDERGLOW_AUTO_OFF_USB=ythe underglow never comes on by itself (zmk 4dd95d7, an nRF52840 split peripheral with a WS2812 strip,CONFIG_ZMK_RGB_UNDERGLOW_EXT_POWERat its default):Two causes in
app/src/rgb_underglow.c:zmk_rgb_underglow_init()runs atCONFIG_APPLICATION_INIT_PRIORITY, beforezmk_usb_init()(ZMK_USB_INIT_PRIORITY, 96), sozmk_usb_is_powered()reads "not powered" and the underglow starts off.rgb_underglow_auto_state()starts withis_awake = true, so the first connection event, the only one a keyboard booted on USB gets, is taken for a wake while awake and ignored. Only a disconnect acts, and the off it saves is restored at the next boot.The fix evaluates the USB rule once the state is known: from the settings commit handler, after
zmk_usb_init()and the saved state (at the end of init withoutCONFIG_SETTINGS), with the sleep state set as after an automatic off, so that the first evaluation and every later USB event take the same path. The saved on/off is not restored with this option, since an automatic off writes it too.With the change, on the same hardware: on when booted on USB, on when plugged in after a battery boot, on when rebooted on USB, off when the cable is pulled. Nothing of this is reachable from the posix tests (no USB), so no test is added.
PR check-list
🤖 Generated with Claude Code