]> git.donarmstrong.com Git - tmk_firmware.git/blob - common/suspend.c
Add option 7bit data to serial_soft.c
[tmk_firmware.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 keyboard state
55     clear_keyboard();
56 #ifdef BACKLIGHT_ENABLE
57     backlight_init();
58 #endif
59 }
60
61 #ifndef NO_SUSPEND_POWER_DOWN
62 /* watchdog timeout */
63 ISR(WDT_vect)
64 {
65     /* wakeup from MCU sleep mode */
66 /*
67     // blink LED
68     static uint8_t led_state = 0;
69     static uint8_t led_count = 0;
70     led_count++;
71     if ((led_count & 0x07) == 0) {
72         led_set((led_state ^= (1<<USB_LED_CAPS_LOCK)));
73     }
74 */
75 }
76 #endif