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 | |
| parent | 569ed9db9da5cdc4fc78584b51a66c7689d79806 (diff) | |
| download | qmk_firmware-7aba1fd1767ecd7df25323c51332c7af986a3805.tar.gz qmk_firmware-7aba1fd1767ecd7df25323c51332c7af986a3805.zip | |
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')
| -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 5bca64685..28219f4dd 100644 --- a/tmk_core/common/avr/suspend.c +++ b/tmk_core/common/avr/suspend.c | |||
| @@ -11,6 +11,9 @@ | |||
| 11 | #include "led.h" | 11 | #include "led.h" |
| 12 | #include "host.h" | 12 | #include "host.h" |
| 13 | #include "rgblight_reconfig.h" | 13 | #include "rgblight_reconfig.h" |
| 14 | #ifdef SPLIT_KEYBOARD | ||
| 15 | #include "split_flags.h" | ||
| 16 | #endif | ||
| 14 | 17 | ||
| 15 | #ifdef PROTOCOL_LUFA | 18 | #ifdef PROTOCOL_LUFA |
| 16 | #include "lufa.h" | 19 | #include "lufa.h" |
| @@ -22,6 +25,9 @@ | |||
| 22 | 25 | ||
| 23 | #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) | 26 | #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) |
| 24 | #include "rgblight.h" | 27 | #include "rgblight.h" |
| 28 | extern rgblight_config_t rgblight_config; | ||
| 29 | static bool rgblight_enabled; | ||
| 30 | static bool is_suspended; | ||
| 25 | #endif | 31 | #endif |
| 26 | 32 | ||
| 27 | 33 | ||
| @@ -46,8 +52,7 @@ __asm__ __volatile__ ( \ | |||
| 46 | * | 52 | * |
| 47 | * FIXME: needs doc | 53 | * FIXME: needs doc |
| 48 | */ | 54 | */ |
| 49 | void suspend_idle(uint8_t time) | 55 | void suspend_idle(uint8_t time) { |
| 50 | { | ||
| 51 | cli(); | 56 | cli(); |
| 52 | set_sleep_mode(SLEEP_MODE_IDLE); | 57 | set_sleep_mode(SLEEP_MODE_IDLE); |
| 53 | sleep_enable(); | 58 | sleep_enable(); |
| @@ -95,8 +100,7 @@ static uint8_t wdt_timeout = 0; | |||
| 95 | * | 100 | * |
| 96 | * FIXME: needs doc | 101 | * FIXME: needs doc |
| 97 | */ | 102 | */ |
| 98 | static void power_down(uint8_t wdto) | 103 | static void power_down(uint8_t wdto) { |
| 99 | { | ||
| 100 | #ifdef PROTOCOL_LUFA | 104 | #ifdef PROTOCOL_LUFA |
| 101 | if (USB_DeviceState == DEVICE_STATE_Configured) return; | 105 | if (USB_DeviceState == DEVICE_STATE_Configured) return; |
| 102 | #endif | 106 | #endif |
| @@ -120,7 +124,14 @@ static void power_down(uint8_t wdto) | |||
| 120 | #ifdef RGBLIGHT_ANIMATIONS | 124 | #ifdef RGBLIGHT_ANIMATIONS |
| 121 | rgblight_timer_disable(); | 125 | rgblight_timer_disable(); |
| 122 | #endif | 126 | #endif |
| 123 | rgblight_disable_noeeprom(); | 127 | if (!is_suspended) { |
| 128 | is_suspended = true; | ||
| 129 | rgblight_enabled = rgblight_config.enable; | ||
| 130 | rgblight_disable_noeeprom(); | ||
| 131 | #ifdef SPLIT_KEYBOARD | ||
| 132 | RGB_DIRTY = true; | ||
| 133 | #endif | ||
| 134 | } | ||
| 124 | #endif | 135 | #endif |
| 125 | suspend_power_down_kb(); | 136 | suspend_power_down_kb(); |
| 126 | 137 | ||
| @@ -145,8 +156,7 @@ static void power_down(uint8_t wdto) | |||
| 145 | * | 156 | * |
| 146 | * FIXME: needs doc | 157 | * FIXME: needs doc |
| 147 | */ | 158 | */ |
| 148 | void suspend_power_down(void) | 159 | void suspend_power_down(void) { |
| 149 | { | ||
| 150 | suspend_power_down_kb(); | 160 | suspend_power_down_kb(); |
| 151 | 161 | ||
| 152 | #ifndef NO_SUSPEND_POWER_DOWN | 162 | #ifndef NO_SUSPEND_POWER_DOWN |
| @@ -156,8 +166,7 @@ void suspend_power_down(void) | |||
| 156 | 166 | ||
| 157 | __attribute__ ((weak)) void matrix_power_up(void) {} | 167 | __attribute__ ((weak)) void matrix_power_up(void) {} |
| 158 | __attribute__ ((weak)) void matrix_power_down(void) {} | 168 | __attribute__ ((weak)) void matrix_power_down(void) {} |
| 159 | bool suspend_wakeup_condition(void) | 169 | bool suspend_wakeup_condition(void) { |
| 160 | { | ||
| 161 | matrix_power_up(); | 170 | matrix_power_up(); |
| 162 | matrix_scan(); | 171 | matrix_scan(); |
| 163 | matrix_power_down(); | 172 | matrix_power_down(); |
| @@ -186,8 +195,7 @@ void suspend_wakeup_init_kb(void) { | |||
| 186 | * | 195 | * |
| 187 | * FIXME: needs doc | 196 | * FIXME: needs doc |
| 188 | */ | 197 | */ |
| 189 | void suspend_wakeup_init(void) | 198 | void suspend_wakeup_init(void) { |
| 190 | { | ||
| 191 | // clear keyboard state | 199 | // clear keyboard state |
| 192 | clear_keyboard(); | 200 | clear_keyboard(); |
| 193 | #ifdef BACKLIGHT_ENABLE | 201 | #ifdef BACKLIGHT_ENABLE |
| @@ -195,10 +203,16 @@ void suspend_wakeup_init(void) | |||
| 195 | #endif | 203 | #endif |
| 196 | led_set(host_keyboard_leds()); | 204 | led_set(host_keyboard_leds()); |
| 197 | #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) | 205 | #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) |
| 198 | #ifdef BOOTLOADER_TEENSY | 206 | is_suspended = false; |
| 199 | wait_ms(10); | 207 | if (rgblight_enabled) { |
| 200 | #endif | 208 | #ifdef BOOTLOADER_TEENSY |
| 201 | rgblight_enable_noeeprom(); | 209 | wait_ms(10); |
| 210 | #endif | ||
| 211 | rgblight_enable_noeeprom(); | ||
| 212 | #ifdef SPLIT_KEYBOARD | ||
| 213 | RGB_DIRTY = true; | ||
| 214 | #endif | ||
| 215 | } | ||
| 202 | #ifdef RGBLIGHT_ANIMATIONS | 216 | #ifdef RGBLIGHT_ANIMATIONS |
| 203 | rgblight_timer_enable(); | 217 | rgblight_timer_enable(); |
| 204 | #endif | 218 | #endif |
| @@ -208,8 +222,7 @@ void suspend_wakeup_init(void) | |||
| 208 | 222 | ||
| 209 | #ifndef NO_SUSPEND_POWER_DOWN | 223 | #ifndef NO_SUSPEND_POWER_DOWN |
| 210 | /* watchdog timeout */ | 224 | /* watchdog timeout */ |
| 211 | ISR(WDT_vect) | 225 | ISR(WDT_vect) { |
| 212 | { | ||
| 213 | // compensate timer for sleep | 226 | // compensate timer for sleep |
| 214 | switch (wdt_timeout) { | 227 | switch (wdt_timeout) { |
| 215 | case WDTO_15MS: | 228 | case WDTO_15MS: |
