Skip to content

Commit d0813ca

Browse files
committed
fix esp32p4 build due to lack of LED_BUILTIN
1 parent cfe6da8 commit d0813ca

File tree

11 files changed

+68
-31
lines changed

11 files changed

+68
-31
lines changed

examples/CDC/cdc_multi/.skip.txt

+1
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

+10-6
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

+7-8
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

+6
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

+4
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

+4
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/MassStorage/msc_external_flash/msc_external_flash.ino

+7-2
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
}

examples/MassStorage/msc_external_flash_sdcard/msc_external_flash_sdcard.ino

+14-8
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ bool flash_changed = false;
6767

6868
// the setup function runs once when you press reset or power the board
6969
void setup() {
70+
#ifdef LED_BUILTIN
7071
pinMode(LED_BUILTIN, OUTPUT);
72+
#endif
7173
Serial.begin(115200);
7274

7375
// MSC with 2 Logical Units: LUN0: External Flash, LUN1: SDCard
@@ -234,11 +236,12 @@ int32_t sdcard_read_cb (uint32_t lba, void* buffer, uint32_t bufsize)
234236
// Callback invoked when received WRITE10 command.
235237
// Process data in buffer to disk's storage and
236238
// return number of written bytes (must be multiple of block size)
237-
int32_t sdcard_write_cb (uint32_t lba, uint8_t* buffer, uint32_t bufsize)
238-
{
239+
int32_t sdcard_write_cb (uint32_t lba, uint8_t* buffer, uint32_t bufsize) {
239240
bool rc;
240241

242+
#ifdef LED_BUILTIN
241243
digitalWrite(LED_BUILTIN, HIGH);
244+
#endif
242245

243246
#if SD_FAT_VERSION >= 20000
244247
rc = sd.card()->writeSectors(lba, buffer, bufsize/512);
@@ -264,7 +267,9 @@ void sdcard_flush_cb (void)
264267

265268
sd_changed = true;
266269

270+
#ifdef LED_BUILTIN
267271
digitalWrite(LED_BUILTIN, LOW);
272+
#endif
268273
}
269274

270275
#ifdef SDCARD_DETECT
@@ -299,8 +304,7 @@ bool sdcard_ready_callback(void)
299304
// Callback invoked when received READ10 command.
300305
// Copy disk's data to buffer (up to bufsize) and
301306
// return number of copied bytes (must be multiple of block size)
302-
int32_t external_flash_read_cb (uint32_t lba, void* buffer, uint32_t bufsize)
303-
{
307+
int32_t external_flash_read_cb (uint32_t lba, void* buffer, uint32_t bufsize) {
304308
// Note: SPIFLash Bock API: readBlocks/writeBlocks/syncBlocks
305309
// already include 4K sector caching internally. We don't need to cache it, yahhhh!!
306310
return flash.readBlocks(lba, (uint8_t*) buffer, bufsize/512) ? bufsize : -1;
@@ -309,9 +313,10 @@ int32_t external_flash_read_cb (uint32_t lba, void* buffer, uint32_t bufsize)
309313
// Callback invoked when received WRITE10 command.
310314
// Process data in buffer to disk's storage and
311315
// return number of written bytes (must be multiple of block size)
312-
int32_t external_flash_write_cb (uint32_t lba, uint8_t* buffer, uint32_t bufsize)
313-
{
316+
int32_t external_flash_write_cb (uint32_t lba, uint8_t* buffer, uint32_t bufsize) {
317+
#ifdef LED_BUILTIN
314318
digitalWrite(LED_BUILTIN, HIGH);
319+
#endif
315320

316321
// Note: SPIFLash Bock API: readBlocks/writeBlocks/syncBlocks
317322
// already include 4K sector caching internally. We don't need to cache it, yahhhh!!
@@ -320,14 +325,15 @@ int32_t external_flash_write_cb (uint32_t lba, uint8_t* buffer, uint32_t bufsize
320325

321326
// Callback invoked when WRITE10 command is completed (status received and accepted by host).
322327
// used to flush any pending cache.
323-
void external_flash_flush_cb (void)
324-
{
328+
void external_flash_flush_cb (void) {
325329
flash.syncBlocks();
326330

327331
// clear file system's cache to force refresh
328332
fatfs.cacheClear();
329333

330334
flash_changed = true;
331335

336+
#ifdef LED_BUILTIN
332337
digitalWrite(LED_BUILTIN, LOW);
338+
#endif
333339
}

examples/MassStorage/msc_sd/.skip.txt

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ feather_esp32s3
33
funhouse
44
magtag
55
metroesp32s2
6+
esp32p4
67
feather_rp2040_tinyusb
78
pico_rp2040_tinyusb_host
89
CH32V20x_EVT

examples/MassStorage/msc_sdfat/msc_sdfat.ino

+7-2
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ Adafruit_USBD_MSC usb_msc;
3232
bool fs_changed;
3333

3434
// the setup function runs once when you press reset or power the board
35-
void setup()
36-
{
35+
void setup() {
3736
Serial.begin(115200);
3837

38+
#ifdef LED_BUILTIN
3939
pinMode(LED_BUILTIN, OUTPUT);
40+
#endif
4041

4142
// Set disk vendor id, product id and revision with string up to 8, 16, 4 characters respectively
4243
usb_msc.setID("Adafruit", "SD Card", "1.0");
@@ -138,7 +139,9 @@ int32_t msc_read_cb (uint32_t lba, void* buffer, uint32_t bufsize) {
138139
int32_t msc_write_cb (uint32_t lba, uint8_t* buffer, uint32_t bufsize) {
139140
bool rc;
140141

142+
#ifdef LED_BUILTIN
141143
digitalWrite(LED_BUILTIN, HIGH);
144+
#endif
142145

143146
#if SD_FAT_VERSION >= 20000
144147
rc = sd.card()->writeSectors(lba, buffer, bufsize/512);
@@ -163,5 +166,7 @@ void msc_flush_cb (void) {
163166

164167
fs_changed = true;
165168

169+
#ifdef LED_BUILTIN
166170
digitalWrite(LED_BUILTIN, LOW);
171+
#endif
167172
}

examples/WebUSB/webusb_serial/webusb_serial.ino

+7-5
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ Adafruit_USBD_WebUSB usb_web;
3434
// Page source can be found at https://github.com/hathach/tinyusb-webusb-page/tree/main/webusb-serial
3535
WEBUSB_URL_DEF(landingPage, 1 /*https*/, "example.tinyusb.org/webusb-serial/index.html");
3636

37-
int led_pin = LED_BUILTIN;
38-
3937
// the setup function runs once when you press reset or power the board
4038
void setup() {
4139
// Manual begin() is required on core without built-in support e.g. mbed rp2040
@@ -44,8 +42,10 @@ void setup() {
4442
}
4543
Serial.begin(115200);
4644

47-
pinMode(led_pin, OUTPUT);
48-
digitalWrite(led_pin, LOW);
45+
#ifdef LED_BUILTIN
46+
pinMode(LED_BUILTIN, OUTPUT);
47+
digitalWrite(LED_BUILTIN, LOW);
48+
#endif
4949

5050
usb_web.setLandingPage(&landingPage);
5151
usb_web.setLineStateCallback(line_state_callback);
@@ -104,7 +104,9 @@ void loop() {
104104
}
105105

106106
void line_state_callback(bool connected) {
107-
digitalWrite(led_pin, connected);
107+
#ifdef LED_BUILTIN
108+
digitalWrite(LED_BUILTIN, connected);
109+
#endif
108110

109111
if (connected) {
110112
usb_web.println("WebUSB interface connected !!");

0 commit comments

Comments
 (0)