Skip to content

PR review #2

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

Merged
merged 2 commits into from
Sep 10, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,3 @@ void loop() {
// blank line to separate data from the two ports:
Serial.println();
}






33 changes: 11 additions & 22 deletions libraries/SoftwareSerial/src/SoftwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,7 @@
//
// Includes
//
#include <stdint.h>
#include <stdarg.h>

#include <wiring_digital.h>
#include <time.h>

#include <Arduino.h>
#include "SoftwareSerial.h"
#include <HardwareTimer.h>
#include <stm32_def.h>
#include <digital_io.h>

#define OVERSAMPLE 3 // in RX, Timer will generate interruption OVERSAMPLE time during a bit. Thus OVERSAMPLE ticks in a bit. (interrupt not synchonized with edge).

Expand Down Expand Up @@ -155,19 +145,16 @@ void SoftwareSerial::setSpeed(uint32_t speed)
// one and returns true if it replaces another
bool SoftwareSerial::listen()
{
if (_receivePin >= 0) {
if (active_listener != this) {
// wait for any transmit to complete as we may change speed
while (active_out)
;
if (active_listener) {
active_listener->stopListening();
}
while (active_out);
active_listener->stopListening();
rx_tick_cnt = 1; // 1 : next interrupt will decrease rx_tick_cnt to 0 which means RX pin level will be considered.
rx_bit_cnt = -1; // rx_bit_cnt = -1 : waiting for start bit
setSpeed(_speed);
active_listener = this;
if (!_half_duplex) {
active_in = this;
active_in = this;
}
return true;
}
Expand All @@ -179,8 +166,7 @@ bool SoftwareSerial::stopListening()
{
if (active_listener == this) {
// wait for any output to complete
while (active_out)
;
while (active_out);
if (_half_duplex) {
setRXTX(false);
}
Expand All @@ -205,9 +191,7 @@ inline void SoftwareSerial::setTX()

inline void SoftwareSerial::setRX()
{
if (_receivePin > 0) {
pinMode(_receivePin, _inverse_logic ? INPUT_PULLDOWN : INPUT_PULLUP); // pullup for normal logic!
}
pinMode(_receivePin, _inverse_logic ? INPUT_PULLDOWN : INPUT_PULLUP); // pullup for normal logic!
}

inline void SoftwareSerial::setRXTX(bool input)
Expand Down Expand Up @@ -308,6 +292,7 @@ inline void SoftwareSerial::recv()
/* static */
inline void SoftwareSerial::handleInterrupt(HardwareTimer *timer)
{
UNUSED(timer);
if (active_in) {
active_in->recv();
}
Expand All @@ -333,9 +318,13 @@ SoftwareSerial::SoftwareSerial(uint16_t receivePin, uint16_t transmitPin, bool i
_receive_buffer_tail(0),
_receive_buffer_head(0)
{
if ((receivePin < NUM_DIGITAL_PINS) || (transmitPin < NUM_DIGITAL_PINS)) {
/* Enable GPIO clock for tx and rx pin*/
set_GPIO_Port_Clock(STM_PORT(digitalPinToPinName(transmitPin)));
set_GPIO_Port_Clock(STM_PORT(digitalPinToPinName(receivePin)));
} else {
_Error_Handler("ERROR: invalid pin number\n", -1);
}
}

//
Expand Down
13 changes: 0 additions & 13 deletions libraries/SoftwareSerial/src/SoftwareSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@
#define SOFTWARESERIAL_H

#include <Arduino.h>
#include <stdint.h>
#include <Stream.h>
#include <Print.h>
#include <HardwareTimer.h>

/******************************************************************************
* Definitions
Expand Down Expand Up @@ -125,13 +121,4 @@ class SoftwareSerial : public Stream {
using Print::write;
};

// Arduino 0012 workaround
#undef int
#undef char
#undef long
#undef byte
#undef float
#undef abs
#undef round

#endif // SOFTWARESERIAL_H