Magic numbers in usb_desc.c

mborgerson

Well-known member
I am modifying the usb descriptors defined in usb_desc.c to add the USB Test and Measurement class device. I think I have most of it correct, as my device seems to enumerate properly. At the end of the file there is code to build a descriptor list;

Code:
const usb_descriptor_list_t usb_descriptor_list[] = {
    //wValue, wIndex, address,          length
    {0x0100, 0x0000, device_descriptor, sizeof(device_descriptor)},
    {0x0600, 0x0000, qualifier_descriptor, sizeof(qualifier_descriptor)},
    {0x0200, 0x0000, usb_config_descriptor_480, CONFIG_DESC_SIZE},
    {0x0700, 0x0000, usb_config_descriptor_12, CONFIG_DESC_SIZE},
#ifdef SEREMU_INTERFACE
    {0x2200, SEREMU_INTERFACE, seremu_report_desc, sizeof(seremu_report_desc)},
    {0x2100, SEREMU_INTERFACE, usb_config_descriptor_480+SEREMU_HID_DESC_OFFSET, 9},
#endif
#ifdef KEYBOARD_INTERFACE
        {0x2200, KEYBOARD_INTERFACE, keyboard_report_desc, sizeof(keyboard_report_desc)},
        {0x2100, KEYBOARD_INTERFACE, usb_config_descriptor_480+KEYBOARD_HID_DESC_OFFSET, 9},
#endif
#ifdef MOUSE_INTERFACE
        {0x2200, MOUSE_INTERFACE, mouse_report_desc, sizeof(mouse_report_desc)},
        {0x2100, MOUSE_INTERFACE, usb_config_descriptor_480+MOUSE_HID_DESC_OFFSET, 9},
#endif
#ifdef JOYSTICK_INTERFACE
        {0x2200, JOYSTICK_INTERFACE, joystick_report_desc, sizeof(joystick_report_desc)},
        {0x2100, JOYSTICK_INTERFACE, usb_config_descriptor_480+JOYSTICK_HID_DESC_OFFSET, 9},
#endif
#ifdef RAWHID_INTERFACE
    {0x2200, RAWHID_INTERFACE, rawhid_report_desc, sizeof(rawhid_report_desc)},
    {0x2100, RAWHID_INTERFACE, usb_config_descriptor_480+RAWHID_HID_DESC_OFFSET, 9},
#endif
#ifdef FLIGHTSIM_INTERFACE
    {0x2200, FLIGHTSIM_INTERFACE, flightsim_report_desc, sizeof(flightsim_report_desc)},
    {0x2100, FLIGHTSIM_INTERFACE, usb_config_descriptor_480+FLIGHTSIM_HID_DESC_OFFSET, 9},
#endif
#ifdef KEYMEDIA_INTERFACE
        {0x2200, KEYMEDIA_INTERFACE, keymedia_report_desc, sizeof(keymedia_report_desc)},
        {0x2100, KEYMEDIA_INTERFACE, usb_config_descriptor_480+KEYMEDIA_HID_DESC_OFFSET, 9},
#endif
#ifdef MULTITOUCH_INTERFACE
        {0x2200, MULTITOUCH_INTERFACE, multitouch_report_desc, sizeof(multitouch_report_desc)},
        {0x2100, MULTITOUCH_INTERFACE, usb_config_descriptor_480+MULTITOUCH_HID_DESC_OFFSET, 9},
#endif
#ifdef MTP_INTERFACE
    {0x0304, 0x0409, (const uint8_t *)&usb_string_mtp, 0},
#endif
#ifdef EXPERIMENTAL_INTERFACE
    {0x03EE, 0x0000, microsoft_os_string_desc, 18},
    {0x0000, 0xEE04, microsoft_os_compatible_id_desc, 40},
#endif
        {0x0300, 0x0000, (const uint8_t *)&string0, 0},
        {0x0301, 0x0409, (const uint8_t *)&usb_string_manufacturer_name, 0},
        {0x0302, 0x0409, (const uint8_t *)&usb_string_product_name, 0},
        {0x0303, 0x0409, (const uint8_t *)&usb_string_serial_number, 0},
    {0, 0, NULL, 0}
};
For each defined interface, there are two lines which define constants. I can figure out what some of the defined values are, but I have no idea where the first two values in the data come from. The most common values are 0x2200 and 0x2100. My new device is much like the MTP interface, which has only one line of values.

Does anyone have a clue as to how I should add my USBTMC interface to this list?
 
Any time I start looking through things like, this, I end up first looking up at the USB in a Nutshell chapters

This describes many of the descriptor formats:
For example the strings at the end:
{0x0301, 0x0409, (const uint8_t *)&usb_string_manufacturer_name, 0},
That first 03 - is the descriptor type of a string
I believe the 01 is the index number... - Note the index number is stored in the device descriptor to tell it that 1 is for the manufacturer name.
The 0x0409 is language code for English US...

The ones that start with 02 are I believe configuration descriptors. ...
 
Any time I start looking through things like, this, I end up first looking up at the USB in a Nutshell chapters

This describes many of the descriptor formats:
For example the strings at the end:
{0x0301, 0x0409, (const uint8_t *)&usb_string_manufacturer_name, 0},
That first 03 - is the descriptor type of a string
I believe the 01 is the index number... - Note the index number is stored in the device descriptor to tell it that 1 is for the manufacturer name.
The 0x0409 is language code for English US...

The ones that start with 02 are I believe configuration descriptors. ...
Thanks for the link to USB in a Nutshell. I'll look it over. I didn't add anything to the descriptor list and the USBTMC device seems to enumerate properly. The USBTMC device, as I have it now, has the standard USB Serial interface and the USBTMC interface--which is just one Bulk IN and one Bulk OUT. I plan to use the Serial connection (between Host Serial and Device Serial) for simple commands for testing and feedback. The Host program will bridge the Host and Device Serial connections with Device Serial --> Host Serial --> T4.1 in loop(): so I can see what's happening inside the device.
 
Back
Top