diff --git a/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino b/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino index f88e58acfc..b386edef65 100644 --- a/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino +++ b/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino @@ -75,9 +75,3 @@ void loop() { // blank line to separate data from the two ports: Serial.println(); } - - - - - - diff --git a/libraries/SoftwareSerial/src/SoftwareSerial.cpp b/libraries/SoftwareSerial/src/SoftwareSerial.cpp index 481218e406..09f1e65a77 100644 --- a/libraries/SoftwareSerial/src/SoftwareSerial.cpp +++ b/libraries/SoftwareSerial/src/SoftwareSerial.cpp @@ -34,17 +34,7 @@ // // Includes // -#include -#include - -#include -#include - -#include #include "SoftwareSerial.h" -#include -#include -#include #define OVERSAMPLE 3 // in RX, Timer will generate interruption OVERSAMPLE time during a bit. Thus OVERSAMPLE ticks in a bit. (interrupt not synchonized with edge). @@ -155,19 +145,16 @@ void SoftwareSerial::setSpeed(uint32_t speed) // one and returns true if it replaces another bool SoftwareSerial::listen() { - if (_receivePin >= 0) { + if (active_listener != this) { // wait for any transmit to complete as we may change speed - while (active_out) - ; - if (active_listener) { - active_listener->stopListening(); - } + while (active_out); + active_listener->stopListening(); rx_tick_cnt = 1; // 1 : next interrupt will decrease rx_tick_cnt to 0 which means RX pin level will be considered. rx_bit_cnt = -1; // rx_bit_cnt = -1 : waiting for start bit setSpeed(_speed); active_listener = this; if (!_half_duplex) { - active_in = this; + active_in = this; } return true; } @@ -179,8 +166,7 @@ bool SoftwareSerial::stopListening() { if (active_listener == this) { // wait for any output to complete - while (active_out) - ; + while (active_out); if (_half_duplex) { setRXTX(false); } @@ -205,9 +191,7 @@ inline void SoftwareSerial::setTX() inline void SoftwareSerial::setRX() { - if (_receivePin > 0) { - pinMode(_receivePin, _inverse_logic ? INPUT_PULLDOWN : INPUT_PULLUP); // pullup for normal logic! - } + pinMode(_receivePin, _inverse_logic ? INPUT_PULLDOWN : INPUT_PULLUP); // pullup for normal logic! } inline void SoftwareSerial::setRXTX(bool input) @@ -308,6 +292,7 @@ inline void SoftwareSerial::recv() /* static */ inline void SoftwareSerial::handleInterrupt(HardwareTimer *timer) { + UNUSED(timer); if (active_in) { active_in->recv(); } @@ -333,9 +318,13 @@ SoftwareSerial::SoftwareSerial(uint16_t receivePin, uint16_t transmitPin, bool i _receive_buffer_tail(0), _receive_buffer_head(0) { + if ((receivePin < NUM_DIGITAL_PINS) || (transmitPin < NUM_DIGITAL_PINS)) { /* Enable GPIO clock for tx and rx pin*/ set_GPIO_Port_Clock(STM_PORT(digitalPinToPinName(transmitPin))); set_GPIO_Port_Clock(STM_PORT(digitalPinToPinName(receivePin))); + } else { + _Error_Handler("ERROR: invalid pin number\n", -1); + } } // diff --git a/libraries/SoftwareSerial/src/SoftwareSerial.h b/libraries/SoftwareSerial/src/SoftwareSerial.h index fcd91342af..7ec0aee188 100644 --- a/libraries/SoftwareSerial/src/SoftwareSerial.h +++ b/libraries/SoftwareSerial/src/SoftwareSerial.h @@ -34,10 +34,6 @@ #define SOFTWARESERIAL_H #include -#include -#include -#include -#include /****************************************************************************** * Definitions @@ -125,13 +121,4 @@ class SoftwareSerial : public Stream { using Print::write; }; -// Arduino 0012 workaround -#undef int -#undef char -#undef long -#undef byte -#undef float -#undef abs -#undef round - #endif // SOFTWARESERIAL_H