Skip to content

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 19 additions & 27 deletions libraries/CurieSoftwareSerial/SoftwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ volatile uint8_t SoftwareSerial::_receive_buffer_head = 0;
//
// Globals
//
uint8_t txPin;
uint8_t rxPin;
Copy link
Contributor

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?

uint16_t bitDelay;
uint16_t rxIntraBitDelay;
Expand Down Expand Up @@ -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)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removing setRxIntMsk?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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;
}

Expand All @@ -108,8 +115,8 @@ bool SoftwareSerial::stopListening()
{
if (active_object == this)
{
setRxIntMsk(false);
active_object = NULL;
detachInterrupt(rxPin);
return true;
}
return false;
Expand Down Expand Up @@ -230,9 +237,9 @@ SoftwareSerial::SoftwareSerial(uint32_t receivePin, uint32_t transmitPin, bool i
{
invertedLogic = inverse_logic;
setTX(transmitPin);
txPin = transmitPin;
_transmitPin = transmitPin;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you use _transmitPin instead of txPin?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

txPin was originally a global variable in the cpp file
i needed a variable that is an instance per each SoftwareSerial object.

setRX(receivePin);
rxPin = receivePin;
_receivePin = receivePin;
}

//
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion libraries/CurieSoftwareSerial/SoftwareSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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);
Expand Down