summaryrefslogtreecommitdiff
path: root/tmk_core
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core')
-rw-r--r--tmk_core/common/avr/suspend.c1
-rw-r--r--tmk_core/common/suspend.h4
-rw-r--r--tmk_core/protocol/chibios/usb_main.c11
-rw-r--r--tmk_core/protocol/lufa/lufa.c24
4 files changed, 35 insertions, 5 deletions
diff --git a/tmk_core/common/avr/suspend.c b/tmk_core/common/avr/suspend.c
index a879d6bab0..807c837e36 100644
--- a/tmk_core/common/avr/suspend.c
+++ b/tmk_core/common/avr/suspend.c
@@ -110,7 +110,6 @@ static void power_down(uint8_t wdto) {
rgblight_disable_noeeprom();
}
# endif
- suspend_power_down_kb();
// TODO: more power saving
// See PicoPower application note
diff --git a/tmk_core/common/suspend.h b/tmk_core/common/suspend.h
index 766df95aa1..9d17d984ed 100644
--- a/tmk_core/common/suspend.h
+++ b/tmk_core/common/suspend.h
@@ -12,3 +12,7 @@ void suspend_wakeup_init_user(void);
void suspend_wakeup_init_kb(void);
void suspend_power_down_user(void);
void suspend_power_down_kb(void);
+
+#ifndef USB_SUSPEND_WAKEUP_DELAY
+# define USB_SUSPEND_WAKEUP_DELAY 200
+#endif
diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c
index 4e3176ab26..67ae8520fd 100644
--- a/tmk_core/protocol/chibios/usb_main.c
+++ b/tmk_core/protocol/chibios/usb_main.c
@@ -701,6 +701,17 @@ void init_usb_driver(USBDriver *usbp) {
void restart_usb_driver(USBDriver *usbp) {
usbStop(usbp);
usbDisconnectBus(usbp);
+
+#if USB_SUSPEND_WAKEUP_DELAY > 0
+ // Some hubs, kvm switches, and monitors do
+ // weird things, with USB device state bouncing
+ // around wildly on wakeup, yielding race
+ // conditions that can corrupt the keyboard state.
+ //
+ // Pause for a while to let things settle...
+ wait_ms(USB_SUSPEND_WAKEUP_DELAY);
+#endif
+
usbStart(usbp, &usbcfg);
usbConnectBus(usbp);
}
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index ce31e54990..3c6b1cffaf 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -498,7 +498,9 @@ void EVENT_USB_Device_Suspend() {
*/
void EVENT_USB_Device_WakeUp() {
print("[W]");
+#if defined(NO_USB_STARTUP_CHECK)
suspend_wakeup_init();
+#endif
#ifdef SLEEP_LED_ENABLE
sleep_led_disable();
@@ -1184,12 +1186,26 @@ int main(void) {
print("Keyboard start.\n");
while (1) {
#if !defined(NO_USB_STARTUP_CHECK)
- while (USB_DeviceState == DEVICE_STATE_Suspended) {
+ if (USB_DeviceState == DEVICE_STATE_Suspended) {
print("[s]");
- suspend_power_down();
- if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) {
- USB_Device_SendRemoteWakeup();
+ while (USB_DeviceState == DEVICE_STATE_Suspended) {
+ suspend_power_down();
+ if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) {
+ USB_Device_SendRemoteWakeup();
+ clear_keyboard();
+
+# if USB_SUSPEND_WAKEUP_DELAY > 0
+ // Some hubs, kvm switches, and monitors do
+ // weird things, with USB device state bouncing
+ // around wildly on wakeup, yielding race
+ // conditions that can corrupt the keyboard state.
+ //
+ // Pause for a while to let things settle...
+ wait_ms(USB_SUSPEND_WAKEUP_DELAY);
+# endif
+ }
}
+ suspend_wakeup_init();
}
#endif