4 #include <avr/interrupt.h>
8 #include "suspend_avr.h"
12 #define wdt_intr_enable(value) \
13 __asm__ __volatile__ ( \
14 "in __tmp_reg__,__SREG__" "\n\t" \
18 "out __SREG__,__tmp_reg__" "\n\t" \
21 : "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \
22 "r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \
23 "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \
24 _BV(WDIE) | (value & 0x07)) ) \
29 void suspend_power_down(void)
31 #ifdef BACKLIGHT_ENABLE
34 #ifndef NO_SUSPEND_POWER_DOWN
35 // Enable watchdog to wake from MCU sleep
39 // Watchdog Interrupt and System Reset Mode
40 //wdt_enable(WDTO_1S);
41 //WDTCSR |= _BV(WDIE);
43 // Watchdog Interrupt Mode
44 wdt_intr_enable(WDTO_120MS);
46 // TODO: more power saving
47 // See PicoPower application note
48 // - I/O port input with pullup
51 // - Power Reduction Register PRR
52 // sleep in power down mode
53 set_sleep_mode(SLEEP_MODE_PWR_DOWN);
59 // Disable watchdog after sleep
64 bool suspend_wakeup_condition(void)
67 for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
68 if (matrix_get_row(r)) return true;
73 // run immediately after wakeup
74 void suspend_wakeup_init(void)
76 // clear keyboard state
78 #ifdef BACKLIGHT_ENABLE
83 #ifndef NO_SUSPEND_POWER_DOWN
84 /* watchdog timeout */
87 /* wakeup from MCU sleep mode */
90 static uint8_t led_state = 0;
91 static uint8_t led_count = 0;
93 if ((led_count & 0x07) == 0) {
94 led_set((led_state ^= (1<<USB_LED_CAPS_LOCK)));