diff options
author | Drashna Jaelre <drashna@live.com> | 2021-08-30 12:21:03 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-30 20:21:03 +0100 |
commit | 15710db4ada682d274c1d02b4d66ed7ac820a821 (patch) | |
tree | 4e398caefe966f5f3c1c749797e060635f998d25 | |
parent | cf28feaf4d27866aad23c382fdd9cf095decefff (diff) | |
download | qmk_firmware-15710db4ada682d274c1d02b4d66ed7ac820a821.tar.gz qmk_firmware-15710db4ada682d274c1d02b4d66ed7ac820a821.zip |
Move feature suspend logic out of platform specific code (#14210)
-rw-r--r-- | quantum/quantum.c | 96 | ||||
-rw-r--r-- | tmk_core/common/avr/suspend.c | 98 | ||||
-rw-r--r-- | tmk_core/common/chibios/suspend.c | 85 | ||||
-rw-r--r-- | tmk_core/common/suspend.h | 2 |
4 files changed, 102 insertions, 179 deletions
diff --git a/quantum/quantum.c b/quantum/quantum.c index e60378afe..9d77fa438 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c | |||
@@ -480,3 +480,99 @@ void api_send_unicode(uint32_t unicode) { | |||
480 | __attribute__((weak)) void startup_user() {} | 480 | __attribute__((weak)) void startup_user() {} |
481 | 481 | ||
482 | __attribute__((weak)) void shutdown_user() {} | 482 | __attribute__((weak)) void shutdown_user() {} |
483 | |||
484 | /** \brief Run keyboard level Power down | ||
485 | * | ||
486 | * FIXME: needs doc | ||
487 | */ | ||
488 | __attribute__((weak)) void suspend_power_down_user(void) {} | ||
489 | /** \brief Run keyboard level Power down | ||
490 | * | ||
491 | * FIXME: needs doc | ||
492 | */ | ||
493 | __attribute__((weak)) void suspend_power_down_kb(void) { suspend_power_down_user(); } | ||
494 | |||
495 | void suspend_power_down_quantum(void) { | ||
496 | #ifndef NO_SUSPEND_POWER_DOWN | ||
497 | // Turn off backlight | ||
498 | # ifdef BACKLIGHT_ENABLE | ||
499 | backlight_set(0); | ||
500 | # endif | ||
501 | |||
502 | # ifdef LED_MATRIX_ENABLE | ||
503 | led_matrix_task(); | ||
504 | # endif | ||
505 | # ifdef RGB_MATRIX_ENABLE | ||
506 | rgb_matrix_task(); | ||
507 | # endif | ||
508 | |||
509 | // Turn off LED indicators | ||
510 | uint8_t leds_off = 0; | ||
511 | # if defined(BACKLIGHT_CAPS_LOCK) && defined(BACKLIGHT_ENABLE) | ||
512 | if (is_backlight_enabled()) { | ||
513 | // Don't try to turn off Caps Lock indicator as it is backlight and backlight is already off | ||
514 | leds_off |= (1 << USB_LED_CAPS_LOCK); | ||
515 | } | ||
516 | # endif | ||
517 | led_set(leds_off); | ||
518 | |||
519 | // Turn off audio | ||
520 | # ifdef AUDIO_ENABLE | ||
521 | stop_all_notes(); | ||
522 | # endif | ||
523 | |||
524 | // Turn off underglow | ||
525 | # if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) | ||
526 | rgblight_suspend(); | ||
527 | # endif | ||
528 | |||
529 | # if defined(LED_MATRIX_ENABLE) | ||
530 | led_matrix_set_suspend_state(true); | ||
531 | # endif | ||
532 | # if defined(RGB_MATRIX_ENABLE) | ||
533 | rgb_matrix_set_suspend_state(true); | ||
534 | # endif | ||
535 | |||
536 | # ifdef OLED_ENABLE | ||
537 | oled_off(); | ||
538 | # endif | ||
539 | # ifdef ST7565_ENABLE | ||
540 | st7565_off(); | ||
541 | # endif | ||
542 | #endif | ||
543 | } | ||
544 | |||
545 | /** \brief run user level code immediately after wakeup | ||
546 | * | ||
547 | * FIXME: needs doc | ||
548 | */ | ||
549 | __attribute__((weak)) void suspend_wakeup_init_user(void) {} | ||
550 | |||
551 | /** \brief run keyboard level code immediately after wakeup | ||
552 | * | ||
553 | * FIXME: needs doc | ||
554 | */ | ||
555 | __attribute__((weak)) void suspend_wakeup_init_kb(void) { suspend_wakeup_init_user(); } | ||
556 | |||
557 | __attribute__((weak)) void suspend_wakeup_init_quantum(void) { | ||
558 | // Turn on backlight | ||
559 | #ifdef BACKLIGHT_ENABLE | ||
560 | backlight_init(); | ||
561 | #endif | ||
562 | |||
563 | // Restore LED indicators | ||
564 | led_set(host_keyboard_leds()); | ||
565 | |||
566 | // Wake up underglow | ||
567 | #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) | ||
568 | rgblight_wakeup(); | ||
569 | #endif | ||
570 | |||
571 | #if defined(LED_MATRIX_ENABLE) | ||
572 | led_matrix_set_suspend_state(false); | ||
573 | #endif | ||
574 | #if defined(RGB_MATRIX_ENABLE) | ||
575 | rgb_matrix_set_suspend_state(false); | ||
576 | #endif | ||
577 | suspend_wakeup_init_kb(); | ||
578 | } | ||
diff --git a/tmk_core/common/avr/suspend.c b/tmk_core/common/avr/suspend.c index 690d7f38c..b614746e6 100644 --- a/tmk_core/common/avr/suspend.c +++ b/tmk_core/common/avr/suspend.c | |||
@@ -16,25 +16,6 @@ | |||
16 | # include "vusb.h" | 16 | # include "vusb.h" |
17 | #endif | 17 | #endif |
18 | 18 | ||
19 | #ifdef BACKLIGHT_ENABLE | ||
20 | # include "backlight.h" | ||
21 | #endif | ||
22 | |||
23 | #ifdef AUDIO_ENABLE | ||
24 | # include "audio.h" | ||
25 | #endif /* AUDIO_ENABLE */ | ||
26 | |||
27 | #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) | ||
28 | # include "rgblight.h" | ||
29 | #endif | ||
30 | |||
31 | #ifdef LED_MATRIX_ENABLE | ||
32 | # include "led_matrix.h" | ||
33 | #endif | ||
34 | #ifdef RGB_MATRIX_ENABLE | ||
35 | # include "rgb_matrix.h" | ||
36 | #endif | ||
37 | |||
38 | /** \brief Suspend idle | 19 | /** \brief Suspend idle |
39 | * | 20 | * |
40 | * FIXME: needs doc | 21 | * FIXME: needs doc |
@@ -50,17 +31,6 @@ void suspend_idle(uint8_t time) { | |||
50 | 31 | ||
51 | // TODO: This needs some cleanup | 32 | // TODO: This needs some cleanup |
52 | 33 | ||
53 | /** \brief Run keyboard level Power down | ||
54 | * | ||
55 | * FIXME: needs doc | ||
56 | */ | ||
57 | __attribute__((weak)) void suspend_power_down_user(void) {} | ||
58 | /** \brief Run keyboard level Power down | ||
59 | * | ||
60 | * FIXME: needs doc | ||
61 | */ | ||
62 | __attribute__((weak)) void suspend_power_down_kb(void) { suspend_power_down_user(); } | ||
63 | |||
64 | #if !defined(NO_SUSPEND_POWER_DOWN) && defined(WDT_vect) | 34 | #if !defined(NO_SUSPEND_POWER_DOWN) && defined(WDT_vect) |
65 | 35 | ||
66 | // clang-format off | 36 | // clang-format off |
@@ -135,41 +105,9 @@ void suspend_power_down(void) { | |||
135 | if (!vusb_suspended) return; | 105 | if (!vusb_suspended) return; |
136 | #endif | 106 | #endif |
137 | 107 | ||
138 | suspend_power_down_kb(); | 108 | suspend_power_down_quantum(); |
139 | 109 | ||
140 | #ifndef NO_SUSPEND_POWER_DOWN | 110 | #ifndef NO_SUSPEND_POWER_DOWN |
141 | // Turn off backlight | ||
142 | # ifdef BACKLIGHT_ENABLE | ||
143 | backlight_set(0); | ||
144 | # endif | ||
145 | |||
146 | // Turn off LED indicators | ||
147 | uint8_t leds_off = 0; | ||
148 | # if defined(BACKLIGHT_CAPS_LOCK) && defined(BACKLIGHT_ENABLE) | ||
149 | if (is_backlight_enabled()) { | ||
150 | // Don't try to turn off Caps Lock indicator as it is backlight and backlight is already off | ||
151 | leds_off |= (1 << USB_LED_CAPS_LOCK); | ||
152 | } | ||
153 | # endif | ||
154 | led_set(leds_off); | ||
155 | |||
156 | // Turn off audio | ||
157 | # ifdef AUDIO_ENABLE | ||
158 | stop_all_notes(); | ||
159 | # endif | ||
160 | |||
161 | // Turn off underglow | ||
162 | # if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) | ||
163 | rgblight_suspend(); | ||
164 | # endif | ||
165 | |||
166 | # if defined(LED_MATRIX_ENABLE) | ||
167 | led_matrix_set_suspend_state(true); | ||
168 | # endif | ||
169 | # if defined(RGB_MATRIX_ENABLE) | ||
170 | rgb_matrix_set_suspend_state(true); | ||
171 | # endif | ||
172 | |||
173 | // Enter sleep state if possible (ie, the MCU has a watchdog timeout interrupt) | 111 | // Enter sleep state if possible (ie, the MCU has a watchdog timeout interrupt) |
174 | # if defined(WDT_vect) | 112 | # if defined(WDT_vect) |
175 | power_down(WDTO_15MS); | 113 | power_down(WDTO_15MS); |
@@ -189,18 +127,6 @@ bool suspend_wakeup_condition(void) { | |||
189 | return false; | 127 | return false; |
190 | } | 128 | } |
191 | 129 | ||
192 | /** \brief run user level code immediately after wakeup | ||
193 | * | ||
194 | * FIXME: needs doc | ||
195 | */ | ||
196 | __attribute__((weak)) void suspend_wakeup_init_user(void) {} | ||
197 | |||
198 | /** \brief run keyboard level code immediately after wakeup | ||
199 | * | ||
200 | * FIXME: needs doc | ||
201 | */ | ||
202 | __attribute__((weak)) void suspend_wakeup_init_kb(void) { suspend_wakeup_init_user(); } | ||
203 | |||
204 | /** \brief run immediately after wakeup | 130 | /** \brief run immediately after wakeup |
205 | * | 131 | * |
206 | * FIXME: needs doc | 132 | * FIXME: needs doc |
@@ -209,27 +135,7 @@ void suspend_wakeup_init(void) { | |||
209 | // clear keyboard state | 135 | // clear keyboard state |
210 | clear_keyboard(); | 136 | clear_keyboard(); |
211 | 137 | ||
212 | // Turn on backlight | 138 | suspend_wakeup_init_quantum(); |
213 | #ifdef BACKLIGHT_ENABLE | ||
214 | backlight_init(); | ||
215 | #endif | ||
216 | |||
217 | // Restore LED indicators | ||
218 | led_set(host_keyboard_leds()); | ||
219 | |||
220 | // Wake up underglow | ||
221 | #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) | ||
222 | rgblight_wakeup(); | ||
223 | #endif | ||
224 | |||
225 | #if defined(LED_MATRIX_ENABLE) | ||
226 | led_matrix_set_suspend_state(false); | ||
227 | #endif | ||
228 | #if defined(RGB_MATRIX_ENABLE) | ||
229 | rgb_matrix_set_suspend_state(false); | ||
230 | #endif | ||
231 | |||
232 | suspend_wakeup_init_kb(); | ||
233 | } | 139 | } |
234 | 140 | ||
235 | #if !defined(NO_SUSPEND_POWER_DOWN) && defined(WDT_vect) | 141 | #if !defined(NO_SUSPEND_POWER_DOWN) && defined(WDT_vect) |
diff --git a/tmk_core/common/chibios/suspend.c b/tmk_core/common/chibios/suspend.c index 38517e06f..991fe6e08 100644 --- a/tmk_core/common/chibios/suspend.c +++ b/tmk_core/common/chibios/suspend.c | |||
@@ -12,25 +12,6 @@ | |||
12 | #include "led.h" | 12 | #include "led.h" |
13 | #include "wait.h" | 13 | #include "wait.h" |
14 | 14 | ||
15 | #ifdef AUDIO_ENABLE | ||
16 | # include "audio.h" | ||
17 | #endif /* AUDIO_ENABLE */ | ||
18 | |||
19 | #ifdef BACKLIGHT_ENABLE | ||
20 | # include "backlight.h" | ||
21 | #endif | ||
22 | |||
23 | #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) | ||
24 | # include "rgblight.h" | ||
25 | #endif | ||
26 | |||
27 | #ifdef LED_MATRIX_ENABLE | ||
28 | # include "led_matrix.h" | ||
29 | #endif | ||
30 | #ifdef RGB_MATRIX_ENABLE | ||
31 | # include "rgb_matrix.h" | ||
32 | #endif | ||
33 | |||
34 | /** \brief suspend idle | 15 | /** \brief suspend idle |
35 | * | 16 | * |
36 | * FIXME: needs doc | 17 | * FIXME: needs doc |
@@ -40,61 +21,12 @@ void suspend_idle(uint8_t time) { | |||
40 | wait_ms(time); | 21 | wait_ms(time); |
41 | } | 22 | } |
42 | 23 | ||
43 | /** \brief Run keyboard level Power down | ||
44 | * | ||
45 | * FIXME: needs doc | ||
46 | */ | ||
47 | __attribute__((weak)) void suspend_power_down_user(void) {} | ||
48 | /** \brief Run keyboard level Power down | ||
49 | * | ||
50 | * FIXME: needs doc | ||
51 | */ | ||
52 | __attribute__((weak)) void suspend_power_down_kb(void) { suspend_power_down_user(); } | ||
53 | |||
54 | /** \brief suspend power down | 24 | /** \brief suspend power down |
55 | * | 25 | * |
56 | * FIXME: needs doc | 26 | * FIXME: needs doc |
57 | */ | 27 | */ |
58 | void suspend_power_down(void) { | 28 | void suspend_power_down(void) { |
59 | #ifdef BACKLIGHT_ENABLE | 29 | suspend_power_down_quantum(); |
60 | backlight_set(0); | ||
61 | #endif | ||
62 | |||
63 | #ifdef LED_MATRIX_ENABLE | ||
64 | led_matrix_task(); | ||
65 | #endif | ||
66 | #ifdef RGB_MATRIX_ENABLE | ||
67 | rgb_matrix_task(); | ||
68 | #endif | ||
69 | |||
70 | // Turn off LED indicators | ||
71 | uint8_t leds_off = 0; | ||
72 | #if defined(BACKLIGHT_CAPS_LOCK) && defined(BACKLIGHT_ENABLE) | ||
73 | if (is_backlight_enabled()) { | ||
74 | // Don't try to turn off Caps Lock indicator as it is backlight and backlight is already off | ||
75 | leds_off |= (1 << USB_LED_CAPS_LOCK); | ||
76 | } | ||
77 | #endif | ||
78 | led_set(leds_off); | ||
79 | |||
80 | // TODO: figure out what to power down and how | ||
81 | // shouldn't power down TPM/FTM if we want a breathing LED | ||
82 | // also shouldn't power down USB | ||
83 | #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) | ||
84 | rgblight_suspend(); | ||
85 | #endif | ||
86 | |||
87 | #if defined(LED_MATRIX_ENABLE) | ||
88 | led_matrix_set_suspend_state(true); | ||
89 | #endif | ||
90 | #if defined(RGB_MATRIX_ENABLE) | ||
91 | rgb_matrix_set_suspend_state(true); | ||
92 | #endif | ||
93 | #ifdef AUDIO_ENABLE | ||
94 | stop_all_notes(); | ||
95 | #endif /* AUDIO_ENABLE */ | ||
96 | |||
97 | suspend_power_down_kb(); | ||
98 | // on AVR, this enables the watchdog for 15ms (max), and goes to | 30 | // on AVR, this enables the watchdog for 15ms (max), and goes to |
99 | // SLEEP_MODE_PWR_DOWN | 31 | // SLEEP_MODE_PWR_DOWN |
100 | 32 | ||
@@ -151,19 +83,6 @@ void suspend_wakeup_init(void) { | |||
151 | host_system_send(0); | 83 | host_system_send(0); |
152 | host_consumer_send(0); | 84 | host_consumer_send(0); |
153 | #endif /* EXTRAKEY_ENABLE */ | 85 | #endif /* EXTRAKEY_ENABLE */ |
154 | #ifdef BACKLIGHT_ENABLE | ||
155 | backlight_init(); | ||
156 | #endif /* BACKLIGHT_ENABLE */ | ||
157 | led_set(host_keyboard_leds()); | ||
158 | #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) | ||
159 | rgblight_wakeup(); | ||
160 | #endif | ||
161 | 86 | ||
162 | #if defined(LED_MATRIX_ENABLE) | 87 | suspend_wakeup_init_quantum(); |
163 | led_matrix_set_suspend_state(false); | ||
164 | #endif | ||
165 | #if defined(RGB_MATRIX_ENABLE) | ||
166 | rgb_matrix_set_suspend_state(false); | ||
167 | #endif | ||
168 | suspend_wakeup_init_kb(); | ||
169 | } | 88 | } |
diff --git a/tmk_core/common/suspend.h b/tmk_core/common/suspend.h index 95845e4b6..081735f90 100644 --- a/tmk_core/common/suspend.h +++ b/tmk_core/common/suspend.h | |||
@@ -10,8 +10,10 @@ void suspend_wakeup_init(void); | |||
10 | 10 | ||
11 | void suspend_wakeup_init_user(void); | 11 | void suspend_wakeup_init_user(void); |
12 | void suspend_wakeup_init_kb(void); | 12 | void suspend_wakeup_init_kb(void); |
13 | void suspend_wakeup_init_quantum(void); | ||
13 | void suspend_power_down_user(void); | 14 | void suspend_power_down_user(void); |
14 | void suspend_power_down_kb(void); | 15 | void suspend_power_down_kb(void); |
16 | void suspend_power_down_quantum(void); | ||
15 | 17 | ||
16 | #ifndef USB_SUSPEND_WAKEUP_DELAY | 18 | #ifndef USB_SUSPEND_WAKEUP_DELAY |
17 | # define USB_SUSPEND_WAKEUP_DELAY 0 | 19 | # define USB_SUSPEND_WAKEUP_DELAY 0 |