aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/common/chibios/suspend.c
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/common/chibios/suspend.c')
-rw-r--r--tmk_core/common/chibios/suspend.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/tmk_core/common/chibios/suspend.c b/tmk_core/common/chibios/suspend.c
new file mode 100644
index 000000000..6ca16034f
--- /dev/null
+++ b/tmk_core/common/chibios/suspend.c
@@ -0,0 +1,65 @@
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
14void suspend_idle(uint8_t time) {
15 // TODO: this is not used anywhere - what units is 'time' in?
16 chThdSleepMilliseconds(time);
17}
18
19void suspend_power_down(void) {
20 // TODO: figure out what to power down and how
21 // shouldn't power down TPM/FTM if we want a breathing LED
22 // also shouldn't power down USB
23
24 // on AVR, this enables the watchdog for 15ms (max), and goes to
25 // SLEEP_MODE_PWR_DOWN
26
27 chThdSleepMilliseconds(17);
28}
29
30__attribute__ ((weak)) void matrix_power_up(void) {}
31__attribute__ ((weak)) void matrix_power_down(void) {}
32bool suspend_wakeup_condition(void)
33{
34 matrix_power_up();
35 matrix_scan();
36 matrix_power_down();
37 for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
38 if (matrix_get_row(r)) return true;
39 }
40 return false;
41}
42
43// run immediately after wakeup
44void suspend_wakeup_init(void)
45{
46 // clear keyboard state
47 // need to do it manually, because we're running from ISR
48 // and clear_keyboard() calls print
49 // so only clear the variables in memory
50 // the reports will be sent from main.c afterwards
51 // or if the PC asks for GET_REPORT
52 clear_mods();
53 clear_weak_mods();
54 clear_keys();
55#ifdef MOUSEKEY_ENABLE
56 mousekey_clear();
57#endif /* MOUSEKEY_ENABLE */
58#ifdef EXTRAKEY_ENABLE
59 host_system_send(0);
60 host_consumer_send(0);
61#endif /* EXTRAKEY_ENABLE */
62#ifdef BACKLIGHT_ENABLE
63 backlight_init();
64#endif /* BACKLIGHT_ENABLE */
65}