diff options
author | Matthijs Kooijman <matthijs@stdin.nl> | 2014-04-23 19:13:58 +0200 |
---|---|---|
committer | Matthijs Kooijman <matthijs@stdin.nl> | 2015-01-26 17:03:25 +0100 |
commit | 5f2f0ef4c8f44aefe5c715abf28f9eda32fcf67e (patch) | |
tree | 46733854d52e1cfd96a897ce0045e2aa4d7f489e /libraries/SoftwareSerial/SoftwareSerial.cpp | |
parent | b6ba4b6aab4f5886866bd125a2e09940892dcac6 (diff) |
Optimize SoftwareSerial::setRxIntMsk()
This precalculates the mask register and value, making setRxIntMask
considerably less complicated. Right now, this is not a big deal, but
simplifying it allows using it inside the ISR next.
Diffstat (limited to 'libraries/SoftwareSerial/SoftwareSerial.cpp')
-rw-r--r-- | libraries/SoftwareSerial/SoftwareSerial.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/libraries/SoftwareSerial/SoftwareSerial.cpp b/libraries/SoftwareSerial/SoftwareSerial.cpp index 42f796b..bee1107 100644 --- a/libraries/SoftwareSerial/SoftwareSerial.cpp +++ b/libraries/SoftwareSerial/SoftwareSerial.cpp @@ -403,6 +403,11 @@ void SoftwareSerial::begin(long speed) // (others might also need it, so we disable the interrupt by using
// the per-pin PCMSK register).
*digitalPinToPCICR(_receivePin) |= _BV(digitalPinToPCICRbit(_receivePin));
+ // Precalculate the pcint mask register and value, so setRxIntMask
+ // can be used inside the ISR without costing too much time.
+ _pcint_maskreg = digitalPinToPCMSK(_receivePin);
+ _pcint_maskvalue = _BV(digitalPinToPCMSKbit(_receivePin));
+
tunedDelay(_tx_delay); // if we were low this establishes the end
}
@@ -417,9 +422,9 @@ void SoftwareSerial::begin(long speed) void SoftwareSerial::setRxIntMsk(bool enable)
{
if (enable)
- *digitalPinToPCMSK(_receivePin) |= _BV(digitalPinToPCMSKbit(_receivePin));
+ *_pcint_maskreg |= _pcint_maskvalue;
else
- *digitalPinToPCMSK(_receivePin) &= ~_BV(digitalPinToPCMSKbit(_receivePin));
+ *_pcint_maskreg &= ~_pcint_maskvalue;
}
void SoftwareSerial::end()
|