Add ESP32 TasmotaSerial uart mapping

- TasmotaSerial library from v3.4.0 to v3.5.0 (#14981)
- TasmotaSerial implement ``end()``
- ESP32 TasmotaSerial uart mapping to support multiple ``begin()`` and implement ``getUart()`` (#14981)
This commit is contained in:
Theo Arends 2022-02-27 13:28:36 +01:00
parent f544fe1e19
commit 9d179c1093
9 changed files with 80 additions and 43 deletions

View File

@ -5,10 +5,13 @@ All notable changes to this project will be documented in this file.
## [11.0.0.3] ## [11.0.0.3]
### Added ### Added
- TasmotaSerial implement ``end()``
- ESP32 TasmotaSerial uart mapping to support multiple ``begin()`` and implement ``getUart()`` (#14981)
### Changed ### Changed
- Extent number of pulsetimers from 8 to 32 (#8266) - Extent number of pulsetimers from 8 to 32 (#8266)
- Tasmota ESP32 Arduino core to v2.0.2.3 (#14979) - Tasmota ESP32 Arduino core to v2.0.2.3 (#14979)
- TasmotaSerial library from v3.4.0 to v3.5.0 (#14981)
### Fixed ### Fixed

View File

@ -107,22 +107,25 @@ The latter links can be used for OTA upgrades too like ``OtaUrl http://ota.tasmo
### Added ### Added
- Command ``SspmMap 0`` to reset Sonoff SPM default mapping - Command ``SspmMap 0`` to reset Sonoff SPM default mapping
- Command ``TcpConnect <port><ip_address>`` to add client connection mode [#14874](https://github.com/arendst/Tasmota/issues/14874) - Command ``TcpConnect <port><ip_address>`` to add client connection mode [#14874](https://github.com/arendst/Tasmota/issues/14874)
- TasmotaSerial implement ``end()``
- ESP32 Berry always enable rules - ESP32 Berry always enable rules
- ESP32 Berry bootloop protection - ESP32 Berry bootloop protection
- ESP32 support for BLE Mi scale V1 [#13517](https://github.com/arendst/Tasmota/issues/13517) - 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 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 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 ### Breaking Changed
### Changed ### Changed
- Adafruit BusIO library from v1.0.10 to v1.11.0 - 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) - 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) - 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 LVGL library from v8.1.0 to v8.2.0
- ESP32 NimBLE library from v1.3.3 to v1.3.6 - 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 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 ### Fixed
- SSPM energy yesterday when zero - SSPM energy yesterday when zero

View File

@ -14,12 +14,16 @@ TasmotaSerial KEYWORD1
####################################### #######################################
begin KEYWORD2 begin KEYWORD2
end KEYWORD2
hardwareSerial KEYWORD2 hardwareSerial KEYWORD2
read KEYWORD2 peek KEYWORD2
write KEYWORD2 write KEYWORD2
read KEYWORD2
available KEYWORD2 available KEYWORD2
flush KEYWORD2 flush KEYWORD2
peek KEYWORD2 rxRead KEYWORD2
getLoopReadMetric KEYWORD2
getUart KEYWORD2
####################################### #######################################
# Constants (LITERAL1) # Constants (LITERAL1)

View File

@ -1,6 +1,6 @@
{ {
"name": "TasmotaSerial", "name": "TasmotaSerial",
"version": "3.4.0", "version": "3.5.0",
"keywords": [ "keywords": [
"serial", "io", "TasmotaSerial" "serial", "io", "TasmotaSerial"
], ],

View File

@ -1,5 +1,5 @@
name=TasmotaSerial name=TasmotaSerial
version=3.4.0 version=3.5.0
author=Theo Arends author=Theo Arends
maintainer=Theo Arends <theo@arends.com> maintainer=Theo Arends <theo@arends.com>
sentence=Implementation of software serial with hardware serial fallback for ESP8266 and ESP32. sentence=Implementation of software serial with hardware serial fallback for ESP8266 and ESP32.

View File

@ -40,7 +40,7 @@ TasmotaSerial *tms_obj_list[16];
#include "driver/uart.h" #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 #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 ((receive_pin >= 0) && !GPIO_IS_VALID_GPIO(receive_pin)) { return; }
if ((transmit_pin >= 0) && !GPIO_IS_VALID_OUTPUT_GPIO(transmit_pin)) { return; } if ((transmit_pin >= 0) && !GPIO_IS_VALID_OUTPUT_GPIO(transmit_pin)) { return; }
m_hardserial = true; m_hardserial = true;
TSerial = nullptr;
#endif // ESP32 #endif // ESP32
m_valid = true; m_valid = true;
} }
TasmotaSerial::~TasmotaSerial(void) { void TasmotaSerial::end(bool turnOffDebug) {
#ifdef ESP8266 #ifdef ESP8266
if (!m_hardserial) { if (m_hardserial) {
Serial.end();
} else {
if (m_rx_pin > -1) { if (m_rx_pin > -1) {
detachInterrupt(m_rx_pin); detachInterrupt(m_rx_pin);
tms_obj_list[m_rx_pin] = NULL; tms_obj_list[m_rx_pin] = NULL;
@ -105,15 +108,34 @@ TasmotaSerial::~TasmotaSerial(void) {
#endif // ESP8266 #endif // ESP8266
#ifdef ESP32 #ifdef ESP32
TSerial->end(); // Serial.printf("TSR: Freeing UART%d\n", m_uart);
tasmota_serial_index++; // This only works if no more uarts are requested otherwise will need a global used_uart log
TSerial->end(turnOffDebug);
bitClear(tasmota_serial_uart_bitmap, m_uart);
#endif // ESP32 #endif // ESP32
} }
TasmotaSerial::~TasmotaSerial(void) {
end();
}
bool TasmotaSerial::isValidGPIOpin(int pin) { bool TasmotaSerial::isValidGPIOpin(int pin) {
return (pin >= -1 && pin <= 5) || (pin >= 12 && pin <= 15); 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) { bool TasmotaSerial::begin(uint32_t speed, uint32_t config) {
if (!m_valid) { return false; } if (!m_valid) { return false; }
@ -129,9 +151,8 @@ bool TasmotaSerial::begin(uint32_t speed, uint32_t config) {
} }
#endif // ESP8266 #endif // ESP8266
#ifdef ESP32 #ifdef ESP32
if (tasmota_serial_index >= 0) { // We prefer UART1 and UART2 and keep UART0 for debugging if (TSerial == nullptr) { // Allow for dynamic change in baudrate or config
m_uart = tasmota_serial_index; if (freeUart()) { // We prefer UART1 and UART2 and keep UART0 for debugging
tasmota_serial_index--;
if (0 == m_uart) { if (0 == m_uart) {
Serial.flush(); Serial.flush();
Serial.end(); Serial.end();
@ -143,6 +164,11 @@ bool TasmotaSerial::begin(uint32_t speed, uint32_t config) {
if (serial_buffer_size > 256) { // RX Buffer can't be resized when Serial is already running (HardwareSerial.cpp) if (serial_buffer_size > 256) { // RX Buffer can't be resized when Serial is already running (HardwareSerial.cpp)
TSerial->setRxBufferSize(serial_buffer_size); TSerial->setRxBufferSize(serial_buffer_size);
} }
} else {
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); 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 // For low bit rate, below 9600, set the Full RX threshold at 10 bytes instead of the default 120
if (speed <= 9600) { if (speed <= 9600) {
@ -162,9 +188,6 @@ bool TasmotaSerial::begin(uint32_t speed, uint32_t config) {
// At 76800 the timeout is ~1ms // At 76800 the timeout is ~1ms
uart_set_rx_timeout(m_uart, 6); uart_set_rx_timeout(m_uart, 6);
} }
} else {
m_valid = false;
}
// Serial.printf("TSR: Using UART%d\n", m_uart); // Serial.printf("TSR: Using UART%d\n", m_uart);
#endif // ESP32 #endif // ESP32
} else { } else {

View File

@ -41,6 +41,7 @@ class TasmotaSerial : public Stream {
virtual ~TasmotaSerial(); virtual ~TasmotaSerial();
bool begin(uint32_t speed = TM_SERIAL_BAUDRATE, uint32_t config = SERIAL_8N1); bool begin(uint32_t speed = TM_SERIAL_BAUDRATE, uint32_t config = SERIAL_8N1);
void end(bool turnOffDebug = true);
bool hardwareSerial(void); bool hardwareSerial(void);
int peek(void); int peek(void);
@ -53,15 +54,18 @@ class TasmotaSerial : public Stream {
void rxRead(void); void rxRead(void);
uint32_t getLoopReadMetric(void) const { return m_bit_follow_metric; } uint32_t getLoopReadMetric(void) const { return m_bit_follow_metric; }
#ifdef ESP32 #ifdef ESP32
uint32_t getUart(void) const { return m_uart; } uint32_t getUart(void) const { return m_uart; }
#endif #endif
bool isValid() { return m_valid; }
using Print::write; using Print::write;
private: private:
bool isValidGPIOpin(int pin); bool isValidGPIOpin(int pin);
#ifdef ESP32
bool freeUart(void);
#endif
size_t txWrite(uint8_t byte); size_t txWrite(uint8_t byte);
// Member variables // Member variables