Skip to content

Commit

Permalink
Serial as a #define
Browse files Browse the repository at this point in the history
  • Loading branch information
SuGlider committed Oct 23, 2023
1 parent d25f9cc commit fa6fb2f
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 30 deletions.
7 changes: 2 additions & 5 deletions cores/esp32/HWCDC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,12 +436,9 @@ void HWCDC::setDebugOutput(bool en)
}
}

#if ARDUINO_USB_MODE
#if ARDUINO_USB_CDC_ON_BOOT//Serial used for USB CDC
HWCDC Serial;
#else
#if ARDUINO_USB_MODE // Hardware JTAG CDC selected
// USBSerial is always available to used
HWCDC USBSerial;
#endif
#endif

#endif /* SOC_USB_SERIAL_JTAG_SUPPORTED */
13 changes: 7 additions & 6 deletions cores/esp32/HWCDC.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,13 @@ class HWCDC: public Stream

};

#if ARDUINO_USB_MODE
#if ARDUINO_USB_CDC_ON_BOOT//Serial used for USB CDC
extern HWCDC Serial;
#else
extern HWCDC USBSerial;
#if ARDUINO_USB_MODE // Hardware JTAG CDC selected
#if ARDUINO_USB_CDC_ON_BOOT //Serial used for USB CDC
// When using CDC on Boot, Arduino Serial is the USB device
#define Serial USBSerial
#endif
// USBSerial is always available to used
extern HWCDC USBSerial;
#endif

#endif /* CONFIG_IDF_TARGET_ESP32C3 */
#endif /* SOC_USB_SERIAL_JTAG_SUPPORTED */
10 changes: 2 additions & 8 deletions cores/esp32/HardwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,8 @@ void serialEvent2(void) {}
#endif /* SOC_UART_NUM > 2 */

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL)
#if ARDUINO_USB_CDC_ON_BOOT //Serial used for USB CDC
// There is always Seria0 for UART0
HardwareSerial Serial0(0);
#else
HardwareSerial Serial(0);
#endif
#if SOC_UART_NUM > 1
HardwareSerial Serial1(1);
#endif
Expand All @@ -127,11 +124,8 @@ HardwareSerial Serial2(2);

void serialEventRun(void)
{
#if ARDUINO_USB_CDC_ON_BOOT //Serial used for USB CDC
if(Serial0.available()) serialEvent();
#else
// Serial is always defined as something (UART0 or USBSerial)
if(Serial.available()) serialEvent();
#endif
#if SOC_UART_NUM > 1
if(Serial1.available()) serialEvent1();
#endif
Expand Down
14 changes: 7 additions & 7 deletions cores/esp32/HardwareSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "esp32-hal.h"
#include "soc/soc_caps.h"
#include "HWCDC.h"
#include "USBCDC.h"

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
Expand Down Expand Up @@ -240,15 +241,14 @@ extern void serialEventRun(void) __attribute__((weak));
#ifndef ARDUINO_USB_CDC_ON_BOOT
#define ARDUINO_USB_CDC_ON_BOOT 0
#endif
#if ARDUINO_USB_CDC_ON_BOOT //Serial used for USB CDC
#if !ARDUINO_USB_MODE
#include "USB.h"
#include "USBCDC.h"
#if !ARDUINO_USB_CDC_ON_BOOT //Serial used for USB CDC
// if not using CDC on Boot, Arduino Serial is the UART0 device
#define Serial Serial0
#endif

// There is always Seria0 for UART0
extern HardwareSerial Serial0;
#else
extern HardwareSerial Serial;
#endif

#if SOC_UART_NUM > 1
extern HardwareSerial Serial1;
#endif
Expand Down
5 changes: 3 additions & 2 deletions cores/esp32/USBCDC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,9 @@ USBCDC::operator bool() const
return connected;
}

#if ARDUINO_USB_CDC_ON_BOOT && !ARDUINO_USB_MODE //Serial used for USB CDC
USBCDC Serial(0);
#if !ARDUINO_USB_MODE // Native USB CDC selected
// USBSerial is always available to used
USBCDC USBSerial;
#endif

#endif /* CONFIG_TINYUSB_CDC_ENABLED */
Expand Down
9 changes: 7 additions & 2 deletions cores/esp32/USBCDC.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,13 @@ class USBCDC: public Stream

};

#if ARDUINO_USB_CDC_ON_BOOT && !ARDUINO_USB_MODE //Serial used for USB CDC
extern USBCDC Serial;
#if !ARDUINO_USB_MODE // Native USB CDC selected
#if ARDUINO_USB_CDC_ON_BOOT //Serial used for USB CDC
// When using CDC on Boot, Arduino Serial is the USB device
#define Serial USBSerial
#endif
// USBSerial is always available to used
extern USBCDC USBSerial;
#endif

#endif /* CONFIG_TINYUSB_CDC_ENABLED */
Expand Down

0 comments on commit fa6fb2f

Please sign in to comment.