SC16IS7xxRK
|
Class for an instance of a UART. More...
#include <SC16IS7xxRK.h>
Public Member Functions | |
SC16IS7xxPort & | withBufferedRead (size_t bufferSize) |
Enable buffered read mode. | |
SC16IS7xxPort & | withTransmissionControlLevels (uint8_t haltLevel, uint8_t resumeLevel) |
Sets the auto RTS hardware flow control levels. Call before begin() to change levels. | |
bool | begin (int baudRate, uint32_t options=OPTIONS_8N1) |
Set up the chip. You must do this before reading or writing. | |
void | blockOnOverrun (bool value=true) |
Defines what should happen when calls to write()/print()/println()/printlnf() that would overrun the buffer. | |
virtual int | available () |
Returns the number of bytes available to read from the serial port. | |
virtual int | availableForWrite () |
Returns the number of bytes available to write into the TX FIFO. | |
virtual int | read () |
Read a single byte from the serial port. | |
virtual int | peek () |
Read a single byte from the serial port, but do not remove it so it can be read again. | |
virtual void | flush () |
Block until all serial data is sent. | |
virtual size_t | write (uint8_t c) |
Write a single byte to the serial port. | |
virtual size_t | write (const uint8_t *buffer, size_t size) |
Write a multiple bytes to the serial port. | |
virtual int | read (uint8_t *buffer, size_t size) |
Read a multiple bytes to the serial port. | |
Protected Member Functions | |
SC16IS7xxPort () | |
Protected constructor; you never construct one of these directly. | |
virtual | ~SC16IS7xxPort () |
Protected destructor; you never delete one of these directly. | |
SC16IS7xxPort (const SC16IS7xxPort &)=delete | |
This class is not copyable. | |
SC16IS7xxPort & | operator= (const SC16IS7xxPort &)=delete |
This class is not copyable. | |
void | handleIIR () |
Handle reading the IIR register and dispatching to the interrupt handler. | |
Protected Attributes | |
bool | hasPeek = false |
There is a byte from the last peek() available. | |
uint8_t | peekByte = 0 |
The byte that was read if hasPeek == true. | |
bool | writeBlocksWhenFull = true |
The write call blocks until there's room to write to the buffer (true) or discards (false) | |
uint8_t | channel = 0 |
Chip channel number for this port (0 or 1) | |
uint8_t | ier = 0 |
Value of the IER register, set from begin() | |
uint8_t | lcr = 0 |
Value of the LCR register, set from begin() | |
uint8_t | efr = 0 |
Value of the EFR register, set from begin() | |
uint8_t | mcr = 0 |
Value of the MCR register, set from begin() | |
uint8_t | tcr = (uint8_t)(30 << 4 | 60) |
Default TCR value for hardware flow control (resume 30, halt 60) | |
uint8_t | tlr = 0 |
Value of the TLR register, set from begin() | |
SC16IS7xxInterface * | interface = nullptr |
Interface object for this chip. | |
SC16IS7xxBuffer * | readBuffer = nullptr |
Buffer object when using withReadBuffer. | |
size_t | bufferedReadSize = 0 |
Size of buffer for buffered read (0 = buffered read not enabled) | |
uint8_t | readFifoInterruptLevel = 30 |
Interrupt when FIFO has 30 characters (or timeout) | |
bool | readDataAvailable = false |
Set from interruptRxTimeout and interruptRHR. | |
std::function< void()> | interruptLineStatus = nullptr |
Function to call for a line status interrupt. | |
std::function< void()> | interruptRxTimeout = nullptr |
Function to call for stale data in RX FIFO. | |
std::function< void()> | interruptRHR = nullptr |
Function to call for RHR FIFO above level. | |
std::function< void()> | interruptTHR = nullptr |
Function to call for THR FIFO below level. | |
std::function< void()> | interruptModemStatus = nullptr |
Function to call for change in modem input status. | |
std::function< void()> | interruptIO = nullptr |
Function to call for GPIO interrupt. | |
std::function< void()> | interruptXoff = nullptr |
Function to call for a received Xoff with software flow control, or special bytes. | |
std::function< void()> | interruptCTS_RTS = nullptr |
Function to call for CTS or RTS transition low to high. | |
Friends | |
class | SC16IS7x2 |
The SC16IS7x0 derives from this, but the SC16IS7x2 has this ports as member variables. | |
class | SC16IS7xxInterface |
Allows the interface to call private members of this class, used to call handleIIR() | |
Class for an instance of a UART.
There is one of these with the SC16IS7x0 and two with the SC16IS7x2. You will not instantiate one of these directly.
|
virtual |
Returns the number of bytes available to read from the serial port.
This is a standard Arduino/Wiring method for Stream objects.
bool SC16IS7xxPort::begin | ( | int | baudRate, |
uint32_t | options = OPTIONS_8N1 |
||
) |
Set up the chip. You must do this before reading or writing.
baudRate | the baud rate (see below) |
options | The number of data bits, parity, and stop bits |
You can call begin more than once if you want to change the baud rate. The FIFOs are cleared when you call begin.
Available baud rates depend on your oscillator, but with a 1.8432 MHz oscillator, the following are supported: 50, 75, 110, 134.5, 150, 300, 600, 1200, 1800, 2000, 2400, 3600, 4800, 7200, 9600, 19200, 38400, 57600, 115200
The valid options in standard number of bits; none=N, even=E, odd=O; number of stop bits format: OPTIONS_8N1, OPTIONS_8E1, OPTIONS_8O1 OPTIONS_8N2, OPTIONS_8E2, OPTIONS_8O2 OPTIONS_7N1, OPTIONS_7E1, OPTIONS_7O1 OPTIONS_7N2, OPTIONS_7E2, OPTIONS_7O2
Unlike the Device OS options, the SC16IS7xx OPTIONS_8N1 value is not 0! If you omit are enabling hardware flow control be sure to set it like SC16IS7xxPort::OPTIONS_8N1 | SC16IS7xxPort::OPTIONS_FLOW_CONTROL_RTS_CTS If you leave off the OPTIONS_8N1 the output will be 5N1, not 8N1!
|
inline |
Defines what should happen when calls to write()/print()/println()/printlnf() that would overrun the buffer.
blockOnOverrun(true) - this is the default setting. When there is no room in the buffer for the data to be written, the program waits/blocks until there is room. This avoids buffer overrun, where data that has not yet been sent over serial is overwritten by new data. Use this option for increased data integrity at the cost of slowing down realtime code execution when lots of serial data is sent at once.
blockOnOverrun(false) - when there is no room in the buffer for data to be written, the data is written anyway, causing the new data to replace the old data. This option is provided when performance is more important than data integrity.
|
virtual |
Block until all serial data is sent.
This is a standard Arduino/Wiring method for Stream objects.
|
protected |
Handle reading the IIR register and dispatching to the interrupt handler.
This is used interally and you cannot call it.
|
virtual |
Read a single byte from the serial port, but do not remove it so it can be read again.
This is a standard Arduino/Wiring method for Stream objects.
|
virtual |
Read a single byte from the serial port.
This is a standard Arduino/Wiring method for Stream objects.
|
virtual |
Read a multiple bytes to the serial port.
buffer | The buffer to read data into. It will not be null terminated. |
size | The maximum number of bytes to read (buffer size) |
This is faster than reading a single byte at time because up to 32 bytes of data can be sent or received in an I2C transaction, greatly reducing overhead. For SPI, 64 bytes can be written at a time.
|
inline |
Enable buffered read mode.
bufferSize | Buffer size in bytes. The buffer is allocated on the heap. |
SC16IS7xxPort & SC16IS7xxPort::withTransmissionControlLevels | ( | uint8_t | haltLevel, |
uint8_t | resumeLevel | ||
) |
Sets the auto RTS hardware flow control levels. Call before begin() to change levels.
haltLevel | Number of characters in receive FIFO to halt transmission. Default: 60. |
resumeLevel | Number of characters in receivee FIFO to resume transmission. Default: 30. |
|
virtual |
Write a multiple bytes to the serial port.
buffer | The buffer to write. Can write binary or text data. |
size | The number of bytes to write |
This is faster than writing a single byte at time because up to 31 bytes of data can be sent or received in an I2C transaction, greatly reducing overhead. For SPI, 64 bytes can be written at a time.
|
virtual |
Write a single byte to the serial port.
c | The byte to write. Can write binary or text data. |
This is a standard Arduino/Wiring method for Stream objects.