diff options
| author | tmk <hasu@tmk-kbd.com> | 2014-11-26 11:25:45 +0900 |
|---|---|---|
| committer | tmk <hasu@tmk-kbd.com> | 2015-01-15 17:08:48 +0900 |
| commit | 05795cb0034e885bec37f782cfc6bddcae262637 (patch) | |
| tree | 8dffd6f416da650e31c8a509d830415dc22cae52 /common | |
| parent | 10a6b2c7d8bc9c5d2657acdeefa1102be5035280 (diff) | |
| download | qmk_firmware-05795cb0034e885bec37f782cfc6bddcae262637.tar.gz qmk_firmware-05795cb0034e885bec37f782cfc6bddcae262637.zip | |
Compensate timer during prower down
Diffstat (limited to 'common')
| -rw-r--r-- | common/avr/suspend.c | 27 | ||||
| -rw-r--r-- | common/suspend.h | 2 |
2 files changed, 17 insertions, 12 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 | */ |
| 55 | void suspend_power_down(uint8_t wdto) | 56 | static uint8_t wdt_timeout = 0; |
| 57 | static 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 | ||
| 83 | void suspend_power_down(void) | ||
| 84 | { | ||
| 85 | power_down(WDTO_15MS); | ||
| 86 | } | ||
| 87 | |||
| 81 | bool suspend_wakeup_condition(void) | 88 | bool 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 */ |
| 104 | ISR(WDT_vect) | 111 | ISR(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 |
diff --git a/common/suspend.h b/common/suspend.h index f339c670a..80617a824 100644 --- a/common/suspend.h +++ b/common/suspend.h | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | void suspend_idle(uint8_t timeout); | 8 | void suspend_idle(uint8_t timeout); |
| 9 | void suspend_power_down(uint8_t timeout); | 9 | void suspend_power_down(void); |
| 10 | bool suspend_wakeup_condition(void); | 10 | bool suspend_wakeup_condition(void); |
| 11 | void suspend_wakeup_init(void); | 11 | void suspend_wakeup_init(void); |
| 12 | 12 | ||
