aboutsummaryrefslogtreecommitdiffstats
path: root/src/generic/usb_cdc.c
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2019-11-25 00:12:56 -0500
committerKevin O'Connor <kevin@koconnor.net>2019-11-25 18:32:52 -0500
commitf76cb92b15afbb5022696bf20c7a0172e3c6f834 (patch)
treee81a0f63ac4ab8650b8b15fc4a6c6a3ddd3c98a4 /src/generic/usb_cdc.c
parentbd6c25c9f8c28831d146f9077a0a2aa636c6e037 (diff)
downloadkutter-f76cb92b15afbb5022696bf20c7a0172e3c6f834.tar.gz
kutter-f76cb92b15afbb5022696bf20c7a0172e3c6f834.tar.xz
kutter-f76cb92b15afbb5022696bf20c7a0172e3c6f834.zip
usb_cdc: Add a usb_fill_serial() helper function
Add a helper function to fill the usb serial string descriptor. Use it in the lpc176x code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/generic/usb_cdc.c')
-rw-r--r--src/generic/usb_cdc.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/generic/usb_cdc.c b/src/generic/usb_cdc.c
index e213a07c..9adc0aa9 100644
--- a/src/generic/usb_cdc.c
+++ b/src/generic/usb_cdc.c
@@ -284,10 +284,27 @@ static const struct descriptor_s {
&cdc_string_manufacturer, SIZE_cdc_string_manufacturer },
{ (USB_DT_STRING<<8) | USB_STR_ID_PRODUCT, USB_LANGID_ENGLISH_US,
&cdc_string_product, SIZE_cdc_string_product },
+#if !CONFIG_USB_SERIAL_NUMBER_CHIPID
{ (USB_DT_STRING<<8) | USB_STR_ID_SERIAL, USB_LANGID_ENGLISH_US,
&cdc_string_serial, SIZE_cdc_string_serial },
+#endif
};
+// Fill in a USB serial string descriptor from a chip id
+void
+usb_fill_serial(struct usb_string_descriptor *desc, int strlen, void *id)
+{
+ desc->bLength = sizeof(*desc) + strlen * sizeof(desc->data[0]);
+ desc->bDescriptorType = USB_DT_STRING;
+
+ uint8_t *src = id;
+ int i;
+ for (i = 0; i < strlen; i++) {
+ uint8_t c = i & 1 ? src[i/2] & 0x0f : src[i/2] >> 4;
+ desc->data[i] = c < 10 ? c + '0' : c - 10 + 'A';
+ }
+}
+
/****************************************************************
* USB endpoint 0 control message handling