Merge pull request #14153 from wir3z/development

Fixed non-8N1 serial issues.
This commit is contained in:
Theo Arends 2021-12-23 10:41:11 +01:00 committed by GitHub
commit d9ab90a2f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 35 additions and 38 deletions

View File

@ -28,7 +28,6 @@ extern "C" {
#include <TasmotaSerial.h> #include <TasmotaSerial.h>
#ifdef ESP8266 #ifdef ESP8266
void IRAM_ATTR callRxRead(void *self) { ((TasmotaSerial*)self)->rxRead(); }; void IRAM_ATTR callRxRead(void *self) { ((TasmotaSerial*)self)->rxRead(); };
// As the Arduino attachInterrupt has no parameter, lists of objects // As the Arduino attachInterrupt has no parameter, lists of objects
@ -140,7 +139,7 @@ bool TasmotaSerial::begin(uint32_t speed, uint32_t config) {
if (m_hardserial) { if (m_hardserial) {
#ifdef ESP8266 #ifdef ESP8266
Serial.flush(); Serial.flush();
Serial.begin(speed, (SerialConfig)config); Serial.begin(speed, (SerialConfig)pgm_read_byte(kTasmotaSerialConfig + config));
if (m_hardswap) { if (m_hardswap) {
Serial.swap(); Serial.swap();
} }

View File

@ -35,6 +35,27 @@
#include <HardwareSerial.h> #include <HardwareSerial.h>
#endif #endif
#ifdef ESP8266
const uint8_t kTasmotaSerialConfig[] PROGMEM = {
SERIAL_5N1, SERIAL_6N1, SERIAL_7N1, SERIAL_8N1,
SERIAL_5N2, SERIAL_6N2, SERIAL_7N2, SERIAL_8N2,
SERIAL_5E1, SERIAL_6E1, SERIAL_7E1, SERIAL_8E1,
SERIAL_5E2, SERIAL_6E2, SERIAL_7E2, SERIAL_8E2,
SERIAL_5O1, SERIAL_6O1, SERIAL_7O1, SERIAL_8O1,
SERIAL_5O2, SERIAL_6O2, SERIAL_7O2, SERIAL_8O2
};
#endif // ESP8266
#ifdef ESP32
const uint32_t kTasmotaSerialConfig[] PROGMEM = {
SERIAL_5N1, SERIAL_6N1, SERIAL_7N1, SERIAL_8N1,
SERIAL_5N2, SERIAL_6N2, SERIAL_7N2, SERIAL_8N2,
SERIAL_5E1, SERIAL_6E1, SERIAL_7E1, SERIAL_8E1,
SERIAL_5E2, SERIAL_6E2, SERIAL_7E2, SERIAL_8E2,
SERIAL_5O1, SERIAL_6O1, SERIAL_7O1, SERIAL_8O1,
SERIAL_5O2, SERIAL_6O2, SERIAL_7O2, SERIAL_8O2
};
#endif // ESP32
class TasmotaSerial : public Stream { class TasmotaSerial : public Stream {
public: public:
TasmotaSerial(int receive_pin, int transmit_pin, int hardware_fallback = 0, int nwmode = 0, int buffer_size = TM_SERIAL_BUFFER_SIZE); TasmotaSerial(int receive_pin, int transmit_pin, int hardware_fallback = 0, int nwmode = 0, int buffer_size = TM_SERIAL_BUFFER_SIZE);

View File

@ -28,6 +28,7 @@ bool knx_started = false;
/*********************************************************************************************\ /*********************************************************************************************\
* Watchdog extension (https://github.com/esp8266/Arduino/issues/1532) * Watchdog extension (https://github.com/esp8266/Arduino/issues/1532)
\*********************************************************************************************/ \*********************************************************************************************/
#include <TasmotaSerial.h>
#ifdef ESP8266 #ifdef ESP8266
#include <Ticker.h> #include <Ticker.h>
@ -1885,15 +1886,14 @@ void SetSerialBegin(void) {
AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_SERIAL "Set to %s %d bit/s"), GetSerialConfig().c_str(), TasmotaGlobal.baudrate); AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_SERIAL "Set to %s %d bit/s"), GetSerialConfig().c_str(), TasmotaGlobal.baudrate);
Serial.flush(); Serial.flush();
#ifdef ESP8266 #ifdef ESP8266
Serial.begin(TasmotaGlobal.baudrate, (SerialConfig)pgm_read_byte(kTasmotaSerialConfig + Settings->serial_config)); Serial.begin(TasmotaGlobal.baudrate, (SerialConfig)ConvertSerialConfig(Settings->serial_config));
SetSerialSwap(); SetSerialSwap();
#endif // ESP8266 #endif // ESP8266
#ifdef ESP32 #ifdef ESP32
delay(10); // Allow time to cleanup queues - if not used hangs ESP32 delay(10); // Allow time to cleanup queues - if not used hangs ESP32
Serial.end(); Serial.end();
delay(10); // Allow time to cleanup queues - if not used hangs ESP32 delay(10); // Allow time to cleanup queues - if not used hangs ESP32
uint32_t config = pgm_read_dword(kTasmotaSerialConfig + Settings->serial_config); Serial.begin(TasmotaGlobal.baudrate, ConvertSerialConfig(Settings->serial_config));
Serial.begin(TasmotaGlobal.baudrate, config);
#endif // ESP32 #endif // ESP32
} }

View File

@ -431,27 +431,6 @@ enum TasmotaSerialConfig {
TS_SERIAL_5O1, TS_SERIAL_6O1, TS_SERIAL_7O1, TS_SERIAL_8O1, TS_SERIAL_5O1, TS_SERIAL_6O1, TS_SERIAL_7O1, TS_SERIAL_8O1,
TS_SERIAL_5O2, TS_SERIAL_6O2, TS_SERIAL_7O2, TS_SERIAL_8O2 }; TS_SERIAL_5O2, TS_SERIAL_6O2, TS_SERIAL_7O2, TS_SERIAL_8O2 };
#ifdef ESP8266
const SerConfu8 kTasmotaSerialConfig[] PROGMEM = {
SERIAL_5N1, SERIAL_6N1, SERIAL_7N1, SERIAL_8N1,
SERIAL_5N2, SERIAL_6N2, SERIAL_7N2, SERIAL_8N2,
SERIAL_5E1, SERIAL_6E1, SERIAL_7E1, SERIAL_8E1,
SERIAL_5E2, SERIAL_6E2, SERIAL_7E2, SERIAL_8E2,
SERIAL_5O1, SERIAL_6O1, SERIAL_7O1, SERIAL_8O1,
SERIAL_5O2, SERIAL_6O2, SERIAL_7O2, SERIAL_8O2
};
#endif // ESP8266
#ifdef ESP32
const uint32_t kTasmotaSerialConfig[] PROGMEM = {
SERIAL_5N1, SERIAL_6N1, SERIAL_7N1, SERIAL_8N1,
SERIAL_5N2, SERIAL_6N2, SERIAL_7N2, SERIAL_8N2,
SERIAL_5E1, SERIAL_6E1, SERIAL_7E1, SERIAL_8E1,
SERIAL_5E2, SERIAL_6E2, SERIAL_7E2, SERIAL_8E2,
SERIAL_5O1, SERIAL_6O1, SERIAL_7O1, SERIAL_8O1,
SERIAL_5O2, SERIAL_6O2, SERIAL_7O2, SERIAL_8O2
};
#endif // ESP32
enum TuyaSupportedFunctions { TUYA_MCU_FUNC_NONE, enum TuyaSupportedFunctions { TUYA_MCU_FUNC_NONE,
TUYA_MCU_FUNC_SWT1 = 1, TUYA_MCU_FUNC_SWT2, TUYA_MCU_FUNC_SWT3, TUYA_MCU_FUNC_SWT4, TUYA_MCU_FUNC_SWT1 = 1, TUYA_MCU_FUNC_SWT2, TUYA_MCU_FUNC_SWT3, TUYA_MCU_FUNC_SWT4,
TUYA_MCU_FUNC_REL1 = 11, TUYA_MCU_FUNC_REL2, TUYA_MCU_FUNC_REL3, TUYA_MCU_FUNC_REL4, TUYA_MCU_FUNC_REL5, TUYA_MCU_FUNC_REL1 = 11, TUYA_MCU_FUNC_REL2, TUYA_MCU_FUNC_REL3, TUYA_MCU_FUNC_REL4, TUYA_MCU_FUNC_REL5,

View File

@ -337,7 +337,7 @@ void setup(void) {
Settings->baudrate = APP_BAUDRATE / 300; Settings->baudrate = APP_BAUDRATE / 300;
Settings->serial_config = TS_SERIAL_8N1; Settings->serial_config = TS_SERIAL_8N1;
} }
SetSerialBaudrate(Settings->baudrate * 300); // Reset serial interface if current baudrate is different from requested baudrate SetSerialBegin(); // Reset serial interface if current serial settings are different from requested serial settings
if (1 == RtcReboot.fast_reboot_count) { // Allow setting override only when all is well if (1 == RtcReboot.fast_reboot_count) { // Allow setting override only when all is well
UpdateQuickPowerCycle(true); UpdateQuickPowerCycle(true);

View File

@ -25,7 +25,7 @@
#define XDRV_08 8 #define XDRV_08 8
#define HARDWARE_FALLBACK 2 #define HARDWARE_FALLBACK 2
const uint8_t SERIAL_BRIDGE_BUFFER_SIZE = 130; const uint16_t SERIAL_BRIDGE_BUFFER_SIZE = 256;
const char kSerialBridgeCommands[] PROGMEM = "|" // No prefix const char kSerialBridgeCommands[] PROGMEM = "|" // No prefix
D_CMND_SSERIALSEND "|" D_CMND_SBAUDRATE; D_CMND_SSERIALSEND "|" D_CMND_SBAUDRATE;
@ -106,7 +106,13 @@ void SerialBridgeInit(void)
serial_bridge_active = false; serial_bridge_active = false;
if (PinUsed(GPIO_SBR_RX) && PinUsed(GPIO_SBR_TX)) { if (PinUsed(GPIO_SBR_RX) && PinUsed(GPIO_SBR_TX)) {
SerialBridgeSerial = new TasmotaSerial(Pin(GPIO_SBR_RX), Pin(GPIO_SBR_TX), HARDWARE_FALLBACK); SerialBridgeSerial = new TasmotaSerial(Pin(GPIO_SBR_RX), Pin(GPIO_SBR_TX), HARDWARE_FALLBACK);
if (SerialBridgeSerial->begin(Settings->sbaudrate * 300)) { // Baud rate is stored div 300 so it fits into 16 bits #ifdef ESP8266
if (SerialBridgeSerial->begin(Settings->sbaudrate * 300, (SerialConfig)ConvertSerialConfig(Settings->serial_config))) // Baud rate is stored div 300 so it fits into 16 bits
#endif // ESP8266
#ifdef ESP32
if (SerialBridgeSerial->begin(Settings->sbaudrate * 300, ConvertSerialConfig(Settings->serial_config))) // Baud rate is stored div 300 so it fits into 16 bits
#endif // ESP32
{
if (SerialBridgeSerial->hardwareSerial()) { if (SerialBridgeSerial->hardwareSerial()) {
ClaimSerial(); ClaimSerial();
serial_bridge_buffer = TasmotaGlobal.serial_in_buffer; // Use idle serial buffer to save RAM serial_bridge_buffer = TasmotaGlobal.serial_in_buffer; // Use idle serial buffer to save RAM

View File

@ -3620,15 +3620,7 @@ chknext:
glob_script_mem.sp = new TasmotaSerial(rxpin, txpin, 1, 0, rxbsiz); glob_script_mem.sp = new TasmotaSerial(rxpin, txpin, 1, 0, rxbsiz);
if (glob_script_mem.sp) { if (glob_script_mem.sp) {
uint32_t config; fvar = glob_script_mem.sp->begin(br, ConvertSerialConfig(sconfig));
#ifdef ESP8266
config = pgm_read_byte(kTasmotaSerialConfig + sconfig);
#endif // ESP8266
#ifdef ESP32
config = pgm_read_dword(kTasmotaSerialConfig + sconfig);
#endif // ESP32
fvar = glob_script_mem.sp->begin(br, config);
uint32_t savc = Settings->serial_config; uint32_t savc = Settings->serial_config;
//setRxBufferSize(TMSBSIZ); //setRxBufferSize(TMSBSIZ);