Skip to content

Commit 7366268

Browse files
Add SoftwareSerial::setRxIntMsk()
This moves the interrupt mask enabling / disabling code into a separate method, so we can call it from multiple spots next.
1 parent 51b8ed2 commit 7366268

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

libraries/SoftwareSerial/SoftwareSerial.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,11 @@ void SoftwareSerial::begin(long speed)
403403
// Set up RX interrupts, but only if we have a valid RX baud rate
404404
if (_rx_delay_stopbit)
405405
{
406+
// Enable the PCINT for the entire port here, but never disable it
407+
// (others might also need it, so we disable the interrupt by using
408+
// the per-pin PCMSK register).
406409
*digitalPinToPCICR(_receivePin) |= _BV(digitalPinToPCICRbit(_receivePin));
407-
*digitalPinToPCMSK(_receivePin) |= _BV(digitalPinToPCMSKbit(_receivePin));
410+
setRxIntMsk(true);
408411
tunedDelay(_tx_delay); // if we were low this establishes the end
409412
}
410413

@@ -416,10 +419,18 @@ void SoftwareSerial::begin(long speed)
416419
listen();
417420
}
418421

422+
void SoftwareSerial::setRxIntMsk(bool enable)
423+
{
424+
if (enable)
425+
*digitalPinToPCMSK(_receivePin) |= _BV(digitalPinToPCMSKbit(_receivePin));
426+
else
427+
*digitalPinToPCMSK(_receivePin) &= ~_BV(digitalPinToPCMSKbit(_receivePin));
428+
}
429+
419430
void SoftwareSerial::end()
420431
{
421432
if (_rx_delay_stopbit)
422-
*digitalPinToPCMSK(_receivePin) &= ~_BV(digitalPinToPCMSKbit(_receivePin));
433+
setRxIntMsk(false);
423434
}
424435

425436

libraries/SoftwareSerial/SoftwareSerial.h

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class SoftwareSerial : public Stream
7474
void tx_pin_write(uint8_t pin_state);
7575
void setTX(uint8_t transmitPin);
7676
void setRX(uint8_t receivePin);
77+
void setRxIntMsk(bool enable);
7778

7879
// private static method for timing
7980
static inline void tunedDelay(uint16_t delay);

0 commit comments

Comments
 (0)