diff options
author | Drashna Jaelre <drashna@live.com> | 2019-01-25 17:11:49 -0800 |
---|---|---|
committer | MechMerlin <30334081+mechmerlin@users.noreply.github.com> | 2019-01-25 17:11:49 -0800 |
commit | 7aba1fd1767ecd7df25323c51332c7af986a3805 (patch) | |
tree | 363e16900c11b4cd1e37c423f87db63c779b482b /tmk_core/common | |
parent | 569ed9db9da5cdc4fc78584b51a66c7689d79806 (diff) |
Fix RGBLIGHT_SLEEP function (#4865)
* Only re-enable RGBLIGHT if it was on when going to sleep
* Reformat file to follow QMK Standards
* Fix check, since this is a loop, whoops
Much thanks to @Rockman18 for catching this and posting the additional code!
Diffstat (limited to 'tmk_core/common')
-rw-r--r-- | tmk_core/common/avr/suspend.c | 47 |
1 files changed, 30 insertions, 17 deletions
diff --git a/tmk_core/common/avr/suspend.c b/tmk_core/common/avr/suspend.c index 5bca646854..28219f4ddd 100644 --- a/tmk_core/common/avr/suspend.c +++ b/tmk_core/common/avr/suspend.c @@ -11,6 +11,9 @@ #include "led.h" #include "host.h" #include "rgblight_reconfig.h" +#ifdef SPLIT_KEYBOARD + #include "split_flags.h" +#endif #ifdef PROTOCOL_LUFA #include "lufa.h" @@ -22,6 +25,9 @@ #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) #include "rgblight.h" + extern rgblight_config_t rgblight_config; + static bool rgblight_enabled; + static bool is_suspended; #endif @@ -46,8 +52,7 @@ __asm__ __volatile__ ( \ * * FIXME: needs doc */ -void suspend_idle(uint8_t time) -{ +void suspend_idle(uint8_t time) { cli(); set_sleep_mode(SLEEP_MODE_IDLE); sleep_enable(); @@ -95,8 +100,7 @@ static uint8_t wdt_timeout = 0; * * FIXME: needs doc */ -static void power_down(uint8_t wdto) -{ +static void power_down(uint8_t wdto) { #ifdef PROTOCOL_LUFA if (USB_DeviceState == DEVICE_STATE_Configured) return; #endif @@ -120,7 +124,14 @@ static void power_down(uint8_t wdto) #ifdef RGBLIGHT_ANIMATIONS rgblight_timer_disable(); #endif - rgblight_disable_noeeprom(); + if (!is_suspended) { + is_suspended = true; + rgblight_enabled = rgblight_config.enable; + rgblight_disable_noeeprom(); + #ifdef SPLIT_KEYBOARD + RGB_DIRTY = true; + #endif + } #endif suspend_power_down_kb(); @@ -145,8 +156,7 @@ static void power_down(uint8_t wdto) * * FIXME: needs doc */ -void suspend_power_down(void) -{ +void suspend_power_down(void) { suspend_power_down_kb(); #ifndef NO_SUSPEND_POWER_DOWN @@ -156,8 +166,7 @@ void suspend_power_down(void) __attribute__ ((weak)) void matrix_power_up(void) {} __attribute__ ((weak)) void matrix_power_down(void) {} -bool suspend_wakeup_condition(void) -{ +bool suspend_wakeup_condition(void) { matrix_power_up(); matrix_scan(); matrix_power_down(); @@ -186,8 +195,7 @@ void suspend_wakeup_init_kb(void) { * * FIXME: needs doc */ -void suspend_wakeup_init(void) -{ +void suspend_wakeup_init(void) { // clear keyboard state clear_keyboard(); #ifdef BACKLIGHT_ENABLE @@ -195,10 +203,16 @@ void suspend_wakeup_init(void) #endif led_set(host_keyboard_leds()); #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) -#ifdef BOOTLOADER_TEENSY - wait_ms(10); -#endif - rgblight_enable_noeeprom(); + is_suspended = false; + if (rgblight_enabled) { + #ifdef BOOTLOADER_TEENSY + wait_ms(10); + #endif + rgblight_enable_noeeprom(); + #ifdef SPLIT_KEYBOARD + RGB_DIRTY = true; + #endif + } #ifdef RGBLIGHT_ANIMATIONS rgblight_timer_enable(); #endif @@ -208,8 +222,7 @@ void suspend_wakeup_init(void) #ifndef NO_SUSPEND_POWER_DOWN /* watchdog timeout */ -ISR(WDT_vect) -{ +ISR(WDT_vect) { // compensate timer for sleep switch (wdt_timeout) { case WDTO_15MS: |