]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/common/chibios/suspend.c
Clueboard 60% support (#1746)
[qmk_firmware.git] / tmk_core / common / chibios / suspend.c
1 /* TODO */
2
3 #include "ch.h"
4 #include "hal.h"
5
6 #include "matrix.h"
7 #include "action.h"
8 #include "action_util.h"
9 #include "mousekey.h"
10 #include "host.h"
11 #include "backlight.h"
12 #include "suspend.h"
13 #include "wait.h"
14
15 void suspend_idle(uint8_t time) {
16         // TODO: this is not used anywhere - what units is 'time' in?
17         wait_ms(time);
18 }
19
20 void suspend_power_down(void) {
21         // TODO: figure out what to power down and how
22         // shouldn't power down TPM/FTM if we want a breathing LED
23         // also shouldn't power down USB
24
25         // on AVR, this enables the watchdog for 15ms (max), and goes to
26         // SLEEP_MODE_PWR_DOWN
27
28         wait_ms(17);
29 }
30
31 __attribute__ ((weak)) void matrix_power_up(void) {}
32 __attribute__ ((weak)) void matrix_power_down(void) {}
33 bool suspend_wakeup_condition(void)
34 {
35     matrix_power_up();
36     matrix_scan();
37     matrix_power_down();
38     for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
39         if (matrix_get_row(r)) return true;
40     }
41     return false;
42 }
43
44 // run immediately after wakeup
45 void suspend_wakeup_init(void)
46 {
47     // clear keyboard state
48     // need to do it manually, because we're running from ISR
49     //  and clear_keyboard() calls print
50     // so only clear the variables in memory
51     // the reports will be sent from main.c afterwards
52     // or if the PC asks for GET_REPORT
53     clear_mods();
54     clear_weak_mods();
55     clear_keys();
56 #ifdef MOUSEKEY_ENABLE
57     mousekey_clear();
58 #endif /* MOUSEKEY_ENABLE */
59 #ifdef EXTRAKEY_ENABLE
60     host_system_send(0);
61     host_consumer_send(0);
62 #endif /* EXTRAKEY_ENABLE */
63 #ifdef BACKLIGHT_ENABLE
64     backlight_init();
65 #endif /* BACKLIGHT_ENABLE */
66 }