Skip to content

Commit 75eca87

Browse files
committed
samples: usb: hid-keyboard: enable and use remote wakeup on button press
USB remote wakeup capability is a common feature of keyboards, allowing them to wake up a suspended host. Currently there is no USB sample that demonstrates remote wakeup, which makes basic evaluation of the functionality non-trivial. Modify the hid-keyboard sample with a minimalistic solution of demonstrating remote wakeup capability. While it is not required to have been configured prior to suspend to issue a wakeup request, from usability perspective I'd say it makes sense. Signed-off-by: Benedek Kupper <kupper.benedek@gmail.com>
1 parent c710f88 commit 75eca87

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

samples/subsys/usb/hid-keyboard/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CONFIG_USBD_LOG_LEVEL_WRN=y
66
CONFIG_USBD_HID_LOG_LEVEL_WRN=y
77
CONFIG_UDC_DRIVER_LOG_LEVEL_WRN=y
88
CONFIG_SAMPLE_USBD_PID=0x0007
9+
CONFIG_SAMPLE_USBD_REMOTE_WAKEUP=y
910

1011
CONFIG_GPIO=y
1112
CONFIG_INPUT=y

samples/subsys/usb/hid-keyboard/src/main.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,17 @@ int main(void)
279279
continue;
280280
}
281281

282+
if (usbd_is_suspended(sample_usbd)) {
283+
/* on a press of any button, send wakeup request */
284+
if (kb_evt.value) {
285+
ret = usbd_wakeup_request(sample_usbd);
286+
if (ret) {
287+
LOG_ERR("Remote wakeup error, %d", ret);
288+
}
289+
}
290+
continue;
291+
}
292+
282293
ret = hid_device_submit_report(hid_dev, KB_REPORT_COUNT, report);
283294
if (ret) {
284295
LOG_ERR("HID submit report error, %d", ret);

0 commit comments

Comments
 (0)