@@ -42,21 +42,17 @@ char SoftwareSerial::_receive_buffer[_SS_MAX_RX_BUFF];
42
42
volatile uint8_t SoftwareSerial::_receive_buffer_tail = 0 ;
43
43
volatile uint8_t SoftwareSerial::_receive_buffer_head = 0 ;
44
44
45
-
46
- //
47
- // Globals
48
- //
49
- uint8_t rxPin;
50
- uint16_t bitDelay;
51
- uint16_t rxIntraBitDelay;
52
- int rxCenteringDelay;
53
- int initRxIntraBitDelay;
54
- int firstIntraBitDelay;
55
- int initRxCenteringDelay;
56
- bool firstStartBit = true ;
57
- bool bufferOverflow = true ;
58
- bool invertedLogic = false ;
59
- bool isSOCGpio = false ;
45
+ static uint8_t _rxPin;
46
+ static uint16_t bitDelay;
47
+ static uint16_t rxIntraBitDelay;
48
+ static int rxCenteringDelay;
49
+ static int initRxIntraBitDelay;
50
+ static int firstIntraBitDelay;
51
+ static int initRxCenteringDelay;
52
+ static bool firstStartBit = true ;
53
+ static bool bufferOverflow = true ;
54
+ static bool invertedLogic = false ;
55
+ static bool isSOCGpio = false ;
60
56
61
57
//
62
58
// Debugging
@@ -94,14 +90,21 @@ bool SoftwareSerial::listen()
94
90
bufferOverflow = false ;
95
91
_receive_buffer_head = _receive_buffer_tail = 0 ;
96
92
active_object = this ;
97
- rxPin = _receivePin;
93
+ _rxPin = _receivePin;
94
+ rxIntraBitDelay = _rx_delay_intrabit;
95
+ rxCenteringDelay = _rx_delay_centering;
96
+ initRxIntraBitDelay = _rx_delay_init_intrabit;
97
+ firstIntraBitDelay = _rx_delay_first_intrabit;
98
+ initRxCenteringDelay = _rx_delay_init_centering;
99
+ invertedLogic = _inverse_logic;
100
+ isSOCGpio = _isSOCGpio;
98
101
if (invertedLogic)
99
102
{
100
- attachInterrupt (rxPin , recv, HIGH);
103
+ attachInterrupt (_rxPin , recv, HIGH);
101
104
}
102
105
else
103
106
{
104
- attachInterrupt (rxPin , recv, LOW);
107
+ attachInterrupt (_rxPin , recv, LOW);
105
108
}
106
109
107
110
return true ;
@@ -116,7 +119,7 @@ bool SoftwareSerial::stopListening()
116
119
if (active_object == this )
117
120
{
118
121
active_object = NULL ;
119
- detachInterrupt (rxPin );
122
+ detachInterrupt (_rxPin );
120
123
return true ;
121
124
}
122
125
return false ;
@@ -131,7 +134,7 @@ void SoftwareSerial::recv()
131
134
uint8_t d = 0 ;
132
135
// If RX line is high, then we don't see any start bit
133
136
// so interrupt is probably not for us
134
- if (invertedLogic ? digitalRead (rxPin ) : !digitalRead (rxPin ))
137
+ if (invertedLogic ? digitalRead (_rxPin ) : !digitalRead (_rxPin ))
135
138
{
136
139
// The very first start bit the sketch receives takes about 5us longer
137
140
if (firstStartBit && !isSOCGpio)
@@ -162,7 +165,7 @@ void SoftwareSerial::recv()
162
165
delayTicks (rxIntraBitDelay);
163
166
}
164
167
d >>= 1 ;
165
- if (digitalRead (rxPin ))
168
+ if (digitalRead (_rxPin ))
166
169
d |= 0x80 ;
167
170
firstStartBit = false ;
168
171
}
@@ -187,15 +190,15 @@ void SoftwareSerial::recv()
187
190
uint8_t loopTimeout = 8 ;
188
191
if (invertedLogic)
189
192
{
190
- while (digitalRead (rxPin ) && (loopTimeout >0 ))
193
+ while (digitalRead (_rxPin ) && (loopTimeout >0 ))
191
194
{
192
195
delayTicks (bitDelay >> 4 );
193
196
loopTimeout--;
194
197
}
195
198
}
196
199
else
197
200
{
198
- while (!digitalRead (rxPin ) && (loopTimeout >0 ))
201
+ while (!digitalRead (_rxPin ) && (loopTimeout >0 ))
199
202
{
200
203
delayTicks (bitDelay >> 4 );
201
204
loopTimeout--;
@@ -208,21 +211,9 @@ void SoftwareSerial::recv()
208
211
209
212
uint32_t SoftwareSerial::rx_pin_read ()
210
213
{
211
- return digitalRead (rxPin );
214
+ return digitalRead (_rxPin );
212
215
}
213
216
214
- //
215
- // Interrupt handling
216
- //
217
-
218
- /* static */
219
- inline void SoftwareSerial::handle_interrupt ()
220
- {
221
- if (active_object)
222
- {
223
- active_object->recv ();
224
- }
225
- }
226
217
227
218
//
228
219
// Constructor
@@ -235,7 +226,7 @@ SoftwareSerial::SoftwareSerial(uint32_t receivePin, uint32_t transmitPin, bool i
235
226
_buffer_overflow(false ),
236
227
_inverse_logic(inverse_logic)
237
228
{
238
- invertedLogic = inverse_logic;
229
+ _inverse_logic = inverse_logic;
239
230
setTX (transmitPin);
240
231
_transmitPin = transmitPin;
241
232
setRX (receivePin);
@@ -283,37 +274,37 @@ void SoftwareSerial::begin(long speed)
283
274
{
284
275
_rx_delay_centering = _rx_delay_intrabit = _rx_delay_stopbit = _tx_delay = 0 ;
285
276
// pre-calculate delays
286
- bitDelay = (F_CPU/speed);
287
- PinDescription *p = &g_APinDescription[rxPin ];
277
+ _bit_delay = (F_CPU/speed);
278
+ PinDescription *p = &g_APinDescription[_rxPin ];
288
279
if (p->ulGPIOType == SOC_GPIO)
289
280
{
290
- isSOCGpio = true ;
281
+ _isSOCGpio = true ;
291
282
}
292
283
// toggling a pin takes about 62 ticks
293
- _tx_delay = bitDelay - 62 ;
284
+ _tx_delay = _bit_delay - 62 ;
294
285
// reading a pin takes about 70 ticks
295
- rxIntraBitDelay = bitDelay - 70 ;
286
+ _rx_delay_intrabit = _bit_delay - 70 ;
296
287
// it takes about 272 ticks from when the start bit is received to when the ISR is called
297
- rxCenteringDelay = (bitDelay / 2 - 272 - 55 );
298
- if (rxCenteringDelay < 0 )
288
+ _rx_delay_centering = (_bit_delay / 2 - 272 - 55 );
289
+ if (_rx_delay_centering < 0 )
299
290
{
300
- firstIntraBitDelay = rxIntraBitDelay + rxCenteringDelay ;
301
- if (firstIntraBitDelay < 0 )
302
- firstIntraBitDelay = 0 ;
303
- rxCenteringDelay = 0 ;
291
+ _rx_delay_first_intrabit = _rx_delay_intrabit + _rx_delay_centering ;
292
+ if (_rx_delay_first_intrabit < 0 )
293
+ _rx_delay_first_intrabit = 0 ;
294
+ _rx_delay_centering = 0 ;
304
295
}
305
296
else
306
297
{
307
- firstIntraBitDelay = rxIntraBitDelay ;
298
+ _rx_delay_first_intrabit = _rx_delay_intrabit ;
308
299
}
309
300
// the first time the ISR is called is about 150 ticks longer
310
- initRxCenteringDelay = rxCenteringDelay - 150 ;
311
- if (initRxCenteringDelay < 0 )
301
+ _rx_delay_init_centering = _rx_delay_centering - 150 ;
302
+ if (_rx_delay_init_centering < 0 )
312
303
{
313
- initRxIntraBitDelay = rxIntraBitDelay + initRxCenteringDelay ;
314
- if (initRxIntraBitDelay < 0 )
315
- initRxIntraBitDelay = 0 ;
316
- initRxCenteringDelay = 0 ;
304
+ _rx_delay_init_intrabit = _rx_delay_intrabit + _rx_delay_init_centering ;
305
+ if (_rx_delay_init_intrabit < 0 )
306
+ _rx_delay_init_intrabit = 0 ;
307
+ _rx_delay_init_centering = 0 ;
317
308
}
318
309
319
310
#if _DEBUG
0 commit comments