Skip to content

Commit 9bb7388

Browse files
authored
Throw major release number to stop confusion over ctor/begin() split of rx/tx pin setting. (#121)
For complete maximum default parameter uses, this is now backward compatible with releases 5.0.4 and prior.
1 parent 1a14723 commit 9bb7388

File tree

9 files changed

+49
-29
lines changed

9 files changed

+49
-29
lines changed

examples/loopback/loopback.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void setup() {
8686
Serial.begin(IUTBITRATE);
8787
Serial.swap();
8888
Serial.setRxBufferSize(2 * BLOCKSIZE);
89-
logger.begin(9600, -1, TX);
89+
logger.begin(9600, swSerialConfig, -1, TX);
9090
#else
9191
Serial.begin(9600);
9292
#endif
@@ -96,7 +96,7 @@ void setup() {
9696
Serial2.setRxBufferSize(2 * BLOCKSIZE);
9797
logger.begin(9600);
9898
#elif defined(HWSOURCESINK)
99-
serialIUT.begin(IUTBITRATE, SERIAL_8N1, D5, D6);
99+
serialIUT.begin(IUTBITRATE, swSerialConfig, D5, D6);
100100
serialIUT.setRxBufferSize(2 * BLOCKSIZE);
101101
logger.begin(9600);
102102
#else
@@ -108,12 +108,12 @@ void setup() {
108108

109109
#if !defined(HWSOURCESINK)
110110
#if defined(ESP8266)
111-
serialIUT.begin(IUTBITRATE, D5, D6, swSerialConfig, false, 4 * BLOCKSIZE);
111+
serialIUT.begin(IUTBITRATE, swSerialConfig, D5, D6, false, 4 * BLOCKSIZE);
112112
#ifdef HALFDUPLEX
113113
serialIUT.enableIntTx(false);
114114
#endif
115115
#elif defined(ESP32)
116-
serialIUT.begin(IUTBITRATE, D5, D6, swSerialConfig, false, 2 * BLOCKSIZE);
116+
serialIUT.begin(IUTBITRATE, swSerialConfig, D5, D6, false, 2 * BLOCKSIZE);
117117
#ifdef HALFDUPLEX
118118
serialIUT.enableIntTx(false);
119119
#endif

examples/onewiretest/onewiretest.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ void setup() {
88
delay(2000);
99
Serial.begin(115200);
1010
Serial.println("\nOne Wire Half Duplex Serial Tester");
11-
swSer1.begin(115200, 12, 12, SWSERIAL_8N1, false, 256);
11+
swSer1.begin(115200, SWSERIAL_8N1, 12, 12, false, 256);
1212
swSer1.enableIntTx(true);
13-
swSer2.begin(115200, 14, 14, SWSERIAL_8N1, false, 256);
13+
swSer2.begin(115200, SWSERIAL_8N1, 14, 14, false, 256);
1414
swSer2.enableIntTx(true);
1515
}
1616

examples/repeater/repeater.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,17 @@ void setup() {
5656
repeater.begin(IUTBITRATE);
5757
repeater.setRxBufferSize(2 * BLOCKSIZE);
5858
repeater.swap();
59-
logger.begin(9600, RX, TX);
59+
logger.begin(9600, swSerialConfig, RX, TX);
6060
#elif defined(ESP32)
6161
repeater.begin(IUTBITRATE, SERIAL_8N1, D7, D8);
6262
repeater.setRxBufferSize(2 * BLOCKSIZE);
6363
logger.begin(9600);
6464
#endif
6565
#else
6666
#if defined(ESP8266)
67-
repeater.begin(IUTBITRATE, D7, D8, swSerialConfig, false, 2 * BLOCKSIZE);
67+
repeater.begin(IUTBITRATE, swSerialConfig, D7, D8, false, 2 * BLOCKSIZE);
6868
#elif defined(ESP32)
69-
repeater.begin(IUTBITRATE, D7, D8, swSerialConfig, false, 2 * BLOCKSIZE);
69+
repeater.begin(IUTBITRATE, swSerialConfig, D7, D8, false, 2 * BLOCKSIZE);
7070
#endif
7171
#ifdef HALFDUPLEX
7272
repeater.enableIntTx(false);

examples/servoTester/servoTester.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ void setup() {
1212
delay(2000);
1313
Serial.begin(115200);
1414
Serial.println("\nAlpha 1S Servo Tester");
15-
swSer.begin(115200, 12, 12, SWSERIAL_8N1, false, 256);
15+
swSer.begin(115200, SWSERIAL_8N1, 12, 12, false, 256);
1616
}
1717

1818
void loop() {

examples/swsertest/swsertest.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SoftwareSerial swSer;
2424

2525
void setup() {
2626
Serial.begin(115200);
27-
swSer.begin(BAUD_RATE, D5, D6, SWSERIAL_8N1, false, 95, 11);
27+
swSer.begin(BAUD_RATE, SWSERIAL_8N1, D5, D6, false, 95, 11);
2828

2929
Serial.println("\nSoftware serial test started");
3030

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "EspSoftwareSerial",
3-
"version": "5.4.0",
3+
"version": "6.0.0",
44
"keywords": [
55
"serial", "io", "softwareserial"
66
],

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=EspSoftwareSerial
2-
version=5.4.0
2+
version=6.0.0
33
author=Peter Lerup, Dirk Kaar
44
maintainer=Peter Lerup <[email protected]>
55
sentence=Implementation of the Arduino software serial for ESP8266/ESP32.

src/SoftwareSerial.cpp

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

37+
SoftwareSerial::SoftwareSerial(int8_t rxPin, int8_t txPin)
38+
{
39+
m_isrOverflow = false;
40+
m_rxPin = rxPin;
41+
m_txPin = txPin;
42+
}
43+
44+
3745
SoftwareSerial::~SoftwareSerial() {
3846
end();
3947
}
@@ -49,12 +57,14 @@ bool SoftwareSerial::isValidGPIOpin(int8_t pin) {
4957
#endif
5058
}
5159

52-
void SoftwareSerial::begin(uint32_t baud, int8_t rxPin, int8_t txPin,
53-
SoftwareSerialConfig config, bool invert, int bufCapacity, int isrBufCapacity) {
54-
m_oneWire = (rxPin == txPin);
60+
void SoftwareSerial::begin(uint32_t baud, SoftwareSerialConfig config,
61+
int8_t rxPin, int8_t txPin,
62+
bool invert, int bufCapacity, int isrBufCapacity) {
63+
if (-1 != rxPin) m_rxPin = rxPin;
64+
if (-1 != txPin) m_txPin = txPin;
65+
m_oneWire = (m_rxPin == m_txPin);
5566
m_invert = invert;
56-
if (isValidGPIOpin(rxPin)) {
57-
m_rxPin = rxPin;
67+
if (isValidGPIOpin(m_rxPin)) {
5868
std::unique_ptr<circular_queue<uint8_t> > buffer(new circular_queue<uint8_t>((bufCapacity > 0) ? bufCapacity : 64));
5969
m_buffer = move(buffer);
6070
std::unique_ptr<circular_queue<uint32_t> > isrBuffer(new circular_queue<uint32_t>((isrBufCapacity > 0) ? isrBufCapacity : (sizeof(uint8_t) * 8 + 2) * bufCapacity));
@@ -64,14 +74,13 @@ void SoftwareSerial::begin(uint32_t baud, int8_t rxPin, int8_t txPin,
6474
pinMode(m_rxPin, INPUT_PULLUP);
6575
}
6676
}
67-
if (isValidGPIOpin(txPin)
77+
if (isValidGPIOpin(m_txPin)
6878
#ifdef ESP8266
69-
|| ((txPin == 16) && !m_oneWire)) {
79+
|| ((m_txPin == 16) && !m_oneWire)) {
7080
#else
7181
) {
7282
#endif
7383
m_txValid = true;
74-
m_txPin = txPin;
7584
if (!m_oneWire) {
7685
pinMode(m_txPin, OUTPUT);
7786
digitalWrite(m_txPin, !m_invert);

src/SoftwareSerial.h

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2828
#include <Stream.h>
2929
#include <functional>
3030

31-
/// If only one tx or rx wanted then use this as parameter for the unused pin.
32-
constexpr int SW_SERIAL_UNUSED_PIN = -1;
33-
3431
enum SoftwareSerialConfig {
3532
SWSERIAL_5N1 = 0,
3633
SWSERIAL_6N1,
@@ -47,11 +44,25 @@ enum SoftwareSerialConfig {
4744
class SoftwareSerial : public Stream {
4845
public:
4946
SoftwareSerial();
47+
/// Ctor to set defaults for pins.
48+
/// @param rxPin the GPIO pin used for RX
49+
/// @param txPin -1 for onewire protocol, GPIO pin used for twowire TX
50+
SoftwareSerial(int8_t rxPin, int8_t txPin = -1);
5051
SoftwareSerial(const SoftwareSerial&) = delete;
5152
SoftwareSerial& operator= (const SoftwareSerial&) = delete;
5253
virtual ~SoftwareSerial();
53-
void begin(uint32_t baud, int8_t rxPin, int8_t txPin = -1,
54-
SoftwareSerialConfig config = SWSERIAL_8N1,
54+
/// Configure the SoftwareSerial object for use.
55+
/// @param baud the TX/RX bitrate
56+
/// @param config sets databits, parity, and stop bit count
57+
/// @param rxPin -1 or default: either no RX pin, or keeps the rxPin set in the ctor
58+
/// @param txPin -1 or default: either no TX pin (onewire), or keeps the txPin set in the ctor
59+
/// @param invert true: uses invert line level logic
60+
/// @param bufCapacity the capacity for the received bytes buffer
61+
/// @param isrBufCapacity 0: derived from bufCapacity. The capacity of the internal asynchronous
62+
/// bit receive buffer, a suggested size is bufCapacity times the sum of
63+
/// start, data, parity and stop bit count.
64+
void begin(uint32_t baud, SoftwareSerialConfig config = SWSERIAL_8N1,
65+
int8_t rxPin = -1, int8_t txPin = -1,
5566
bool invert = false, int bufCapacity = 64, int isrBufCapacity = 0);
5667
uint32_t baudRate();
5768
/// Transmit control pin.
@@ -126,9 +137,9 @@ class SoftwareSerial : public Stream {
126137

127138
// Member variables
128139
bool m_oneWire;
129-
int8_t m_rxPin = SW_SERIAL_UNUSED_PIN;
130-
int8_t m_txPin = SW_SERIAL_UNUSED_PIN;
131-
int8_t m_txEnablePin = SW_SERIAL_UNUSED_PIN;
140+
int8_t m_rxPin = -1;
141+
int8_t m_txPin = -1;
142+
int8_t m_txEnablePin = -1;
132143
bool m_rxValid = false;
133144
bool m_rxEnabled = false;
134145
bool m_txValid = false;

0 commit comments

Comments
 (0)