diff --git a/CHANGELOG.md b/CHANGELOG.md index 23d9a9477..0b88719a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,10 +5,13 @@ All notable changes to this project will be documented in this file. ## [11.0.0.3] ### Added +- TasmotaSerial implement ``end()`` +- ESP32 TasmotaSerial uart mapping to support multiple ``begin()`` and implement ``getUart()`` (#14981) ### Changed - Extent number of pulsetimers from 8 to 32 (#8266) - Tasmota ESP32 Arduino core to v2.0.2.3 (#14979) +- TasmotaSerial library from v3.4.0 to v3.5.0 (#14981) ### Fixed diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 1bf897276..4dea19ea9 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -107,22 +107,25 @@ The latter links can be used for OTA upgrades too like ``OtaUrl http://ota.tasmo ### Added - Command ``SspmMap 0`` to reset Sonoff SPM default mapping - Command ``TcpConnect `` to add client connection mode [#14874](https://github.com/arendst/Tasmota/issues/14874) +- TasmotaSerial implement ``end()`` - ESP32 Berry always enable rules - ESP32 Berry bootloop protection - ESP32 support for BLE Mi scale V1 [#13517](https://github.com/arendst/Tasmota/issues/13517) - ESP32 integrate Homekit in Bluetooth binary [#14818](https://github.com/arendst/Tasmota/issues/14818) - ESP32 Berry virtual Alexa hue device [#14833](https://github.com/arendst/Tasmota/issues/14833) +- ESP32 TasmotaSerial uart mapping to support multiple ``begin()`` and implement ``getUart()`` [#14981](https://github.com/arendst/Tasmota/issues/14981) ### Breaking Changed ### Changed - Adafruit BusIO library from v1.0.10 to v1.11.0 +- TasmotaSerial library from v3.4.0 to v3.5.0 [#14981](https://github.com/arendst/Tasmota/issues/14981) - Sonoff SPM increase max number of relays supported to 32 (8 SPM-4Relay modules) - Extent number of pulsetimers from 8 to 32 [#8266](https://github.com/arendst/Tasmota/issues/8266) +- ESP32 Arduino core from v2.0.2.2 to v2.0.2.3 - ESP32 LVGL library from v8.1.0 to v8.2.0 - ESP32 NimBLE library from v1.3.3 to v1.3.6 - ESP32 update the internal Berry type system to sync with Skiars Berry repository. No expected impact on code, but .bec files need to be generated again [#14811](https://github.com/arendst/Tasmota/issues/14811) -- ESP32 Arduino core from v2.0.2.2 to v2.0.2.3 ### Fixed - SSPM energy yesterday when zero diff --git a/lib/default/TasmotaSerial-3.4.0/README.md b/lib/default/TasmotaSerial-3.5.0/README.md similarity index 100% rename from lib/default/TasmotaSerial-3.4.0/README.md rename to lib/default/TasmotaSerial-3.5.0/README.md diff --git a/lib/default/TasmotaSerial-3.4.0/examples/swsertest/swsertest.ino b/lib/default/TasmotaSerial-3.5.0/examples/swsertest/swsertest.ino similarity index 100% rename from lib/default/TasmotaSerial-3.4.0/examples/swsertest/swsertest.ino rename to lib/default/TasmotaSerial-3.5.0/examples/swsertest/swsertest.ino diff --git a/lib/default/TasmotaSerial-3.4.0/keywords.txt b/lib/default/TasmotaSerial-3.5.0/keywords.txt similarity index 86% rename from lib/default/TasmotaSerial-3.4.0/keywords.txt rename to lib/default/TasmotaSerial-3.5.0/keywords.txt index f9bde9254..4f18fb23e 100644 --- a/lib/default/TasmotaSerial-3.4.0/keywords.txt +++ b/lib/default/TasmotaSerial-3.5.0/keywords.txt @@ -14,12 +14,16 @@ TasmotaSerial KEYWORD1 ####################################### begin KEYWORD2 +end KEYWORD2 hardwareSerial KEYWORD2 -read KEYWORD2 +peek KEYWORD2 write KEYWORD2 +read KEYWORD2 available KEYWORD2 flush KEYWORD2 -peek KEYWORD2 +rxRead KEYWORD2 +getLoopReadMetric KEYWORD2 +getUart KEYWORD2 ####################################### # Constants (LITERAL1) diff --git a/lib/default/TasmotaSerial-3.4.0/library.json b/lib/default/TasmotaSerial-3.5.0/library.json similarity index 94% rename from lib/default/TasmotaSerial-3.4.0/library.json rename to lib/default/TasmotaSerial-3.5.0/library.json index e9e2294fb..45c0c4508 100644 --- a/lib/default/TasmotaSerial-3.4.0/library.json +++ b/lib/default/TasmotaSerial-3.5.0/library.json @@ -1,6 +1,6 @@ { "name": "TasmotaSerial", - "version": "3.4.0", + "version": "3.5.0", "keywords": [ "serial", "io", "TasmotaSerial" ], diff --git a/lib/default/TasmotaSerial-3.4.0/library.properties b/lib/default/TasmotaSerial-3.5.0/library.properties similarity index 94% rename from lib/default/TasmotaSerial-3.4.0/library.properties rename to lib/default/TasmotaSerial-3.5.0/library.properties index d254a7355..759c7f39d 100644 --- a/lib/default/TasmotaSerial-3.4.0/library.properties +++ b/lib/default/TasmotaSerial-3.5.0/library.properties @@ -1,5 +1,5 @@ name=TasmotaSerial -version=3.4.0 +version=3.5.0 author=Theo Arends maintainer=Theo Arends sentence=Implementation of software serial with hardware serial fallback for ESP8266 and ESP32. diff --git a/lib/default/TasmotaSerial-3.4.0/src/TasmotaSerial.cpp b/lib/default/TasmotaSerial-3.5.0/src/TasmotaSerial.cpp similarity index 84% rename from lib/default/TasmotaSerial-3.4.0/src/TasmotaSerial.cpp rename to lib/default/TasmotaSerial-3.5.0/src/TasmotaSerial.cpp index 150d740b0..278acaabd 100644 --- a/lib/default/TasmotaSerial-3.4.0/src/TasmotaSerial.cpp +++ b/lib/default/TasmotaSerial-3.5.0/src/TasmotaSerial.cpp @@ -40,7 +40,7 @@ TasmotaSerial *tms_obj_list[16]; #include "driver/uart.h" -static int tasmota_serial_index = SOC_UART_NUM -1; // Available UART +static uint32_t tasmota_serial_uart_bitmap = 0; // Assigned UARTs #endif // ESP32 @@ -87,13 +87,16 @@ TasmotaSerial::TasmotaSerial(int receive_pin, int transmit_pin, int hardware_fal if ((receive_pin >= 0) && !GPIO_IS_VALID_GPIO(receive_pin)) { return; } if ((transmit_pin >= 0) && !GPIO_IS_VALID_OUTPUT_GPIO(transmit_pin)) { return; } m_hardserial = true; + TSerial = nullptr; #endif // ESP32 m_valid = true; } -TasmotaSerial::~TasmotaSerial(void) { +void TasmotaSerial::end(bool turnOffDebug) { #ifdef ESP8266 - if (!m_hardserial) { + if (m_hardserial) { + Serial.end(); + } else { if (m_rx_pin > -1) { detachInterrupt(m_rx_pin); tms_obj_list[m_rx_pin] = NULL; @@ -105,15 +108,34 @@ TasmotaSerial::~TasmotaSerial(void) { #endif // ESP8266 #ifdef ESP32 - TSerial->end(); - tasmota_serial_index++; // This only works if no more uarts are requested otherwise will need a global used_uart log +// Serial.printf("TSR: Freeing UART%d\n", m_uart); + + TSerial->end(turnOffDebug); + bitClear(tasmota_serial_uart_bitmap, m_uart); #endif // ESP32 } +TasmotaSerial::~TasmotaSerial(void) { + end(); +} + bool TasmotaSerial::isValidGPIOpin(int pin) { return (pin >= -1 && pin <= 5) || (pin >= 12 && pin <= 15); } +#ifdef ESP32 +bool TasmotaSerial::freeUart(void) { + for (uint32_t i = SOC_UART_NUM -1; i >= 0; i--) { + if (0 == bitRead(tasmota_serial_uart_bitmap, i)) { + m_uart = i; + bitSet(tasmota_serial_uart_bitmap, m_uart); + return true; + } + } + return false; +} +#endif + bool TasmotaSerial::begin(uint32_t speed, uint32_t config) { if (!m_valid) { return false; } @@ -129,41 +151,42 @@ bool TasmotaSerial::begin(uint32_t speed, uint32_t config) { } #endif // ESP8266 #ifdef ESP32 - if (tasmota_serial_index >= 0) { // We prefer UART1 and UART2 and keep UART0 for debugging - m_uart = tasmota_serial_index; - tasmota_serial_index--; - if (0 == m_uart) { - Serial.flush(); - Serial.end(); - delay(10); // Allow time to cleanup queues - if not used hangs ESP32 - TSerial = &Serial; + if (TSerial == nullptr) { // Allow for dynamic change in baudrate or config + if (freeUart()) { // We prefer UART1 and UART2 and keep UART0 for debugging + if (0 == m_uart) { + Serial.flush(); + Serial.end(); + delay(10); // Allow time to cleanup queues - if not used hangs ESP32 + TSerial = &Serial; + } else { + TSerial = new HardwareSerial(m_uart); + } + if (serial_buffer_size > 256) { // RX Buffer can't be resized when Serial is already running (HardwareSerial.cpp) + TSerial->setRxBufferSize(serial_buffer_size); + } } else { - TSerial = new HardwareSerial(m_uart); - } - if (serial_buffer_size > 256) { // RX Buffer can't be resized when Serial is already running (HardwareSerial.cpp) - TSerial->setRxBufferSize(serial_buffer_size); - } - TSerial->begin(speed, config, m_rx_pin, m_tx_pin); - // For low bit rate, below 9600, set the Full RX threshold at 10 bytes instead of the default 120 - if (speed <= 9600) { - // At 9600, 10 chars are ~10ms - uart_set_rx_full_threshold(m_uart, 10); - } else if (speed < 115200) { - // At 19200, 120 chars are ~60ms - // At 76800, 120 chars are ~15ms - uart_set_rx_full_threshold(m_uart, 120); - } else { - // At 115200, 256 chars are ~20ms - // Zigbee requires to keep frames together, i.e. 256 bytes max - uart_set_rx_full_threshold(m_uart, 256); - } - // For bitrate below 115200, set the Rx time out to 6 chars instead of the default 10 - if (speed < 115200) { - // At 76800 the timeout is ~1ms - uart_set_rx_timeout(m_uart, 6); + m_valid = false; + return m_valid; // As we currently only support hardware serial on ESP32 it's safe to exit here } + } + TSerial->begin(speed, config, m_rx_pin, m_tx_pin); + // For low bit rate, below 9600, set the Full RX threshold at 10 bytes instead of the default 120 + if (speed <= 9600) { + // At 9600, 10 chars are ~10ms + uart_set_rx_full_threshold(m_uart, 10); + } else if (speed < 115200) { + // At 19200, 120 chars are ~60ms + // At 76800, 120 chars are ~15ms + uart_set_rx_full_threshold(m_uart, 120); } else { - m_valid = false; + // At 115200, 256 chars are ~20ms + // Zigbee requires to keep frames together, i.e. 256 bytes max + uart_set_rx_full_threshold(m_uart, 256); + } + // For bitrate below 115200, set the Rx time out to 6 chars instead of the default 10 + if (speed < 115200) { + // At 76800 the timeout is ~1ms + uart_set_rx_timeout(m_uart, 6); } // Serial.printf("TSR: Using UART%d\n", m_uart); #endif // ESP32 diff --git a/lib/default/TasmotaSerial-3.4.0/src/TasmotaSerial.h b/lib/default/TasmotaSerial-3.5.0/src/TasmotaSerial.h similarity index 95% rename from lib/default/TasmotaSerial-3.4.0/src/TasmotaSerial.h rename to lib/default/TasmotaSerial-3.5.0/src/TasmotaSerial.h index 3a90626fe..f0ff57cd2 100644 --- a/lib/default/TasmotaSerial-3.4.0/src/TasmotaSerial.h +++ b/lib/default/TasmotaSerial-3.5.0/src/TasmotaSerial.h @@ -41,6 +41,7 @@ class TasmotaSerial : public Stream { virtual ~TasmotaSerial(); bool begin(uint32_t speed = TM_SERIAL_BAUDRATE, uint32_t config = SERIAL_8N1); + void end(bool turnOffDebug = true); bool hardwareSerial(void); int peek(void); @@ -53,15 +54,18 @@ class TasmotaSerial : public Stream { void rxRead(void); uint32_t getLoopReadMetric(void) const { return m_bit_follow_metric; } - #ifdef ESP32 uint32_t getUart(void) const { return m_uart; } #endif + bool isValid() { return m_valid; } using Print::write; private: bool isValidGPIOpin(int pin); +#ifdef ESP32 + bool freeUart(void); +#endif size_t txWrite(uint8_t byte); // Member variables