-
-
Notifications
You must be signed in to change notification settings - Fork 283
Jira-429 CurieSoftwareSerial fixes #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,6 @@ volatile uint8_t SoftwareSerial::_receive_buffer_head = 0; | |
// | ||
// Globals | ||
// | ||
uint8_t txPin; | ||
uint8_t rxPin; | ||
uint16_t bitDelay; | ||
uint16_t rxIntraBitDelay; | ||
|
@@ -95,8 +94,16 @@ bool SoftwareSerial::listen() | |
bufferOverflow = false; | ||
_receive_buffer_head = _receive_buffer_tail = 0; | ||
active_object = this; | ||
|
||
setRxIntMsk(true); | ||
rxPin = _receivePin; | ||
if(invertedLogic) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why removing setRxIntMsk? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removing since it is unused. |
||
attachInterrupt(rxPin, recv, HIGH); | ||
} | ||
else | ||
{ | ||
attachInterrupt(rxPin, recv, LOW); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
|
@@ -108,8 +115,8 @@ bool SoftwareSerial::stopListening() | |
{ | ||
if (active_object == this) | ||
{ | ||
setRxIntMsk(false); | ||
active_object = NULL; | ||
detachInterrupt(rxPin); | ||
return true; | ||
} | ||
return false; | ||
|
@@ -230,9 +237,9 @@ SoftwareSerial::SoftwareSerial(uint32_t receivePin, uint32_t transmitPin, bool i | |
{ | ||
invertedLogic = inverse_logic; | ||
setTX(transmitPin); | ||
txPin = transmitPin; | ||
_transmitPin = transmitPin; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you use _transmitPin instead of txPin? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. txPin was originally a global variable in the cpp file |
||
setRX(receivePin); | ||
rxPin = receivePin; | ||
_receivePin = receivePin; | ||
} | ||
|
||
// | ||
|
@@ -313,24 +320,9 @@ void SoftwareSerial::begin(long speed) | |
pinMode(_DEBUG_PIN1, OUTPUT); | ||
pinMode(_DEBUG_PIN2, OUTPUT); | ||
#endif | ||
digitalRead(rxPin); | ||
if(invertedLogic) | ||
{ | ||
attachInterrupt(rxPin, recv, HIGH); | ||
} | ||
else | ||
{ | ||
attachInterrupt(rxPin, recv, LOW); | ||
} | ||
|
||
listen(); | ||
} | ||
|
||
void SoftwareSerial::setRxIntMsk(bool enable) | ||
{ | ||
|
||
} | ||
|
||
void SoftwareSerial::end() | ||
{ | ||
stopListening(); | ||
|
@@ -380,29 +372,29 @@ size_t SoftwareSerial::write(uint8_t b) | |
|
||
// Write the start bit | ||
if (invertedLogic) | ||
digitalWrite(txPin, HIGH); | ||
digitalWrite(_transmitPin, HIGH); | ||
else | ||
digitalWrite(txPin, LOW); | ||
digitalWrite(_transmitPin, LOW); | ||
|
||
delayTicks(delay); | ||
|
||
// Write each of the 8 bits | ||
for (uint8_t i = 8; i > 0; --i) | ||
{ | ||
if (b & 1) // choose bit | ||
digitalWrite(txPin, HIGH); | ||
digitalWrite(_transmitPin, HIGH); | ||
else | ||
digitalWrite(txPin, LOW); | ||
digitalWrite(_transmitPin, LOW); | ||
|
||
delayTicks(delay); | ||
b >>= 1; | ||
} | ||
|
||
// restore pin to natural state | ||
if (invertedLogic) | ||
digitalWrite(txPin, LOW); | ||
digitalWrite(_transmitPin, LOW); | ||
else | ||
digitalWrite(txPin, HIGH); | ||
digitalWrite(_transmitPin, HIGH); | ||
|
||
interrupts(); | ||
delayTicks(delay); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ class SoftwareSerial : public Stream | |
private: | ||
// per object data | ||
uint32_t _receivePin; | ||
uint32_t _transmitPin; | ||
uint32_t _receiveBitMask; | ||
volatile uint32_t *_receivePortRegister; | ||
uint32_t _transmitBitMask; | ||
|
@@ -66,7 +67,6 @@ class SoftwareSerial : public Stream | |
void tx_pin_write(uint32_t pin_state) __attribute__((__always_inline__)); | ||
void setTX(uint8_t transmitPin); | ||
void setRX(uint8_t receivePin); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this function no longer necessary? Maybe it should get removed from .cpp file as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did remove it from the cpp file |
||
void setRxIntMsk(bool enable); | ||
|
||
// Return num - sub, or 1 if the result would be < 1 | ||
static uint16_t subtract_cap(uint16_t num, uint16_t sub); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove txPin?