]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/common/chibios/suspend.c
Generate API docs from source code comments (#2491)
[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 /** \brief suspend idle
16  *
17  * FIXME: needs doc
18  */
19 void suspend_idle(uint8_t time) {
20         // TODO: this is not used anywhere - what units is 'time' in?
21         wait_ms(time);
22 }
23
24 /** \brief suspend power down
25  *
26  * FIXME: needs doc
27  */
28 void suspend_power_down(void) {
29         // TODO: figure out what to power down and how
30         // shouldn't power down TPM/FTM if we want a breathing LED
31         // also shouldn't power down USB
32
33         // on AVR, this enables the watchdog for 15ms (max), and goes to
34         // SLEEP_MODE_PWR_DOWN
35
36         wait_ms(17);
37 }
38
39 /** \brief suspend wakeup condition
40  *
41  * FIXME: needs doc
42  */
43 __attribute__ ((weak)) void matrix_power_up(void) {}
44 __attribute__ ((weak)) void matrix_power_down(void) {}
45 bool suspend_wakeup_condition(void)
46 {
47     matrix_power_up();
48     matrix_scan();
49     matrix_power_down();
50     for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
51         if (matrix_get_row(r)) return true;
52     }
53     return false;
54 }
55
56 /** \brief suspend wakeup condition
57  *
58  * run immediately after wakeup
59  * FIXME: needs doc
60  */
61 void suspend_wakeup_init(void)
62 {
63     // clear keyboard state
64     // need to do it manually, because we're running from ISR
65     //  and clear_keyboard() calls print
66     // so only clear the variables in memory
67     // the reports will be sent from main.c afterwards
68     // or if the PC asks for GET_REPORT
69     clear_mods();
70     clear_weak_mods();
71     clear_keys();
72 #ifdef MOUSEKEY_ENABLE
73     mousekey_clear();
74 #endif /* MOUSEKEY_ENABLE */
75 #ifdef EXTRAKEY_ENABLE
76     host_system_send(0);
77     host_consumer_send(0);
78 #endif /* EXTRAKEY_ENABLE */
79 #ifdef BACKLIGHT_ENABLE
80     backlight_init();
81 #endif /* BACKLIGHT_ENABLE */
82 }