Skip to content

Commit

Permalink
support esp32p4
Browse files Browse the repository at this point in the history
  • Loading branch information
hathach committed Mar 7, 2025
1 parent 8ef3020 commit 7f7ac74
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 31 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/githubci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
# ESP32 ci use dev json
- 'feather_esp32s2'
- 'feather_esp32s3'
- 'esp32p4'
# nRF52
- 'cpb'
- 'nrf52840'
Expand All @@ -69,6 +70,7 @@ jobs:
uses: actions/checkout@v4
with:
repository: adafruit/ci-arduino
ref: add-esp32p4
path: ci

- name: pre-install
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Following core has TinyUSB as either the primary usb stack or selectable via men
- [adafruit/Adafruit_nRF52_Arduino](https://github.com/adafruit/Adafruit_nRF52_Arduino)
- [adafruit/ArduinoCore-samd](https://github.com/adafruit/ArduinoCore-samd)
- [earlephilhower/arduino-pico](https://github.com/earlephilhower/arduino-pico)
- [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32) additional Tools menu is needed
- [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32) Host mode using MAX3421E controller should work with all chips. Device mode only support S2/S3/P4 and additional Tools menu are needed
- `USB Mode=USB-OTG (TinyUSB)` for S3 and P4
- `USB CDC On Boot=Enabled`, `USB Firmware MSC On Boot=Disabled`, `USB DFU On Boot=Disabled`
- [openwch/arduino_core_ch32](https://github.com/openwch/arduino_core_ch32)
Expand Down
2 changes: 0 additions & 2 deletions examples/MIDI/midi_test/midi_test.ino
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ void setup() {

Serial.begin(115200);

pinMode(LED_BUILTIN, OUTPUT);

usb_midi.setStringDescriptor("TinyUSB MIDI");

// Initialize MIDI, and listen to all MIDI channels
Expand Down
8 changes: 4 additions & 4 deletions src/arduino/Adafruit_USBD_CDC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
#define TINYUSB_API_VERSION 0
#endif

#define BULK_PACKET_SIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)

// SerialTinyUSB can be macro expanding to "Serial" on supported cores
Adafruit_USBD_CDC SerialTinyUSB;

Expand Down Expand Up @@ -71,8 +69,10 @@ uint16_t Adafruit_USBD_CDC::getInterfaceDescriptor(uint8_t itfnum_deprecated,
uint8_t _strid = 0;
#endif

uint8_t const desc[] = {TUD_CDC_DESCRIPTOR(itfnum, _strid, ep_notif, 8,
ep_out, ep_in, BULK_PACKET_SIZE)};
uint16_t const mps =
(TUD_OPT_HIGH_SPEED ? 512 : 64); // TODO actual link speed
uint8_t const desc[] = {
TUD_CDC_DESCRIPTOR(itfnum, _strid, ep_notif, 8, ep_out, ep_in, mps)};

uint16_t const len = sizeof(desc);

Expand Down
16 changes: 3 additions & 13 deletions src/arduino/Adafruit_USBD_Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,6 @@ void Adafruit_USBD_Device::task(void) {
#endif
}

bool Adafruit_USBD_Device::mounted(void) { return tud_mounted(); }

bool Adafruit_USBD_Device::suspended(void) { return tud_suspended(); }

bool Adafruit_USBD_Device::ready(void) { return tud_ready(); }

bool Adafruit_USBD_Device::remoteWakeup(void) { return tud_remote_wakeup(); }

bool Adafruit_USBD_Device::detach(void) { return tud_disconnect(); }

bool Adafruit_USBD_Device::attach(void) { return tud_connect(); }

void Adafruit_USBD_Device::clearConfiguration(void) {
tusb_desc_device_t const desc_dev = {.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
Expand Down Expand Up @@ -257,8 +245,10 @@ bool Adafruit_USBD_Device::begin(uint8_t rhport) {
// follow USBCDC cdc descriptor
uint8_t itfnum = allocInterface(2);
uint8_t strid = addStringDescriptor("TinyUSB Serial");
uint16_t const mps =
(TUD_OPT_HIGH_SPEED ? 512 : 64); // TODO actual link speed
uint8_t const desc_cdc[TUD_CDC_DESC_LEN] = {
TUD_CDC_DESCRIPTOR(itfnum, strid, 0x85, 64, 0x03, 0x84, 64)};
TUD_CDC_DESCRIPTOR(itfnum, strid, 0x85, 64, 0x03, 0x84, mps)};

memcpy(_desc_cfg + _desc_cfg_len, desc_cdc, sizeof(desc_cdc));
_desc_cfg_len += sizeof(desc_cdc);
Expand Down
13 changes: 7 additions & 6 deletions src/arduino/Adafruit_USBD_Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,15 @@ class Adafruit_USBD_Device {
void task(void);

// physical disable/enable pull-up
bool detach(void);
bool attach(void);
bool detach(void) { return tud_disconnect(); }
bool attach(void) { return tud_connect(); }

//------------- status -------------//
bool mounted(void);
bool suspended(void);
bool ready(void);
bool remoteWakeup(void);
bool mounted(void) { return tud_mounted(); }
bool suspended(void) { return tud_suspended(); }
bool ready(void) { return tud_ready(); }
bool remoteWakeup(void) { return tud_remote_wakeup(); }
tusb_speed_t getSpeed(void) { return tud_speed_get(); }

private:
uint16_t const *descriptor_string_cb(uint8_t index, uint16_t langid);
Expand Down
6 changes: 3 additions & 3 deletions src/arduino/msc/Adafruit_USBD_MSC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

#include "Adafruit_USBD_MSC.h"

#define BULK_PACKET_SIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)

static Adafruit_USBD_MSC *_msc_dev = NULL;

Adafruit_USBD_MSC::Adafruit_USBD_MSC(void) {
Expand All @@ -51,8 +49,10 @@ uint16_t Adafruit_USBD_MSC::getInterfaceDescriptor(uint8_t itfnum_deprecated,
uint8_t const ep_in = TinyUSBDevice.allocEndpoint(TUSB_DIR_IN);
uint8_t const ep_out = TinyUSBDevice.allocEndpoint(TUSB_DIR_OUT);

uint16_t const mps =
(TUD_OPT_HIGH_SPEED ? 512 : 64); // TODO actual link speed
uint8_t const desc[] = {
TUD_MSC_DESCRIPTOR(itfnum, _strid, ep_out, ep_in, BULK_PACKET_SIZE)};
TUD_MSC_DESCRIPTOR(itfnum, _strid, ep_out, ep_in, mps)};
uint16_t const len = sizeof(desc);

if (bufsize < len) {
Expand Down
3 changes: 1 addition & 2 deletions src/arduino/ports/esp32/tusb_config_esp32.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ extern "C" {

#if CONFIG_IDF_TARGET_ESP32P4
#define CFG_TUD_MAX_SPEED OPT_MODE_HIGH_SPEED
#define CFG_TUH_MAX_SPEED OPT_MODE_HIGH_SPEED
#else
#define CFG_TUD_MAX_SPEED OPT_MODE_FULL_SPEED
#define CFG_TUH_MAX_SPEED OPT_MODE_FULL_SPEED
#endif

#ifndef CFG_TUSB_OS
Expand Down Expand Up @@ -141,6 +139,7 @@ extern "C" {
// Enable host stack with MAX3421E (host shield)
#define CFG_TUH_ENABLED 1
#define CFG_TUH_MAX3421 1
#define CFG_TUH_MAX_SPEED OPT_MODE_FULL_SPEED

#ifndef CFG_TUH_MAX3421_ENDPOINT_TOTAL
#define CFG_TUH_MAX3421_ENDPOINT_TOTAL (8 + 4 * (CFG_TUH_DEVICE_MAX - 1))
Expand Down

0 comments on commit 7f7ac74

Please sign in to comment.