aboutsummaryrefslogtreecommitdiff
path: root/common/avr/suspend.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/avr/suspend.c')
-rw-r--r--common/avr/suspend.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/common/avr/suspend.c b/common/avr/suspend.c
index 66a579fd7..80243f02b 100644
--- a/common/avr/suspend.c
+++ b/common/avr/suspend.c
@@ -7,6 +7,7 @@
7#include "backlight.h" 7#include "backlight.h"
8#include "suspend_avr.h" 8#include "suspend_avr.h"
9#include "suspend.h" 9#include "suspend.h"
10#include "timer.h"
10#ifdef PROTOCOL_LUFA 11#ifdef PROTOCOL_LUFA
11#include "lufa.h" 12#include "lufa.h"
12#endif 13#endif
@@ -52,11 +53,13 @@ void suspend_idle(uint8_t time)
52 * WDTO_4S 53 * WDTO_4S
53 * WDTO_8S 54 * WDTO_8S
54 */ 55 */
55void suspend_power_down(uint8_t wdto) 56static uint8_t wdt_timeout = 0;
57static void power_down(uint8_t wdto)
56{ 58{
57#ifdef PROTOCOL_LUFA 59#ifdef PROTOCOL_LUFA
58 if (USB_DeviceState == DEVICE_STATE_Configured) return; 60 if (USB_DeviceState == DEVICE_STATE_Configured) return;
59#endif 61#endif
62 wdt_timeout = wdto;
60 63
61 // Watchdog Interrupt Mode 64 // Watchdog Interrupt Mode
62 wdt_intr_enable(wdto); 65 wdt_intr_enable(wdto);
@@ -67,7 +70,6 @@ void suspend_power_down(uint8_t wdto)
67 // - prescale clock 70 // - prescale clock
68 // - BOD disable 71 // - BOD disable
69 // - Power Reduction Register PRR 72 // - Power Reduction Register PRR
70
71 set_sleep_mode(SLEEP_MODE_PWR_DOWN); 73 set_sleep_mode(SLEEP_MODE_PWR_DOWN);
72 sleep_enable(); 74 sleep_enable();
73 sei(); 75 sei();
@@ -78,6 +80,11 @@ void suspend_power_down(uint8_t wdto)
78 wdt_disable(); 80 wdt_disable();
79} 81}
80 82
83void suspend_power_down(void)
84{
85 power_down(WDTO_15MS);
86}
87
81bool suspend_wakeup_condition(void) 88bool suspend_wakeup_condition(void)
82{ 89{
83 matrix_power_up(); 90 matrix_power_up();
@@ -103,15 +110,13 @@ void suspend_wakeup_init(void)
103/* watchdog timeout */ 110/* watchdog timeout */
104ISR(WDT_vect) 111ISR(WDT_vect)
105{ 112{
106 /* wakeup from MCU sleep mode */ 113 // compensate timer for sleep
107/* 114 switch (wdt_timeout) {
108 // blink LED 115 case WDTO_15MS:
109 static uint8_t led_state = 0; 116 timer_count += 15 + 2; // WDTO_15MS + 2(from observation)
110 static uint8_t led_count = 0; 117 break;
111 led_count++; 118 default:
112 if ((led_count & 0x07) == 0) { 119 ;
113 led_set((led_state ^= (1<<USB_LED_CAPS_LOCK)));
114 } 120 }
115*/
116} 121}
117#endif 122#endif