Merge pull request #4288 from chaosmaster/patch-2

TasmotaSerial: use Serial.swap to map UART0 to GPIO13 and GPIO15
This commit is contained in:
Theo Arends 2018-11-06 10:21:45 +01:00 committed by GitHub
commit ca1cf987c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -80,6 +80,7 @@ TasmotaSerial::TasmotaSerial(int receive_pin, int transmit_pin, bool hardware_fa
{ {
m_valid = false; m_valid = false;
m_hardserial = 0; m_hardserial = 0;
m_hardswap = 0;
m_stop_bits = 1; m_stop_bits = 1;
if (!((isValidGPIOpin(receive_pin)) && (isValidGPIOpin(transmit_pin) || transmit_pin == 16))) { if (!((isValidGPIOpin(receive_pin)) && (isValidGPIOpin(transmit_pin) || transmit_pin == 16))) {
return; return;
@ -89,6 +90,9 @@ TasmotaSerial::TasmotaSerial(int receive_pin, int transmit_pin, bool hardware_fa
m_in_pos = m_out_pos = 0; m_in_pos = m_out_pos = 0;
if (hardware_fallback && (((3 == m_rx_pin) && (1 == m_tx_pin)) || ((3 == m_rx_pin) && (-1 == m_tx_pin)) || ((-1 == m_rx_pin) && (1 == m_tx_pin)))) { if (hardware_fallback && (((3 == m_rx_pin) && (1 == m_tx_pin)) || ((3 == m_rx_pin) && (-1 == m_tx_pin)) || ((-1 == m_rx_pin) && (1 == m_tx_pin)))) {
m_hardserial = 1; m_hardserial = 1;
} else if (hardware_fallback && (((13 == m_rx_pin) && (15 == m_tx_pin)) || ((13 == m_rx_pin) && (-1 == m_tx_pin)) || ((-1 == m_rx_pin) && (15 == m_tx_pin)))) {
m_hardserial = 1;
m_hardswap = 1;
} else { } else {
if (m_rx_pin > -1) { if (m_rx_pin > -1) {
m_buffer = (uint8_t*)malloc(TM_SERIAL_BUFFER_SIZE); m_buffer = (uint8_t*)malloc(TM_SERIAL_BUFFER_SIZE);
@ -134,6 +138,9 @@ bool TasmotaSerial::begin(long speed, int stop_bits) {
} else { } else {
Serial.begin(speed, SERIAL_8N1); Serial.begin(speed, SERIAL_8N1);
} }
if(m_hardswap) {
Serial.swap();
}
} else { } else {
// Use getCycleCount() loop to get as exact timing as possible // Use getCycleCount() loop to get as exact timing as possible
m_bit_time = ESP.getCpuFreqMHz() *1000000 /speed; m_bit_time = ESP.getCpuFreqMHz() *1000000 /speed;

View File

@ -62,6 +62,7 @@ class TasmotaSerial : public Stream {
// Member variables // Member variables
bool m_valid; bool m_valid;
bool m_hardserial; bool m_hardserial;
bool m_hardswap;
bool m_high_speed; bool m_high_speed;
int m_rx_pin; int m_rx_pin;
int m_tx_pin; int m_tx_pin;