Unverified Commit 230758b1 authored by Earle F. Philhower, III's avatar Earle F. Philhower, III Committed by GitHub

Add invert option to SWSerial (#563)

Thanks to @StefanKellerAC !
parent d7e02c6f
...@@ -54,7 +54,7 @@ public: ...@@ -54,7 +54,7 @@ public:
// Not to be called by users, only from the IRQ handler. In public so that the C-language IQR callback can access it // Not to be called by users, only from the IRQ handler. In public so that the C-language IQR callback can access it
void _handleIRQ(); void _handleIRQ();
private: protected:
bool _running = false; bool _running = false;
pin_size_t _tx, _rx; pin_size_t _tx, _rx;
int _baud; int _baud;
......
...@@ -26,12 +26,34 @@ class SoftwareSerial : public SerialPIO { ...@@ -26,12 +26,34 @@ class SoftwareSerial : public SerialPIO {
public: public:
// Note the rx/tx pins are swapped in PIO vs SWSerial // 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) { SoftwareSerial(pin_size_t rx, pin_size_t tx, bool invert = false) : SerialPIO(tx, rx) {
if (invert) { _invert = invert;
panic("SoftwareSerial inverted operation not supported\n"); }
~SoftwareSerial() {
if (_invert) {
gpio_set_outover(_tx, 0);
gpio_set_outover(_rx, 0);
} }
} }
virtual void begin(unsigned long baud = 115200) override {
begin(baud, SERIAL_8N1);
};
void begin(unsigned long baud, uint16_t config) override {
SerialPIO::begin(baud, config);
if (_invert) {
gpio_set_outover(_tx, GPIO_OVERRIDE_INVERT);
gpio_set_inover(_rx, GPIO_OVERRIDE_INVERT);
}
}
void listen() { /* noop */ } void listen() { /* noop */ }
bool isListening() { bool isListening() {
return true; return true;
} }
private:
bool _invert;
}; };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment