1
1
/*
2
- SoftwareSerial.cpp (formerly NewSoftSerial.cpp) -
2
+ SoftwareSerial.cpp (formerly NewSoftSerial.cpp) -
3
3
Multi-instance software serial library for Arduino/Wiring
4
4
-- Interrupt-driven receive and other improvements by ladyada
5
5
(http://ladyada.net)
6
6
-- Tuning, circular buffer, derivation from class Print/Stream,
7
7
multi-instance support, porting to 8MHz processors,
8
- various optimizations, PROGMEM delay tables, inverse logic and
8
+ various optimizations, PROGMEM delay tables, inverse logic and
9
9
direct port writing by Mikal Hart (http://www.arduiniana.org)
10
10
-- Pin change interrupt macros by Paul Stoffregen (http://www.pjrc.com)
11
11
-- 20MHz processor support by Garrett Mace (http://www.macetech.com)
@@ -37,9 +37,9 @@ The latest version of this library can always be found at
37
37
#define _DEBUG 0
38
38
#define _DEBUG_PIN1 11
39
39
#define _DEBUG_PIN2 13
40
- //
40
+ //
41
41
// Includes
42
- //
42
+ //
43
43
#include < avr/interrupt.h>
44
44
#include < avr/pgmspace.h>
45
45
#include < Arduino.h>
@@ -50,7 +50,7 @@ The latest version of this library can always be found at
50
50
// Statics
51
51
//
52
52
SoftwareSerial *SoftwareSerial::active_object = 0 ;
53
- uint8_t SoftwareSerial::_receive_buffer[_SS_MAX_RX_BUFF];
53
+ uint8_t SoftwareSerial::_receive_buffer[_SS_MAX_RX_BUFF];
54
54
volatile uint8_t SoftwareSerial::_receive_buffer_tail = 0 ;
55
55
volatile uint8_t SoftwareSerial::_receive_buffer_head = 0 ;
56
56
@@ -79,13 +79,13 @@ inline void DebugPulse(uint8_t, uint8_t) {}
79
79
// Private methods
80
80
//
81
81
82
- /* static */
83
- inline void SoftwareSerial::tunedDelay (uint16_t delay) {
82
+ /* static */
83
+ inline void SoftwareSerial::tunedDelay (uint16_t delay) {
84
84
_delay_loop_2 (delay);
85
85
}
86
86
87
87
// This function sets the current object as the "listening"
88
- // one and returns true if it replaces another
88
+ // one and returns true if it replaces another
89
89
bool SoftwareSerial::listen ()
90
90
{
91
91
if (!_rx_delay_stopbit)
@@ -139,7 +139,7 @@ void SoftwareSerial::recv()
139
139
" push r26 \n\t "
140
140
" push r27 \n\t "
141
141
::);
142
- #endif
142
+ #endif
143
143
144
144
uint8_t d = 0 ;
145
145
@@ -176,8 +176,8 @@ void SoftwareSerial::recv()
176
176
// save new data in buffer: tail points to where byte goes
177
177
_receive_buffer[_receive_buffer_tail] = d; // save new byte
178
178
_receive_buffer_tail = next;
179
- }
180
- else
179
+ }
180
+ else
181
181
{
182
182
DebugPulse (_DEBUG_PIN1, 1 );
183
183
_buffer_overflow = true ;
@@ -256,7 +256,7 @@ ISR(PCINT3_vect, ISR_ALIASOF(PCINT0_vect));
256
256
//
257
257
// Constructor
258
258
//
259
- SoftwareSerial::SoftwareSerial (int8_t receivePin, int8_t transmitPin, bool inverse_logic /* = false */ ) :
259
+ SoftwareSerial::SoftwareSerial (int8_t receivePin, int8_t transmitPin, bool inverse_logic /* = false */ ) :
260
260
_rx_delay_centering(0 ),
261
261
_rx_delay_intrabit(0 ),
262
262
_rx_delay_stopbit(0 ),
@@ -312,7 +312,7 @@ uint16_t SoftwareSerial::subtract_cap(uint16_t num, uint16_t sub) {
312
312
//
313
313
314
314
void SoftwareSerial::begin (long speed)
315
- {
315
+ {
316
316
_rx_delay_centering = _rx_delay_intrabit = _rx_delay_stopbit = _tx_delay = 0 ;
317
317
318
318
// Precalculate the various delays, in number of 4-cycle delays
@@ -380,12 +380,12 @@ void SoftwareSerial::begin(long speed)
380
380
381
381
#if defined(INT_AND_PCINT)
382
382
else
383
- #endif
383
+ #endif
384
384
#if defined(INT_ONLY) || defined(INT_AND_PCINT)
385
385
{
386
386
// Direct interrupts
387
387
attachInterrupt (digitalPinToInterrupt (_receivePin), isr, CHANGE);
388
-
388
+
389
389
#if GCC_VERSION > 40800
390
390
// Timings counted from gcc 4.8.2 output. This works up to 115200 on
391
391
// 16Mhz and 57600 on 8Mhz.
@@ -469,7 +469,7 @@ int SoftwareSerial::available()
469
469
if (!isListening ())
470
470
return 0 ;
471
471
472
- return (_receive_buffer_tail + _SS_MAX_RX_BUFF - _receive_buffer_head) % _SS_MAX_RX_BUFF;
472
+ return (( uint16_t )( _receive_buffer_tail + _SS_MAX_RX_BUFF - _receive_buffer_head) ) % _SS_MAX_RX_BUFF;
473
473
}
474
474
475
475
size_t SoftwareSerial::write (uint8_t b)
@@ -523,7 +523,7 @@ size_t SoftwareSerial::write(uint8_t b)
523
523
524
524
SREG = oldSREG; // turn interrupts back on
525
525
tunedDelay (_tx_delay);
526
-
526
+
527
527
return 1 ;
528
528
}
529
529
0 commit comments