Skip to content

Commit

Permalink
Remove restriction on free use of TX/RX. Fixes #168
Browse files Browse the repository at this point in the history
  • Loading branch information
dok-net committed Jun 11, 2020
1 parent 42c182f commit 5a84bc8
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 18 deletions.
10 changes: 9 additions & 1 deletion examples/loopback/loopback.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,20 @@
// Hardware Serial2 defaults to D4 (rx), D3 (tx).
// For local hardware loopback, connect D5 (rx) to D3 (tx), D6 (tx) to D4 (rx).

#if defined(ESP8266) && !defined(D5)
#ifndef D5
#if defined(ESP8266)
#define D5 (14)
#define D6 (12)
#define D7 (13)
#define D8 (15)
#define TX (1)
#elif defined(ESP32)
#define D5 (18)
#define D6 (19)
#define D7 (23)
#define D8 (5)
#define TX (1)
#endif
#endif

// Pick only one of HWLOOPBACK, HWSOURCESWSINK, or HWSOURCESINK
Expand Down
10 changes: 9 additions & 1 deletion examples/repeater/repeater.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@
// On ESP32:
// For software or hardware loopback, connect source rx to local D8 (tx), source tx to local D7 (rx).

#if defined(ESP8266) && !defined(D5)
#ifndef D5
#if defined(ESP8266)
#define D5 (14)
#define D6 (12)
#define D7 (13)
#define D8 (15)
#define TX (1)
#elif defined(ESP32)
#define D5 (18)
#define D6 (19)
#define D7 (23)
#define D8 (5)
#define TX (1)
#endif
#endif

#define HWLOOPBACK 1
Expand Down
11 changes: 10 additions & 1 deletion examples/swsertest/swsertest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@

#include <SoftwareSerial.h>

#if defined(ESP8266) && !defined(D5)
#ifndef D5
#if defined(ESP8266)
#define D5 (14)
#define D6 (12)
#define D7 (13)
#define D8 (15)
#define TX (1)
#elif defined(ESP32)
#define D5 (18)
#define D6 (19)
#define D7 (23)
#define D8 (5)
#define TX (1)
#endif
#endif

#ifdef ESP32
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "EspSoftwareSerial",
"version": "6.8.2",
"version": "6.8.3",
"keywords": [
"serial", "io", "softwareserial"
],
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=EspSoftwareSerial
version=6.8.2
version=6.8.3
author=Peter Lerup, Dirk Kaar
maintainer=Dirk Kaar <[email protected]>
sentence=Implementation of the Arduino software serial for ESP8266/ESP32.
Expand Down
14 changes: 2 additions & 12 deletions src/SoftwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,11 @@ bool SoftwareSerial::isValidGPIOpin(int8_t pin) {

bool SoftwareSerial::isValidRxGPIOpin(int8_t pin) {
return isValidGPIOpin(pin)
#if defined(ESP8266) || defined(ESP32)
&& (pin != 1)
#endif
#if defined(ESP8266)
&& (pin != 16)
#endif
;
}
bool SoftwareSerial::isValidTxGPIOpin(int8_t pin) {
return isValidGPIOpin(pin)
#if defined(ESP8266) || defined(ESP32)
&& (pin != 3)
#endif
;
}

void SoftwareSerial::begin(uint32_t baud, SoftwareSerialConfig config,
int8_t rxPin, int8_t txPin,
Expand Down Expand Up @@ -102,7 +92,7 @@ void SoftwareSerial::begin(uint32_t baud, SoftwareSerialConfig config,
pinMode(m_rxPin, INPUT_PULLUP);
}
}
if (isValidTxGPIOpin(m_txPin)) {
if (isValidGPIOpin(m_txPin)) {
m_txValid = true;
if (!m_oneWire) {
pinMode(m_txPin, OUTPUT);
Expand Down Expand Up @@ -130,7 +120,7 @@ uint32_t SoftwareSerial::baudRate() {
}

void SoftwareSerial::setTransmitEnablePin(int8_t txEnablePin) {
if (isValidTxGPIOpin(txEnablePin)) {
if (isValidGPIOpin(txEnablePin)) {
m_txEnableValid = true;
m_txEnablePin = txEnablePin;
pinMode(m_txEnablePin, OUTPUT);
Expand Down
1 change: 0 additions & 1 deletion src/SoftwareSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ class SoftwareSerial : public Stream {
uint32_t dutyCycle, uint32_t offCycle, bool withStopBit);
bool isValidGPIOpin(int8_t pin);
bool isValidRxGPIOpin(int8_t pin);
bool isValidTxGPIOpin(int8_t pin);
/* check m_rxValid that calling is safe */
void rxBits();
void rxBits(const uint32_t& isrCycle);
Expand Down

0 comments on commit 5a84bc8

Please sign in to comment.