Skip to content

Commit b5c27ae

Browse files
bigdinotechcalvinatintel
authored andcommitted
ATLEDGE-429 CurieSoftwareSerial fixes
-Creating a new CurieSoftwareSerial object no longer break functionality of previous ones. -Minor Cleanup
1 parent f9d1d5c commit b5c27ae

File tree

2 files changed

+20
-28
lines changed

2 files changed

+20
-28
lines changed

libraries/CurieSoftwareSerial/SoftwareSerial.cpp

+19-27
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ volatile uint8_t SoftwareSerial::_receive_buffer_head = 0;
4646
//
4747
// Globals
4848
//
49-
uint8_t txPin;
5049
uint8_t rxPin;
5150
uint16_t bitDelay;
5251
uint16_t rxIntraBitDelay;
@@ -95,8 +94,16 @@ bool SoftwareSerial::listen()
9594
bufferOverflow = false;
9695
_receive_buffer_head = _receive_buffer_tail = 0;
9796
active_object = this;
98-
99-
setRxIntMsk(true);
97+
rxPin = _receivePin;
98+
if(invertedLogic)
99+
{
100+
attachInterrupt(rxPin, recv, HIGH);
101+
}
102+
else
103+
{
104+
attachInterrupt(rxPin, recv, LOW);
105+
}
106+
100107
return true;
101108
}
102109

@@ -108,8 +115,8 @@ bool SoftwareSerial::stopListening()
108115
{
109116
if (active_object == this)
110117
{
111-
setRxIntMsk(false);
112118
active_object = NULL;
119+
detachInterrupt(rxPin);
113120
return true;
114121
}
115122
return false;
@@ -230,9 +237,9 @@ SoftwareSerial::SoftwareSerial(uint32_t receivePin, uint32_t transmitPin, bool i
230237
{
231238
invertedLogic = inverse_logic;
232239
setTX(transmitPin);
233-
txPin = transmitPin;
240+
_transmitPin = transmitPin;
234241
setRX(receivePin);
235-
rxPin = receivePin;
242+
_receivePin = receivePin;
236243
}
237244

238245
//
@@ -313,24 +320,9 @@ void SoftwareSerial::begin(long speed)
313320
pinMode(_DEBUG_PIN1, OUTPUT);
314321
pinMode(_DEBUG_PIN2, OUTPUT);
315322
#endif
316-
digitalRead(rxPin);
317-
if(invertedLogic)
318-
{
319-
attachInterrupt(rxPin, recv, HIGH);
320-
}
321-
else
322-
{
323-
attachInterrupt(rxPin, recv, LOW);
324-
}
325-
326323
listen();
327324
}
328325

329-
void SoftwareSerial::setRxIntMsk(bool enable)
330-
{
331-
332-
}
333-
334326
void SoftwareSerial::end()
335327
{
336328
stopListening();
@@ -380,29 +372,29 @@ size_t SoftwareSerial::write(uint8_t b)
380372

381373
// Write the start bit
382374
if (invertedLogic)
383-
digitalWrite(txPin, HIGH);
375+
digitalWrite(_transmitPin, HIGH);
384376
else
385-
digitalWrite(txPin, LOW);
377+
digitalWrite(_transmitPin, LOW);
386378

387379
delayTicks(delay);
388380

389381
// Write each of the 8 bits
390382
for (uint8_t i = 8; i > 0; --i)
391383
{
392384
if (b & 1) // choose bit
393-
digitalWrite(txPin, HIGH);
385+
digitalWrite(_transmitPin, HIGH);
394386
else
395-
digitalWrite(txPin, LOW);
387+
digitalWrite(_transmitPin, LOW);
396388

397389
delayTicks(delay);
398390
b >>= 1;
399391
}
400392

401393
// restore pin to natural state
402394
if (invertedLogic)
403-
digitalWrite(txPin, LOW);
395+
digitalWrite(_transmitPin, LOW);
404396
else
405-
digitalWrite(txPin, HIGH);
397+
digitalWrite(_transmitPin, HIGH);
406398

407399
interrupts();
408400
delayTicks(delay);

libraries/CurieSoftwareSerial/SoftwareSerial.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class SoftwareSerial : public Stream
3939
private:
4040
// per object data
4141
uint32_t _receivePin;
42+
uint32_t _transmitPin;
4243
uint32_t _receiveBitMask;
4344
volatile uint32_t *_receivePortRegister;
4445
uint32_t _transmitBitMask;
@@ -66,7 +67,6 @@ class SoftwareSerial : public Stream
6667
void tx_pin_write(uint32_t pin_state) __attribute__((__always_inline__));
6768
void setTX(uint8_t transmitPin);
6869
void setRX(uint8_t receivePin);
69-
void setRxIntMsk(bool enable);
7070

7171
// Return num - sub, or 1 if the result would be < 1
7272
static uint16_t subtract_cap(uint16_t num, uint16_t sub);

0 commit comments

Comments
 (0)