Skip to content

Commit 7b22bd0

Browse files
authored
Merge pull request #503 from adafruit/support-esp32p4
support esp32p4
2 parents 8ef3020 + 36396f4 commit 7b22bd0

File tree

19 files changed

+92
-63
lines changed

19 files changed

+92
-63
lines changed

.github/workflows/githubci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ jobs:
5050
# ESP32 ci use dev json
5151
- 'feather_esp32s2'
5252
- 'feather_esp32s3'
53+
- 'esp32p4'
5354
# nRF52
5455
- 'cpb'
5556
- 'nrf52840'

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Following core has TinyUSB as either the primary usb stack or selectable via men
3838
- [adafruit/Adafruit_nRF52_Arduino](https://github.com/adafruit/Adafruit_nRF52_Arduino)
3939
- [adafruit/ArduinoCore-samd](https://github.com/adafruit/ArduinoCore-samd)
4040
- [earlephilhower/arduino-pico](https://github.com/earlephilhower/arduino-pico)
41-
- [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32) additional Tools menu is needed
41+
- [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
4242
- `USB Mode=USB-OTG (TinyUSB)` for S3 and P4
4343
- `USB CDC On Boot=Enabled`, `USB Firmware MSC On Boot=Disabled`, `USB DFU On Boot=Disabled`
4444
- [openwch/arduino_core_ch32](https://github.com/openwch/arduino_core_ch32)

examples/CDC/cdc_multi/.skip.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ feather_esp32s3
33
funhouse
44
magtag
55
metroesp32s2
6+
esp32p4
67
pico_rp2040_tinyusb_host

examples/CDC/cdc_multi/cdc_multi.ino

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,27 @@
2525

2626
#include <Adafruit_TinyUSB.h>
2727

28-
#define LED LED_BUILTIN
29-
3028
// Create 2nd instance of CDC Ports.
3129
#ifdef ARDUINO_ARCH_ESP32
32-
#error "Currently multiple CDCs on ESP32-Sx is not yet supported. An PR to update core/esp32/USBCDC and/or pre-built libusb are needed."
30+
#error "Currently multiple CDCs on ESP32 is not yet supported"
3331
// for ESP32, we need to specify instance number when declaring object
3432
Adafruit_USBD_CDC USBSer1(1);
3533
#else
3634
Adafruit_USBD_CDC USBSer1;
3735
#endif
3836

3937
void setup() {
40-
pinMode(LED, OUTPUT);
38+
#ifdef LED_BUILTIN
39+
pinMode(LED_BUILTIN, OUTPUT);
40+
#endif
4141

4242
Serial.begin(115200);
4343

4444
// check to see if multiple CDCs are enabled
4545
if ( CFG_TUD_CDC < 2 ) {
46-
digitalWrite(LED, HIGH); // LED on for error indicator
46+
#ifdef LED_BUILTIN
47+
digitalWrite(LED_BUILTIN, HIGH); // LED on for error indicator
48+
#endif
4749

4850
while(1) {
4951
Serial.printf("CFG_TUD_CDC must be at least 2, current value is %u\n", CFG_TUD_CDC);
@@ -96,7 +98,9 @@ void loop() {
9698

9799
if (delay_without_delaying(500)) {
98100
LEDstate = !LEDstate;
99-
digitalWrite(LED, LEDstate);
101+
#ifdef LED_BUILTIN
102+
digitalWrite(LED_BUILTIN, LEDstate);
103+
#endif
100104
}
101105
}
102106

examples/CDC/no_serial/no_serial.ino

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@
1818
* Note: this will cause device to loose the touch1200 and require
1919
* user manual interaction to put device into bootloader/DFU mode.
2020
*/
21-
22-
int led = LED_BUILTIN;
23-
24-
void setup()
25-
{
21+
void setup() {
2622
// Manual begin() is required on core without built-in support e.g. mbed rp2040
2723
if (!TinyUSBDevice.isInitialized()) {
2824
TinyUSBDevice.begin(0);
@@ -38,11 +34,12 @@ void setup()
3834
TinyUSBDevice.attach();
3935
}
4036

41-
pinMode(led, OUTPUT);
37+
#ifdef LED_BUILTIN
38+
pinMode(LED_BUILTIN, OUTPUT);
39+
#endif
4240
}
4341

44-
void loop()
45-
{
42+
void loop() {
4643
#ifdef TINYUSB_NEED_POLLING_TASK
4744
// Manual call tud_task since it isn't called by Core's background
4845
TinyUSBDevice.task();
@@ -53,6 +50,8 @@ void loop()
5350
static uint8_t led_state = 0;
5451
if (millis() - ms > 1000) {
5552
ms = millis();
53+
#ifdef LED_BUILTIN
5654
digitalWrite(LED_BUILTIN, 1-led_state);
55+
#endif
5756
}
5857
}

examples/DualRole/MassStorage/msc_data_logger/msc_data_logger.ino

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ void data_log(void) {
7373
}
7474

7575
// Turn on LED when start writing
76+
#ifdef LED_BUILTIN
7677
digitalWrite(LED_BUILTIN, HIGH);
78+
#endif
7779

7880
f_log = fatfs.open(LOG_FILE, O_WRITE | O_APPEND | O_CREAT);
7981

@@ -112,7 +114,9 @@ void usbhost_rtos_task(void *param) {
112114
void setup() {
113115
Serial.begin(115200);
114116

117+
#ifdef LED_BUILTIN
115118
pinMode(LED_BUILTIN, OUTPUT);
119+
#endif
116120

117121
#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
118122
// init host stack on controller (rhport) 1
@@ -172,10 +176,12 @@ bool write_complete_callback(uint8_t dev_addr, tuh_msc_complete_data_t const *cb
172176
(void) dev_addr;
173177
(void) cb_data;
174178

179+
#ifdef LED_BUILTIN
175180
// turn off LED after write is complete
176181
// Note this only marks the usb transfer is complete, device can take longer to actual
177182
// write data to physical flash
178183
digitalWrite(LED_BUILTIN, LOW);
184+
#endif
179185

180186
return true;
181187
}

examples/HID/hid_boot_keyboard/hid_boot_keyboard.ino

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ void setup() {
7474
}
7575

7676
// led pin
77+
#ifdef LED_BUILTIN
7778
pinMode(LED_BUILTIN, OUTPUT);
7879
digitalWrite(LED_BUILTIN, LOW);
80+
#endif
7981

8082
// overwrite input pin with PIN_BUTTONx
8183
#ifdef PIN_BUTTON1
@@ -176,6 +178,8 @@ void hid_report_callback(uint8_t report_id, hid_report_type_t report_type, uint8
176178
// Kana (4) | Compose (3) | ScrollLock (2) | CapsLock (1) | Numlock (0)
177179
uint8_t ledIndicator = buffer[0];
178180

181+
#ifdef LED_BUILTIN
179182
// turn on LED if capslock is set
180183
digitalWrite(LED_BUILTIN, ledIndicator & KEYBOARD_LED_CAPSLOCK);
184+
#endif
181185
}

examples/MIDI/midi_multi_ports/midi_multi_ports.ino

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
Adafruit_USBD_MIDI usb_midi(3);
2121

2222
void setup() {
23+
#ifdef LED_BUILTIN
2324
pinMode(LED_BUILTIN, OUTPUT);
25+
#endif
2426

2527
// Manual begin() is required on core without built-in support e.g. mbed rp2040
2628
if (!TinyUSBDevice.isInitialized()) {
@@ -52,6 +54,8 @@ void loop() {
5254
static uint8_t led_state = 0;
5355
if (millis() - ms > 1000) {
5456
ms = millis();
57+
#ifdef LED_BUILTIN
5558
digitalWrite(LED_BUILTIN, 1-led_state);
59+
#endif
5660
}
5761
}

examples/MIDI/midi_test/midi_test.ino

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ void setup() {
4444

4545
Serial.begin(115200);
4646

47-
pinMode(LED_BUILTIN, OUTPUT);
48-
4947
usb_midi.setStringDescriptor("TinyUSB MIDI");
5048

5149
// Initialize MIDI, and listen to all MIDI channels

examples/MassStorage/msc_external_flash/msc_external_flash.ino

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ bool fs_formatted = false;
4848
bool fs_changed = true;;
4949

5050
// the setup function runs once when you press reset or power the board
51-
void setup()
52-
{
51+
void setup() {
52+
#ifdef LED_BUILTIN
5353
pinMode(LED_BUILTIN, OUTPUT);
54+
#endif
5455

5556
Serial.begin(115200);
5657

@@ -150,7 +151,9 @@ int32_t msc_read_cb (uint32_t lba, void* buffer, uint32_t bufsize) {
150151
// Process data in buffer to disk's storage and
151152
// return number of written bytes (must be multiple of block size)
152153
int32_t msc_write_cb (uint32_t lba, uint8_t* buffer, uint32_t bufsize) {
154+
#ifdef LED_BUILTIN
153155
digitalWrite(LED_BUILTIN, HIGH);
156+
#endif
154157

155158
// Note: SPIFLash Block API: readBlocks/writeBlocks/syncBlocks
156159
// already include 4K sector caching internally. We don't need to cache it, yahhhh!!
@@ -168,5 +171,7 @@ void msc_flush_cb (void) {
168171

169172
fs_changed = true;
170173

174+
#ifdef LED_BUILTIN
171175
digitalWrite(LED_BUILTIN, LOW);
176+
#endif
172177
}

0 commit comments

Comments
 (0)