Skip to content

Commit a3cb35e

Browse files
committed
Due to compelling use case, refactored ctor and begin() to allow Arduino AVR, ESP32 HW serial and ESP8266-previous API compatibility.
1 parent 38e3f1a commit a3cb35e

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/SoftwareSerial.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ SoftwareSerial::SoftwareSerial() {
3434
m_isrOverflow = false;
3535
}
3636

37-
SoftwareSerial::SoftwareSerial(int8_t rxPin, int8_t txPin)
37+
SoftwareSerial::SoftwareSerial(int8_t rxPin, int8_t txPin, bool invert)
3838
{
3939
m_isrOverflow = false;
4040
m_rxPin = rxPin;
4141
m_txPin = txPin;
42+
m_invert = invert;
4243
}
4344

44-
4545
SoftwareSerial::~SoftwareSerial() {
4646
end();
4747
}
@@ -100,6 +100,10 @@ void SoftwareSerial::begin(uint32_t baud, SoftwareSerialConfig config,
100100
if (!m_rxEnabled) { enableRx(true); }
101101
}
102102

103+
void SoftwareSerial::begin(uint32_t baud, SoftwareSerialConfig config) {
104+
begin(baud, config, -1, -1, m_invert);
105+
}
106+
103107
void SoftwareSerial::end()
104108
{
105109
enableRx(false);

src/SoftwareSerial.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class SoftwareSerial : public Stream {
9191
/// Ctor to set defaults for pins.
9292
/// @param rxPin the GPIO pin used for RX
9393
/// @param txPin -1 for onewire protocol, GPIO pin used for twowire TX
94-
SoftwareSerial(int8_t rxPin, int8_t txPin = -1);
94+
SoftwareSerial(int8_t rxPin, int8_t txPin = -1, bool invert = false);
9595
SoftwareSerial(const SoftwareSerial&) = delete;
9696
SoftwareSerial& operator= (const SoftwareSerial&) = delete;
9797
virtual ~SoftwareSerial();
@@ -105,9 +105,10 @@ class SoftwareSerial : public Stream {
105105
/// @param isrBufCapacity 0: derived from bufCapacity. The capacity of the internal asynchronous
106106
/// bit receive buffer, a suggested size is bufCapacity times the sum of
107107
/// start, data, parity and stop bit count.
108-
void begin(uint32_t baud, SoftwareSerialConfig config = SWSERIAL_8N1,
109-
int8_t rxPin = -1, int8_t txPin = -1,
108+
void begin(uint32_t baud, SoftwareSerialConfig config,
109+
int8_t rxPin, int8_t txPin = -1,
110110
bool invert = false, int bufCapacity = 64, int isrBufCapacity = 0);
111+
void begin(uint32_t baud, SoftwareSerialConfig config = SWSERIAL_8N1);
111112
uint32_t baudRate();
112113
/// Transmit control pin.
113114
void setTransmitEnablePin(int8_t txEnablePin);

0 commit comments

Comments
 (0)