Add recent changes from esp-idf

This commit is contained in:
Tomas Rezucha 2022-10-20 15:45:56 +02:00
parent e280297ef5
commit 06e9a22dbb
7 changed files with 46 additions and 59 deletions

0
.gitmodules vendored
View File

27
Kconfig
View File

@ -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

View File

@ -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,

View File

@ -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

View File

@ -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;
}

View File

@ -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);

View File

@ -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 */