From f5ad52fe7f5d266e25a2a90235e5650172942015 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 13 Jun 2024 11:46:13 +0700 Subject: [PATCH] more update for ch32 --- examples/CDC/serial_echo/serial_echo.ino | 1 + src/arduino/Adafruit_TinyUSB_API.h | 2 +- src/arduino/Adafruit_USBD_CDC.h | 3 ++- src/arduino/Adafruit_USBD_Interface.h | 2 +- src/arduino/ports/ch32/tusb_config_ch32.h | 1 - src/tusb_config.h | 2 +- 6 files changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/CDC/serial_echo/serial_echo.ino b/examples/CDC/serial_echo/serial_echo.ino index fb611c80..0d480892 100644 --- a/examples/CDC/serial_echo/serial_echo.ino +++ b/examples/CDC/serial_echo/serial_echo.ino @@ -13,6 +13,7 @@ /* This sketch demonstrates USB CDC Serial echo (convert to upper case) using SerialTinyUSB which * is available for both core with built-in USB support and without. + * Note: on core with built-in support Serial is alias to SerialTinyUSB */ void setup() { diff --git a/src/arduino/Adafruit_TinyUSB_API.h b/src/arduino/Adafruit_TinyUSB_API.h index aa7b617b..77826a69 100644 --- a/src/arduino/Adafruit_TinyUSB_API.h +++ b/src/arduino/Adafruit_TinyUSB_API.h @@ -33,7 +33,7 @@ #define TINYUSB_API_VERSION 30000 #if defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_NRF52_ADAFRUIT) || \ - defined(ARDUINO_ARCH_ESP32) || \ + defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_CH32) || \ (defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED)) #define TINYUSB_HAS_BUITLTIN_CORE_SUPPORT #endif diff --git a/src/arduino/Adafruit_USBD_CDC.h b/src/arduino/Adafruit_USBD_CDC.h index 9d115b41..9c0952f3 100644 --- a/src/arduino/Adafruit_USBD_CDC.h +++ b/src/arduino/Adafruit_USBD_CDC.h @@ -96,7 +96,8 @@ class Adafruit_USBD_CDC : public Stream, public Adafruit_USBD_Interface { extern Adafruit_USBD_CDC SerialTinyUSB; // Built-in support "Serial" is assigned to TinyUSB CDC -#if defined(USE_TINYUSB) +// CH32 defines Serial as alias in WSerial.h +#if defined(USE_TINYUSB) && !defined(ARDUINO_ARCH_CH32) #define SerialTinyUSB Serial #endif diff --git a/src/arduino/Adafruit_USBD_Interface.h b/src/arduino/Adafruit_USBD_Interface.h index 3527516c..8457f69d 100644 --- a/src/arduino/Adafruit_USBD_Interface.h +++ b/src/arduino/Adafruit_USBD_Interface.h @@ -28,7 +28,7 @@ #include #include -#if defined(CH32V20x) || defined(CH32V30x) +#if defined(ARDUINO_ARCH_CH32) || defined(CH32V20x) || defined(CH32V30x) // HACK: required for ch32 core version 1.0.4 or prior, removed when 1.0.5 is // released extern "C" void yield(void); diff --git a/src/arduino/ports/ch32/tusb_config_ch32.h b/src/arduino/ports/ch32/tusb_config_ch32.h index 0235e1cf..a0ae7c49 100644 --- a/src/arduino/ports/ch32/tusb_config_ch32.h +++ b/src/arduino/ports/ch32/tusb_config_ch32.h @@ -34,7 +34,6 @@ extern "C" { //-------------------------------------------------------------------- #if defined(CH32V20x) #define CFG_TUSB_MCU OPT_MCU_CH32V20X -#define CFG_TUD_WCH_USBIP_FSDEV 1 // use USBD #elif defined(CH32V30x) #define CFG_TUSB_MCU OPT_MCU_CH32V307 #endif diff --git a/src/tusb_config.h b/src/tusb_config.h index 51099a98..c2e0702b 100644 --- a/src/tusb_config.h +++ b/src/tusb_config.h @@ -51,7 +51,7 @@ // Note: For platformio prioritize this file over the one in BSP in all cases -#elif defined(CH32V20x) || defined(CH32V30x) // using build.series +#elif defined(ARDUINO_ARCH_CH32) || defined(CH32V20x) || defined(CH32V30x) #include "arduino/ports/ch32/tusb_config_ch32.h" #else #error TinyUSB Arduino Library does not support your core yet