Skip to content

Commit

Permalink
add support for running tinyusb + max3421 on no OTG MCU such as esp32
Browse files Browse the repository at this point in the history
  • Loading branch information
hathach committed Nov 21, 2023
1 parent f3e0ff7 commit 61e908e
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 5 deletions.
2 changes: 2 additions & 0 deletions examples/DualRole/CDC/serial_host_bridge/usbh_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions examples/DualRole/HID/hid_device_report/usbh_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions examples/DualRole/HID/hid_mouse_log_filter/usbh_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions examples/DualRole/HID/hid_mouse_tremor_filter/usbh_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions examples/DualRole/HID/hid_remapper/usbh_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions examples/DualRole/MassStorage/msc_data_logger/usbh_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions examples/DualRole/MassStorage/msc_file_explorer/usbh_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions examples/DualRole/Simple/device_info/usbh_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 3 additions & 4 deletions src/arduino/Adafruit_USBH_Host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#ifdef ARDUINO_ARCH_ESP32
#include "arduino/ports/esp32/tusb_config_esp32.h"
#include "driver/gpio.h"
#include <Arduino.h>
#define MSBFIRST SPI_MSBFIRST
#endif

Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/arduino/ports/esp32/tusb_config_esp32.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/tusb_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 61e908e

Please sign in to comment.