Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

samples: usb: hid-keyboard: enable and use remote wakeup on button press #79341

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

benedekkupper
Copy link
Contributor

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.

tmon-nordic
tmon-nordic previously approved these changes Oct 3, 2024
Copy link
Contributor

@tmon-nordic tmon-nordic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"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." from USB perspective it is slightly different. The device is not configured to "issue a wakeup request", but the device can be either allowed to or prohibited from issuing wakeup request.

If host suspended device with cleared remote wakeup feature, then every button press will result in an error log entry regardless how many times it is pressed.

@benedekkupper
Copy link
Contributor Author

"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." from USB perspective it is slightly different. The device is not configured to "issue a wakeup request", but the device can be either allowed to or prohibited from issuing wakeup request.

If host suspended device with cleared remote wakeup feature, then every button press will result in an error log entry regardless how many times it is pressed.

Right, what I meant was that there is no hard dependency between the HID interface being configured and the ability for remote wakeup (since that is controlled independently with a SET_FEATURE request).

I noticed that the device_next stack is not clearing this flag when the host sends a reset signal, even though the USB 2.0 spec requires it:

The Remote Wakeup field indicates whether the device is currently enabled to request remote wakeup. The
default mode for devices that support remote wakeup is disabled. If D1 is reset to zero, the ability of the
device to signal remote wakeup is disabled. If D1 is set to one, the ability of the device to signal remote
wakeup is enabled. The Remote Wakeup field can be modified by the SetFeature() and ClearFeature()
requests using the DEVICE_REMOTE_WAKEUP feature selector. This field is reset to zero when the
device is reset.

@tmon-nordic
Copy link
Contributor

I noticed that the device_next stack is not clearing this flag when the host sends a reset signal

Can you submit a separate PR with a fix?

@benedekkupper
Copy link
Contributor Author

I noticed that the device_next stack is not clearing this flag when the host sends a reset signal

Can you submit a separate PR with a fix?

Here you go: #79410

Comment on lines 282 to 292
if (usbd_is_suspended(sample_usbd)) {
/* on a press of any button, send wakeup request */
if (kb_evt.value) {
ret = usbd_wakeup_request(sample_usbd);
if (ret) {
LOG_ERR("Remote wakeup error, %d", ret);
}
}
continue; /* cannot communicate in suspend */
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think it should be handled by the application but by the stack (#73362).

Copy link
Contributor Author

@benedekkupper benedekkupper Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I can only propose:
We could still merge this for the time window between now and when that MR is finally ready, at which point these changes can be undone. I'd really like to have a simple reference sample for evaluating this functionality sooner rather than later.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could still merge this for the time window between now and when that MR is finally ready, at which point these changes can be undone.I'd really like to have a simple reference sample for evaluating this functionality sooner rather than later.

Why do you need a "simple reference sample" in the tree to evaluate it? Why can you not use shell command for evaluation?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shell command is not quite suitable for USB certification, while a simple button press in hid-keyboard sample is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shell command is not quite suitable for USB certification, while a simple button press in hid-keyboard sample is.

This I fully agree with. It's valuable to have a single step way of evaluating the remote wakeup functionality, if there's a sample that is easily distributed, and the end user just needs to select the target board, build and flash as-is. Remote wakeup is a pretty widely used functionality for HID keyboards, so from that perspective I'd also rather have this than not.

I have no idea how the shell command functionality would work, but I have to clarify here that remote wakeup has to be evaluateable as part of a whole USB operation. (We found an issue in our design that the USB HID interface isn't responsive after remote wakeup, which was only observed with NCS 2.6.1, but not with NCS 2.7.0. Not exactly relevant here, I'm just trying to make a point.)

samples/subsys/usb/hid-keyboard/src/main.c Outdated Show resolved Hide resolved
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 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Samples Samples area: USB Universal Serial Bus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants