From d1708bc87f1f0a9c22910f25cad7c849fabd8289 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 13 Jun 2024 11:31:12 +0700 Subject: [PATCH] move menu check to TinyUSB_API --- src/Adafruit_TinyUSB.h | 7 ------- src/arduino/Adafruit_TinyUSB_API.h | 17 ++++++++++++++--- src/arduino/Adafruit_USBD_CDC.h | 6 ++++-- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/Adafruit_TinyUSB.h b/src/Adafruit_TinyUSB.h index bb836b3b..7c3f5dcc 100644 --- a/src/Adafruit_TinyUSB.h +++ b/src/Adafruit_TinyUSB.h @@ -25,13 +25,6 @@ #ifndef ADAFRUIT_TINYUSB_H_ #define ADAFRUIT_TINYUSB_H_ -// Error message for Core that must select TinyUSB via menu -#if !defined(USE_TINYUSB) && \ - (defined(ARDUINO_ARCH_SAMD) || \ - (defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED))) -#error TinyUSB is not selected, please select it in "Tools->Menu->USB Stack" -#endif - // ESP32 out-of-sync #ifdef ARDUINO_ARCH_ESP32 #include "arduino/ports/esp32/tusb_config_esp32.h" diff --git a/src/arduino/Adafruit_TinyUSB_API.h b/src/arduino/Adafruit_TinyUSB_API.h index 92ebbd16..aa7b617b 100644 --- a/src/arduino/Adafruit_TinyUSB_API.h +++ b/src/arduino/Adafruit_TinyUSB_API.h @@ -32,13 +32,24 @@ // TinyUSB_API, USBD_CDC, USBD_Device, USBD_Interface, #define TINYUSB_API_VERSION 30000 +#if defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_NRF52_ADAFRUIT) || \ + defined(ARDUINO_ARCH_ESP32) || \ + (defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED)) +#define TINYUSB_HAS_BUITLTIN_CORE_SUPPORT +#endif + // Core that has built-in support: Adafruit SAMD, Adafruit nRF, rp2040, esp32 -#if !(defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_NRF52_ADAFRUIT) || \ - defined(ARDUINO_ARCH_ESP32) || \ - (defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED))) +#if !defined(TINYUSB_HAS_BUITLTIN_CORE_SUPPORT) #define TINYUSB_NEED_POLLING_TASK #endif +// Error message for Core that must select TinyUSB via menu (built-in except +// esp32) +#if !defined(USE_TINYUSB) && (defined(TINYUSB_HAS_BUITLTIN_CORE_SUPPORT) && \ + !defined(ARDUINO_ARCH_ESP32)) +#error TinyUSB is not selected, please select it in "Tools->Menu->USB Stack" +#endif + //--------------------------------------------------------------------+ // Core API // Should be called by BSP Core to initialize, process task diff --git a/src/arduino/Adafruit_USBD_CDC.h b/src/arduino/Adafruit_USBD_CDC.h index 027bfe5b..9d115b41 100644 --- a/src/arduino/Adafruit_USBD_CDC.h +++ b/src/arduino/Adafruit_USBD_CDC.h @@ -95,11 +95,13 @@ class Adafruit_USBD_CDC : public Stream, public Adafruit_USBD_Interface { extern Adafruit_USBD_CDC SerialTinyUSB; -// Built-in support "Serial" is used with TinyUSB CDC +// Built-in support "Serial" is assigned to TinyUSB CDC #if defined(USE_TINYUSB) -#define Serial SerialTinyUSB +#define SerialTinyUSB Serial #endif +extern Adafruit_USBD_CDC SerialTinyUSB; + #endif // else of ESP32 #endif // __cplusplus