Skip to content

Commit

Permalink
Some renaming after review feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
dok-net committed Mar 4, 2023
1 parent ffcec7d commit 156a2dd
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 60 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ Except at high bitrates, depending on other ongoing activity,
interrupts in particular, this software serial adapter
supports full duplex receive and send. At high bitrates (115200bps)
send bit timing can be improved at the expense of blocking concurrent
full duplex receives, with the `SoftwareSerial::enableIntTx(false)` function call.
full duplex receives, with the
`EspSoftwareSerial::UART::enableIntTx(false)` function call.

The same functionality is given as the corresponding AVR library but
several instances can be active at the same time. Speed up to 115200 baud
Expand All @@ -33,7 +34,7 @@ This library supports ESP8266, ESP32, ESP32-S2 and ESP32-C3 devices.

The memory footprint can be optimized to just fit the amount of expected
incoming asynchronous data.
For this, the `SoftwareSerial` constructor provides two arguments. First, the
For this, the `EspSoftwareSerial::UART` constructor provides two arguments. First, the
octet buffer capacity for assembled received octets can be set. Read calls are
satisfied from this buffer, freeing it in return.
Second, the signal edge detection buffer of 32bit fields can be resized.
Expand Down Expand Up @@ -75,8 +76,8 @@ chances are that you can reduce the `isrBufCapacity` footprint without losing da
and each time you call read to fetch from the octet buffer, you reduce the
need for space there.

## SoftwareSerialConfig and parity
The configuration of the data stream is done via a `SoftwareSerialConfig`
## EspSoftwareSerial::Config and parity
The configuration of the data stream is done via a `EspSoftwareSerial::Config`
argument to `begin()`. Word lengths can be set to between 5 and 8 bits, parity
can be N(one), O(dd) or E(ven) and 1 or 2 stop bits can be used. The default is
`SWSERIAL_8N1` using 8 bits, no parity and 1 stop bit but any combination can
Expand All @@ -92,15 +93,15 @@ individually set in each call to `write()`.

This allows a simple implementation of protocols where the parity bit is used to
distinguish between data and addresses/commands ("9-bit" protocols). First set
up SoftwareSerial with parity mode SPACE, e.g. `SWSERIAL_8S1`. This will add a
up EspSoftwareSerial::UART with parity mode SPACE, e.g. `SWSERIAL_8S1`. This will add a
parity bit to every byte sent, setting it to logical zero (SPACE parity).

To detect incoming bytes with the parity bit set (MARK parity), use the
`readParity()` function. To send a byte with the parity bit set, just add
`MARK` as the second argument when writing, e.g. `write(ch, SWSERIAL_PARITY_MARK)`.

## Checking for correct pin selection / configuration
In general, most pins on the ESP8266 and ESP32 devices can be used by SoftwareSerial,
In general, most pins on the ESP8266 and ESP32 devices can be used by EspSoftwareSerial,
however each device has a number of pins that have special functions or require careful
handling to prevent undesirable situations, for example they are connected to the
on-board SPI flash memory or they are used to determine boot and programming modes
Expand All @@ -112,7 +113,7 @@ in sections 2.2 (Pin Descriptions) and 2.4 (Strapping pins). There is a discussi
dedicated to the use of GPIO12 in this
[note about GPIO12](https://github.com/espressif/esp-idf/tree/release/v3.2/examples/storage/sd_card#note-about-gpio12).
Refer to the `isValidPin()`, `isValidRxPin()` and `isValidTxPin()`
functions in the `SoftwareSerialGpioCapabilities` class for the GPIO restrictions
functions in the `EspSoftwareSerial::GpioCapabilities` class for the GPIO restrictions
enforced by this library by default.

The easiest and safest method is to test the object returned at runtime, to see if
Expand All @@ -124,15 +125,15 @@ it is valid. For example:
#define MYPORT_TX 12
#define MYPORT_RX 13
SoftwareSerial myPort;
EspSoftwareSerial::UART myPort;
[...]
Serial.begin(115200); // Standard hardware serial port
myPort.begin(38400, SWSERIAL_8N1, MYPORT_RX, MYPORT_TX, false);
if (!myPort) { // If the object did not initialize, then its configuration is invalid
Serial.println("Invalid SoftwareSerial pin configuration, check config");
Serial.println("Invalid EspSoftwareSerial pin configuration, check config");
while (1) { // Don't continue with invalid configuration
delay (1000);
}
Expand All @@ -155,7 +156,7 @@ The responsible maintainer of the esp8266 repository has kindly shared the
following command line instructions to use, if one wishes to manually
update EspSoftwareSerial to a newer release than pulled in via the ESP8266 Arduino BSP:

To update esp8266/arduino SoftwareSerial submodule to lastest master:
To update esp8266/arduino EspSoftwareSerial submodule to lastest master:

Clean it (optional):
```shell
Expand Down
6 changes: 3 additions & 3 deletions examples/bitpattern/bitpattern.ino
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
#endif
#endif

SoftwareSerial::UART swSer;
EspSoftwareSerial::UART swSer;
#ifdef ESP8266
auto logSer = SoftwareSerial::UART(-1, TX);
auto logSer = EspSoftwareSerial::UART(-1, TX);
auto hwSer = Serial;
#else
auto logSer = Serial;
Expand All @@ -39,7 +39,7 @@ void setup() {
#endif
logSer.begin(115200);
logSer.println(PSTR("\nOne Wire Half Duplex Bitpattern and Datarate Test"));
swSer.begin(TESTBPS, SoftwareSerial::SERIAL_8N1, D6, D5);
swSer.begin(TESTBPS, EspSoftwareSerial::SERIAL_8N1, D6, D5);
swSer.enableIntTx(true);
logSer.println(PSTR("Tx on swSer"));
}
Expand Down
28 changes: 14 additions & 14 deletions examples/loopback/loopback.ino
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#include <SoftwareSerial.h>

// On ESP8266:
// Local SoftwareSerial loopback, connect D5 (rx) and D6 (tx).
// Local EspSoftwareSerial loopback, connect D5 (rx) and D6 (tx).
// For local hardware loopback, connect D5 to D8 (tx), D6 to D7 (rx).
// For hardware send/sink, connect D7 (rx) and D8 (tx).
// Hint: The logger is run at 9600bps such that enableIntTx(true) can remain unchanged. Blocking
// interrupts severely impacts the ability of the SoftwareSerial devices to operate concurrently
// interrupts severely impacts the ability of the EspSoftwareSerial devices to operate concurrently
// and/or in duplex mode.
// Operating in software serial full duplex mode, runs at 19200bps and few errors (~2.5%).
// Operating in software serial half duplex mode (both loopback and repeater),
// runs at 57600bps with nearly no errors.
// Operating loopback in full duplex, and repeater in half duplex, runs at 38400bps with nearly no errors.
// On ESP32:
// For SoftwareSerial or hardware send/sink, connect D5 (rx) and D6 (tx).
// For EspSoftwareSerial or hardware send/sink, connect D5 (rx) and D6 (tx).
// Hardware Serial2 defaults to D4 (rx), D3 (tx).
// For local hardware loopback, connect D5 (rx) to D3 (tx), D6 (tx) to D4 (rx).

Expand Down Expand Up @@ -47,10 +47,10 @@ constexpr int IUTBITRATE = 19200;
#endif

#if defined(ESP8266)
constexpr SoftwareSerial::Config swSerialConfig = SoftwareSerial::SERIAL_8E1;
constexpr EspSoftwareSerial::Config swSerialConfig = EspSoftwareSerial::SERIAL_8E1;
constexpr SerialConfig hwSerialConfig = ::SERIAL_8E1;
#elif defined(ESP32)
constexpr SoftwareSerial::Config swSerialConfig = SoftwareSerial::SERIAL_8E1;
constexpr EspSoftwareSerial::Config swSerialConfig = EspSoftwareSerial::SERIAL_8E1;
constexpr uint32_t hwSerialConfig = ::SERIAL_8E1;
#else
constexpr unsigned swSerialConfig = 3;
Expand All @@ -72,27 +72,27 @@ constexpr int ReportInterval = IUTBITRATE / 8;
#if defined(ESP8266)
#if defined(HWLOOPBACK) || defined(HWSOURCESWSINK)
HardwareSerial& hwSerial(Serial);
SoftwareSerial::UART serialIUT;
SoftwareSerial::UART logger;
EspSoftwareSerial::UART serialIUT;
EspSoftwareSerial::UART logger;
#elif defined(HWSOURCESINK)
HardwareSerial& serialIUT(Serial);
SoftwareSerial::UART logger;
EspSoftwareSerial::UART logger;
#else
SoftwareSerial::UART serialIUT;
EspSoftwareSerial::UART serialIUT;
HardwareSerial& logger(Serial);
#endif
#elif defined(ESP32)
#if defined(HWLOOPBACK) || defined (HWSOURCESWSINK)
HardwareSerial& hwSerial(Serial2);
SoftwareSerial::UART serialIUT;
EspSoftwareSerial::UART serialIUT;
#elif defined(HWSOURCESINK)
HardwareSerial& serialIUT(Serial2);
#else
SoftwareSerial::UART serialIUT;
EspSoftwareSerial::UART serialIUT;
#endif
HardwareSerial& logger(Serial);
#else
SoftwareSerial::UART serialIUT(14, 12);
EspSoftwareSerial::UART serialIUT(14, 12);
HardwareSerial& logger(Serial);
#endif

Expand All @@ -102,7 +102,7 @@ void setup() {
Serial.begin(IUTBITRATE, hwSerialConfig, ::SERIAL_FULL, 1, invert);
Serial.swap();
Serial.setRxBufferSize(2 * BLOCKSIZE);
logger.begin(9600, SoftwareSerial::SERIAL_8N1, -1, TX);
logger.begin(9600, EspSoftwareSerial::SERIAL_8N1, -1, TX);
#else
logger.begin(9600);
#endif
Expand Down Expand Up @@ -134,7 +134,7 @@ void setup() {
logger.begin(9600);
#endif

logger.println(PSTR("Loopback example for EspSoftwareSerial"));
logger.println(PSTR("Loopback example for EspEspSoftwareSerial"));

start = micros();
txCount = 0;
Expand Down
12 changes: 6 additions & 6 deletions examples/onewiretest/onewiretest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
#endif
#endif

SoftwareSerial::UART swSer1;
SoftwareSerial::UART swSer2;
EspSoftwareSerial::UART swSer1;
EspSoftwareSerial::UART swSer2;

void setup() {
delay(2000);
Serial.begin(115200);
Serial.println(PSTR("\nOne Wire Half Duplex Serial Tester"));
swSer1.begin(115200, SoftwareSerial::SERIAL_8N1, D6, D6, false, 256);
swSer1.begin(115200, EspSoftwareSerial::SERIAL_8N1, D6, D6, false, 256);
// high speed half duplex, turn off interrupts during tx
swSer1.enableIntTx(false);
swSer2.begin(115200, SoftwareSerial::SERIAL_8N1, D5, D5, false, 256);
swSer2.begin(115200, EspSoftwareSerial::SERIAL_8N1, D5, D5, false, 256);
// high speed half duplex, turn off interrupts during tx
swSer2.enableIntTx(false);
}
Expand All @@ -36,7 +36,7 @@ void loop() {

}

void checkSwSerial(SoftwareSerial::UART* ss) {
void checkSwSerial(EspSoftwareSerial::UART* ss) {
byte ch;
while (!Serial.available());
ss->enableTx(true);
Expand All @@ -45,7 +45,7 @@ void checkSwSerial(SoftwareSerial::UART* ss) {
ss->write(ch);
}
ss->enableTx(false);
// wait 1 second for the reply from SoftwareSerial if any
// wait 1 second for the reply from EspSoftwareSerial if any
delay(1000);
if (ss->available()) {
Serial.print(PSTR("\nResult:"));
Expand Down
4 changes: 2 additions & 2 deletions examples/onreceive/onreceive.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define BAUD_RATE 115200
#define MAX_FRAMEBITS (1 + 8 + 1 + 2)

SoftwareSerial::UART testSerial;
EspSoftwareSerial::UART testSerial;

// Becomes set from ISR / IRQ callback function.
std::atomic<bool> rxPending(false);
Expand All @@ -30,7 +30,7 @@ void setup() {
Serial.begin(115200);
Serial.setDebugOutput(false);
Serial.swap();
testSerial.begin(BAUD_RATE, SoftwareSerial::SERIAL_8N1, RX, TX);
testSerial.begin(BAUD_RATE, EspSoftwareSerial::SERIAL_8N1, RX, TX);
// Only half duplex this way, but reliable TX timings for high bps
testSerial.enableIntTx(false);
testSerial.onReceive(receiveHandler);
Expand Down
20 changes: 10 additions & 10 deletions examples/repeater/repeater.ino
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include <SoftwareSerial.h>

// On ESP8266:
// SoftwareSerial loopback for remote source (loopback.ino), or hardware loopback.
// EspSoftwareSerial loopback for remote source (loopback.ino), or hardware loopback.
// Connect source D5 (rx) to local D8 (tx), source D6 (tx) to local D7 (rx).
// Hint: The logger is run at 9600bps such that enableIntTx(true) can remain unchanged. Blocking
// interrupts severely impacts the ability of the SoftwareSerial devices to operate concurrently
// interrupts severely impacts the ability of the EspSoftwareSerial devices to operate concurrently
// and/or in duplex mode.
// On ESP32:
// For software or hardware loopback, connect source rx to local D8 (tx), source tx to local D7 (rx).
Expand Down Expand Up @@ -37,10 +37,10 @@ constexpr int IUTBITRATE = 19200;
#endif

#if defined(ESP8266)
constexpr SoftwareSerial::Config swSerialConfig = SoftwareSerial::SERIAL_8E1;
constexpr EspSoftwareSerial::Config swSerialConfig = EspSoftwareSerial::SERIAL_8E1;
constexpr SerialConfig hwSerialConfig = ::SERIAL_8E1;
#elif defined(ESP32)
constexpr SoftwareSerial::Config swSerialConfig = SoftwareSerial::SERIAL_8E1;
constexpr EspSoftwareSerial::Config swSerialConfig = EspSoftwareSerial::SERIAL_8E1;
constexpr uint32_t hwSerialConfig = ::SERIAL_8E1;
#else
constexpr unsigned swSerialConfig = 3;
Expand All @@ -60,20 +60,20 @@ constexpr int ReportInterval = IUTBITRATE / 8;
#if defined(ESP8266)
#if defined(HWLOOPBACK)
HardwareSerial& repeater(Serial);
SoftwareSerial::UART logger;
EspSoftwareSerial::UART logger;
#else
SoftwareSerial::UART repeater;
EspSoftwareSerial::UART repeater;
HardwareSerial& logger(Serial);
#endif
#elif defined(ESP32)
#if defined(HWLOOPBACK)
HardwareSerial& repeater(Serial2);
#else
SoftwareSerial::UART repeater;
EspSoftwareSerial::UART repeater;
#endif
HardwareSerial& logger(Serial);
#else
SoftwareSerial::UART repeater(14, 12);
EspSoftwareSerial::UART repeater(14, 12);
HardwareSerial& logger(Serial);
#endif

Expand All @@ -83,7 +83,7 @@ void setup() {
repeater.begin(IUTBITRATE, hwSerialConfig, ::SERIAL_FULL, 1, invert);
repeater.swap();
repeater.setRxBufferSize(2 * BLOCKSIZE);
logger.begin(9600, SoftwareSerial::SERIAL_8N1, -1, TX);
logger.begin(9600, EspSoftwareSerial::SERIAL_8N1, -1, TX);
#else
repeater.begin(IUTBITRATE, swSerialConfig, D7, D8, invert, 4 * BLOCKSIZE);
#ifdef HALFDUPLEX
Expand All @@ -107,7 +107,7 @@ void setup() {
logger.begin(9600);
#endif

logger.println(PSTR("Repeater example for EspSoftwareSerial"));
logger.println(PSTR("Repeater example for EspEspSoftwareSerial"));
start = micros();
rxCount = 0;
seqErrors = 0;
Expand Down
10 changes: 5 additions & 5 deletions examples/swsertest/swsertest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@

#ifndef SWAPSERIAL
auto& usbSerial = Serial;
SoftwareSerial::UART testSerial;
EspSoftwareSerial::UART testSerial;
#else
SoftwareSerial::UART usbSerial;
EspSoftwareSerial::UART usbSerial;
auto& testSerial = Serial;
#endif

Expand All @@ -48,15 +48,15 @@ void setup() {
usbSerial.begin(115200);
// Important: the buffer size optimizations here, in particular the isrBufSize (11) that is only sufficiently
// large to hold a single word (up to start - 8 data - parity - stop), are on the basis that any char written
// to the loopback SoftwareSerial adapter gets read before another write is performed.
// to the loopback EspSoftwareSerial adapter gets read before another write is performed.
// Block writes with a size greater than 1 would usually fail. Do not copy this into your own project without
// reading the documentation.
testSerial.begin(BAUD_RATE, SoftwareSerial::SERIAL_8N1, D7, D8, false, 95, 11);
testSerial.begin(BAUD_RATE, EspSoftwareSerial::SERIAL_8N1, D7, D8, false, 95, 11);
#else
testSerial.begin(115200);
testSerial.setDebugOutput(false);
testSerial.swap();
usbSerial.begin(BAUD_RATE, SoftwareSerial::SERIAL_8N1, RX, TX, false, 95);
usbSerial.begin(BAUD_RATE, EspSoftwareSerial::SERIAL_8N1, RX, TX, false, 95);
#endif

usbSerial.println(PSTR("\nSoftware serial test started"));
Expand Down
3 changes: 2 additions & 1 deletion keywords.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#######################################
# Syntax Coloring Map for SoftwareSerial
# Syntax Coloring Map for EspSoftwareSerial
# (esp8266)
#######################################

#######################################
# Datatypes (KEYWORD1)
#######################################

EspSoftwareSerial KEYWORD1
SoftwareSerial KEYWORD1

#######################################
Expand Down
2 changes: 1 addition & 1 deletion src/SoftwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "SoftwareSerial.h"
#include <Arduino.h>

using namespace SoftwareSerial;
using namespace EspSoftwareSerial;

constexpr bool GpioCapabilities::isValidPin(int8_t pin) {
#if defined(ESP8266)
Expand Down
Loading

0 comments on commit 156a2dd

Please sign in to comment.