diff options
author | Matthijs Kooijman <matthijs@stdin.nl> | 2013-06-04 11:22:19 +0200 |
---|---|---|
committer | Matthijs Kooijman <matthijs@stdin.nl> | 2015-01-26 17:03:25 +0100 |
commit | 7366268025c04aa15a94d88191c0a510302236b0 (patch) | |
tree | ead74f7d181ab2e79485c3a16d2950c9112a6269 /libraries/SoftwareSerial | |
parent | 51b8ed26752caacecb23c75a11c1e1f1b26dea5a (diff) |
Add SoftwareSerial::setRxIntMsk()
This moves the interrupt mask enabling / disabling code into a separate
method, so we can call it from multiple spots next.
Diffstat (limited to 'libraries/SoftwareSerial')
-rw-r--r-- | libraries/SoftwareSerial/SoftwareSerial.cpp | 15 | ||||
-rw-r--r-- | libraries/SoftwareSerial/SoftwareSerial.h | 1 |
2 files changed, 14 insertions, 2 deletions
diff --git a/libraries/SoftwareSerial/SoftwareSerial.cpp b/libraries/SoftwareSerial/SoftwareSerial.cpp index ac9e30b..8bf56e5 100644 --- a/libraries/SoftwareSerial/SoftwareSerial.cpp +++ b/libraries/SoftwareSerial/SoftwareSerial.cpp @@ -403,8 +403,11 @@ void SoftwareSerial::begin(long speed) // Set up RX interrupts, but only if we have a valid RX baud rate
if (_rx_delay_stopbit)
{
+ // Enable the PCINT for the entire port here, but never disable it
+ // (others might also need it, so we disable the interrupt by using
+ // the per-pin PCMSK register).
*digitalPinToPCICR(_receivePin) |= _BV(digitalPinToPCICRbit(_receivePin));
- *digitalPinToPCMSK(_receivePin) |= _BV(digitalPinToPCMSKbit(_receivePin));
+ setRxIntMsk(true);
tunedDelay(_tx_delay); // if we were low this establishes the end
}
@@ -416,10 +419,18 @@ void SoftwareSerial::begin(long speed) listen();
}
+void SoftwareSerial::setRxIntMsk(bool enable)
+{
+ if (enable)
+ *digitalPinToPCMSK(_receivePin) |= _BV(digitalPinToPCMSKbit(_receivePin));
+ else
+ *digitalPinToPCMSK(_receivePin) &= ~_BV(digitalPinToPCMSKbit(_receivePin));
+}
+
void SoftwareSerial::end()
{
if (_rx_delay_stopbit)
- *digitalPinToPCMSK(_receivePin) &= ~_BV(digitalPinToPCMSKbit(_receivePin));
+ setRxIntMsk(false);
}
diff --git a/libraries/SoftwareSerial/SoftwareSerial.h b/libraries/SoftwareSerial/SoftwareSerial.h index a6a60b5..31bd229 100644 --- a/libraries/SoftwareSerial/SoftwareSerial.h +++ b/libraries/SoftwareSerial/SoftwareSerial.h @@ -74,6 +74,7 @@ private: void tx_pin_write(uint8_t pin_state);
void setTX(uint8_t transmitPin);
void setRX(uint8_t receivePin);
+ void setRxIntMsk(bool enable);
// private static method for timing
static inline void tunedDelay(uint16_t delay);
|