diff --git a/README.md b/README.md index 013b653..f0f812b 100644 --- a/README.md +++ b/README.md @@ -79,9 +79,10 @@ 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 be used, e.g. ``SWSERIAL_7E2``. If using EVEN or ODD parity, any parity errors -can be detected with the ``peekParityError()`` function. Note that parity -checking must be done before ``read()``, as the parity information is removed -from the buffer when reading the corresponding byte. +can be detected with the ``readParity()`` and ``parityEven()`` or ``parityOdd()`` +functions respectively. Note that the result of ``readParity()`` always applies +to the preceding ``read()`` or ``peek()`` call, and is undefined if they report +no data or an error. To allow flexible 9-bit and data/addressing protocols, the additional parity modes MARK and SPACE are also available. Furthermore, the parity mode can be @@ -93,8 +94,8 @@ up SoftwareSerial 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 -``peekParityError()`` function. To send a byte with the parity bit set, just add -``MARK`` as the second argument when writing, e.g. ``write(ch, MARK)``. +``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)``. ## Using and updating EspSoftwareSerial in the esp8266com/esp8266 Arduino build environment diff --git a/library.json b/library.json index 5b92632..1a8e310 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "EspSoftwareSerial", - "version": "6.12.0", + "version": "6.12.1", "keywords": [ "serial", "io", "softwareserial" ], diff --git a/library.properties b/library.properties index 635be59..f35c2fd 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=EspSoftwareSerial -version=6.12.0 +version=6.12.1 author=Dirk Kaar, Peter Lerup maintainer=Dirk Kaar sentence=Implementation of the Arduino software serial for ESP8266/ESP32. diff --git a/src/SoftwareSerial.cpp b/src/SoftwareSerial.cpp index f42cdd5..6c3ec85 100644 --- a/src/SoftwareSerial.cpp +++ b/src/SoftwareSerial.cpp @@ -421,7 +421,6 @@ int SoftwareSerial::peek() { } void SoftwareSerial::rxBits() { - int isrAvail = m_isrBuffer->available(); #ifdef ESP8266 if (m_isrOverflow.load()) { m_overflow = true; @@ -433,10 +432,11 @@ void SoftwareSerial::rxBits() { } #endif + m_isrBuffer->for_each([this](const uint32_t& isrCycle) { rxBits(isrCycle); }); + // stop bit can go undetected if leading data bits are at same level // and there was also no next start bit yet, so one byte may be pending. - // low-cost check first - if (!isrAvail && m_rxCurBit >= -1 && m_rxCurBit < m_pduBits - m_stopBits) { + if (m_rxCurBit >= -1 && m_rxCurBit < m_pduBits - m_stopBits) { uint32_t detectionCycles = (m_pduBits - m_stopBits - m_rxCurBit) * m_bitCycles; if (ESP.getCycleCount() - m_isrLastCycle > detectionCycles) { // Produce faux stop bit level, prevents start bit maldetection @@ -444,8 +444,6 @@ void SoftwareSerial::rxBits() { rxBits(((m_isrLastCycle + detectionCycles) | 1) ^ m_invert); } } - - m_isrBuffer->for_each([this](const uint32_t& isrCycle) { rxBits(isrCycle); }); } void SoftwareSerial::rxBits(const uint32_t& isrCycle) { diff --git a/src/SoftwareSerial.h b/src/SoftwareSerial.h index 675912e..1a2490d 100644 --- a/src/SoftwareSerial.h +++ b/src/SoftwareSerial.h @@ -138,7 +138,7 @@ class SoftwareSerial : public Stream { } int peek() override; int read() override; - /// @returns The verbatim parity bit associated with the last read() or peek() call + /// @returns The verbatim parity bit associated with the last successful read() or peek() call bool readParity() { return m_lastReadParity;