]> git.gir.st - tmk_keyboard.git/blob - common/suspend.c
Add supsend and wakeup to pjrc stack
[tmk_keyboard.git] / common / suspend.c
1 #include "suspend.h"
2 #include "matrix.h"
3 #include "action.h"
4
5
6 void 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
38 bool 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
47 // run immediately after wakeup
48 void suspend_wakeup_init(void)
49 {
50 // clear matrix and keyboard state
51 matrix_init();
52 clear_keyboard();
53 }
54
55 #ifndef NO_SUSPEND_POWER_DOWN
56 /* watchdog timeout */
57 ISR(WDT_vect)
58 {
59 /* wakeup from MCU sleep mode */
60 /*
61 // blink LED
62 static uint8_t led_state = 0;
63 static uint8_t led_count = 0;
64 led_count++;
65 if ((led_count & 0x07) == 0) {
66 led_set((led_state ^= (1<<USB_LED_CAPS_LOCK)));
67 }
68 */
69 }
70 #endif
Imprint / Impressum