From 8a3d615d43cdc74f604d472f6f39a47cb452379e Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Sun, 6 Oct 2024 23:24:22 -0300 Subject: [PATCH] feat(uart): eliminates nonexistent functions loop() calls Serial Events functions when those are declared. The way it was declared was forcing to alway call avalable() to then call an empty function. This commit fixes it. --- cores/esp32/HardwareSerial.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/cores/esp32/HardwareSerial.cpp b/cores/esp32/HardwareSerial.cpp index 2e1f2701e9a..c82cbb43d3b 100644 --- a/cores/esp32/HardwareSerial.cpp +++ b/cores/esp32/HardwareSerial.cpp @@ -24,16 +24,13 @@ #endif void serialEvent(void) __attribute__((weak)); -void serialEvent(void) {} #if SOC_UART_NUM > 1 void serialEvent1(void) __attribute__((weak)); -void serialEvent1(void) {} #endif /* SOC_UART_NUM > 1 */ #if SOC_UART_NUM > 2 void serialEvent2(void) __attribute__((weak)); -void serialEvent2(void) {} #endif /* SOC_UART_NUM > 2 */ #if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL) @@ -48,37 +45,35 @@ HardwareSerial Serial2(2); #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) { #if HWCDC_SERIAL_IS_DEFINED == 1 // Hardware JTAG CDC Event - if (HWCDCSerial.available()) { + if (HWCDCSerialEvent && HWCDCSerial.available()) { HWCDCSerialEvent(); } #endif #if USB_SERIAL_IS_DEFINED == 1 // Native USB CDC Event - if (USBSerial.available()) { + if (USBSerialEvent && USBSerial.available()) { USBSerialEvent(); } #endif // UART0 is default serialEvent() - if (Serial0.available()) { + if (serialEvent && Serial0.available()) { serialEvent(); } #if SOC_UART_NUM > 1 - if (Serial1.available()) { + if (serialEvent1 && Serial1.available()) { serialEvent1(); } #endif #if SOC_UART_NUM > 2 - if (Serial2.available()) { + if (serialEvent2 && Serial2.available()) { serialEvent2(); } #endif