summaryrefslogtreecommitdiff
path: root/tmk_core/protocol/lufa/lufa.c
diff options
context:
space:
mode:
authorJoshua Diamond <josh@windowoffire.com>2021-02-01 19:12:41 -0500
committerDrashna Jael're <drashna@live.com>2021-02-02 09:29:51 -0800
commit0aaf72a2b9bef2fb035f03dfa14fdbd6ef01fbfb (patch)
tree837806eeb0d28a3c01592b70bca10caf756ddcc5 /tmk_core/protocol/lufa/lufa.c
parent9ee0271c00c05ee5dddb7d77b04b5ec2fac2bd41 (diff)
Address wake from sleep instability (#11450)
* resolve race condition between suspend and wake in LUFA * avoid multiple calls to suspend_power_down() / suspend_wakeup_init() * Remove duplicate suspend_power_down_kb() call * pause on wakeup to wait for USB state to settle * need the repeated suspend_power_down() (that's where the sleep is) * more efficient implementation * fine tune the pause after sending wakeup * speculative chibios version of pause-after-wake * make wakeup delay configurable, and adjust value * better location for wakeup delay
Diffstat (limited to 'tmk_core/protocol/lufa/lufa.c')
-rw-r--r--tmk_core/protocol/lufa/lufa.c24
1 files changed, 20 insertions, 4 deletions
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