Browse Source

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 b0791400f6
("usb: device_next: cdc_acm: allow setting the interface description").

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
pull/91396/head
Johann Fischer 1 month ago committed by Benjamin Cabé
parent
commit
79a80730b2
  1. 7
      dts/bindings/usb/zephyr,hid-device.yaml
  2. 2
      samples/subsys/usb/hid-keyboard/app.overlay
  3. 2
      samples/subsys/usb/hid-keyboard/large_in_report.overlay
  4. 2
      samples/subsys/usb/hid-mouse/usbd_next.overlay
  5. 23
      subsys/usb/device_next/class/usbd_hid.c

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

@ -8,11 +8,10 @@ compatible: "zephyr,hid-device" @@ -8,11 +8,10 @@ compatible: "zephyr,hid-device"
include: base.yaml
properties:
interface-name:
type: string
label:
description: |
HID device name. When this property is present, a USB device will use it
as the string descriptor of the interface.
The string defined by the label property is also used for the USB device
interface string descriptor.
protocol-code:
type: string

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

@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
/ {
hid_dev_0: hid_dev_0 {
compatible = "zephyr,hid-device";
interface-name = "HID0";
label = "HID0";
protocol-code = "keyboard";
in-report-size = <64>;
in-polling-period-us = <1000>;

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

@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
/ {
hid_dev_0: hid_dev_0 {
compatible = "zephyr,hid-device";
interface-name = "HID0";
label = "HID0";
in-report-size = <256>;
in-polling-period-us = <1000>;
};

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

@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
/ {
hid_dev_0: hid_dev_0 {
compatible = "zephyr,hid-device";
interface-name = "HID0";
label = "HID0";
protocol-code = "none";
in-polling-period-us = <1000>;
in-report-size = <64>;

23
subsys/usb/device_next/class/usbd_hid.c

@ -65,6 +65,7 @@ struct hid_device_config { @@ -65,6 +65,7 @@ struct hid_device_config {
struct usbd_class_data *c_data;
struct net_buf_pool *pool_out;
struct net_buf_pool *pool_in;
struct usbd_desc_node *const if_desc_data;
const struct usb_desc_header **fs_desc;
const struct usb_desc_header **hs_desc;
};
@ -488,8 +489,21 @@ static void *usbd_hid_get_desc(struct usbd_class_data *const c_data, @@ -488,8 +489,21 @@ static void *usbd_hid_get_desc(struct usbd_class_data *const c_data,
static int usbd_hid_init(struct usbd_class_data *const c_data)
{
struct usbd_context *uds_ctx = usbd_class_get_ctx(c_data);
const struct device *dev = usbd_class_get_private(c_data);
const struct hid_device_config *dcfg = dev->config;
struct usbd_hid_descriptor *const desc = dcfg->desc;
LOG_DBG("HID class %s init", c_data->name);
if (dcfg->if_desc_data != NULL && desc->if0.iInterface == 0) {
if (usbd_add_descriptor(uds_ctx, dcfg->if_desc_data)) {
LOG_ERR("Failed to add interface string descriptor");
} else {
desc->if0.iInterface = usbd_str_desc_get_idx(dcfg->if_desc_data);
}
}
return 0;
}
@ -750,6 +764,12 @@ static const struct hid_device_driver_api hid_device_api = { @@ -750,6 +764,12 @@ static const struct hid_device_driver_api hid_device_api = {
HID_OUT_POOL_DEFINE(n); \
USBD_HID_INTERFACE_DEFINE(n); \
\
IF_ENABLED(DT_INST_NODE_HAS_PROP(n, label), ( \
USBD_DESC_STRING_DEFINE(hid_if_desc_data_##n, \
DT_INST_PROP(n, label), \
USBD_DUT_STRING_INTERFACE); \
)) \
\
USBD_DEFINE_CLASS(hid_##n, \
&usbd_hid_api, \
(void *)DEVICE_DT_GET(DT_DRV_INST(n)), NULL); \
@ -761,6 +781,9 @@ static const struct hid_device_driver_api hid_device_api = { @@ -761,6 +781,9 @@ static const struct hid_device_driver_api hid_device_api = {
.pool_out = HID_OUT_POOL_ADDR(n), \
.fs_desc = hid_fs_desc_##n, \
.hs_desc = hid_hs_desc_##n, \
IF_ENABLED(DT_INST_NODE_HAS_PROP(n, label), ( \
.if_desc_data = &hid_if_desc_data_##n, \
)) \
}; \
\
static struct hid_device_data hid_data_##n; \

Loading…
Cancel
Save