adafruit / Adafruit_TinyUSB_Arduino

Arduino library for TinyUSB
MIT License
469 stars 122 forks source link

Fix compile error for missing "USB" definition #202

Closed maxgerhardt closed 2 years ago

maxgerhardt commented 2 years ago

Trying to use this library (master version) with the Arduino-ESP32 2.0.4 stable core release gives

.pio/libdeps/esp32-s3-devkitc-1/Adafruit TinyUSB Library/src/arduino/webusb/Adafruit_USBD_WebUSB.cpp: In constructor 'Adafruit_USBD_WebUSB::Adafruit_USBD_WebUSB(const void*)':
.pio/libdeps/esp32-s3-devkitc-1/Adafruit TinyUSB Library/src/arduino/webusb/Adafruit_USBD_WebUSB.cpp:151:3: error: 'USB' was not declared in this scope
   USB.usbVersion(0x0210);
   ^~~

Because the extern ESPUSB USB; is only in USB.h which doesn't get auto-included by Arduino.h, an explicit #include "USB.h" should be made.

Test project: Use https://github.com/maxgerhardt/pio-esp32s3-tinyusb but in the platformio.ini, instead of the link to my fork, use the main repo, and it will error out.

Sidenote: HardwareSerial.h configurably includes USB.h, but only #if ARDUINO_USB_CDC_ON_BOOT (source), so inclusion is not always guaranteed in all configurations.

Also adds an ESP32S3 board to the CI.

jhsa commented 2 years ago

I also had this error on ESP32 S3. It would not compile on the Arduino IDE. Adafruit TinyUSB Library/src/arduino/webusb/Adafruit_USBD_WebUSB.cpp:151:3: error: 'USB' was not declared in this scope Adding "USB.h"to Adafruit_USBD_WebUSB.cpp apparently fixed the issue.

jhsa commented 2 years ago

Something I forgot to mention, Arduino did compile for the ESP32_S2 without that line of code added. After adding "USB.h" it still compiles for the S2, so, all good I guess. Thanks a lot for all.

hathach commented 2 years ago

oh, I see it is probably inconsistent include path for S2, S3. All good

jhsa commented 2 years ago

oh, I see it is probably inconsistent include path for S2, S3. All good

Thank you for all.