Rolled out parity changes due to potential timing issues.

This commit is contained in:
wir3z 2021-12-22 09:47:20 -07:00
parent b8752b7272
commit ee39f84bc2
2 changed files with 14 additions and 39 deletions

View File

@ -55,7 +55,6 @@ TasmotaSerial::TasmotaSerial(int receive_pin, int transmit_pin, int hardware_fal
m_hardserial = false;
m_hardswap = false;
m_stop_bits = 1;
m_parity = -1;
m_nwmode = nwmode;
serial_buffer_size = buffer_size;
m_rx_pin = receive_pin;
@ -122,17 +121,20 @@ bool TasmotaSerial::isValidGPIOpin(int pin) {
bool TasmotaSerial::begin(uint32_t speed, uint32_t config) {
if (!m_valid) { return false; }
// get the number of stop bits
m_stop_bits = (config &0x20) ? 2 : 1;
// check for parity
if (config &0x02) { // parity is enabled
if (config &0x01) {
m_parity = HIGH; // odd parity
} else {
m_parity = LOW; // even parity
if (config > 2) {
// Legacy support where software serial fakes two stop bits if either stop bits is 2 or parity is not None
m_stop_bits = ((config &0x30) >> 5) +1;
if ((1 == m_stop_bits) && (config &0x03)) {
m_stop_bits++;
}
} else {
m_parity = -1; // no parity
m_stop_bits = ((config -1) &1) +1;
#ifdef ESP8266
config = (2 == m_stop_bits) ? (uint32_t)SERIAL_8N2 : (uint32_t)SERIAL_8N1;
#endif // ESP8266
#ifdef ESP32
config = (2 == m_stop_bits) ? SERIAL_8N2 : SERIAL_8N1;
#endif // ESP32
}
if (m_hardserial) {
@ -283,23 +285,14 @@ int TasmotaSerial::available(void) {
void IRAM_ATTR TasmotaSerial::_fast_write(uint8_t b) {
uint32_t wait = m_bit_time;
uint32_t start = ESP.getCycleCount();
uint8_t numOnes = 0;
uint8_t bit;
// Start bit;
digitalWrite(m_tx_pin, LOW);
TM_SERIAL_WAIT_SND_FAST;
for (uint32_t i = 0; i < 8; i++) {
bit = (b &1);
numOnes += bit;
digitalWrite(m_tx_pin, bit ? HIGH : LOW);
digitalWrite(m_tx_pin, (b & 1) ? HIGH : LOW);
TM_SERIAL_WAIT_SND_FAST;
b >>= 1;
}
// parity bit
if (m_parity != -1) {
digitalWrite(m_tx_pin, (numOnes %2) ? !m_parity : m_parity);
TM_SERIAL_WAIT_SND_FAST;
}
// Stop bit(s)
digitalWrite(m_tx_pin, HIGH);
for (uint32_t i = 0; i < m_stop_bits; i++) {
@ -325,23 +318,14 @@ size_t TasmotaSerial::write(uint8_t b) {
uint32_t wait = m_bit_time;
//digitalWrite(m_tx_pin, HIGH); // already in HIGH mode
uint32_t start = ESP.getCycleCount();
uint8_t numOnes = 0;
uint8_t bit;
// Start bit;
digitalWrite(m_tx_pin, LOW);
TM_SERIAL_WAIT_SND;
for (uint32_t i = 0; i < 8; i++) {
bit = (b &1);
numOnes += bit;
digitalWrite(m_tx_pin, bit ? HIGH : LOW);
digitalWrite(m_tx_pin, (b & 1) ? HIGH : LOW);
TM_SERIAL_WAIT_SND;
b >>= 1;
}
// parity bit
if (m_parity != -1) {
digitalWrite(m_tx_pin, (numOnes %2) ? !m_parity : m_parity);
TM_SERIAL_WAIT_SND;
}
// Stop bit(s)
digitalWrite(m_tx_pin, HIGH);
// re-enable interrupts during stop bits, it's not an issue if they are longer than expected
@ -375,12 +359,6 @@ void IRAM_ATTR TasmotaSerial::rxRead(void) {
m_in_pos = next;
}
// just consume the parity bit -- no parity checking is occuring
if (m_parity != -1) {
TM_SERIAL_WAIT_RCV_LOOP; // wait for the parity bit
wait += m_bit_time / 4;
}
TM_SERIAL_WAIT_RCV_LOOP; // wait for stop bit
if (2 == m_stop_bits) {
wait += m_bit_time;

View File

@ -35,8 +35,6 @@
#include <HardwareSerial.h>
#endif
extern uint32_t ConvertSerialConfig(uint8_t serial_config);
class TasmotaSerial : public Stream {
public:
TasmotaSerial(int receive_pin, int transmit_pin, int hardware_fallback = 0, int nwmode = 0, int buffer_size = TM_SERIAL_BUFFER_SIZE);
@ -70,7 +68,6 @@ class TasmotaSerial : public Stream {
int m_rx_pin;
int m_tx_pin;
uint32_t m_stop_bits;
uint32_t m_parity;
uint32_t ss_byte;
uint32_t ss_bstart;
uint32_t ss_index;