forked from len0rd/rockbox
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
This commit is contained in:
parent
4be81c2385
commit
c0a59b9a6a
2 changed files with 17 additions and 10 deletions
|
@ -39,6 +39,14 @@
|
||||||
|
|
||||||
extern int usb_max_pkt_size;
|
extern int usb_max_pkt_size;
|
||||||
|
|
||||||
|
enum {
|
||||||
|
USB_STRING_INDEX_LANGUAGE,
|
||||||
|
USB_STRING_INDEX_MANUFACTURER,
|
||||||
|
USB_STRING_INDEX_PRODUCT,
|
||||||
|
USB_STRING_INDEX_SERIAL,
|
||||||
|
USB_STRING_INDEX_MAX,
|
||||||
|
};
|
||||||
|
|
||||||
struct usb_class_driver;
|
struct usb_class_driver;
|
||||||
|
|
||||||
void usb_core_init(void);
|
void usb_core_init(void);
|
||||||
|
|
|
@ -90,9 +90,9 @@ static struct usb_device_descriptor __attribute__((aligned(2)))
|
||||||
.idVendor = USB_VENDOR_ID,
|
.idVendor = USB_VENDOR_ID,
|
||||||
.idProduct = USB_PRODUCT_ID,
|
.idProduct = USB_PRODUCT_ID,
|
||||||
.bcdDevice = 0x0100,
|
.bcdDevice = 0x0100,
|
||||||
.iManufacturer = 1,
|
.iManufacturer = USB_STRING_INDEX_MANUFACTURER,
|
||||||
.iProduct = 2,
|
.iProduct = USB_STRING_INDEX_PRODUCT,
|
||||||
.iSerialNumber = 3,
|
.iSerialNumber = USB_STRING_INDEX_SERIAL,
|
||||||
.bNumConfigurations = 1
|
.bNumConfigurations = 1
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
@ -141,12 +141,12 @@ static const struct usb_string_descriptor __attribute__((aligned(2)))
|
||||||
lang_descriptor =
|
lang_descriptor =
|
||||||
USB_STRING_INITIALIZER(u"\x0409"); /* LANGID US English */
|
USB_STRING_INITIALIZER(u"\x0409"); /* LANGID US English */
|
||||||
|
|
||||||
static const struct usb_string_descriptor* const usb_strings[] =
|
static const struct usb_string_descriptor* const usb_strings[USB_STRING_INDEX_MAX] =
|
||||||
{
|
{
|
||||||
&lang_descriptor,
|
[USB_STRING_INDEX_LANGUAGE] = &lang_descriptor,
|
||||||
&usb_string_iManufacturer,
|
[USB_STRING_INDEX_MANUFACTURER] = &usb_string_iManufacturer,
|
||||||
&usb_string_iProduct,
|
[USB_STRING_INDEX_PRODUCT] = &usb_string_iProduct,
|
||||||
&usb_string_iSerial
|
[USB_STRING_INDEX_SERIAL] = &usb_string_iSerial,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int usb_address = 0;
|
static int usb_address = 0;
|
||||||
|
@ -637,8 +637,7 @@ static void request_handler_device_get_descriptor(struct usb_ctrlrequest* req)
|
||||||
|
|
||||||
case USB_DT_STRING:
|
case USB_DT_STRING:
|
||||||
logf("STRING %d", index);
|
logf("STRING %d", index);
|
||||||
if((unsigned)index < (sizeof(usb_strings) /
|
if((unsigned)index < USB_STRING_INDEX_MAX) {
|
||||||
sizeof(struct usb_string_descriptor*))) {
|
|
||||||
size = usb_strings[index]->bLength;
|
size = usb_strings[index]->bLength;
|
||||||
ptr = usb_strings[index];
|
ptr = usb_strings[index];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue