Fix correct use of uart0

This commit is contained in:
Theo Arends 2022-01-19 12:22:30 +01:00
parent b0dafb57a4
commit 71bc58eeae

View File

@ -40,13 +40,7 @@ TasmotaSerial *tms_obj_list[16];
#include "driver/uart.h" #include "driver/uart.h"
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 static int tasmota_serial_index = SOC_UART_NUM -1; // Available UART
static int tasmota_serial_index = 2; // Allow UART2 and UART1 only
#elif CONFIG_IDF_TARGET_ESP32S2 // ESP32-S2
static int tasmota_serial_index = 1; // Allow UART1 only
#elif CONFIG_IDF_TARGET_ESP32C3 // ESP32-C3
static int tasmota_serial_index = 1; // Allow UART1 only
#endif
#endif // ESP32 #endif // ESP32
@ -90,7 +84,6 @@ TasmotaSerial::TasmotaSerial(int receive_pin, int transmit_pin, int hardware_fal
} }
#endif // ESP8266 #endif // ESP8266
#ifdef ESP32 #ifdef ESP32
// if (transmit_pin > 33) { return; } // GPIO34 - GPIO39 are Input only
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;
@ -113,7 +106,7 @@ TasmotaSerial::~TasmotaSerial(void) {
#ifdef ESP32 #ifdef ESP32
TSerial->end(); TSerial->end();
tasmota_serial_index++; tasmota_serial_index++; // This only works if no more uarts are requested otherwise will need a global used_uart log
#endif // ESP32 #endif // ESP32
} }
@ -136,11 +129,17 @@ bool TasmotaSerial::begin(uint32_t speed, uint32_t config) {
} }
#endif // ESP8266 #endif // ESP8266
#ifdef ESP32 #ifdef ESP32
// if (tasmota_serial_index > 0) { // We only support UART1 and UART2 and keep UART0 for debugging
if (tasmota_serial_index >= 0) { // We prefer UART1 and UART2 and keep UART0 for debugging if (tasmota_serial_index >= 0) { // We prefer UART1 and UART2 and keep UART0 for debugging
m_uart = tasmota_serial_index; m_uart = tasmota_serial_index;
tasmota_serial_index--; tasmota_serial_index--;
TSerial = new HardwareSerial(m_uart); 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) 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);
} }
@ -195,7 +194,6 @@ bool TasmotaSerial::hardwareSerial(void) {
return m_hardserial; return m_hardserial;
#endif // ESP8266 #endif // ESP8266
#ifdef ESP32 #ifdef ESP32
// return false; // On ESP32 do not mess with Serial0 buffers
return (0 == m_uart); // We prefer UART1 and UART2 and keep UART0 for debugging return (0 == m_uart); // We prefer UART1 and UART2 and keep UART0 for debugging
#endif // ESP32 #endif // ESP32
} }