@@ -247,15 +247,15 @@ ISR(PCINT3_vect, ISR_ALIASOF(PCINT0_vect));
247
247
// Constructor
248
248
//
249
249
SoftwareSerial::SoftwareSerial (uint8_t receivePin, uint8_t transmitPin, bool inverse_logic /* = false */ ) :
250
+ _receivePin(receivePin),
251
+ _transmitPin(transmitPin),
250
252
_rx_delay_centering(0 ),
251
253
_rx_delay_intrabit(0 ),
252
254
_rx_delay_stopbit(0 ),
253
255
_tx_delay(0 ),
254
256
_buffer_overflow(false ),
255
257
_inverse_logic(inverse_logic)
256
258
{
257
- setTX (transmitPin);
258
- setRX (receivePin);
259
259
}
260
260
261
261
//
@@ -266,27 +266,26 @@ SoftwareSerial::~SoftwareSerial()
266
266
end ();
267
267
}
268
268
269
- void SoftwareSerial::setTX ( uint8_t tx )
269
+ void SoftwareSerial::setupTX ( )
270
270
{
271
271
// First write, then set output. If we do this the other way around,
272
272
// the pin would be output low for a short while before switching to
273
273
// output hihg. Now, it is input with pullup for a short while, which
274
274
// is fine. With inverse logic, either order is fine.
275
- digitalWrite (tx , _inverse_logic ? LOW : HIGH);
276
- pinMode (tx , OUTPUT);
277
- _transmitBitMask = digitalPinToBitMask (tx );
278
- uint8_t port = digitalPinToPort (tx );
275
+ digitalWrite (_transmitPin , _inverse_logic ? LOW : HIGH);
276
+ pinMode (_transmitPin , OUTPUT);
277
+ _transmitBitMask = digitalPinToBitMask (_transmitPin );
278
+ uint8_t port = digitalPinToPort (_transmitPin );
279
279
_transmitPortRegister = portOutputRegister (port);
280
280
}
281
281
282
- void SoftwareSerial::setRX ( uint8_t rx )
282
+ void SoftwareSerial::setupRX ( )
283
283
{
284
- pinMode (rx , INPUT);
284
+ pinMode (_receivePin , INPUT);
285
285
if (!_inverse_logic)
286
- digitalWrite (rx, HIGH); // pullup for normal logic!
287
- _receivePin = rx;
288
- _receiveBitMask = digitalPinToBitMask (rx);
289
- uint8_t port = digitalPinToPort (rx);
286
+ digitalWrite (_receivePin, HIGH); // pullup for normal logic!
287
+ _receiveBitMask = digitalPinToBitMask (_receivePin);
288
+ uint8_t port = digitalPinToPort (_receivePin);
290
289
_receivePortRegister = portInputRegister (port);
291
290
}
292
291
@@ -303,6 +302,9 @@ uint16_t SoftwareSerial::subtract_cap(uint16_t num, uint16_t sub) {
303
302
304
303
void SoftwareSerial::begin (long speed)
305
304
{
305
+ setupTX ();
306
+ setupRX ();
307
+
306
308
_rx_delay_centering = _rx_delay_intrabit = _rx_delay_stopbit = _tx_delay = 0 ;
307
309
308
310
// Precalculate the various delays, in number of 4-cycle delays
0 commit comments