From 9a4618b05b9f1093908c2153c719c5eb5d4a79ee Mon Sep 17 00:00:00 2001 From: Joshua Diamond Date: Mon, 1 Feb 2021 19:12:41 -0500 Subject: 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 --- tmk_core/protocol/chibios/usb_main.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tmk_core/protocol/chibios/usb_main.c') diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c index cb7aeb23b2..13b1e34d28 100644 --- a/tmk_core/protocol/chibios/usb_main.c +++ b/tmk_core/protocol/chibios/usb_main.c @@ -708,6 +708,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); } -- cgit v1.2.3