Skip to content

Commit

Permalink
fix(esp_tinyusb): Provide default descriptors for Vendor specific class
Browse files Browse the repository at this point in the history
  • Loading branch information
tore-espressif committed Sep 20, 2024
1 parent 98078c3 commit e659ac9
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 19 deletions.
3 changes: 2 additions & 1 deletion device/esp_tinyusb/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Unreleased
## 1.4.5

- CDC-ACM: Fixed memory leak at VFS unregister
- Vendor specific: Provided default configuration

## 1.4.4

Expand Down
9 changes: 9 additions & 0 deletions device/esp_tinyusb/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,13 @@ menu "TinyUSB Stack"
bool "None"
endchoice
endmenu # "Network driver (ECM/NCM/RNDIS)"

menu "Vendor Specific Interface"
config TINYUSB_VENDOR_COUNT
int "TinyUSB Vendor specific interfaces count"
default 0
range 0 2
help
Setting value greater than 0 will enable TinyUSB Vendor specific feature.
endmenu # "Vendor Specific Interface"
endmenu # "TinyUSB Stack"
8 changes: 4 additions & 4 deletions device/esp_tinyusb/descriptors_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ esp_err_t tinyusb_set_descriptors(const tinyusb_config_t *config)

// Select FullSpeed configuration descriptor
if (config->configuration_descriptor == NULL) {
// Default configuration descriptor is provided only for CDC, MSC and NCM classes
#if (CFG_TUD_HID > 0 || CFG_TUD_MIDI > 0 || CFG_TUD_CUSTOM_CLASS > 0 || CFG_TUD_ECM_RNDIS > 0 || CFG_TUD_DFU > 0 || CFG_TUD_DFU_RUNTIME > 0 || CFG_TUD_BTH > 0)
// Default configuration descriptor must be provided for the following classes
#if (CFG_TUD_HID > 0 || CFG_TUD_MIDI > 0 || CFG_TUD_ECM_RNDIS > 0 || CFG_TUD_DFU > 0 || CFG_TUD_DFU_RUNTIME > 0 || CFG_TUD_BTH > 0)
ESP_GOTO_ON_FALSE(config->configuration_descriptor, ESP_ERR_INVALID_ARG, fail, TAG, "Configuration descriptor must be provided for this device");
#else
ESP_LOGW(TAG, "No FullSpeed configuration descriptor provided, using default.");
Expand All @@ -192,8 +192,8 @@ esp_err_t tinyusb_set_descriptors(const tinyusb_config_t *config)
#if (TUD_OPT_HIGH_SPEED)
// High Speed
if (config->hs_configuration_descriptor == NULL) {
// Default configuration descriptor is provided only for CDC, MSC and NCM classes
#if (CFG_TUD_HID > 0 || CFG_TUD_MIDI > 0 || CFG_TUD_CUSTOM_CLASS > 0 || CFG_TUD_ECM_RNDIS > 0 || CFG_TUD_DFU > 0 || CFG_TUD_DFU_RUNTIME > 0 || CFG_TUD_BTH > 0)
// Default configuration descriptor must be provided for the following classes
#if (CFG_TUD_HID > 0 || CFG_TUD_MIDI > 0 || CFG_TUD_ECM_RNDIS > 0 || CFG_TUD_DFU > 0 || CFG_TUD_DFU_RUNTIME > 0 || CFG_TUD_BTH > 0)
ESP_GOTO_ON_FALSE(config->hs_configuration_descriptor, ESP_ERR_INVALID_ARG, fail, TAG, "HighSpeed configuration descriptor must be provided for this device");
#else
ESP_LOGW(TAG, "No HighSpeed configuration descriptor provided, using default.");
Expand Down
2 changes: 1 addition & 1 deletion device/esp_tinyusb/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## IDF Component Manager Manifest File
description: Espressif's additions to TinyUSB
documentation: "https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/api-reference/peripherals/usb_device.html"
version: "1.4.4"
version: "1.4.5"
url: https://github.com/espressif/esp-usb/tree/master/device/esp_tinyusb
dependencies:
idf: '>=5.0' # IDF 4.x contains TinyUSB as submodule
Expand Down
13 changes: 6 additions & 7 deletions device/esp_tinyusb/include/tusb_config.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* SPDX-FileCopyrightText: 2019 Ha Thach (tinyusb.org),
* SPDX-FileContributor: 2020 Espressif Systems (Shanghai) CO LTD
* SPDX-FileContributor: 2020-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-License-Identifier: MIT
*
* Copyright (c) 2019 Ha Thach (tinyusb.org),
Expand Down Expand Up @@ -55,8 +55,8 @@ extern "C" {
# define CONFIG_TINYUSB_MIDI_COUNT 0
#endif

#ifndef CONFIG_TINYUSB_CUSTOM_CLASS_ENABLED
# define CONFIG_TINYUSB_CUSTOM_CLASS_ENABLED 0
#ifndef CONFIG_TINYUSB_VENDOR_COUNT
# define CONFIG_TINYUSB_VENDOR_COUNT 0
#endif

#ifndef CONFIG_TINYUSB_NET_MODE_ECM_RNDIS
Expand Down Expand Up @@ -128,9 +128,8 @@ extern "C" {
#define CFG_TUD_MIDI_TX_BUFSIZE 64

// Vendor FIFO size of TX and RX
// If not configured vendor endpoints will not be buffered
#define CFG_TUD_VENDOR_RX_BUFSIZE 64
#define CFG_TUD_VENDOR_TX_BUFSIZE 64
#define CFG_TUD_VENDOR_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
#define CFG_TUD_VENDOR_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)

// DFU macros
#define CFG_TUD_DFU_XFER_BUFSIZE CONFIG_TINYUSB_DFU_BUFSIZE
Expand All @@ -143,7 +142,7 @@ extern "C" {
#define CFG_TUD_MSC CONFIG_TINYUSB_MSC_ENABLED
#define CFG_TUD_HID CONFIG_TINYUSB_HID_COUNT
#define CFG_TUD_MIDI CONFIG_TINYUSB_MIDI_COUNT
#define CFG_TUD_CUSTOM_CLASS CONFIG_TINYUSB_CUSTOM_CLASS_ENABLED
#define CFG_TUD_VENDOR CONFIG_TINYUSB_VENDOR_COUNT
#define CFG_TUD_ECM_RNDIS CONFIG_TINYUSB_NET_MODE_ECM_RNDIS
#define CFG_TUD_NCM CONFIG_TINYUSB_NET_MODE_NCM
#define CFG_TUD_DFU CONFIG_TINYUSB_DFU_MODE_DFU
Expand Down
52 changes: 46 additions & 6 deletions device/esp_tinyusb/usb_descriptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
#define _PID_MAP(itf, n) ((CFG_TUD_##itf) << (n))
#define USB_TUSB_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | \
_PID_MAP(MIDI, 3) ) //| _PID_MAP(AUDIO, 4) | _PID_MAP(VENDOR, 5) )
_PID_MAP(MIDI, 3) | _PID_MAP(AUDIO, 4) | _PID_MAP(VENDOR, 5) )

/**** Kconfig driven Descriptor ****/

Expand Down Expand Up @@ -96,20 +96,20 @@ const char *descriptor_str_default[] = {

#if CONFIG_TINYUSB_CDC_ENABLED
CONFIG_TINYUSB_DESC_CDC_STRING, // 4: CDC Interface
#else
"",
#endif

#if CONFIG_TINYUSB_MSC_ENABLED
CONFIG_TINYUSB_DESC_MSC_STRING, // 5: MSC Interface
#else
"",
#endif

#if CONFIG_TINYUSB_NET_MODE_ECM_RNDIS || CONFIG_TINYUSB_NET_MODE_NCM
"USB net", // 6. NET Interface
"", // 7. MAC
#endif

#if CFG_TUD_VENDOR
"Vendor specific", // 8. Vendor specific
#endif
NULL // NULL: Must be last. Indicates end of array
};

Expand All @@ -134,14 +134,23 @@ enum {
ITF_NUM_NET_DATA,
#endif

#if CFG_TUD_VENDOR
ITF_VENDOR,
#endif

#if CFG_TUD_VENDOR > 1
ITF_VENDOR1,
#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_NCM * TUD_CDC_NCM_DESC_LEN
CFG_TUD_NCM * TUD_CDC_NCM_DESC_LEN +
CFG_TUD_VENDOR * TUD_VENDOR_DESC_LEN
};

//------------- USB Endpoint numbers -------------//
Expand All @@ -166,6 +175,14 @@ enum {
EPNUM_NET_NOTIF,
EPNUM_NET_DATA,
#endif

#if CFG_TUD_VENDOR
EPNUM_0_VENDOR,
#endif

#if CFG_TUD_VENDOR > 1
EPNUM_1_VENDOR
#endif
};

//------------- STRID -------------//
Expand All @@ -187,6 +204,9 @@ enum {
STRID_MAC,
#endif

#if CFG_TUD_VENDOR
STRID_VENDOR_INTERFACE,
#endif
};

//------------- Configuration Descriptor -------------//
Expand All @@ -213,6 +233,16 @@ uint8_t const descriptor_fs_cfg_default[] = {
// 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_NCM_DESCRIPTOR(ITF_NUM_NET, STRID_NET_INTERFACE, STRID_MAC, (0x80 | EPNUM_NET_NOTIF), 64, EPNUM_NET_DATA, (0x80 | EPNUM_NET_DATA), 64, CFG_TUD_NET_MTU),
#endif

#if CFG_TUD_VENDOR
// Interface number, string index, EP Out & IN address, EP size
TUD_VENDOR_DESCRIPTOR(ITF_VENDOR, STRID_VENDOR_INTERFACE, EPNUM_0_VENDOR, 0x80 | EPNUM_0_VENDOR, 64),
#endif

#if CFG_TUD_VENDOR > 1
// Interface number, string index, EP Out & IN address, EP size
TUD_VENDOR_DESCRIPTOR(ITF_VENDOR1, STRID_VENDOR_INTERFACE, EPNUM_1_VENDOR, 0x80 | EPNUM_1_VENDOR, 64),
#endif
};

#if (TUD_OPT_HIGH_SPEED)
Expand All @@ -239,6 +269,16 @@ uint8_t const descriptor_hs_cfg_default[] = {
// 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_NCM_DESCRIPTOR(ITF_NUM_NET, STRID_NET_INTERFACE, STRID_MAC, (0x80 | EPNUM_NET_NOTIF), 64, EPNUM_NET_DATA, (0x80 | EPNUM_NET_DATA), 512, CFG_TUD_NET_MTU),
#endif

#if CFG_TUD_VENDOR
// Interface number, string index, EP Out & IN address, EP size
TUD_VENDOR_DESCRIPTOR(ITF_VENDOR, STRID_VENDOR_INTERFACE, EPNUM_0_VENDOR, 0x80 | EPNUM_0_VENDOR, 512),
#endif

#if CFG_TUD_VENDOR > 1
// Interface number, string index, EP Out & IN address, EP size
TUD_VENDOR_DESCRIPTOR(ITF_VENDOR1, STRID_VENDOR_INTERFACE, EPNUM_1_VENDOR, 0x80 | EPNUM_1_VENDOR, 512),
#endif
};
#endif // TUD_OPT_HIGH_SPEED

Expand Down

0 comments on commit e659ac9

Please sign in to comment.