Skip to content

Commit 5b6861d

Browse files
authored
Merge pull request #2 from fpistm/pr-645_rev
PR review
2 parents 267002c + da7d1d9 commit 5b6861d

File tree

3 files changed

+11
-41
lines changed

3 files changed

+11
-41
lines changed

libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,3 @@ void loop() {
7575
// blank line to separate data from the two ports:
7676
Serial.println();
7777
}
78-
79-
80-
81-
82-
83-

libraries/SoftwareSerial/src/SoftwareSerial.cpp

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,7 @@
3434
//
3535
// Includes
3636
//
37-
#include <stdint.h>
38-
#include <stdarg.h>
39-
40-
#include <wiring_digital.h>
41-
#include <time.h>
42-
43-
#include <Arduino.h>
4437
#include "SoftwareSerial.h"
45-
#include <HardwareTimer.h>
46-
#include <stm32_def.h>
47-
#include <digital_io.h>
4838

4939
#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).
5040

@@ -155,19 +145,16 @@ void SoftwareSerial::setSpeed(uint32_t speed)
155145
// one and returns true if it replaces another
156146
bool SoftwareSerial::listen()
157147
{
158-
if (_receivePin >= 0) {
148+
if (active_listener != this) {
159149
// wait for any transmit to complete as we may change speed
160-
while (active_out)
161-
;
162-
if (active_listener) {
163-
active_listener->stopListening();
164-
}
150+
while (active_out);
151+
active_listener->stopListening();
165152
rx_tick_cnt = 1; // 1 : next interrupt will decrease rx_tick_cnt to 0 which means RX pin level will be considered.
166153
rx_bit_cnt = -1; // rx_bit_cnt = -1 : waiting for start bit
167154
setSpeed(_speed);
168155
active_listener = this;
169156
if (!_half_duplex) {
170-
active_in = this;
157+
active_in = this;
171158
}
172159
return true;
173160
}
@@ -179,8 +166,7 @@ bool SoftwareSerial::stopListening()
179166
{
180167
if (active_listener == this) {
181168
// wait for any output to complete
182-
while (active_out)
183-
;
169+
while (active_out);
184170
if (_half_duplex) {
185171
setRXTX(false);
186172
}
@@ -205,9 +191,7 @@ inline void SoftwareSerial::setTX()
205191

206192
inline void SoftwareSerial::setRX()
207193
{
208-
if (_receivePin > 0) {
209-
pinMode(_receivePin, _inverse_logic ? INPUT_PULLDOWN : INPUT_PULLUP); // pullup for normal logic!
210-
}
194+
pinMode(_receivePin, _inverse_logic ? INPUT_PULLDOWN : INPUT_PULLUP); // pullup for normal logic!
211195
}
212196

213197
inline void SoftwareSerial::setRXTX(bool input)
@@ -308,6 +292,7 @@ inline void SoftwareSerial::recv()
308292
/* static */
309293
inline void SoftwareSerial::handleInterrupt(HardwareTimer *timer)
310294
{
295+
UNUSED(timer);
311296
if (active_in) {
312297
active_in->recv();
313298
}
@@ -333,9 +318,13 @@ SoftwareSerial::SoftwareSerial(uint16_t receivePin, uint16_t transmitPin, bool i
333318
_receive_buffer_tail(0),
334319
_receive_buffer_head(0)
335320
{
321+
if ((receivePin < NUM_DIGITAL_PINS) || (transmitPin < NUM_DIGITAL_PINS)) {
336322
/* Enable GPIO clock for tx and rx pin*/
337323
set_GPIO_Port_Clock(STM_PORT(digitalPinToPinName(transmitPin)));
338324
set_GPIO_Port_Clock(STM_PORT(digitalPinToPinName(receivePin)));
325+
} else {
326+
_Error_Handler("ERROR: invalid pin number\n", -1);
327+
}
339328
}
340329

341330
//

libraries/SoftwareSerial/src/SoftwareSerial.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@
3434
#define SOFTWARESERIAL_H
3535

3636
#include <Arduino.h>
37-
#include <stdint.h>
38-
#include <Stream.h>
39-
#include <Print.h>
40-
#include <HardwareTimer.h>
4137

4238
/******************************************************************************
4339
* Definitions
@@ -125,13 +121,4 @@ class SoftwareSerial : public Stream {
125121
using Print::write;
126122
};
127123

128-
// Arduino 0012 workaround
129-
#undef int
130-
#undef char
131-
#undef long
132-
#undef byte
133-
#undef float
134-
#undef abs
135-
#undef round
136-
137124
#endif // SOFTWARESERIAL_H

0 commit comments

Comments
 (0)