Skip to content

Commit 274dde6

Browse files
committed
Add end() method
1 parent 82920c0 commit 274dde6

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

libraries/SoftwareSerial/src/SoftwareSerial.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ SoftwareSerial::SoftwareSerial(uint8_t rxPin, uint8_t txPin, bool invertLogic)
6666
// Destructor
6767
SoftwareSerial::~SoftwareSerial()
6868
{
69-
// Todo: call an "end" function that will detach the interrupt before removing the object
70-
// (otherwise rx interrupts will try to access an invalid object)
69+
end(); // End detaches the interrupt which removes the reference to this object that is stored in the GPIO core
7170
}
7271

7372
void SoftwareSerial::begin(uint32_t baudRate)
@@ -115,6 +114,11 @@ void SoftwareSerial::begin(uint32_t baudRate, HardwareSerial_Config_e SSconfig)
115114
ap3_serial_handle = this; // right now this is needed for the cmpr7 isr.
116115
}
117116

117+
void SoftwareSerial::end(void){
118+
detachInterrupt(_rxPin);
119+
// todo: anything else?
120+
}
121+
118122
int SoftwareSerial::available()
119123
{
120124
return (rxBufferHead + AP3_SS_BUFFER_SIZE - rxBufferTail) % AP3_SS_BUFFER_SIZE;

libraries/SoftwareSerial/src/SoftwareSerial.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class SoftwareSerial
4848

4949
void begin(uint32_t baudRate);
5050
void begin(uint32_t baudRate, HardwareSerial_Config_e SSconfig);
51+
void end(void);
5152

5253
ap3_err_t softwareserialSetConfig(HardwareSerial_Config_e SSconfig);
5354
int available();

0 commit comments

Comments
 (0)