Skip to content

Commit 94f7ac2

Browse files
committed
[Generic Serial] Add SerialUSB
If USB CDC is enabled then the generic "Serial" used will be SerialUSB else this is the HardwareSerial if one is defined. If Serial is defined before (build_opt.h, variant.h) then this is the one used. ISO for generic "serialEvent". Signed-off-by: Frederic.Pillon <[email protected]>
1 parent 9a234ee commit 94f7ac2

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

cores/arduino/USBSerial.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ extern __IO uint32_t UserRxBufPtrIn;
3737
extern __IO uint32_t UserRxBufPtrOut;
3838

3939
USBSerial SerialUSB;
40+
void serialEventUSB() __attribute__((weak));
4041

4142
void USBSerial::begin(uint32_t /* baud_count */) {
4243
// uart config is ignored in USB-CDC

cores/arduino/WSerial.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,8 @@ void serialEventRun(void)
3535
#if defined(HAVE_HWSERIALLP1)
3636
if (serialEventLP1 && SerialLP1.available()) serialEventLP1();
3737
#endif
38+
#if defined(HAVE_SERIALUSB)
39+
if (serialEventUSB && SerialUSB.available()) serialEventUSB();
40+
#endif
3841
}
3942

cores/arduino/WSerial.h

+19-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,25 @@
33

44
#include "variant.h"
55
#include "HardwareSerial.h"
6+
#include "USBSerial.h"
67

7-
#if defined(HAL_UART_MODULE_ENABLED)
8+
#if defined (USBCON) && defined(USBD_USE_CDC)
9+
#ifndef DISABLE_GENERIC_SERIALUSB
10+
#define ENABLE_SERIALUSB
11+
#if !defined(Serial)
12+
#define Serial SerialUSB
13+
#define serialEvent serialEventUSB
14+
#endif
15+
#endif
16+
17+
#if defined(ENABLE_SERIALUSB)
18+
#define HAVE_SERIALUSB
19+
#endif
20+
21+
extern void serialEventUSB(void) __attribute__((weak));
22+
#endif /* USBCON && USBD_USE_CDC */
823

24+
#if defined(HAL_UART_MODULE_ENABLED)
925
#if !defined(HWSERIAL_NONE) && defined(SERIAL_UART_INSTANCE)
1026
#if SERIAL_UART_INSTANCE == 0
1127
#define ENABLE_HWSERIALLP1
@@ -147,8 +163,8 @@ extern void serialEvent8(void) __attribute__((weak));
147163
extern void serialEvent9(void) __attribute__((weak));
148164
extern void serialEvent10(void) __attribute__((weak));
149165
extern void serialEventLP1(void) __attribute__((weak));
150-
151166
#endif /* HAL_UART_MODULE_ENABLED */
167+
152168
extern void serialEventRun(void) __attribute__((weak));
153169

154-
#endif // WIRING_SERIAL_H
170+
#endif /* WIRING_SERIAL_H */

cores/arduino/wiring.h

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242

4343
#ifdef __cplusplus
4444
#include "Tone.h"
45-
#include "USBSerial.h"
4645
#include "WCharacter.h"
4746
#include "WSerial.h"
4847
#include "WMath.h"

0 commit comments

Comments
 (0)