Skip to content

Commit

Permalink
FROMPULL: usb: device: add USB_CONFIGURATION_STRING_DESC KConfig option
Browse files Browse the repository at this point in the history
This change adds a Kconfig option "USB_CONFIGURATION_STRING_DESC_ENABLE"
to enable the USB configuration string descriptor. The default
configuration string is specified in "USB_CONFIGURATION_STRING_DESC."

Signed-off-by: Ren Chen <Ren.Chen@ite.com.tw>

Manaul cherry-pick of:
zephyrproject-rtos/zephyr#74917

BUG=b:327546783
BUG=b:347662534
BUG=b:351756600
TEST=emerge-staryu hammerd and Keyboard automatic upgrade pass

Change-Id: If20aa1de4b6b2512525de1a5a34a7d18981e9f3c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/5633083
Reviewed-by: Fabio Baltieri <fabiobaltieri@google.com>
Commit-Queue: Fabio Baltieri <fabiobaltieri@google.com>
Tested-by: Fabio Baltieri <fabiobaltieri@google.com>
  • Loading branch information
Chenhongren authored and Chromeos LUCI committed Jul 9, 2024
1 parent 161c1da commit 07d749a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
17 changes: 17 additions & 0 deletions subsys/usb/device/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ config USB_DEVICE_SN
Serial Number String will be derived from
Hardware Information Driver (HWINFO).

config USB_CONFIGURATION_STRING_DESC_ENABLE
bool "USB configuration string descriptor support"
help
Enable string descriptor that describes the default configuration.
Since there is only one configuration, this string descriptor may not
provide much useful information.

if USB_CONFIGURATION_STRING_DESC_ENABLE

config USB_CONFIGURATION_STRING_DESC
string "USB configuration string descriptor"
default "Default Configuration"
help
String descriptor that describes the default configuration.

endif # USB_CONFIGURATION_STRING_DESC_ENABLE

config USB_COMPOSITE_DEVICE
bool "Use Interface Association Descriptor code triple"
help
Expand Down
24 changes: 24 additions & 0 deletions subsys/usb/device/usb_descriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ struct common_descriptor {
#define USB_DESC_PRODUCT_IDX 2
#define USB_DESC_SERIAL_NUMBER_IDX 3

#ifdef CONFIG_USB_CONFIGURATION_STRING_DESC_ENABLE
#define USB_DESC_CONFIGURATION_IDX 4
#endif

/*
* Device and configuration descriptor placed in the device section,
* no additional descriptor may be placed there.
Expand Down Expand Up @@ -86,7 +90,11 @@ USBD_DEVICE_DESCR_DEFINE(primary) struct common_descriptor common_desc = {
.wTotalLength = 0,
.bNumInterfaces = 0,
.bConfigurationValue = 1,
#ifdef CONFIG_USB_CONFIGURATION_STRING_DESC_ENABLE
.iConfiguration = USB_DESC_CONFIGURATION_IDX,
#else
.iConfiguration = 0,
#endif
.bmAttributes = USB_SCD_RESERVED |
COND_CODE_1(CONFIG_USB_SELF_POWERED,
(USB_SCD_SELF_POWERED), (0)) |
Expand Down Expand Up @@ -116,6 +124,14 @@ struct usb_string_desription {
uint8_t bDescriptorType;
uint8_t bString[USB_BSTRING_LENGTH(CONFIG_USB_DEVICE_SN)];
} __packed utf16le_sn;

#ifdef CONFIG_USB_CONFIGURATION_STRING_DESC_ENABLE
struct usb_conf_descriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bString[USB_BSTRING_LENGTH(CONFIG_USB_CONFIGURATION_STRING_DESC)];
} __packed utf16le_conf;
#endif
} __packed;

/*
Expand Down Expand Up @@ -149,6 +165,14 @@ USBD_STRING_DESCR_DEFINE(primary) struct usb_string_desription string_descr = {
.bDescriptorType = USB_DESC_STRING,
.bString = CONFIG_USB_DEVICE_SN,
},
#ifdef CONFIG_USB_CONFIGURATION_STRING_DESC_ENABLE
/* Configuration String Descriptor */
.utf16le_conf = {
.bLength = USB_STRING_DESCRIPTOR_LENGTH(CONFIG_USB_CONFIGURATION_STRING_DESC),
.bDescriptorType = USB_DESC_STRING,
.bString = CONFIG_USB_CONFIGURATION_STRING_DESC,
},
#endif
};

/* This element marks the end of the entire descriptor. */
Expand Down

0 comments on commit 07d749a

Please sign in to comment.