Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

usbstack: Revise usb string descriptor table to use enum values for indices

This makes it possible for macros of conditionally included string
descriptors to get a correct index no matter what other usb drivers
are enabled or disabled due to the nature behavior of enums.

Change-Id: I8ccebbd316605bed0f5d90b6b73fab4a333c02fa

authored by

James Buren and committed by
Aidan MacDonald
c0a59b9a 4be81c23

+17 -10
+8
firmware/export/usb_core.h
··· 39 39 40 40 extern int usb_max_pkt_size; 41 41 42 + enum { 43 + USB_STRING_INDEX_LANGUAGE, 44 + USB_STRING_INDEX_MANUFACTURER, 45 + USB_STRING_INDEX_PRODUCT, 46 + USB_STRING_INDEX_SERIAL, 47 + USB_STRING_INDEX_MAX, 48 + }; 49 + 42 50 struct usb_class_driver; 43 51 44 52 void usb_core_init(void);
+9 -10
firmware/usbstack/usb_core.c
··· 90 90 .idVendor = USB_VENDOR_ID, 91 91 .idProduct = USB_PRODUCT_ID, 92 92 .bcdDevice = 0x0100, 93 - .iManufacturer = 1, 94 - .iProduct = 2, 95 - .iSerialNumber = 3, 93 + .iManufacturer = USB_STRING_INDEX_MANUFACTURER, 94 + .iProduct = USB_STRING_INDEX_PRODUCT, 95 + .iSerialNumber = USB_STRING_INDEX_SERIAL, 96 96 .bNumConfigurations = 1 97 97 } ; 98 98 ··· 141 141 lang_descriptor = 142 142 USB_STRING_INITIALIZER(u"\x0409"); /* LANGID US English */ 143 143 144 - static const struct usb_string_descriptor* const usb_strings[] = 144 + static const struct usb_string_descriptor* const usb_strings[USB_STRING_INDEX_MAX] = 145 145 { 146 - &lang_descriptor, 147 - &usb_string_iManufacturer, 148 - &usb_string_iProduct, 149 - &usb_string_iSerial 146 + [USB_STRING_INDEX_LANGUAGE] = &lang_descriptor, 147 + [USB_STRING_INDEX_MANUFACTURER] = &usb_string_iManufacturer, 148 + [USB_STRING_INDEX_PRODUCT] = &usb_string_iProduct, 149 + [USB_STRING_INDEX_SERIAL] = &usb_string_iSerial, 150 150 }; 151 151 152 152 static int usb_address = 0; ··· 637 637 638 638 case USB_DT_STRING: 639 639 logf("STRING %d", index); 640 - if((unsigned)index < (sizeof(usb_strings) / 641 - sizeof(struct usb_string_descriptor*))) { 640 + if((unsigned)index < USB_STRING_INDEX_MAX) { 642 641 size = usb_strings[index]->bLength; 643 642 ptr = usb_strings[index]; 644 643 }