From f3e0ff74cc0ca83a746716caf6873be9257ab714 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 21 Nov 2023 13:28:44 +0700 Subject: [PATCH 1/3] add max3421_readRegister() max3421_readRegister(), max3421_writeIOPINS1(), max3421_writeIOPINS2() to usbhost with max3421 update examples to work with featherwing usb host max3421 --- .../CDC/serial_host_bridge/usbh_helper.h | 7 ++++-- .../HID/hid_device_report/usbh_helper.h | 7 ++++-- .../hid_mouse_log_filter.ino | 5 +++- .../HID/hid_mouse_log_filter/usbh_helper.h | 7 ++++-- .../hid_mouse_tremor_filter.ino | 5 +++- .../HID/hid_mouse_tremor_filter/usbh_helper.h | 7 ++++-- .../HID/hid_remapper/hid_remapper.ino | 5 +++- .../DualRole/HID/hid_remapper/usbh_helper.h | 7 ++++-- .../msc_data_logger/msc_data_logger.ino | 5 +++- .../MassStorage/msc_data_logger/usbh_helper.h | 7 ++++-- .../msc_file_explorer/msc_file_explorer.ino | 5 +++- .../msc_file_explorer/usbh_helper.h | 7 ++++-- .../Simple/device_info/device_info.ino | 6 +++-- .../DualRole/Simple/device_info/usbh_helper.h | 7 ++++-- src/arduino/Adafruit_USBH_Host.cpp | 24 ++++++++++++++++++- src/arduino/Adafruit_USBH_Host.h | 13 ++++++++++ 16 files changed, 100 insertions(+), 24 deletions(-) diff --git a/examples/DualRole/CDC/serial_host_bridge/usbh_helper.h b/examples/DualRole/CDC/serial_host_bridge/usbh_helper.h index b8d9e569..4258a084 100644 --- a/examples/DualRole/CDC/serial_host_bridge/usbh_helper.h +++ b/examples/DualRole/CDC/serial_host_bridge/usbh_helper.h @@ -39,9 +39,12 @@ #if defined(ARDUINO_METRO_ESP32S2) Adafruit_USBH_Host USBHost(&SPI, 15, 14); - #else - // Default use SPI and pin 10, 9 for CS and INT + #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); + #else + // default to FeatherWing USB Host MAX3421E: CS and INT are pin D11, D10 + Adafruit_USBH_Host USBHost(&SPI, 11, 10); #endif #else // Native USB Host such as rp2040 diff --git a/examples/DualRole/HID/hid_device_report/usbh_helper.h b/examples/DualRole/HID/hid_device_report/usbh_helper.h index b8d9e569..4258a084 100644 --- a/examples/DualRole/HID/hid_device_report/usbh_helper.h +++ b/examples/DualRole/HID/hid_device_report/usbh_helper.h @@ -39,9 +39,12 @@ #if defined(ARDUINO_METRO_ESP32S2) Adafruit_USBH_Host USBHost(&SPI, 15, 14); - #else - // Default use SPI and pin 10, 9 for CS and INT + #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); + #else + // default to FeatherWing USB Host MAX3421E: CS and INT are pin D11, D10 + Adafruit_USBH_Host USBHost(&SPI, 11, 10); #endif #else // Native USB Host such as rp2040 diff --git a/examples/DualRole/HID/hid_mouse_log_filter/hid_mouse_log_filter.ino b/examples/DualRole/HID/hid_mouse_log_filter/hid_mouse_log_filter.ino index 6e5956dd..375604b4 100644 --- a/examples/DualRole/HID/hid_mouse_log_filter/hid_mouse_log_filter.ino +++ b/examples/DualRole/HID/hid_mouse_log_filter/hid_mouse_log_filter.ino @@ -57,10 +57,13 @@ void setup() { Serial.begin(115200); usb_hid.begin(); -#ifndef ARDUINO_ARCH_RP2040 +#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421 // init host stack on controller (rhport) 1 // For rp2040: this is called in core1's setup1() USBHost.begin(1); + + // FeatherWing USB Host use MAX3421E's GPIO0 as VBUS enable (active high) + USBHost.max3421_writeIOPINS1(0x01, false); #endif //while ( !Serial ) delay(10); // wait for native usb 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 b8d9e569..4258a084 100644 --- a/examples/DualRole/HID/hid_mouse_log_filter/usbh_helper.h +++ b/examples/DualRole/HID/hid_mouse_log_filter/usbh_helper.h @@ -39,9 +39,12 @@ #if defined(ARDUINO_METRO_ESP32S2) Adafruit_USBH_Host USBHost(&SPI, 15, 14); - #else - // Default use SPI and pin 10, 9 for CS and INT + #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); + #else + // default to FeatherWing USB Host MAX3421E: CS and INT are pin D11, D10 + Adafruit_USBH_Host USBHost(&SPI, 11, 10); #endif #else // Native USB Host such as rp2040 diff --git a/examples/DualRole/HID/hid_mouse_tremor_filter/hid_mouse_tremor_filter.ino b/examples/DualRole/HID/hid_mouse_tremor_filter/hid_mouse_tremor_filter.ino index 23a16ef5..f26507da 100644 --- a/examples/DualRole/HID/hid_mouse_tremor_filter/hid_mouse_tremor_filter.ino +++ b/examples/DualRole/HID/hid_mouse_tremor_filter/hid_mouse_tremor_filter.ino @@ -68,10 +68,13 @@ void setup() { coeffs[0] = butterworth_lowpass(CUTOFF_FREQUENCY, SAMPLING_FREQUENCY); coeffs[1] = butterworth_lowpass(CUTOFF_FREQUENCY, SAMPLING_FREQUENCY); -#ifndef ARDUINO_ARCH_RP2040 +#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421 // init host stack on controller (rhport) 1 // For rp2040: this is called in core1's setup1() USBHost.begin(1); + + // FeatherWing USB Host use MAX3421E's GPIO0 as VBUS enable (active high) + USBHost.max3421_writeIOPINS1(0x01, false); #endif //while ( !Serial ) delay(10); // wait for native usb 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 b8d9e569..4258a084 100644 --- a/examples/DualRole/HID/hid_mouse_tremor_filter/usbh_helper.h +++ b/examples/DualRole/HID/hid_mouse_tremor_filter/usbh_helper.h @@ -39,9 +39,12 @@ #if defined(ARDUINO_METRO_ESP32S2) Adafruit_USBH_Host USBHost(&SPI, 15, 14); - #else - // Default use SPI and pin 10, 9 for CS and INT + #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); + #else + // default to FeatherWing USB Host MAX3421E: CS and INT are pin D11, D10 + Adafruit_USBH_Host USBHost(&SPI, 11, 10); #endif #else // Native USB Host such as rp2040 diff --git a/examples/DualRole/HID/hid_remapper/hid_remapper.ino b/examples/DualRole/HID/hid_remapper/hid_remapper.ino index a3231546..535a2413 100644 --- a/examples/DualRole/HID/hid_remapper/hid_remapper.ino +++ b/examples/DualRole/HID/hid_remapper/hid_remapper.ino @@ -51,10 +51,13 @@ void setup() { Serial.begin(115200); usb_hid.begin(); -#ifndef ARDUINO_ARCH_RP2040 +#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421 // init host stack on controller (rhport) 1 // For rp2040: this is called in core1's setup1() USBHost.begin(1); + + // FeatherWing USB Host use MAX3421E's GPIO0 as VBUS enable (active high) + USBHost.max3421_writeIOPINS1(0x01, false); #endif //while ( !Serial ) delay(10); // wait for native usb diff --git a/examples/DualRole/HID/hid_remapper/usbh_helper.h b/examples/DualRole/HID/hid_remapper/usbh_helper.h index b8d9e569..4258a084 100644 --- a/examples/DualRole/HID/hid_remapper/usbh_helper.h +++ b/examples/DualRole/HID/hid_remapper/usbh_helper.h @@ -39,9 +39,12 @@ #if defined(ARDUINO_METRO_ESP32S2) Adafruit_USBH_Host USBHost(&SPI, 15, 14); - #else - // Default use SPI and pin 10, 9 for CS and INT + #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); + #else + // default to FeatherWing USB Host MAX3421E: CS and INT are pin D11, D10 + Adafruit_USBH_Host USBHost(&SPI, 11, 10); #endif #else // Native USB Host such as rp2040 diff --git a/examples/DualRole/MassStorage/msc_data_logger/msc_data_logger.ino b/examples/DualRole/MassStorage/msc_data_logger/msc_data_logger.ino index 75e9d696..3526c217 100644 --- a/examples/DualRole/MassStorage/msc_data_logger/msc_data_logger.ino +++ b/examples/DualRole/MassStorage/msc_data_logger/msc_data_logger.ino @@ -114,10 +114,13 @@ void setup() { pinMode(LED_BUILTIN, OUTPUT); -#ifndef ARDUINO_ARCH_RP2040 +#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421 // init host stack on controller (rhport) 1 // For rp2040: this is called in core1's setup1() USBHost.begin(1); + + // FeatherWing USB Host use MAX3421E's GPIO0 as VBUS enable (active high) + USBHost.max3421_writeIOPINS1(0x01, false); #endif #ifdef USE_FREERTOS diff --git a/examples/DualRole/MassStorage/msc_data_logger/usbh_helper.h b/examples/DualRole/MassStorage/msc_data_logger/usbh_helper.h index b8d9e569..4258a084 100644 --- a/examples/DualRole/MassStorage/msc_data_logger/usbh_helper.h +++ b/examples/DualRole/MassStorage/msc_data_logger/usbh_helper.h @@ -39,9 +39,12 @@ #if defined(ARDUINO_METRO_ESP32S2) Adafruit_USBH_Host USBHost(&SPI, 15, 14); - #else - // Default use SPI and pin 10, 9 for CS and INT + #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); + #else + // default to FeatherWing USB Host MAX3421E: CS and INT are pin D11, D10 + Adafruit_USBH_Host USBHost(&SPI, 11, 10); #endif #else // Native USB Host such as rp2040 diff --git a/examples/DualRole/MassStorage/msc_file_explorer/msc_file_explorer.ino b/examples/DualRole/MassStorage/msc_file_explorer/msc_file_explorer.ino index a9968d23..c4945c27 100644 --- a/examples/DualRole/MassStorage/msc_file_explorer/msc_file_explorer.ino +++ b/examples/DualRole/MassStorage/msc_file_explorer/msc_file_explorer.ino @@ -44,10 +44,13 @@ bool is_mounted = false; void setup() { Serial.begin(115200); -#ifndef ARDUINO_ARCH_RP2040 +#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421 // init host stack on controller (rhport) 1 // For rp2040: this is called in core1's setup1() USBHost.begin(1); + + // FeatherWing USB Host use MAX3421E's GPIO0 as VBUS enable (active high) + USBHost.max3421_writeIOPINS1(0x01, false); #endif // while ( !Serial ) delay(10); // wait for native usb diff --git a/examples/DualRole/MassStorage/msc_file_explorer/usbh_helper.h b/examples/DualRole/MassStorage/msc_file_explorer/usbh_helper.h index b8d9e569..4258a084 100644 --- a/examples/DualRole/MassStorage/msc_file_explorer/usbh_helper.h +++ b/examples/DualRole/MassStorage/msc_file_explorer/usbh_helper.h @@ -39,9 +39,12 @@ #if defined(ARDUINO_METRO_ESP32S2) Adafruit_USBH_Host USBHost(&SPI, 15, 14); - #else - // Default use SPI and pin 10, 9 for CS and INT + #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); + #else + // default to FeatherWing USB Host MAX3421E: CS and INT are pin D11, D10 + Adafruit_USBH_Host USBHost(&SPI, 11, 10); #endif #else // Native USB Host such as rp2040 diff --git a/examples/DualRole/Simple/device_info/device_info.ino b/examples/DualRole/Simple/device_info/device_info.ino index 1d32e0e6..ea0a16b7 100644 --- a/examples/DualRole/Simple/device_info/device_info.ino +++ b/examples/DualRole/Simple/device_info/device_info.ino @@ -68,10 +68,13 @@ dev_info_t dev_info[CFG_TUH_DEVICE_MAX] = { 0 }; void setup() { Serial.begin(115200); -#ifndef ARDUINO_ARCH_RP2040 +#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421 // init host stack on controller (rhport) 1 // For rp2040: this is called in core1's setup1() USBHost.begin(1); + + // FeatherWing USB Host use MAX3421E's GPIO0 as VBUS enable (active high) + USBHost.max3421_writeIOPINS1(0x01, false); #endif // while ( !Serial ) delay(10); // wait for native usb @@ -94,7 +97,6 @@ void loop() { //------------- Core0 -------------// void loop() { - } //------------- Core1 -------------// diff --git a/examples/DualRole/Simple/device_info/usbh_helper.h b/examples/DualRole/Simple/device_info/usbh_helper.h index b8d9e569..4258a084 100644 --- a/examples/DualRole/Simple/device_info/usbh_helper.h +++ b/examples/DualRole/Simple/device_info/usbh_helper.h @@ -39,9 +39,12 @@ #if defined(ARDUINO_METRO_ESP32S2) Adafruit_USBH_Host USBHost(&SPI, 15, 14); - #else - // Default use SPI and pin 10, 9 for CS and INT + #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); + #else + // default to FeatherWing USB Host MAX3421E: CS and INT are pin D11, D10 + Adafruit_USBH_Host USBHost(&SPI, 11, 10); #endif #else // Native USB Host such as rp2040 diff --git a/src/arduino/Adafruit_USBH_Host.cpp b/src/arduino/Adafruit_USBH_Host.cpp index 3fcf4ea7..9a035259 100644 --- a/src/arduino/Adafruit_USBH_Host.cpp +++ b/src/arduino/Adafruit_USBH_Host.cpp @@ -40,7 +40,7 @@ Adafruit_USBH_Host *Adafruit_USBH_Host::_instance = NULL; Adafruit_USBH_Host::Adafruit_USBH_Host(void) { Adafruit_USBH_Host::_instance = this; - + _rhport = 0; #if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421 _spi = NULL; _cs = _intr = _sck = _mosi = _miso = -1; @@ -48,6 +48,15 @@ Adafruit_USBH_Host::Adafruit_USBH_Host(void) { } #if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421 + +// API to read MAX3421's register. Implemented by TinyUSB +extern "C" uint8_t tuh_max3421_reg_read(uint8_t rhport, uint8_t reg, + bool in_isr); + +// API to write MAX3421's register. Implemented by TinyUSB +extern "C" bool tuh_max3421_reg_write(uint8_t rhport, uint8_t reg, uint8_t data, + bool in_isr); + static void max3421_isr(void); #if defined(ARDUINO_ARCH_ESP32) @@ -57,6 +66,7 @@ static void max3421_intr_task(void *param); Adafruit_USBH_Host::Adafruit_USBH_Host(SPIClass *spi, int8_t cs, int8_t intr) { Adafruit_USBH_Host::_instance = this; + _rhport = 0; _spi = spi; _cs = cs; _intr = intr; @@ -66,6 +76,7 @@ Adafruit_USBH_Host::Adafruit_USBH_Host(SPIClass *spi, int8_t cs, int8_t intr) { Adafruit_USBH_Host::Adafruit_USBH_Host(SPIClass *spi, int8_t sck, int8_t mosi, int8_t miso, int8_t cs, int8_t intr) { Adafruit_USBH_Host::_instance = this; + _rhport = 0; _spi = spi; _cs = cs; _intr = intr; @@ -73,6 +84,16 @@ Adafruit_USBH_Host::Adafruit_USBH_Host(SPIClass *spi, int8_t sck, int8_t mosi, _mosi = mosi; _miso = miso; } + +uint8_t Adafruit_USBH_Host::max3421_readRegister(uint8_t reg, bool in_isr) { + return tuh_max3421_reg_read(_rhport, reg, in_isr); +} + +bool Adafruit_USBH_Host::max3421_writeRegister(uint8_t reg, uint8_t data, + bool in_isr) { + return tuh_max3421_reg_write(_rhport, reg, data, in_isr); +} + #endif bool Adafruit_USBH_Host::configure(uint8_t rhport, uint32_t cfg_id, @@ -118,6 +139,7 @@ bool Adafruit_USBH_Host::begin(uint8_t rhport) { attachInterrupt(_intr, max3421_isr, FALLING); #endif + _rhport = rhport; return tuh_init(rhport); } diff --git a/src/arduino/Adafruit_USBH_Host.h b/src/arduino/Adafruit_USBH_Host.h index 882b370f..3eb60db1 100644 --- a/src/arduino/Adafruit_USBH_Host.h +++ b/src/arduino/Adafruit_USBH_Host.h @@ -56,6 +56,17 @@ class Adafruit_USBH_Host { Adafruit_USBH_Host(SPIClass *spi, int8_t cs, int8_t intr); Adafruit_USBH_Host(SPIClass *spi, int8_t sck, int8_t mosi, int8_t miso, int8_t cs, int8_t intr); + + uint8_t max3421_readRegister(uint8_t reg, bool in_isr); + bool max3421_writeRegister(uint8_t reg, uint8_t data, bool in_isr); + bool max3421_writeIOPINS1(uint8_t data, bool in_isr) { + enum { IOPINS1_ADDR = 20u << 3 }; // 0xA0 + return max3421_writeRegister(IOPINS1_ADDR, data, in_isr); + } + bool max3421_writeIOPINS2(uint8_t data, bool in_isr) { + enum { IOPINS2_ADDR = 21u << 3 }; // 0xA8 + return max3421_writeRegister(IOPINS2_ADDR, data, in_isr); + } #endif public: @@ -75,6 +86,8 @@ class Adafruit_USBH_Host { static Adafruit_USBH_Host *_instance; private: + uint8_t _rhport; + friend void tuh_max3421_spi_cs_api(uint8_t rhport, bool active); friend bool tuh_max3421_spi_xfer_api(uint8_t rhport, uint8_t const *tx_buf, uint8_t *rx_buf, size_t xfer_bytes); From 61e908e428c79fa576547579bc836ae444e9830a Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 21 Nov 2023 16:33:26 +0700 Subject: [PATCH 2/3] 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 From 2ca4b908bccf686f6eb2845949dd83ea9e342c36 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 21 Nov 2023 16:58:54 +0700 Subject: [PATCH 3/3] fix build with esp32s2,s3 --- src/arduino/Adafruit_USBH_Host.cpp | 1 - src/arduino/ports/esp32/tusb_config_esp32.h | 8 -------- src/tusb_config.h | 6 ++++++ 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/arduino/Adafruit_USBH_Host.cpp b/src/arduino/Adafruit_USBH_Host.cpp index b5bbef91..094345ef 100644 --- a/src/arduino/Adafruit_USBH_Host.cpp +++ b/src/arduino/Adafruit_USBH_Host.cpp @@ -27,7 +27,6 @@ #include "arduino/ports/esp32/tusb_config_esp32.h" #include "driver/gpio.h" #include -#define MSBFIRST SPI_MSBFIRST #endif #include "tusb_option.h" diff --git a/src/arduino/ports/esp32/tusb_config_esp32.h b/src/arduino/ports/esp32/tusb_config_esp32.h index c719cdc5..2fcd23f6 100644 --- a/src/arduino/ports/esp32/tusb_config_esp32.h +++ b/src/arduino/ports/esp32/tusb_config_esp32.h @@ -63,14 +63,6 @@ extern "C" { // 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 6630bbea..38b15d1b 100644 --- a/src/tusb_config.h +++ b/src/tusb_config.h @@ -42,9 +42,15 @@ // 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 "sdkconfig.h" #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 #include "../../arduino_tinyusb/include/tusb_config.h" #else + #define CFG_TUSB_OS OPT_OS_FREERTOS + // clang-format off + #define CFG_TUSB_OS_INC_PATH freertos/ + // clang-format on + #include "arduino/ports/esp32/tusb_config_esp32.h" #endif