From f851cad162b8b37884c26b601a92946894b7bdc7 Mon Sep 17 00:00:00 2001 From: Johann Fischer Date: Wed, 24 Jul 2024 13:49:40 +0200 Subject: [PATCH] usb: device_next: add device configuration change notification 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 --- include/zephyr/usb/usbd_msg.h | 3 +++ samples/subsys/usb/hid-keyboard/src/main.c | 4 ++++ subsys/usb/device_next/usbd_ch9.c | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/include/zephyr/usb/usbd_msg.h b/include/zephyr/usb/usbd_msg.h index 13d0f01ef047a6..cec39dc63688da 100644 --- a/include/zephyr/usb/usbd_msg.h +++ b/include/zephyr/usb/usbd_msg.h @@ -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 */ @@ -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", diff --git a/samples/subsys/usb/hid-keyboard/src/main.c b/samples/subsys/usb/hid-keyboard/src/main.c index 7f423c87935049..14f360beb3a8d2 100644 --- a/samples/subsys/usb/hid-keyboard/src/main.c +++ b/samples/subsys/usb/hid-keyboard/src/main.c @@ -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)) { diff --git a/subsys/usb/device_next/usbd_ch9.c b/subsys/usb/device_next/usbd_ch9.c index d3eebcaccc5bd9..45775e88c532ae 100644 --- a/subsys/usb/device_next/usbd_ch9.c +++ b/subsys/usb/device_next/usbd_ch9.c @@ -19,6 +19,7 @@ #include "usbd_class.h" #include "usbd_class_api.h" #include "usbd_interface.h" +#include "usbd_msg.h" #include LOG_MODULE_REGISTER(usbd_ch9, CONFIG_USBD_LOG_LEVEL); @@ -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; }