diff options
author | Joshua Diamond <josh@windowoffire.com> | 2022-11-10 04:27:40 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-10 20:27:40 +1100 |
commit | f6baf916a9ac14cd150f65054573cd1a0e732c5a (patch) | |
tree | a778b28cec51794450c144051831668e9fd388b8 /quantum/rgblight | |
parent | bc269702ee5e9317deb18eb9c7f2717454f6740f (diff) |
Avoid repeated calls to rgblight_set() in tight succession when setting lighting layers (#18338)
Co-authored-by: Sergey Vlasov <sigprof@gmail.com>
Diffstat (limited to 'quantum/rgblight')
-rw-r--r-- | quantum/rgblight/rgblight.c | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/quantum/rgblight/rgblight.c b/quantum/rgblight/rgblight.c index 37cd7a66ab..f832854c5f 100644 --- a/quantum/rgblight/rgblight.c +++ b/quantum/rgblight/rgblight.c @@ -127,6 +127,8 @@ LED_TYPE led[RGBLED_NUM]; #ifdef RGBLIGHT_LAYERS rgblight_segment_t const *const *rgblight_layers = NULL; + +static bool deferred_set_layer_state = false; #endif rgblight_ranges_t rgblight_ranges = {0, RGBLED_NUM, 0, RGBLED_NUM, RGBLED_NUM}; @@ -748,17 +750,13 @@ void rgblight_set_layer_state(uint8_t layer, bool enabled) { rgblight_status.enabled_layer_mask &= ~mask; } RGBLIGHT_SPLIT_SET_CHANGE_LAYERS; - // Static modes don't have a ticker running to update the LEDs - if (rgblight_status.timer_enabled == false) { - rgblight_mode_noeeprom(rgblight_config.mode); - } -# ifdef RGBLIGHT_LAYERS_OVERRIDE_RGB_OFF - // If not enabled, then nothing else will actually set the LEDs... - if (!rgblight_config.enable) { - rgblight_set(); - } -# endif + // Calling rgblight_set() here (directly or indirectly) could + // potentially cause timing issues when there are multiple + // successive calls to rgblight_set_layer_state(). Instead, + // set a flag and do it the next time rgblight_task() runs. + + deferred_set_layer_state = true; } bool rgblight_get_layer_state(uint8_t layer) { @@ -1154,8 +1152,26 @@ void rgblight_task(void) { } } -# ifdef RGBLIGHT_LAYER_BLINK +# ifdef RGBLIGHT_LAYERS +# ifdef RGBLIGHT_LAYER_BLINK rgblight_blink_layer_repeat_helper(); +# endif + + if (deferred_set_layer_state) { + deferred_set_layer_state = false; + + // Static modes don't have a ticker running to update the LEDs + if (rgblight_status.timer_enabled == false) { + rgblight_mode_noeeprom(rgblight_config.mode); + } + +# ifdef RGBLIGHT_LAYERS_OVERRIDE_RGB_OFF + // If not enabled, then nothing else will actually set the LEDs... + if (!rgblight_config.enable) { + rgblight_set(); + } +# endif + } # endif } |