]> git.gir.st - tmk_keyboard.git/blob - common/suspend.c
Merge branch 'macro_mediakey'(Fix issue #42)
[tmk_keyboard.git] / common / suspend.c
1 #include "suspend.h"
2 #include "matrix.h"
3 #include "action.h"
4 #include "backlight.h"
5
6
7 void suspend_power_down(void)
8 {
9 #ifdef BACKLIGHT_ENABLE
10 backlight_set(0);
11 #endif
12 #ifndef NO_SUSPEND_POWER_DOWN
13 // Enable watchdog to wake from MCU sleep
14 cli();
15 wdt_reset();
16
17 // Watchdog Interrupt and System Reset Mode
18 //wdt_enable(WDTO_1S);
19 //WDTCSR |= _BV(WDIE);
20
21 // Watchdog Interrupt Mode
22 wdt_intr_enable(WDTO_120MS);
23
24 // TODO: more power saving
25 // See PicoPower application note
26 // - I/O port input with pullup
27 // - prescale clock
28 // - BOD disable
29 // - Power Reduction Register PRR
30 // sleep in power down mode
31 set_sleep_mode(SLEEP_MODE_PWR_DOWN);
32 sleep_enable();
33 sei();
34 sleep_cpu();
35 sleep_disable();
36
37 // Disable watchdog after sleep
38 wdt_disable();
39 #endif
40 }
41
42 bool suspend_wakeup_condition(void)
43 {
44 matrix_scan();
45 for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
46 if (matrix_get_row(r)) return true;
47 }
48 return false;
49 }
50
51 // run immediately after wakeup
52 void suspend_wakeup_init(void)
53 {
54 // clear matrix and keyboard state
55 matrix_init();
56 clear_keyboard();
57 #ifdef BACKLIGHT_ENABLE
58 backlight_init();
59 #endif
60 }
61
62 #ifndef NO_SUSPEND_POWER_DOWN
63 /* watchdog timeout */
64 ISR(WDT_vect)
65 {
66 /* wakeup from MCU sleep mode */
67 /*
68 // blink LED
69 static uint8_t led_state = 0;
70 static uint8_t led_count = 0;
71 led_count++;
72 if ((led_count & 0x07) == 0) {
73 led_set((led_state ^= (1<<USB_LED_CAPS_LOCK)));
74 }
75 */
76 }
77 #endif
Imprint / Impressum