Skip to content

Commit

Permalink
Revert "[Bug] Restore usb suspend wakeup delay (qmk#21676)"
Browse files Browse the repository at this point in the history
This reverts commit e8e989f.
  • Loading branch information
drashna committed Aug 24, 2023
1 parent 5d828a9 commit 5570a16
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 14 deletions.
31 changes: 23 additions & 8 deletions tmk_core/protocol/chibios/chibios.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,26 @@ void console_task(void);
void midi_ep_task(void);
#endif

/* TESTING
* Amber LED blinker thread, times are in milliseconds.
*/
/* set this variable to non-zero anywhere to blink once */
// static THD_WORKING_AREA(waThread1, 128);
// static THD_FUNCTION(Thread1, arg) {

// (void)arg;
// chRegSetThreadName("blinker");
// while (true) {
// systime_t time;

// time = USB_DRIVER.state == USB_ACTIVE ? 250 : 500;
// palClearLine(LINE_CAPS_LOCK);
// chSysPolledDelayX(MS2RTC(STM32_HCLK, time));
// palSetLine(LINE_CAPS_LOCK);
// chSysPolledDelayX(MS2RTC(STM32_HCLK, time));
// }
// }

/* Early initialisation
*/
__attribute__((weak)) void early_hardware_init_pre(void) {
Expand Down Expand Up @@ -115,6 +135,9 @@ void boardInit(void) {

void protocol_setup(void) {
usb_device_state_init();

// TESTING
// chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
}

static host_driver_t *driver = NULL;
Expand Down Expand Up @@ -166,14 +189,6 @@ void protocol_pre_task(void) {
if ((USB_DRIVER.status & USB_GETSTATUS_REMOTE_WAKEUP_ENABLED) && suspend_wakeup_condition()) {
usbWakeupHost(&USB_DRIVER);
restart_usb_driver(&USB_DRIVER);
# 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
}
}
/* Woken up */
Expand Down
27 changes: 21 additions & 6 deletions tmk_core/protocol/chibios/usb_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,19 +784,34 @@ void init_usb_driver(USBDriver *usbp) {
#endif
}

restart_usb_driver(usbp);
/*
* Activates the USB driver and then the USB bus pull-up on D+.
* Note, a delay is inserted in order to not have to disconnect the cable
* after a reset.
*/
usbDisconnectBus(usbp);
usbStop(usbp);
wait_ms(50);
usbStart(usbp, &usbcfg);
usbConnectBus(usbp);

chVTObjectInit(&keyboard_idle_timer);
}

/** @brief Restarts the USB driver and emulates a physical bus reconnection.
* Note that the bus reconnection is MCU and even board specific, so it might
* be a NOP on some hardware platforms.
*/
__attribute__((weak)) void restart_usb_driver(USBDriver *usbp) {
usbDisconnectBus(usbp);
usbStop(usbp);
wait_ms(50);

#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);
}
Expand Down

0 comments on commit 5570a16

Please sign in to comment.