Skip to content

Commit

Permalink
usb: device_next: add device configuration change notification
Browse files Browse the repository at this point in the history
Notify only if the device configuration has changed. Pass only the
configuration value as the message status, the actual device speed can
be obtained with usbd_bus_speed().

Signed-off-by: Johann Fischer <[email protected]>
  • Loading branch information
jfischer-no authored and nashif committed Aug 16, 2024
1 parent cd3dae7 commit f851cad
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/zephyr/usb/usbd_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ enum usbd_msg_type {
USBD_MSG_SUSPEND,
/** Bus reset detected */
USBD_MSG_RESET,
/** Device changed configuration */
USBD_MSG_CONFIGURATION,
/** Non-correctable UDC error message */
USBD_MSG_UDC_ERROR,
/** Unrecoverable device stack error message */
Expand All @@ -61,6 +63,7 @@ static const char *const usbd_msg_type_list[] = {
"Device resumed",
"Device suspended",
"Bus reset",
"New device configuration",
"Controller error",
"Stack error",
"CDC ACM line coding",
Expand Down
4 changes: 4 additions & 0 deletions samples/subsys/usb/hid-keyboard/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ static void msg_cb(struct usbd_context *const usbd_ctx,
{
LOG_INF("USBD message: %s", usbd_msg_type_string(msg->type));

if (msg->type == USBD_MSG_CONFIGURATION) {
LOG_INF("\tConfiguration value %d", msg->status);
}

if (usbd_can_detect_vbus(usbd_ctx)) {
if (msg->type == USBD_MSG_VBUS_READY) {
if (usbd_enable(usbd_ctx)) {
Expand Down
5 changes: 5 additions & 0 deletions subsys/usb/device_next/usbd_ch9.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "usbd_class.h"
#include "usbd_class_api.h"
#include "usbd_interface.h"
#include "usbd_msg.h"

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(usbd_ch9, CONFIG_USBD_LOG_LEVEL);
Expand Down Expand Up @@ -171,6 +172,10 @@ static int sreq_set_configuration(struct usbd_context *const uds_ctx)
uds_ctx->ch9_data.state = USBD_STATE_CONFIGURED;
}

if (ret == 0) {
usbd_msg_pub_simple(uds_ctx, USBD_MSG_CONFIGURATION, setup->wValue);
}

return ret;
}

Expand Down

0 comments on commit f851cad

Please sign in to comment.