Skip to content

Commit 7328690

Browse files
jfischer-nofabiobaltieri
authored andcommitted
samples: usb: add a sample USB 2.0 Extension Descriptor
Add a sample USB 2.0 Extension Descriptor. Signed-off-by: Johann Fischer <[email protected]>
1 parent b0d7d70 commit 7328690

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

samples/subsys/usb/common/Kconfig.sample_usbd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,9 @@ config SAMPLE_USBD_MAX_POWER
4545
help
4646
bMaxPower value in the sample configuration in 2 mA units.
4747

48+
config SAMPLE_USBD_20_EXTENSION_DESC
49+
bool "Use default USB 2.0 Extension Descriptor"
50+
help
51+
Set bcdUSB value to 0201 and use default USB 2.0 Extension Descriptor.
52+
4853
endmenu

samples/subsys/usb/common/sample_usbd_init.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <zephyr/device.h>
1010
#include <zephyr/usb/usbd.h>
11+
#include <zephyr/usb/bos.h>
1112
#include <zephyr/sys/iterable_sections.h>
1213

1314
#include <zephyr/logging/log.h>
@@ -37,6 +38,19 @@ USBD_CONFIGURATION_DEFINE(sample_hs_config,
3738
attributes,
3839
CONFIG_SAMPLE_USBD_MAX_POWER);
3940

41+
/*
42+
* This does not yet provide valuable information, but rather serves as an
43+
* example, and will be improved in the future.
44+
*/
45+
static const struct usb_bos_capability_lpm bos_cap_lpm = {
46+
.bLength = sizeof(struct usb_bos_capability_lpm),
47+
.bDescriptorType = USB_DESC_DEVICE_CAPABILITY,
48+
.bDevCapabilityType = USB_BOS_CAPABILITY_EXTENSION,
49+
.bmAttributes = 0UL,
50+
};
51+
52+
USBD_DESC_BOS_DEFINE(sample_usbext, sizeof(bos_cap_lpm), &bos_cap_lpm);
53+
4054
static int register_fs_classes(struct usbd_contex *uds_ctx)
4155
{
4256
int err = 0;
@@ -169,6 +183,17 @@ struct usbd_contex *sample_usbd_init_device(usbd_msg_cb_t msg_cb)
169183
}
170184
}
171185

186+
if (IS_ENABLED(CONFIG_SAMPLE_USBD_20_EXTENSION_DESC)) {
187+
(void)usbd_device_set_bcd(&sample_usbd, USBD_SPEED_FS, 0x0201);
188+
(void)usbd_device_set_bcd(&sample_usbd, USBD_SPEED_HS, 0x0201);
189+
190+
err = usbd_add_descriptor(&sample_usbd, &sample_usbext);
191+
if (err) {
192+
LOG_ERR("Failed to add USB 2.0 Extension Descriptor");
193+
return NULL;
194+
}
195+
}
196+
172197
err = usbd_init(&sample_usbd);
173198
if (err) {
174199
LOG_ERR("Failed to initialize device support");

0 commit comments

Comments
 (0)