aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/avr/suspend.c27
-rw-r--r--common/suspend.h2
-rw-r--r--keyboard/hhkb_rn42/MEMO.txt7
-rw-r--r--keyboard/hhkb_rn42/matrix.c2
-rw-r--r--keyboard/hhkb_rn42/rn42/main.c2
-rw-r--r--protocol/lufa/lufa.c2
6 files changed, 27 insertions, 15 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
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
8void suspend_idle(uint8_t timeout); 8void suspend_idle(uint8_t timeout);
9void suspend_power_down(uint8_t timeout); 9void suspend_power_down(void);
10bool suspend_wakeup_condition(void); 10bool suspend_wakeup_condition(void);
11void suspend_wakeup_init(void); 11void suspend_wakeup_init(void);
12 12
diff --git a/keyboard/hhkb_rn42/MEMO.txt b/keyboard/hhkb_rn42/MEMO.txt
index 337dad603..062ee3399 100644
--- a/keyboard/hhkb_rn42/MEMO.txt
+++ b/keyboard/hhkb_rn42/MEMO.txt
@@ -9,10 +9,15 @@ Bug:
9 - Do not power-down during USB connection is active - DONE 11/11 9 - Do not power-down during USB connection is active - DONE 11/11
10 (USB_DeviceState == USB_DEVICE_Configured) is used to check USB connection 10 (USB_DeviceState == USB_DEVICE_Configured) is used to check USB connection
11 matrix_power_down() matrix.c - 11/23 11 matrix_power_down() matrix.c - 11/23
12- timer is slow while power down - DONE 11/26
13 - time out interrupt is lost while power down?
14 - interrupt of watchdog timer compensates timer counter(avr/suspend.c)
12 15
13Todo: 16Todo:
14 17
15Design: 18Design:
19- suspend.h - DONE 11/26
20 - remove argument from suspend_power_down() for backward compatitibility
16- remove MCU dependent power saving code from core/keyboard 21- remove MCU dependent power saving code from core/keyboard
17 - it should be located in project matrix.c - DONE 11/23 22 - it should be located in project matrix.c - DONE 11/23
18- HHKB matrix.c needs matrix_prev? 23- HHKB matrix.c needs matrix_prev?
@@ -47,6 +52,8 @@ Power saving:
47- During USB suspend change clock source to internal RC from external Xtal(6.8) 52- During USB suspend change clock source to internal RC from external Xtal(6.8)
48- FRZCLK: you can freeze clock for power saving. still WAKEUPI and VBUSTI interrupts are available while freezing.(21.7.3) 53- FRZCLK: you can freeze clock for power saving. still WAKEUPI and VBUSTI interrupts are available while freezing.(21.7.3)
49- Suspend: Clear Suspend Bit, Freeze clock, disable PLL, MCU sleep(21.13) 54- Suspend: Clear Suspend Bit, Freeze clock, disable PLL, MCU sleep(21.13)
55- Voltage reference(8.1.1)
56 - to reduce power consumption while power down mode
50 57
51Improving: 58Improving:
52- BT LED; connecting, linked, sleeping, deep sleeping 59- BT LED; connecting, linked, sleeping, deep sleeping
diff --git a/keyboard/hhkb_rn42/matrix.c b/keyboard/hhkb_rn42/matrix.c
index c6c444ff5..513a271e4 100644
--- a/keyboard/hhkb_rn42/matrix.c
+++ b/keyboard/hhkb_rn42/matrix.c
@@ -186,6 +186,6 @@ void matrix_power_down(void) {
186 if (USB_DeviceState == DEVICE_STATE_Configured) return; 186 if (USB_DeviceState == DEVICE_STATE_Configured) return;
187 if (timer_elapsed32(matrix_last_modified) <= MATRIX_POWER_SAVE) return; 187 if (timer_elapsed32(matrix_last_modified) <= MATRIX_POWER_SAVE) return;
188 KEY_POWER_OFF(); 188 KEY_POWER_OFF();
189 suspend_power_down(WDTO_15MS); 189 suspend_power_down();
190 matrix_power = false; 190 matrix_power = false;
191} 191}
diff --git a/keyboard/hhkb_rn42/rn42/main.c b/keyboard/hhkb_rn42/rn42/main.c
index 43d887067..a3a37c074 100644
--- a/keyboard/hhkb_rn42/rn42/main.c
+++ b/keyboard/hhkb_rn42/rn42/main.c
@@ -85,7 +85,7 @@ int main(void)
85 print("Keyboard start.\n"); 85 print("Keyboard start.\n");
86 while (1) { 86 while (1) {
87 while (USB_DeviceState == DEVICE_STATE_Suspended) { 87 while (USB_DeviceState == DEVICE_STATE_Suspended) {
88 suspend_power_down(WDTO_120MS); 88 suspend_power_down();
89 if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) { 89 if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) {
90 USB_Device_SendRemoteWakeup(); 90 USB_Device_SendRemoteWakeup();
91 } 91 }
diff --git a/protocol/lufa/lufa.c b/protocol/lufa/lufa.c
index 6802f3b63..ee15b7f45 100644
--- a/protocol/lufa/lufa.c
+++ b/protocol/lufa/lufa.c
@@ -587,7 +587,7 @@ int main(void)
587 print("Keyboard start.\n"); 587 print("Keyboard start.\n");
588 while (1) { 588 while (1) {
589 while (USB_DeviceState == DEVICE_STATE_Suspended) { 589 while (USB_DeviceState == DEVICE_STATE_Suspended) {
590 suspend_power_down(WDTO_120MS); 590 suspend_power_down();
591 if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) { 591 if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) {
592 USB_Device_SendRemoteWakeup(); 592 USB_Device_SendRemoteWakeup();
593 } 593 }