diff options
author | tmk <nobody@nowhere> | 2014-11-20 17:06:46 +0900 |
---|---|---|
committer | tmk <nobody@nowhere> | 2014-11-20 17:24:56 +0900 |
commit | c2d830c07c823c48a17c214b093ec1bab989fb6a (patch) | |
tree | 388b86cd7bfbf3b78528a498c8e3f39a20fc778f /common | |
parent | 6c06b9031fd09479d552f9750a3b1cfe259678fd (diff) | |
download | qmk_firmware-c2d830c07c823c48a17c214b093ec1bab989fb6a.tar.gz qmk_firmware-c2d830c07c823c48a17c214b093ec1bab989fb6a.zip |
USB initialize when plug-in during battery powered
Diffstat (limited to 'common')
-rw-r--r-- | common/avr/suspend.c | 49 | ||||
-rw-r--r-- | common/suspend.h | 3 |
2 files changed, 36 insertions, 16 deletions
diff --git a/common/avr/suspend.c b/common/avr/suspend.c index f44a036be..66a579fd7 100644 --- a/common/avr/suspend.c +++ b/common/avr/suspend.c | |||
@@ -7,6 +7,9 @@ | |||
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 | #ifdef PROTOCOL_LUFA | ||
11 | #include "lufa.h" | ||
12 | #endif | ||
10 | 13 | ||
11 | 14 | ||
12 | #define wdt_intr_enable(value) \ | 15 | #define wdt_intr_enable(value) \ |
@@ -26,30 +29,45 @@ __asm__ __volatile__ ( \ | |||
26 | ) | 29 | ) |
27 | 30 | ||
28 | 31 | ||
29 | void suspend_power_down(void) | 32 | void suspend_idle(uint8_t time) |
30 | { | 33 | { |
31 | #ifdef BACKLIGHT_ENABLE | ||
32 | backlight_set(0); | ||
33 | #endif | ||
34 | #ifndef NO_SUSPEND_POWER_DOWN | ||
35 | // Enable watchdog to wake from MCU sleep | ||
36 | cli(); | 34 | cli(); |
37 | wdt_reset(); | 35 | set_sleep_mode(SLEEP_MODE_IDLE); |
36 | sleep_enable(); | ||
37 | sei(); | ||
38 | sleep_cpu(); | ||
39 | sleep_disable(); | ||
40 | } | ||
41 | |||
42 | /* Power down MCU with watchdog timer | ||
43 | * wdto: watchdog timer timeout defined in <avr/wdt.h> | ||
44 | * WDTO_15MS | ||
45 | * WDTO_30MS | ||
46 | * WDTO_60MS | ||
47 | * WDTO_120MS | ||
48 | * WDTO_250MS | ||
49 | * WDTO_500MS | ||
50 | * WDTO_1S | ||
51 | * WDTO_2S | ||
52 | * WDTO_4S | ||
53 | * WDTO_8S | ||
54 | */ | ||
55 | void suspend_power_down(uint8_t wdto) | ||
56 | { | ||
57 | #ifdef PROTOCOL_LUFA | ||
58 | if (USB_DeviceState == DEVICE_STATE_Configured) return; | ||
59 | #endif | ||
38 | 60 | ||
39 | // Watchdog Interrupt and System Reset Mode | ||
40 | //wdt_enable(WDTO_1S); | ||
41 | //WDTCSR |= _BV(WDIE); | ||
42 | |||
43 | // Watchdog Interrupt Mode | 61 | // Watchdog Interrupt Mode |
44 | wdt_intr_enable(WDTO_120MS); | 62 | wdt_intr_enable(wdto); |
45 | 63 | ||
46 | // TODO: more power saving | 64 | // TODO: more power saving |
47 | // See PicoPower application note | 65 | // See PicoPower application note |
48 | // - I/O port input with pullup | 66 | // - I/O port input with pullup |
49 | // - prescale clock | 67 | // - prescale clock |
50 | // - BOD disable | 68 | // - BOD disable |
51 | // - Power Reduction Register PRR | 69 | // - Power Reduction Register PRR |
52 | // sleep in power down mode | 70 | |
53 | set_sleep_mode(SLEEP_MODE_PWR_DOWN); | 71 | set_sleep_mode(SLEEP_MODE_PWR_DOWN); |
54 | sleep_enable(); | 72 | sleep_enable(); |
55 | sei(); | 73 | sei(); |
@@ -58,12 +76,13 @@ void suspend_power_down(void) | |||
58 | 76 | ||
59 | // Disable watchdog after sleep | 77 | // Disable watchdog after sleep |
60 | wdt_disable(); | 78 | wdt_disable(); |
61 | #endif | ||
62 | } | 79 | } |
63 | 80 | ||
64 | bool suspend_wakeup_condition(void) | 81 | bool suspend_wakeup_condition(void) |
65 | { | 82 | { |
83 | matrix_power_up(); | ||
66 | matrix_scan(); | 84 | matrix_scan(); |
85 | matrix_power_down(); | ||
67 | for (uint8_t r = 0; r < MATRIX_ROWS; r++) { | 86 | for (uint8_t r = 0; r < MATRIX_ROWS; r++) { |
68 | if (matrix_get_row(r)) return true; | 87 | if (matrix_get_row(r)) return true; |
69 | } | 88 | } |
diff --git a/common/suspend.h b/common/suspend.h index 9b76f280d..f339c670a 100644 --- a/common/suspend.h +++ b/common/suspend.h | |||
@@ -5,7 +5,8 @@ | |||
5 | #include <stdbool.h> | 5 | #include <stdbool.h> |
6 | 6 | ||
7 | 7 | ||
8 | void suspend_power_down(void); | 8 | void suspend_idle(uint8_t timeout); |
9 | void suspend_power_down(uint8_t timeout); | ||
9 | bool suspend_wakeup_condition(void); | 10 | bool suspend_wakeup_condition(void); |
10 | void suspend_wakeup_init(void); | 11 | void suspend_wakeup_init(void); |
11 | 12 | ||