Skip to content

Commit

Permalink
Chibios USB: Take into account if host wants remote wakeup or not (qm…
Browse files Browse the repository at this point in the history
…k#21287)

According to the USB 2.0 spec, remote wakeup should be disabled by
default, and should only be enabled if the host explicitly requests
it. The chibios driver code already takes care of storing this
information, and returning it on GET_STATUS requests. However our
application code has been ignoring it so far.

This is a USB compliance issue, but also a bug that causes trouble
in some cases: On RP2040 targets this has been causing problems if
a key is held down while the keyboard is plugged in. The keyboard
would fail to enumerate until all keys are released. With this
change that behavior is fixed.

Note that for LUFA targets this is already done correctly.
  • Loading branch information
purdeaandrei authored and akeep committed Oct 2, 2023
1 parent f6ab6cc commit 0938425
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tmk_core/protocol/chibios/chibios.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
#include "suspend.h"
#include "wait.h"

#define USB_GETSTATUS_REMOTE_WAKEUP_ENABLED (2U)

/* -------------------------
* TMK host driver defs
* -------------------------
Expand Down Expand Up @@ -187,7 +189,7 @@ void protocol_pre_task(void) {
/* Do this in the suspended state */
suspend_power_down(); // on AVR this deep sleeps for 15ms
/* Remote wakeup */
if (suspend_wakeup_condition()) {
if ((USB_DRIVER.status & USB_GETSTATUS_REMOTE_WAKEUP_ENABLED) && suspend_wakeup_condition()) {
usbWakeupHost(&USB_DRIVER);
restart_usb_driver(&USB_DRIVER);
}
Expand Down

0 comments on commit 0938425

Please sign in to comment.