From 06e49ccf9b0fd5896be7dee8a0e6704cd4427fdb Mon Sep 17 00:00:00 2001 From: Maxim Prokhorov Date: Tue, 17 Oct 2023 00:26:53 +0300 Subject: [PATCH] uart: swserial workaround for recent Core version fix #2592 (for real this time) --- code/espurna/uart.cpp | 37 +++++++++++++++++++++++++++++------- code/test/build/nondefault.h | 1 + 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/code/espurna/uart.cpp b/code/espurna/uart.cpp index e4238f39..51998b60 100644 --- a/code/espurna/uart.cpp +++ b/code/espurna/uart.cpp @@ -73,6 +73,29 @@ namespace driver { namespace uart { namespace { +namespace types { + +using HardwareConfig = ::SerialConfig; +using HardwareMode = ::SerialMode; + +#if UART_SOFTWARE_SUPPORT +#if defined(ARDUINO_ESP8266_RELEASE_2_7_2) \ + || defined(ARDUINO_ESP8266_RELEASE_2_7_3) \ + || defined(ARDUINO_ESP8266_RELEASE_2_7_4) + || defined(ARDUINO_ESP8266_RELEASE_3_0_0) \ + || defined(ARDUINO_ESP8266_RELEASE_3_0_1) \ + || defined(ARDUINO_ESP8266_RELEASE_3_1_0) \ + || defined(ARDUINO_ESP8266_RELEASE_3_1_1) +using SoftwareConfig = ::SoftwareSerialConfig; +#elif defined(ARDUINO_ESP8266_RELEASE_3_1_2) +using SoftwareConfig = ::EspSoftwareSerial::Config; +#else +using SoftwareConfig = ::EspSoftwareSerial::Config; +#endif +#endif + +} // namespace types + namespace build { // i.e. uart0, uart1 and a single sw port @@ -173,8 +196,8 @@ template constexpr T from_config(Config); template <> -constexpr ::SerialConfig from_config(Config config) { - return static_cast<::SerialConfig>( +constexpr types::HardwareConfig from_config(Config config) { + return static_cast( data_bits_from_config(config.data_bits) | parity_from_config(config.parity) | stop_bits_from_config(config.stop_bits)); @@ -276,8 +299,8 @@ BasePortPtr hardware_port( auto* ptr = new HardwareSerial(number); ptr->begin(baudrate, - from_config<::SerialConfig>(config), - static_cast(mode), + from_config(config), + static_cast(mode), tx, invert); if ((number == 0) && (build::uart0_swapped(tx, rx))) { ptr->flush(); @@ -319,8 +342,8 @@ constexpr int software_serial_stop_bits_from_config(uint8_t bits) { } template <> -constexpr ::SoftwareSerialConfig from_config(Config config) { - return static_cast<::SoftwareSerialConfig>( +constexpr types::SoftwareConfig from_config(Config config) { + return static_cast( software_serial_data_bits_from_config(config.data_bits) | software_serial_parity_from_config(config.parity) | software_serial_stop_bits_from_config(config.stop_bits)); @@ -334,7 +357,7 @@ BasePortPtr software_serial_port( const int8_t rx_pin = (rx == GPIO_NONE) ? -1 : rx; auto* ptr = new SoftwareSerial(rx_pin, tx_pin, invert); - ptr->begin(baudrate, from_config<::SoftwareSerialConfig>(config)); + ptr->begin(baudrate, from_config(config)); return std::make_unique( BasePort{ diff --git a/code/test/build/nondefault.h b/code/test/build/nondefault.h index 3d6f1c13..637d881c 100644 --- a/code/test/build/nondefault.h +++ b/code/test/build/nondefault.h @@ -10,6 +10,7 @@ #define RPN_RULES_SUPPORT 1 #define SSDP_SUPPORT 1 #define UART_MQTT_SUPPORT 1 +#define UART_SOFTWARE_SUPPORT 1 #define TERMINAL_WEB_API_SUPPORT 1 #define TERMINAL_MQTT_SUPPORT 1 #define PROMETHEUS_SUPPORT 1