4 #include <avr/interrupt.h>
8 #include "suspend_avr.h"
15 #define wdt_intr_enable(value) \
16 __asm__ __volatile__ ( \
17 "in __tmp_reg__,__SREG__" "\n\t" \
21 "out __SREG__,__tmp_reg__" "\n\t" \
24 : "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \
25 "r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \
26 "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \
27 _BV(WDIE) | (value & 0x07)) ) \
32 void suspend_idle(uint8_t time)
35 set_sleep_mode(SLEEP_MODE_IDLE);
42 /* Power down MCU with watchdog timer
43 * wdto: watchdog timer timeout defined in <avr/wdt.h>
55 void suspend_power_down(uint8_t wdto)
58 if (USB_DeviceState == DEVICE_STATE_Configured) return;
61 // Watchdog Interrupt Mode
62 wdt_intr_enable(wdto);
64 // TODO: more power saving
65 // See PicoPower application note
66 // - I/O port input with pullup
69 // - Power Reduction Register PRR
71 set_sleep_mode(SLEEP_MODE_PWR_DOWN);
77 // Disable watchdog after sleep
81 bool suspend_wakeup_condition(void)
86 for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
87 if (matrix_get_row(r)) return true;
92 // run immediately after wakeup
93 void suspend_wakeup_init(void)
95 // clear keyboard state
97 #ifdef BACKLIGHT_ENABLE
102 #ifndef NO_SUSPEND_POWER_DOWN
103 /* watchdog timeout */
106 /* wakeup from MCU sleep mode */
109 static uint8_t led_state = 0;
110 static uint8_t led_count = 0;
112 if ((led_count & 0x07) == 0) {
113 led_set((led_state ^= (1<<USB_LED_CAPS_LOCK)));