From 06e9a22dbbe174a159506b65e51600da74e699a5 Mon Sep 17 00:00:00 2001 From: Tomas Rezucha Date: Thu, 20 Oct 2022 15:45:56 +0200 Subject: [PATCH] Add recent changes from esp-idf --- .gitmodules | 0 Kconfig | 27 +++++++------------------- additions/include/tinyusb_types.h | 2 +- additions/include/tusb_config.h | 14 +++++++------- additions/src/descriptors_control.c | 6 ++++++ additions/src/tinyusb.c | 30 +++++++++++++++++++++++------ additions/src/usb_descriptors.c | 26 +------------------------ 7 files changed, 46 insertions(+), 59 deletions(-) delete mode 100644 .gitmodules diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index e69de29b..00000000 diff --git a/Kconfig b/Kconfig index 72aee1ab..324fe70e 100644 --- a/Kconfig +++ b/Kconfig @@ -94,20 +94,6 @@ menu "TinyUSB Stack" default "Espressif MSC Device" help Name of the MSC device. - - config TINYUSB_DESC_HID_STRING - depends on TINYUSB_HID_COUNT > 0 - string "HID Device String" - default "Espressif HID Device" - help - Name of the HID device - - config TINYUSB_DESC_MIDI_STRING - depends on TINYUSB_MIDI_ENABLED - string "MIDI Device String" - default "Espressif MIDI Device" - help - Name of the MIDI device endmenu # "Descriptor configuration" menu "Massive Storage Class (MSC)" @@ -157,13 +143,14 @@ menu "TinyUSB Stack" CDC FIFO size of TX channel. endmenu # "Communication Device Class" - menu "MIDI" - config TINYUSB_MIDI_ENABLED - bool "Enable TinyUSB MIDI feature" - default n + menu "Musical Instrument Digital Interface (MIDI)" + config TINYUSB_MIDI_COUNT + int "TinyUSB MIDI interfaces count" + default 0 + range 0 2 help - Enable TinyUSB MIDI feature. - endmenu # "MIDI" + Setting value greater than 0 will enable TinyUSB MIDI feature. + endmenu # "Musical Instrument Digital Interface (MIDI)" menu "Human Interface Device Class (HID)" config TINYUSB_HID_COUNT diff --git a/additions/include/tinyusb_types.h b/additions/include/tinyusb_types.h index 2c59f114..1f01fe13 100644 --- a/additions/include/tinyusb_types.h +++ b/additions/include/tinyusb_types.h @@ -11,7 +11,7 @@ extern "C" { #endif #define USB_ESPRESSIF_VID 0x303A -#define USB_STRING_DESCRIPTOR_ARRAY_SIZE 7 +#define USB_STRING_DESCRIPTOR_ARRAY_SIZE 8 // (4 + TINYUSB_STR_DESC_LEN) typedef enum{ TINYUSB_USBDEV_0, diff --git a/additions/include/tusb_config.h b/additions/include/tusb_config.h index 36dbc5b4..da2a5f9e 100644 --- a/additions/include/tusb_config.h +++ b/additions/include/tusb_config.h @@ -37,6 +37,10 @@ extern "C" { # define CONFIG_TINYUSB_CDC_ENABLED 0 #endif +#ifndef CONFIG_TINYUSB_CDC_COUNT +# define CONFIG_TINYUSB_CDC_COUNT 0 +#endif + #ifndef CONFIG_TINYUSB_MSC_ENABLED # define CONFIG_TINYUSB_MSC_ENABLED 0 #endif @@ -45,8 +49,8 @@ extern "C" { # define CONFIG_TINYUSB_HID_COUNT 0 #endif -#ifndef CONFIG_TINYUSB_MIDI_ENABLED -# define CONFIG_TINYUSB_MIDI_ENABLED 0 +#ifndef CONFIG_TINYUSB_MIDI_COUNT +# define CONFIG_TINYUSB_MIDI_COUNT 0 #endif #ifndef CONFIG_TINYUSB_CUSTOM_CLASS_ENABLED @@ -88,14 +92,10 @@ extern "C" { #define CFG_TUD_MIDI_TX_BUFSIZE 64 // Enabled device class driver -#if defined(CONFIG_TINYUSB_CDC_COUNT) #define CFG_TUD_CDC CONFIG_TINYUSB_CDC_COUNT -#else -#define CFG_TUD_CDC 0 -#endif #define CFG_TUD_MSC CONFIG_TINYUSB_MSC_ENABLED #define CFG_TUD_HID CONFIG_TINYUSB_HID_COUNT -#define CFG_TUD_MIDI CONFIG_TINYUSB_MIDI_ENABLED +#define CFG_TUD_MIDI CONFIG_TINYUSB_MIDI_COUNT #define CFG_TUD_CUSTOM_CLASS CONFIG_TINYUSB_CUSTOM_CLASS_ENABLED #ifdef __cplusplus diff --git a/additions/src/descriptors_control.c b/additions/src/descriptors_control.c index 3857e2eb..7e9ed4cb 100644 --- a/additions/src/descriptors_control.c +++ b/additions/src/descriptors_control.c @@ -59,6 +59,12 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) // Convert ASCII string into UTF-16 if ( index >= sizeof(s_str_descriptor) / sizeof(s_str_descriptor[0]) ) { + ESP_LOGE(TAG, "String index (%u) is out of bounds, check your string descriptor", index); + return NULL; + } + + if (s_str_descriptor[index] == NULL) { + ESP_LOGE(TAG, "String index (%u) points to NULL, check your string descriptor", index); return NULL; } diff --git a/additions/src/tinyusb.c b/additions/src/tinyusb.c index d1f0dc13..a081030c 100644 --- a/additions/src/tinyusb.c +++ b/additions/src/tinyusb.c @@ -56,13 +56,31 @@ esp_err_t tinyusb_driver_install(const tinyusb_config_t *config) } ESP_RETURN_ON_ERROR(usb_new_phy(&phy_conf, &phy_hdl), TAG, "Install USB PHY failed"); -#if (CONFIG_TINYUSB_HID_COUNT > 0) - // For HID device, configuration descriptor must be provided - ESP_RETURN_ON_FALSE(config->configuration_descriptor, ESP_ERR_INVALID_ARG, TAG, "Configuration descriptor must be provided for HID device"); + if (config->configuration_descriptor) { + cfg_descriptor = config->configuration_descriptor; + } else { +#if (CONFIG_TINYUSB_HID_COUNT > 0 || CONFIG_TINYUSB_MIDI_COUNT > 0) + // For HID device, configuration descriptor must be provided + ESP_RETURN_ON_FALSE(config->configuration_descriptor, ESP_ERR_INVALID_ARG, TAG, "Configuration descriptor must be provided for this device"); +#else + cfg_descriptor = descriptor_cfg_kconfig; + ESP_LOGW(TAG, "The device's configuration descriptor is not provided by user, using default."); #endif - dev_descriptor = config->device_descriptor ? config->device_descriptor : &descriptor_dev_kconfig; - string_descriptor = config->string_descriptor ? config->string_descriptor : descriptor_str_kconfig; - cfg_descriptor = config->configuration_descriptor ? config->configuration_descriptor : descriptor_cfg_kconfig; + } + + if (config->string_descriptor) { + string_descriptor = config->string_descriptor; + } else { + string_descriptor = descriptor_str_kconfig; + ESP_LOGW(TAG, "The device's string descriptor is not provided by user, using default."); + } + + if (config->device_descriptor) { + dev_descriptor = config->device_descriptor; + } else { + dev_descriptor = &descriptor_dev_kconfig; + ESP_LOGW(TAG, "The device's device descriptor is not provided by user, using default."); + } tusb_set_descriptor(dev_descriptor, string_descriptor, cfg_descriptor); diff --git a/additions/src/usb_descriptors.c b/additions/src/usb_descriptors.c index ccb99089..d4d3004e 100644 --- a/additions/src/usb_descriptors.c +++ b/additions/src/usb_descriptors.c @@ -54,9 +54,6 @@ tusb_desc_strarray_device_t descriptor_str_tinyusb = { "TinyUSB", // 1: Manufacturer "TinyUSB Device", // 2: Product "123456", // 3: Serials, should use chip ID - "TinyUSB CDC", // 4: CDC Interface - "TinyUSB MSC", // 5: MSC Interface - "TinyUSB MIDI" // 6: MIDI }; /* End of TinyUSB default */ @@ -120,12 +117,6 @@ tusb_desc_strarray_device_t descriptor_str_kconfig = { "", #endif -#if CONFIG_TINYUSB_MIDI_ENABLED - CONFIG_TINYUSB_DESC_MIDI_STRING // 6: MIDI -#else - "", -#endif - }; //------------- Configuration Descriptor -------------// @@ -144,19 +135,13 @@ enum { ITF_NUM_MSC, #endif -#if CFG_TUD_MIDI - ITF_NUM_MIDI, - ITF_NUM_MIDI_STREAMING, -#endif - ITF_NUM_TOTAL }; enum { TUSB_DESC_TOTAL_LEN = TUD_CONFIG_DESC_LEN + CFG_TUD_CDC * TUD_CDC_DESC_LEN + - CFG_TUD_MSC * TUD_MSC_DESC_LEN + - CFG_TUD_MIDI * TUD_MIDI_DESC_LEN + CFG_TUD_MSC * TUD_MSC_DESC_LEN }; //------------- USB Endpoint numbers -------------// @@ -176,10 +161,6 @@ enum { #if CFG_TUD_MSC EPNUM_MSC, #endif - -#if CFG_TUD_MIDI - EPNUM_MIDI, -#endif }; uint8_t const descriptor_cfg_kconfig[] = { @@ -200,11 +181,6 @@ uint8_t const descriptor_cfg_kconfig[] = { // Interface number, string index, EP Out & EP In address, EP size TUD_MSC_DESCRIPTOR(ITF_NUM_MSC, 5, EPNUM_MSC, 0x80 | EPNUM_MSC, 64), // highspeed 512 #endif - -#if CFG_TUD_MIDI - // Interface number, string index, EP Out & EP In address, EP size - TUD_MIDI_DESCRIPTOR(ITF_NUM_MIDI, 6, EPNUM_MIDI, 0x80 | EPNUM_MIDI, 64) // highspeed 512 -#endif }; /* End of Kconfig driven Descriptor */