mirror of https://github.com/arendst/Tasmota.git
Merge pull request #13641 from s-hadinger/serial_lowbitrate
Make serial more responsive at low bitrate
This commit is contained in:
commit
0ef9e0f29c
|
@ -38,6 +38,8 @@ TasmotaSerial *tms_obj_list[16];
|
|||
#endif // ESP8266
|
||||
#ifdef ESP32
|
||||
|
||||
#include "driver/uart.h"
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
|
||||
static int tasmota_serial_index = 2; // Allow UART2 and UART1 only
|
||||
#elif CONFIG_IDF_TARGET_ESP32S2 // ESP32-S2
|
||||
|
@ -155,6 +157,24 @@ bool TasmotaSerial::begin(uint32_t speed, uint32_t config) {
|
|||
if (serial_buffer_size > 256) {
|
||||
TSerial->setRxBufferSize(serial_buffer_size);
|
||||
}
|
||||
// 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);
|
||||
}
|
||||
} else {
|
||||
m_valid = false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue