From 25972bffbb8cecdb0c3164b54bf8f197346c970e Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Mon, 14 Oct 2024 14:23:25 +0200 Subject: [PATCH] USB support only when tiny USB enabled --- CMakeLists.txt | 39 +++++++++++++++++++++--------------- cores/esp32/FirmwareMSC.h | 2 ++ cores/esp32/HWCDC.cpp | 2 ++ cores/esp32/HardwareSerial.h | 2 ++ 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c8c719a2491..4838c32df64 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,8 +41,7 @@ set(CORE_SRCS cores/esp32/esp32-hal-sigmadelta.c cores/esp32/esp32-hal-spi.c cores/esp32/esp32-hal-time.c - cores/esp32/esp32-hal-timer.c - cores/esp32/esp32-hal-tinyusb.c + cores/esp32/esp32-hal-timer.c cores/esp32/esp32-hal-touch.c cores/esp32/esp32-hal-uart.c cores/esp32/esp32-hal-rmt.c @@ -63,9 +62,6 @@ set(CORE_SRCS cores/esp32/StreamString.cpp cores/esp32/Tone.cpp cores/esp32/HWCDC.cpp - cores/esp32/USB.cpp - cores/esp32/USBCDC.cpp - cores/esp32/USBMSC.cpp cores/esp32/FirmwareMSC.cpp cores/esp32/firmware_msc_fat.c cores/esp32/wiring_pulse.c @@ -73,6 +69,13 @@ set(CORE_SRCS cores/esp32/WMath.cpp cores/esp32/WString.cpp ) +if(IDF_TARGET MATCHES "esp32s2|esp32s3|esp32p4" AND CONFIG_TINYUSB_ENABLED) + list(APPEND CORE_SRCS + cores/esp32/esp32-hal-tinyusb.c + cores/esp32/USB.cpp + cores/esp32/USBCDC.cpp + cores/esp32/USBMSC.cpp) +endif() set(ARDUINO_ALL_LIBRARIES ArduinoOTA @@ -95,11 +98,13 @@ set(ARDUINO_ALL_LIBRARIES SPI Ticker Update - USB WebServer WiFi Wire ) +if(IDF_TARGET MATCHES "esp32s2|esp32s3|esp32p4" AND CONFIG_TINYUSB_ENABLED) + list(APPEND ARDUINO_ALL_LIBRARIES USB) +endif() set(ARDUINO_LIBRARY_ArduinoOTA_SRCS libraries/ArduinoOTA/src/ArduinoOTA.cpp) set(ARDUINO_LIBRARY_ArduinoOTA_REQUIRES esp_https_ota) @@ -149,16 +154,18 @@ set(ARDUINO_LIBRARY_Update_SRCS libraries/Update/src/Updater.cpp libraries/Update/src/HttpsOTAUpdate.cpp) -set(ARDUINO_LIBRARY_USB_SRCS - libraries/USB/src/USBHID.cpp - libraries/USB/src/USBMIDI.cpp - libraries/USB/src/USBHIDMouse.cpp - libraries/USB/src/USBHIDKeyboard.cpp - libraries/USB/src/USBHIDGamepad.cpp - libraries/USB/src/USBHIDConsumerControl.cpp - libraries/USB/src/USBHIDSystemControl.cpp - libraries/USB/src/USBHIDVendor.cpp - libraries/USB/src/USBVendor.cpp) +if(IDF_TARGET MATCHES "esp32s2|esp32s3|esp32p4" AND CONFIG_TINYUSB_ENABLED) + set(ARDUINO_LIBRARY_USB_SRCS + libraries/USB/src/USBHID.cpp + libraries/USB/src/USBMIDI.cpp + libraries/USB/src/USBHIDMouse.cpp + libraries/USB/src/USBHIDKeyboard.cpp + libraries/USB/src/USBHIDGamepad.cpp + libraries/USB/src/USBHIDConsumerControl.cpp + libraries/USB/src/USBHIDSystemControl.cpp + libraries/USB/src/USBHIDVendor.cpp + libraries/USB/src/USBVendor.cpp) +endif() set(ARDUINO_LIBRARY_WebServer_SRCS libraries/WebServer/src/WebServer.cpp diff --git a/cores/esp32/FirmwareMSC.h b/cores/esp32/FirmwareMSC.h index 3eaa184bcd6..cc428bc69b8 100644 --- a/cores/esp32/FirmwareMSC.h +++ b/cores/esp32/FirmwareMSC.h @@ -14,7 +14,9 @@ #pragma once #include +#if defined __has_include && __has_include("USBMSC.h") #include "USBMSC.h" +#endif #if CONFIG_TINYUSB_MSC_ENABLED diff --git a/cores/esp32/HWCDC.cpp b/cores/esp32/HWCDC.cpp index 170e323a035..f0411f1d171 100644 --- a/cores/esp32/HWCDC.cpp +++ b/cores/esp32/HWCDC.cpp @@ -11,7 +11,9 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +#if defined __has_include && __has_include("USB.h") #include "USB.h" +#endif #if SOC_USB_SERIAL_JTAG_SUPPORTED #include "esp32-hal.h" diff --git a/cores/esp32/HardwareSerial.h b/cores/esp32/HardwareSerial.h index 8eb7f2c91a6..66fe3517d0a 100644 --- a/cores/esp32/HardwareSerial.h +++ b/cores/esp32/HardwareSerial.h @@ -51,7 +51,9 @@ #include "esp32-hal.h" #include "soc/soc_caps.h" #include "HWCDC.h" +#if defined __has_include && __has_include("USBCDC.h") #include "USBCDC.h" +#endif #include "freertos/FreeRTOS.h" #include "freertos/task.h"