Skip to content

Commit f851cad

Browse files
jfischer-nonashif
authored andcommitted
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 <[email protected]>
1 parent cd3dae7 commit f851cad

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

include/zephyr/usb/usbd_msg.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ enum usbd_msg_type {
4040
USBD_MSG_SUSPEND,
4141
/** Bus reset detected */
4242
USBD_MSG_RESET,
43+
/** Device changed configuration */
44+
USBD_MSG_CONFIGURATION,
4345
/** Non-correctable UDC error message */
4446
USBD_MSG_UDC_ERROR,
4547
/** Unrecoverable device stack error message */
@@ -61,6 +63,7 @@ static const char *const usbd_msg_type_list[] = {
6163
"Device resumed",
6264
"Device suspended",
6365
"Bus reset",
66+
"New device configuration",
6467
"Controller error",
6568
"Stack error",
6669
"CDC ACM line coding",

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ static void msg_cb(struct usbd_context *const usbd_ctx,
149149
{
150150
LOG_INF("USBD message: %s", usbd_msg_type_string(msg->type));
151151

152+
if (msg->type == USBD_MSG_CONFIGURATION) {
153+
LOG_INF("\tConfiguration value %d", msg->status);
154+
}
155+
152156
if (usbd_can_detect_vbus(usbd_ctx)) {
153157
if (msg->type == USBD_MSG_VBUS_READY) {
154158
if (usbd_enable(usbd_ctx)) {

subsys/usb/device_next/usbd_ch9.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "usbd_class.h"
2020
#include "usbd_class_api.h"
2121
#include "usbd_interface.h"
22+
#include "usbd_msg.h"
2223

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

175+
if (ret == 0) {
176+
usbd_msg_pub_simple(uds_ctx, USBD_MSG_CONFIGURATION, setup->wValue);
177+
}
178+
174179
return ret;
175180
}
176181

0 commit comments

Comments
 (0)