4 #include <avr/interrupt.h>
8 #include "suspend_avr.h"
19 #endif /* AUDIO_ENABLE */
23 #define wdt_intr_enable(value) \
24 __asm__ __volatile__ ( \
25 "in __tmp_reg__,__SREG__" "\n\t" \
29 "out __SREG__,__tmp_reg__" "\n\t" \
32 : "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \
33 "r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \
34 "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \
35 _BV(WDIE) | (value & 0x07)) ) \
40 void suspend_idle(uint8_t time)
43 set_sleep_mode(SLEEP_MODE_IDLE);
50 /* Power down MCU with watchdog timer
51 * wdto: watchdog timer timeout defined in <avr/wdt.h>
63 static uint8_t wdt_timeout = 0;
64 static void power_down(uint8_t wdto)
67 if (USB_DeviceState == DEVICE_STATE_Configured) return;
71 // Watchdog Interrupt Mode
72 wdt_intr_enable(wdto);
74 #ifdef BACKLIGHT_ENABLE
78 // Turn off LED indicators
82 // This sometimes disables the start-up noise, so it's been disabled
84 #endif /* AUDIO_ENABLE */
86 // TODO: more power saving
87 // See PicoPower application note
88 // - I/O port input with pullup
91 // - Power Reduction Register PRR
92 set_sleep_mode(SLEEP_MODE_PWR_DOWN);
98 // Disable watchdog after sleep
102 void suspend_power_down(void)
104 power_down(WDTO_15MS);
107 __attribute__ ((weak)) void matrix_power_up(void) {}
108 __attribute__ ((weak)) void matrix_power_down(void) {}
109 bool suspend_wakeup_condition(void)
111 #ifdef BACKLIGHT_ENABLE
117 for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
118 if (matrix_get_row(r)) return true;
123 // run immediately after wakeup
124 void suspend_wakeup_init(void)
126 // clear keyboard state
128 #ifdef BACKLIGHT_ENABLE
132 led_set(host_keyboard_leds());
135 #ifndef NO_SUSPEND_POWER_DOWN
136 /* watchdog timeout */
139 // compensate timer for sleep
140 switch (wdt_timeout) {
142 timer_count += 15 + 2; // WDTO_15MS + 2(from observation)