Skip to content

Serial as a #define #8798

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adds USB Serial Events
  • Loading branch information
SuGlider committed Oct 24, 2023
commit 6e4d4e592232bd09a6d20dc849088ce7aeb0e11c
4 changes: 2 additions & 2 deletions cores/esp32/HWCDC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,9 @@ void HWCDC::setDebugOutput(bool en)
}
}

#if ARDUINO_USB_MODE // Hardware JTAG CDC selected
#if ARDUINO_USB_MODE // Hardware JTAG CDC selected
// USBSerial is always available to be used
HWCDC USBSerial;
HWCDC HWCDCSerial;
#endif

#endif /* SOC_USB_SERIAL_JTAG_SUPPORTED */
12 changes: 5 additions & 7 deletions cores/esp32/HWCDC.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,12 @@ class HWCDC: public Stream
uint32_t baudRate(){return 115200;}

};

#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
#if ARDUINO_USB_MODE // Hardware JTAG CDC selected
#ifndef HWCDC_SERIAL_IS_DEFINED
#define HWCDC_SERIAL_IS_DEFINED 1
#endif
// USBSerial is always available to be used
extern HWCDC USBSerial;
// HWCDCSerial is always available to be used
extern HWCDC HWCDCSerial;
#endif

#endif /* SOC_USB_SERIAL_JTAG_SUPPORTED */
21 changes: 19 additions & 2 deletions cores/esp32/HardwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,27 @@ HardwareSerial Serial1(1);
HardwareSerial Serial2(2);
#endif

#if HWCDC_SERIAL_IS_DEFINED == 1 // Hardware JTAG CDC Event
extern void HWCDCSerialEvent (void)__attribute__((weak));
void HWCDCSerialEvent(void) {}
#endif

#if USB_SERIAL_IS_DEFINED == 1 // Native USB CDC Event
// Used by Hardware Serial for USB CDC events
extern void USBSerialEvent (void)__attribute__((weak));
void USBSerialEvent(void) {}
#endif

void serialEventRun(void)
{
// Serial is always defined as something (UART0 or USBSerial)
if(Serial.available()) serialEvent();
#if HWCDC_SERIAL_IS_DEFINED == 1 // Hardware JTAG CDC Event
if(HWCDCSerial.available()) HWCDCSerialEvent();
#endif
#if USB_SERIAL_IS_DEFINED == 1 // Native USB CDC Event
if(USBSerial.available()) USBSerialEvent();
#endif
// UART0 is default serialEvent()
if(Serial0.available()) serialEvent();
#if SOC_UART_NUM > 1
if(Serial1.available()) serialEvent1();
#endif
Expand Down
16 changes: 11 additions & 5 deletions cores/esp32/HardwareSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,20 +241,26 @@ 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_CDC_ON_BOOT //Serial used from Native_USB_CDC | HW_CDC_JTAG
#if ARDUINO_USB_MODE // Hardware CDC mode
// Arduino Serial is the HW JTAG CDC device
#define Serial HWCDCSerial
#else // !ARDUINO_USB_MODE -- Native USB Mode
// Arduino Serial is the Native USB CDC device
#define Serial USBSerial
#endif // ARDUINO_USB_MODE
#else // !ARDUINO_USB_CDC_ON_BOOT -- Serial is used from UART0
// if not using CDC on Boot, Arduino Serial is the UART0 device
#define Serial Serial0
#endif

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

#if SOC_UART_NUM > 1
extern HardwareSerial Serial1;
#endif
#if SOC_UART_NUM > 2
extern HardwareSerial Serial2;
#endif
#endif
#endif //!defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL)

#endif // HardwareSerial_h
8 changes: 4 additions & 4 deletions cores/esp32/USBCDC.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ class USBCDC: public Stream
};

#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
#ifndef USB_SERIAL_IS_DEFINED
#define USB_SERIAL_IS_DEFINED 1
#endif
// USBSerial is always available to be used
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the whole #if ARDUINO_USB_CDC_ON_BOOT block should be in HardwareSerial.h. Same goes for HWCDC.h.

#if !ARDUINO_USB_MODE        // Native USB CDC selected
extern USBCDC USBSerial;
#endif

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

extern USBCDC USBSerial;
#endif


#endif /* CONFIG_TINYUSB_CDC_ENABLED */
#endif /* SOC_USB_OTG_SUPPORTED */