Skip to content

Conversation

@fabiobaltieri
Copy link
Member

Add an optional suspend callback to let a downstream hid driver be notified of HID suspend and resume events.

Add an optional suspend callback to let a downstream hid driver be
notified of HID suspend and resume events.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
@fabiobaltieri
Copy link
Member Author

@jfischer-no using this on an hid device to detect when the host goes into suspend, is this the right thing? Can't quite tell it from the controller apis apparently.

@zephyrbot zephyrbot added the area: USB Universal Serial Bus label Nov 8, 2025
@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 8, 2025

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.

I like this approach better than relying on USB notifications in the application, because here the call is synchronous and therefore the state never gets out-of-sync.

@tmon-nordic tmon-nordic requested a review from josuah November 10, 2025 14:38
@fabiobaltieri
Copy link
Member Author

I like this approach better than relying on USB notifications in the application, because here the call is synchronous and therefore the state never gets out-of-sync.

Ok... what notifications are you referring to though?

@tmon-nordic
Copy link
Contributor

I like this approach better than relying on USB notifications in the application, because here the call is synchronous and therefore the state never gets out-of-sync.

Ok... what notifications are you referring to though?

usbd_msg_pub_simple(uds_ctx, USBD_MSG_SUSPEND, 0);
and
usbd_msg_pub_simple(uds_ctx, USBD_MSG_RESUME, 0);

@fabiobaltieri
Copy link
Member Author

@tmon-nordic ok but I think USBD_MSG_RESUME and USBD_MSG_SUSPEND are a different thing, that's the first thing I tried to use but it seems like they refer to the whole usb device controller, the ones in this PR and the ones I needed seemingly gets called when the host goes into suspend and stops polling the HID endpoint. I'm using them downstream to control a keyboard underglow and these two works fine. :-)

@tmon-nordic
Copy link
Contributor

@tmon-nordic ok but I think USBD_MSG_RESUME and USBD_MSG_SUSPEND are a different thing

No, they are the same. The difference is that USBD_MSG_RESUME and USBD_MSG_SUSPEND are subject to getting lost due to the IMHO bad design choice of

if (k_mem_slab_alloc(&usbd_msg_slab, (void **)&m_pkt, K_NO_WAIT)) {

when CONFIG_USBD_MSG_DEFERRED_MODE is not enabled.

@fabiobaltieri
Copy link
Member Author

fabiobaltieri commented Nov 10, 2025

No, they are the same. The difference is that USBD_MSG_RESUME and USBD_MSG_SUSPEND are subject to getting lost due to the IMHO bad design choice of

Ok very interesting, well, this is cheap enough and works reliably then... Thanks for the pointers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: USB Universal Serial Bus

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants