SWSerial wasn't even building due to a typo in the header, and SerialPIO needs to set the OE-invert flag after PIO initialization for transmit. Fixes #2419
53 lines
1.5 KiB
C++
53 lines
1.5 KiB
C++
/*
|
|
SoftwareSerial wrapper for SerialPIO
|
|
|
|
Copyright (c) 2022 Earle F. Philhower, III <earlephilhower@yahoo.com>
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with this library; if not, write to the Free Software
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "SerialPIO.h"
|
|
|
|
class SoftwareSerial : public SerialPIO {
|
|
public:
|
|
// Note the rx/tx pins are swapped in PIO vs SWSerial
|
|
SoftwareSerial(pin_size_t rx, pin_size_t tx, bool invert = false) : SerialPIO(tx, rx) {
|
|
_invert = invert;
|
|
}
|
|
|
|
~SoftwareSerial() {
|
|
}
|
|
|
|
virtual void begin(unsigned long baud = 115200) override {
|
|
begin(baud, SERIAL_8N1);
|
|
};
|
|
|
|
void begin(unsigned long baud, uint16_t config) override {
|
|
setInvertTX(_invert);
|
|
setInvertRX(_invert);
|
|
SerialPIO::begin(baud, config);
|
|
}
|
|
|
|
void listen() { /* noop */ }
|
|
|
|
bool isListening() {
|
|
return true;
|
|
}
|
|
|
|
private:
|
|
bool _invert;
|
|
};
|