aboutsummaryrefslogtreecommitdiff
path: root/common/suspend.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/suspend.c')
-rw-r--r--common/suspend.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/common/suspend.c b/common/suspend.c
new file mode 100644
index 000000000..397e0729a
--- /dev/null
+++ b/common/suspend.c
@@ -0,0 +1,51 @@
1#include "suspend.h"
2#include "matrix.h"
3#include "action.h"
4
5
6void suspend_power_down(void)
7{
8#ifndef NO_SUSPEND_POWER_DOWN
9 // Enable watchdog to wake from MCU sleep
10 cli();
11 wdt_reset();
12
13 // Watchdog Interrupt and System Reset Mode
14 //wdt_enable(WDTO_1S);
15 //WDTCSR |= _BV(WDIE);
16
17 // Watchdog Interrupt Mode
18 wdt_intr_enable(WDTO_120MS);
19
20 // TODO: more power saving
21 // See PicoPower application note
22 // - I/O port input with pullup
23 // - prescale clock
24 // - BOD disable
25 // - Power Reduction Register PRR
26 // sleep in power down mode
27 set_sleep_mode(SLEEP_MODE_PWR_DOWN);
28 sleep_enable();
29 sei();
30 sleep_cpu();
31 sleep_disable();
32
33 // Disable watchdog after sleep
34 wdt_disable();
35#endif
36}
37
38bool suspend_wakeup_condition(void)
39{
40 matrix_scan();
41 for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
42 if (matrix_get_row(r)) return true;
43 }
44 return false;
45}
46
47void suspend_wakeup_init(void)
48{
49 matrix_init();
50 clear_keyboard();
51}