From 61e908e428c79fa576547579bc836ae444e9830a Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 21 Nov 2023 16:33:26 +0700 Subject: [PATCH] add support for running tinyusb + max3421 on no OTG MCU such as esp32 --- .../DualRole/CDC/serial_host_bridge/usbh_helper.h | 2 ++ .../DualRole/HID/hid_device_report/usbh_helper.h | 2 ++ .../HID/hid_mouse_log_filter/usbh_helper.h | 2 ++ .../HID/hid_mouse_tremor_filter/usbh_helper.h | 2 ++ examples/DualRole/HID/hid_remapper/usbh_helper.h | 2 ++ .../MassStorage/msc_data_logger/usbh_helper.h | 2 ++ .../MassStorage/msc_file_explorer/usbh_helper.h | 2 ++ examples/DualRole/Simple/device_info/usbh_helper.h | 2 ++ src/arduino/Adafruit_USBH_Host.cpp | 7 +++---- src/arduino/ports/esp32/tusb_config_esp32.h | 14 ++++++++++++++ src/tusb_config.h | 6 +++++- 11 files changed, 38 insertions(+), 5 deletions(-) diff --git a/examples/DualRole/CDC/serial_host_bridge/usbh_helper.h b/examples/DualRole/CDC/serial_host_bridge/usbh_helper.h index 4258a084..dcc48cc3 100644 --- a/examples/DualRole/CDC/serial_host_bridge/usbh_helper.h +++ b/examples/DualRole/CDC/serial_host_bridge/usbh_helper.h @@ -39,6 +39,8 @@ #if defined(ARDUINO_METRO_ESP32S2) Adafruit_USBH_Host USBHost(&SPI, 15, 14); + #elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32_V2) + Adafruit_USBH_Host USBHost(&SPI, 27, 33); #elif defined(ARDUINO_METRO_ESP32S3) || defined(ADAFRUIT_METRO_M4_EXPRESS) || defined(ADAFRUIT_METRO_M0_EXPRESS) // For Metro shape CS and INT are pin 10, 9 (host shield default) Adafruit_USBH_Host USBHost(&SPI, 10, 9); diff --git a/examples/DualRole/HID/hid_device_report/usbh_helper.h b/examples/DualRole/HID/hid_device_report/usbh_helper.h index 4258a084..dcc48cc3 100644 --- a/examples/DualRole/HID/hid_device_report/usbh_helper.h +++ b/examples/DualRole/HID/hid_device_report/usbh_helper.h @@ -39,6 +39,8 @@ #if defined(ARDUINO_METRO_ESP32S2) Adafruit_USBH_Host USBHost(&SPI, 15, 14); + #elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32_V2) + Adafruit_USBH_Host USBHost(&SPI, 27, 33); #elif defined(ARDUINO_METRO_ESP32S3) || defined(ADAFRUIT_METRO_M4_EXPRESS) || defined(ADAFRUIT_METRO_M0_EXPRESS) // For Metro shape CS and INT are pin 10, 9 (host shield default) Adafruit_USBH_Host USBHost(&SPI, 10, 9); diff --git a/examples/DualRole/HID/hid_mouse_log_filter/usbh_helper.h b/examples/DualRole/HID/hid_mouse_log_filter/usbh_helper.h index 4258a084..dcc48cc3 100644 --- a/examples/DualRole/HID/hid_mouse_log_filter/usbh_helper.h +++ b/examples/DualRole/HID/hid_mouse_log_filter/usbh_helper.h @@ -39,6 +39,8 @@ #if defined(ARDUINO_METRO_ESP32S2) Adafruit_USBH_Host USBHost(&SPI, 15, 14); + #elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32_V2) + Adafruit_USBH_Host USBHost(&SPI, 27, 33); #elif defined(ARDUINO_METRO_ESP32S3) || defined(ADAFRUIT_METRO_M4_EXPRESS) || defined(ADAFRUIT_METRO_M0_EXPRESS) // For Metro shape CS and INT are pin 10, 9 (host shield default) Adafruit_USBH_Host USBHost(&SPI, 10, 9); diff --git a/examples/DualRole/HID/hid_mouse_tremor_filter/usbh_helper.h b/examples/DualRole/HID/hid_mouse_tremor_filter/usbh_helper.h index 4258a084..dcc48cc3 100644 --- a/examples/DualRole/HID/hid_mouse_tremor_filter/usbh_helper.h +++ b/examples/DualRole/HID/hid_mouse_tremor_filter/usbh_helper.h @@ -39,6 +39,8 @@ #if defined(ARDUINO_METRO_ESP32S2) Adafruit_USBH_Host USBHost(&SPI, 15, 14); + #elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32_V2) + Adafruit_USBH_Host USBHost(&SPI, 27, 33); #elif defined(ARDUINO_METRO_ESP32S3) || defined(ADAFRUIT_METRO_M4_EXPRESS) || defined(ADAFRUIT_METRO_M0_EXPRESS) // For Metro shape CS and INT are pin 10, 9 (host shield default) Adafruit_USBH_Host USBHost(&SPI, 10, 9); diff --git a/examples/DualRole/HID/hid_remapper/usbh_helper.h b/examples/DualRole/HID/hid_remapper/usbh_helper.h index 4258a084..dcc48cc3 100644 --- a/examples/DualRole/HID/hid_remapper/usbh_helper.h +++ b/examples/DualRole/HID/hid_remapper/usbh_helper.h @@ -39,6 +39,8 @@ #if defined(ARDUINO_METRO_ESP32S2) Adafruit_USBH_Host USBHost(&SPI, 15, 14); + #elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32_V2) + Adafruit_USBH_Host USBHost(&SPI, 27, 33); #elif defined(ARDUINO_METRO_ESP32S3) || defined(ADAFRUIT_METRO_M4_EXPRESS) || defined(ADAFRUIT_METRO_M0_EXPRESS) // For Metro shape CS and INT are pin 10, 9 (host shield default) Adafruit_USBH_Host USBHost(&SPI, 10, 9); diff --git a/examples/DualRole/MassStorage/msc_data_logger/usbh_helper.h b/examples/DualRole/MassStorage/msc_data_logger/usbh_helper.h index 4258a084..dcc48cc3 100644 --- a/examples/DualRole/MassStorage/msc_data_logger/usbh_helper.h +++ b/examples/DualRole/MassStorage/msc_data_logger/usbh_helper.h @@ -39,6 +39,8 @@ #if defined(ARDUINO_METRO_ESP32S2) Adafruit_USBH_Host USBHost(&SPI, 15, 14); + #elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32_V2) + Adafruit_USBH_Host USBHost(&SPI, 27, 33); #elif defined(ARDUINO_METRO_ESP32S3) || defined(ADAFRUIT_METRO_M4_EXPRESS) || defined(ADAFRUIT_METRO_M0_EXPRESS) // For Metro shape CS and INT are pin 10, 9 (host shield default) Adafruit_USBH_Host USBHost(&SPI, 10, 9); diff --git a/examples/DualRole/MassStorage/msc_file_explorer/usbh_helper.h b/examples/DualRole/MassStorage/msc_file_explorer/usbh_helper.h index 4258a084..dcc48cc3 100644 --- a/examples/DualRole/MassStorage/msc_file_explorer/usbh_helper.h +++ b/examples/DualRole/MassStorage/msc_file_explorer/usbh_helper.h @@ -39,6 +39,8 @@ #if defined(ARDUINO_METRO_ESP32S2) Adafruit_USBH_Host USBHost(&SPI, 15, 14); + #elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32_V2) + Adafruit_USBH_Host USBHost(&SPI, 27, 33); #elif defined(ARDUINO_METRO_ESP32S3) || defined(ADAFRUIT_METRO_M4_EXPRESS) || defined(ADAFRUIT_METRO_M0_EXPRESS) // For Metro shape CS and INT are pin 10, 9 (host shield default) Adafruit_USBH_Host USBHost(&SPI, 10, 9); diff --git a/examples/DualRole/Simple/device_info/usbh_helper.h b/examples/DualRole/Simple/device_info/usbh_helper.h index 4258a084..dcc48cc3 100644 --- a/examples/DualRole/Simple/device_info/usbh_helper.h +++ b/examples/DualRole/Simple/device_info/usbh_helper.h @@ -39,6 +39,8 @@ #if defined(ARDUINO_METRO_ESP32S2) Adafruit_USBH_Host USBHost(&SPI, 15, 14); + #elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32_V2) + Adafruit_USBH_Host USBHost(&SPI, 27, 33); #elif defined(ARDUINO_METRO_ESP32S3) || defined(ADAFRUIT_METRO_M4_EXPRESS) || defined(ADAFRUIT_METRO_M0_EXPRESS) // For Metro shape CS and INT are pin 10, 9 (host shield default) Adafruit_USBH_Host USBHost(&SPI, 10, 9); diff --git a/src/arduino/Adafruit_USBH_Host.cpp b/src/arduino/Adafruit_USBH_Host.cpp index 9a035259..b5bbef91 100644 --- a/src/arduino/Adafruit_USBH_Host.cpp +++ b/src/arduino/Adafruit_USBH_Host.cpp @@ -26,6 +26,7 @@ #ifdef ARDUINO_ARCH_ESP32 #include "arduino/ports/esp32/tusb_config_esp32.h" #include "driver/gpio.h" +#include #define MSBFIRST SPI_MSBFIRST #endif @@ -123,15 +124,13 @@ bool Adafruit_USBH_Host::begin(uint8_t rhport) { #ifdef ARDUINO_ARCH_ESP32 // ESP32 SPI assign pins when begin() of declaration as standard API _spi->begin(_sck, _miso, _mosi, -1); -#else - _spi->begin(); -#endif -#ifdef ARDUINO_ARCH_ESP32 // Create an task for executing interrupt handler in thread mode max3421_intr_sem = xSemaphoreCreateBinary(); xTaskCreateUniversal(max3421_intr_task, "max3421 intr", 2048, NULL, 5, NULL, ARDUINO_RUNNING_CORE); +#else + _spi->begin(); #endif // Interrupt pin diff --git a/src/arduino/ports/esp32/tusb_config_esp32.h b/src/arduino/ports/esp32/tusb_config_esp32.h index 20c64f5d..c719cdc5 100644 --- a/src/arduino/ports/esp32/tusb_config_esp32.h +++ b/src/arduino/ports/esp32/tusb_config_esp32.h @@ -57,6 +57,20 @@ extern "C" { #define CFG_TUH_LOG_LEVEL 2 #endif +//-------------------------------------------------------------------- +// COMMON CONFIGURATION +// Note: it is possible to use tinyusb + max3421e as host controller +// with no OTG USB MCU such as eps32, c3 etc... +//-------------------------------------------------------------------- + +#ifndef CFG_TUSB_OS +#define CFG_TUSB_OS OPT_OS_FREERTOS + +// clang-format off +#define CFG_TUSB_OS_INC_PATH freertos/ +// clang-format on +#endif + // #ifndef CFG_TUSB_DEBUG // #define CFG_TUSB_DEBUG 0 // #endif diff --git a/src/tusb_config.h b/src/tusb_config.h index 52676c35..6630bbea 100644 --- a/src/tusb_config.h +++ b/src/tusb_config.h @@ -42,7 +42,11 @@ // Note: when compiling core Arduino IDEs will include tusb_config.h in the BSP // sdk/include/arduino_tinyusb/include. While compiling .c file in this library this // file will be used instead. For consistency: include the one in BSP here as well - #include "../../arduino_tinyusb/include/tusb_config.h" + #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 + #include "../../arduino_tinyusb/include/tusb_config.h" + #else + #include "arduino/ports/esp32/tusb_config_esp32.h" + #endif // Note: For platformio prioritize this file over the one in BSP in all cases