diff --git a/examples/device/net_lwip_webserver/src/usb_descriptors.c b/examples/device/net_lwip_webserver/src/usb_descriptors.c index 3e61112e..b531bc79 100644 --- a/examples/device/net_lwip_webserver/src/usb_descriptors.c +++ b/examples/device/net_lwip_webserver/src/usb_descriptors.c @@ -69,7 +69,7 @@ tusb_desc_device_t const desc_device = .iProduct = STRID_PRODUCT, .iSerialNumber = STRID_SERIAL, - .bNumConfigurations = 0x02 + .bNumConfigurations = 0x02 // multiple configurations }; // Invoked when received GET DEVICE DESCRIPTOR @@ -91,8 +91,8 @@ enum enum { - CONFIG_NUM_DEFAULT = 1, - CONFIG_NUM_ALTERNATE = 2, + CONFIG_NUM_RNDIS = 1, + CONFIG_NUM_ECM = 2, }; #define MAIN_CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_RNDIS_DESC_LEN) @@ -106,30 +106,41 @@ enum #define EPNUM_CDC 2 #endif -static uint8_t const main_configuration[] = +static uint8_t const rndis_configuration[] = { // Config number, interface count, string index, total length, attribute, power in mA - TUD_CONFIG_DESCRIPTOR(CONFIG_NUM_DEFAULT, ITF_NUM_TOTAL, 0, MAIN_CONFIG_TOTAL_LEN, 0, 100), + TUD_CONFIG_DESCRIPTOR(CONFIG_NUM_RNDIS, ITF_NUM_TOTAL, 0, MAIN_CONFIG_TOTAL_LEN, 0, 100), // Interface number, string index, EP notification address and size, EP data address (out, in) and size. TUD_RNDIS_DESCRIPTOR(ITF_NUM_CDC, STRID_INTERFACE, 0x81, 8, EPNUM_CDC, 0x80 | EPNUM_CDC, CFG_TUD_NET_ENDPOINT_SIZE), }; -static uint8_t const alt_configuration[] = +static uint8_t const ecm_configuration[] = { // Config number, interface count, string index, total length, attribute, power in mA - TUD_CONFIG_DESCRIPTOR(CONFIG_NUM_ALTERNATE, ITF_NUM_TOTAL, 0, ALT_CONFIG_TOTAL_LEN, 0, 100), + TUD_CONFIG_DESCRIPTOR(CONFIG_NUM_ECM, ITF_NUM_TOTAL, 0, ALT_CONFIG_TOTAL_LEN, 0, 100), // Interface number, description string index, MAC address string index, EP notification address and size, EP data address (out, in), and size, max segment size. TUD_CDC_ECM_DESCRIPTOR(ITF_NUM_CDC, STRID_INTERFACE, STRID_MAC, 0x81, 64, EPNUM_CDC, 0x80 | EPNUM_CDC, CFG_TUD_NET_ENDPOINT_SIZE, CFG_TUD_NET_MTU), }; +// Configuration array: RNDIS and CDC-ECM +// - Windows only works with RNDIS +// - MacOS only works with CDC-ECM +// - Linux will work on both +// Note index is Num-1x +static uint8_t const * const configuration_arr[2] = +{ + [CONFIG_NUM_RNDIS-1] = rndis_configuration, + [CONFIG_NUM_ECM-1 ] = ecm_configuration +}; + // Invoked when received GET CONFIGURATION DESCRIPTOR // Application return pointer to descriptor // Descriptor contents must exist long enough for transfer to complete uint8_t const * tud_descriptor_configuration_cb(uint8_t index) { - return (0 == index) ? main_configuration : alt_configuration; + return configuration_arr[index]; } //--------------------------------------------------------------------+