SC16IS7xxRK
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Friends
SC16IS7xxPort Class Reference

Class for an instance of a UART. More...

#include <SC16IS7xxRK.h>

Inheritance diagram for SC16IS7xxPort:
SC16IS7x0

Public Member Functions

SC16IS7xxPortwithBufferedRead (size_t bufferSize)
 Enable buffered read mode.
 
SC16IS7xxPortwithTransmissionControlLevels (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.
 

Static Public Attributes

static const uint32_t OPTIONS_8N1 = 0b000011
 8 data bits, no parity, 1 stop bit
 
static const uint32_t OPTIONS_8E1 = 0b011011
 8 data bits, even parity, 1 stop bit
 
static const uint32_t OPTIONS_8O1 = 0b001011
 8 data bits, odd parity, 1 stop bit
 
static const uint32_t OPTIONS_8N2 = 0b000111
 8 data bits, no parity, 2 stop bits
 
static const uint32_t OPTIONS_8E2 = 0b011111
 8 data bits, even parity, 2 stop bits
 
static const uint32_t OPTIONS_8O2 = 0b001111
 8 data bits, odd parity, 2 stop bits
 
static const uint32_t OPTIONS_7N1 = 0b000010
 7 data bits, no parity, 1 stop bit
 
static const uint32_t OPTIONS_7E1 = 0b011010
 7 data bits, even parity, 1 stop bit
 
static const uint32_t OPTIONS_7O1 = 0b001010
 7 data bits, odd parity, 1 stop bit
 
static const uint32_t OPTIONS_7N2 = 0b000110
 7 data bits, no parity, 2 stop bits
 
static const uint32_t OPTIONS_7E2 = 0b011110
 7 data bits, even parity, 2 stop bits
 
static const uint32_t OPTIONS_7O2 = 0b001110
 7 data bits, odd parity, 2 stop bits
 
static const uint32_t OPTIONS_FLOW_CONTROL_NONE = 0b00000000
 No hardware flow control (default)
 
static const uint32_t OPTIONS_FLOW_CONTROL_RTS = 0b01000000
 RTS flow control (/RTS output indicates this side can receive data)
 
static const uint32_t OPTIONS_FLOW_CONTROL_CTS = 0b10000000
 CTS flow control (/CTS input indicates the other side can receive data)
 
static const uint32_t OPTIONS_FLOW_CONTROL_RTS_CTS = 0b11000000
 Hardware flow control in both directions.
 

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.
 
SC16IS7xxPortoperator= (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()
 
SC16IS7xxInterfaceinterface = nullptr
 Interface object for this chip.
 
SC16IS7xxBufferreadBuffer = 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()
 

Detailed Description

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.

Member Function Documentation

◆ available()

int SC16IS7xxPort::available ( )
virtual

Returns the number of bytes available to read from the serial port.

This is a standard Arduino/Wiring method for Stream objects.

◆ begin()

bool SC16IS7xxPort::begin ( int  baudRate,
uint32_t  options = OPTIONS_8N1 
)

Set up the chip. You must do this before reading or writing.

Parameters
baudRatethe baud rate (see below)
optionsThe 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!

◆ blockOnOverrun()

void SC16IS7xxPort::blockOnOverrun ( bool  value = true)
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.

◆ flush()

void SC16IS7xxPort::flush ( )
virtual

Block until all serial data is sent.

This is a standard Arduino/Wiring method for Stream objects.

◆ handleIIR()

void SC16IS7xxPort::handleIIR ( )
protected

Handle reading the IIR register and dispatching to the interrupt handler.

This is used interally and you cannot call it.

◆ peek()

int SC16IS7xxPort::peek ( )
virtual

Read a single byte from the serial port, but do not remove it so it can be read again.

Returns
a byte value 0 - 255 or -1 if no data is available.

This is a standard Arduino/Wiring method for Stream objects.

◆ read() [1/2]

int SC16IS7xxPort::read ( )
virtual

Read a single byte from the serial port.

Returns
a byte value 0 - 255 or -1 if no data is available.

This is a standard Arduino/Wiring method for Stream objects.

◆ read() [2/2]

int SC16IS7xxPort::read ( uint8_t *  buffer,
size_t  size 
)
virtual

Read a multiple bytes to the serial port.

Parameters
bufferThe buffer to read data into. It will not be null terminated.
sizeThe maximum number of bytes to read (buffer size)
Returns
The number of bytes actually read or -1 if there are no bytes available to read.

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.

◆ withBufferedRead()

SC16IS7xxPort & SC16IS7xxPort::withBufferedRead ( size_t  bufferSize)
inline

Enable buffered read mode.

Parameters
bufferSizeBuffer size in bytes. The buffer is allocated on the heap.

◆ withTransmissionControlLevels()

SC16IS7xxPort & SC16IS7xxPort::withTransmissionControlLevels ( uint8_t  haltLevel,
uint8_t  resumeLevel 
)

Sets the auto RTS hardware flow control levels. Call before begin() to change levels.

Parameters
haltLevelNumber of characters in receive FIFO to halt transmission. Default: 60.
resumeLevelNumber of characters in receivee FIFO to resume transmission. Default: 30.
Returns
SC16IS7xxPort&

◆ write() [1/2]

size_t SC16IS7xxPort::write ( const uint8_t *  buffer,
size_t  size 
)
virtual

Write a multiple bytes to the serial port.

Parameters
bufferThe buffer to write. Can write binary or text data.
sizeThe number of bytes to write
Returns
The number of bytes written.

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.

◆ write() [2/2]

size_t SC16IS7xxPort::write ( uint8_t  c)
virtual

Write a single byte to the serial port.

Parameters
cThe byte to write. Can write binary or text data.

This is a standard Arduino/Wiring method for Stream objects.


The documentation for this class was generated from the following files: