Skip to content

Commit 79a8073

Browse files
jfischer-nokartben
authored andcommitted
usb: device_next: allow to use label as interface string descriptor
The intention was to use the "interface-name" string property in the interface string descriptor, but using the label property is acceptable again. Therefore, allow the use of the DT label property string in the interface string descriptor. Follow exactly the same approach as in the CDC ACM implementation introduced in the commit b079140 ("usb: device_next: cdc_acm: allow setting the interface description"). Signed-off-by: Johann Fischer <[email protected]>
1 parent 204a1cf commit 79a8073

File tree

5 files changed

+29
-7
lines changed

5 files changed

+29
-7
lines changed

dts/bindings/usb/zephyr,hid-device.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ compatible: "zephyr,hid-device"
88
include: base.yaml
99

1010
properties:
11-
interface-name:
12-
type: string
11+
label:
1312
description: |
14-
HID device name. When this property is present, a USB device will use it
15-
as the string descriptor of the interface.
13+
The string defined by the label property is also used for the USB device
14+
interface string descriptor.
1615
1716
protocol-code:
1817
type: string

samples/subsys/usb/hid-keyboard/app.overlay

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/ {
88
hid_dev_0: hid_dev_0 {
99
compatible = "zephyr,hid-device";
10-
interface-name = "HID0";
10+
label = "HID0";
1111
protocol-code = "keyboard";
1212
in-report-size = <64>;
1313
in-polling-period-us = <1000>;

samples/subsys/usb/hid-keyboard/large_in_report.overlay

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/ {
88
hid_dev_0: hid_dev_0 {
99
compatible = "zephyr,hid-device";
10-
interface-name = "HID0";
10+
label = "HID0";
1111
in-report-size = <256>;
1212
in-polling-period-us = <1000>;
1313
};

samples/subsys/usb/hid-mouse/usbd_next.overlay

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/ {
88
hid_dev_0: hid_dev_0 {
99
compatible = "zephyr,hid-device";
10-
interface-name = "HID0";
10+
label = "HID0";
1111
protocol-code = "none";
1212
in-polling-period-us = <1000>;
1313
in-report-size = <64>;

subsys/usb/device_next/class/usbd_hid.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ struct hid_device_config {
6565
struct usbd_class_data *c_data;
6666
struct net_buf_pool *pool_out;
6767
struct net_buf_pool *pool_in;
68+
struct usbd_desc_node *const if_desc_data;
6869
const struct usb_desc_header **fs_desc;
6970
const struct usb_desc_header **hs_desc;
7071
};
@@ -488,8 +489,21 @@ static void *usbd_hid_get_desc(struct usbd_class_data *const c_data,
488489

489490
static int usbd_hid_init(struct usbd_class_data *const c_data)
490491
{
492+
struct usbd_context *uds_ctx = usbd_class_get_ctx(c_data);
493+
const struct device *dev = usbd_class_get_private(c_data);
494+
const struct hid_device_config *dcfg = dev->config;
495+
struct usbd_hid_descriptor *const desc = dcfg->desc;
496+
491497
LOG_DBG("HID class %s init", c_data->name);
492498

499+
if (dcfg->if_desc_data != NULL && desc->if0.iInterface == 0) {
500+
if (usbd_add_descriptor(uds_ctx, dcfg->if_desc_data)) {
501+
LOG_ERR("Failed to add interface string descriptor");
502+
} else {
503+
desc->if0.iInterface = usbd_str_desc_get_idx(dcfg->if_desc_data);
504+
}
505+
}
506+
493507
return 0;
494508
}
495509

@@ -750,6 +764,12 @@ static const struct hid_device_driver_api hid_device_api = {
750764
HID_OUT_POOL_DEFINE(n); \
751765
USBD_HID_INTERFACE_DEFINE(n); \
752766
\
767+
IF_ENABLED(DT_INST_NODE_HAS_PROP(n, label), ( \
768+
USBD_DESC_STRING_DEFINE(hid_if_desc_data_##n, \
769+
DT_INST_PROP(n, label), \
770+
USBD_DUT_STRING_INTERFACE); \
771+
)) \
772+
\
753773
USBD_DEFINE_CLASS(hid_##n, \
754774
&usbd_hid_api, \
755775
(void *)DEVICE_DT_GET(DT_DRV_INST(n)), NULL); \
@@ -761,6 +781,9 @@ static const struct hid_device_driver_api hid_device_api = {
761781
.pool_out = HID_OUT_POOL_ADDR(n), \
762782
.fs_desc = hid_fs_desc_##n, \
763783
.hs_desc = hid_hs_desc_##n, \
784+
IF_ENABLED(DT_INST_NODE_HAS_PROP(n, label), ( \
785+
.if_desc_data = &hid_if_desc_data_##n, \
786+
)) \
764787
}; \
765788
\
766789
static struct hid_device_data hid_data_##n; \

0 commit comments

Comments
 (0)