Developer World
Spresense Arduino Library v3.3.0-b2e6327
SoftwareSerial.h
Go to the documentation of this file.
1/*
2 * SoftwareSerial.h - Spresense Arduino Software Serial library
3 * Copyright 2018 Sony Semiconductor Solutions Corporation
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#ifndef SoftwareSerial_h
21#define SoftwareSerial_h
22
39#include <inttypes.h>
40#include <Stream.h>
41
42#ifndef SS_MAX_RX_BUFF
43#define SS_MAX_RX_BUFF 64
44#endif
45
54class SoftwareSerial : public Stream
55{
56private:
57 uint8_t _receivePin;
58 uint8_t _transmitPin;
59 uint32_t _receivePinRegAddr;
60 uint32_t _transmitPinRegAddr;
62 unsigned long _rx_delay_centering;
63 unsigned long _rx_delay_intrabit;
64 unsigned long _tx_delay;
66 uint16_t _buffer_overflow:1;
68 uint8_t _receive_buffer[SS_MAX_RX_BUFF];
69 volatile uint8_t _receive_buffer_tail;
70 volatile uint8_t _receive_buffer_head;
75 inline void recv();
76
82 static inline void tunedDelay(unsigned long delay);
83
90 static bool isActiveListener(SoftwareSerial *object);
91
99 static bool addActiveListener(SoftwareSerial *object, int irq);
100
106 static void removeActiveListener(SoftwareSerial *object);
107
114 static SoftwareSerial *findActiveListener(int irq);
115
116public:
123 SoftwareSerial(uint8_t receivePin, uint8_t transmitPin);
124
129
135 void begin(long speed);
136
140 void end();
141
147 bool listen();
148
154 bool isListening() { return isActiveListener(this); }
155
162
168 bool overflow() { bool ret = _buffer_overflow; if (ret) _buffer_overflow = false; return ret; }
169
176 int peek();
177
184 virtual size_t write(uint8_t byte);
185
191 virtual int read();
192
198 virtual int available();
199
203 virtual void flush();
204
205 using Print::write;
206
214 static inline int handle_interrupt(int irq, FAR void* context, FAR void *arg);
215};
216
219#endif
SoftwareSerial controller.
Definition: SoftwareSerial.h:55
SoftwareSerial(uint8_t receivePin, uint8_t transmitPin)
Create SoftwareSerial object.
bool stopListening()
Stop listening.
static int handle_interrupt(int irq, FAR void *context, FAR void *arg)
Interrupt handling.
int peek()
Get a character that was received on the RX pin of the SoftwareSerial object.
bool isListening()
Checks if the SoftwareSerial object is listening.
Definition: SoftwareSerial.h:154
void end()
Deinitialize the serial communication.
bool overflow()
Checks if a SoftwareSerial buffer overflow has occurred.
Definition: SoftwareSerial.h:168
bool listen()
Sets the current object as the "listening" one.
virtual size_t write(uint8_t byte)
Send a single byte to the transmit pin of SoftwareSerial object.
virtual int available()
Get the number of bytes available for reading from a SoftwareSerial objects.
virtual void flush()
There is no tx buffering, simply return.
void begin(long speed)
Initialize the serial communication.
~SoftwareSerial()
Destroy SoftwareSerial object.
virtual int read()
Read data from buffer.
#define SS_MAX_RX_BUFF
Definition: SoftwareSerial.h:43