Skip to content

Commit 2d3f1b4

Browse files
Merge pull request #161 from AmbiqAI/feat/webusb-descriptors
Enable overriding usb descriptors such as serial number.
2 parents 296b185 + be62dc3 commit 2d3f1b4

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

neuralspot/ns-usb/includes-api/usb_descriptors.h

+7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@
2727

2828
enum { VENDOR_REQUEST_WEBUSB = 1, VENDOR_REQUEST_MICROSOFT = 2 };
2929

30+
enum {
31+
USB_DESCRIPTOR_MANUFACTURER = 0x01,
32+
USB_DESCRIPTOR_PRODUCT = 0x02,
33+
USB_DESCRIPTOR_SERIAL = 0x03,
34+
};
35+
36+
extern char const *usb_string_desc_arr[6];
3037
extern uint8_t const desc_ms_os_20[];
3138

3239
#endif /* USB_DESCRIPTORS_H_ */

neuralspot/ns-usb/src/overrides/usb_descriptors.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ tusb_desc_device_t const desc_device = {
5858
.idProduct = USB_PID,
5959
.bcdDevice = 0x0100,
6060

61-
.iManufacturer = 0x01,
62-
.iProduct = 0x02,
63-
.iSerialNumber = 0x03,
61+
.iManufacturer = USB_DESCRIPTOR_MANUFACTURER,
62+
.iProduct = USB_DESCRIPTOR_PRODUCT,
63+
.iSerialNumber = USB_DESCRIPTOR_SERIAL,
6464

6565
.bNumConfigurations = 0x01};
6666

@@ -69,7 +69,7 @@ tusb_desc_device_t const desc_device = {
6969
//--------------------------------------------------------------------+
7070

7171
// array of pointer to string descriptors
72-
static char const *string_desc_arr[] = {
72+
char const *usb_string_desc_arr[6] = {
7373
(const char[]){0x09, 0x04}, // 0: is supported language is English (0x0409)
7474
"TinyUSB", // 1: Manufacturer
7575
"TinyUSB Device", // 2: Product
@@ -255,19 +255,19 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
255255
uint8_t chr_count;
256256

257257
if (index == 0) {
258-
memcpy(&_desc_str[1], string_desc_arr[0], 2);
258+
memcpy(&_desc_str[1], usb_string_desc_arr[0], 2);
259259
chr_count = 1;
260260
} else {
261261
//
262262
// Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
263263
// https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
264264
//
265265

266-
if (!(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0]))) {
266+
if (!(index < sizeof(usb_string_desc_arr) / sizeof(usb_string_desc_arr[0]))) {
267267
return NULL;
268268
}
269269

270-
const char *str = string_desc_arr[index];
270+
const char *str = usb_string_desc_arr[index];
271271

272272
//
273273
// Cap at max char

0 commit comments

Comments
 (0)