SC16IS7xxRK
|
Class for SC16IS740, SC16IS750, SC16IS760 single I2C or SPI UART. More...
#include <SC16IS7xxRK.h>
Public Member Functions | |
SC16IS7x0 () | |
Default constructor. | |
virtual | ~SC16IS7x0 () |
Since the object is typically a global variable, it is not intended to be deleted. | |
SC16IS7x0 & | withI2C (TwoWire *wire, uint8_t addr=0) |
Chip is connected by I2C. | |
SC16IS7x0 & | withSPI (SPIClass *spi, pin_t csPin, size_t speedMHz=4) |
Chip is connected by SPI. | |
SC16IS7xxPort & | a () |
Convenience accessor for the port object. | |
SC16IS7xxPort & | operator[] (size_t index) |
Convenience accessor for the port object. | |
void | forEachPort (std::function< void(SC16IS7xxPort *port)> callback) |
Call callback for each port. | |
Public Member Functions inherited from SC16IS7xxPort | |
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. | |
Public Member Functions inherited from SC16IS7xxInterface | |
SC16IS7xxInterface & | withI2C (TwoWire *wire=&Wire, uint8_t addr=0) |
Chip is connected by I2C. | |
SC16IS7xxInterface & | withSPI (SPIClass *spi, pin_t csPin, size_t speedMHz) |
Chip is connected by SPI. | |
SC16IS7xxInterface & | withOscillatorFrequency (int freqHz) |
Set the oscillator frequency for the chip. | |
SC16IS7xxInterface & | withEnableGPIO (bool enable=true) |
Enable GPIO mode on SC16IS750, SC16IS760, SC16IS752, SC16IS762. | |
SC16IS7xxInterface & | withIRQ (pin_t irqPin, PinMode mode=INPUT_PULLUP) |
Sets the pin used for IRQ (hardware interrupts). This is optional. | |
SC16IS7xxInterface & | softwareReset () |
Do a software reset of the device. | |
bool | powerOnCheck () |
Do a check to see if the device is set to the expected power-on values. | |
uint8_t | readRegister (uint8_t channel, uint8_t reg) |
Read a register. | |
bool | writeRegister (uint8_t channel, uint8_t reg, uint8_t value) |
Write a register. | |
virtual void | forEachPort (std::function< void(SC16IS7xxPort *port)> callback)=0 |
Calls a callback for each port on this chip. | |
Protected Member Functions | |
SC16IS7x0 (const SC16IS7x0 &)=delete | |
This class is not copyable. | |
SC16IS7x0 & | operator= (const SC16IS7x0 &)=delete |
This class is not copyable. | |
Protected Member Functions inherited from SC16IS7xxPort | |
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 Member Functions inherited from SC16IS7xxInterface | |
virtual | ~SC16IS7xxInterface () |
You cannot instantiate this directly. | |
SC16IS7xxInterface (const SC16IS7xxInterface &)=delete | |
You cannot delete this directly. | |
SC16IS7xxInterface & | operator= (const SC16IS7xxInterface &)=delete |
This class is not copyable. | |
void | beginTransaction () |
Begins a SPI or I2C transaction. | |
void | endTransaction () |
Ends a SPI or I2C transaction. | |
bool | readInternal (uint8_t channel, uint8_t *buffer, size_t size) |
Internal function to read data. | |
virtual bool | writeInternal (uint8_t channel, const uint8_t *buffer, size_t size) |
Internal function to write data. | |
size_t | readInternalMax () const |
Maximum number of bytes that can be read by readInternal. | |
size_t | writeInternalMax () const |
Maximum number of bytes that can be written by writeInternal. | |
void | registerThreadFunction (std::function< void()> fn) |
Adds a new function to be called from the worker thread. | |
void | threadFunction () |
Thread function called from FreeRTOS. Never returns! | |
Additional Inherited Members | |
Static Public Attributes inherited from SC16IS7xxPort | |
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. | |
Static Public Attributes inherited from SC16IS7xxInterface | |
static const uint8_t | RHR_THR_REG = 0x00 |
Receive Holding Register (RHR) and Transmit Holding Register (THR) | |
static const uint8_t | IER_REG = 0x01 |
Interrupt Enable Register (IER) | |
static const uint8_t | FCR_IIR_REG = 0x02 |
Interrupt Identification Register (IIR) and FIFO Control Register (FCR) | |
static const uint8_t | LCR_REG = 0x03 |
Line Control Register (LCR) | |
static const uint8_t | MCR_REG = 0x04 |
Modem Control Register (MCR) | |
static const uint8_t | LSR_REG = 0x05 |
Line Status Register (LSR) | |
static const uint8_t | MSR_REG = 0x06 |
Modem Status Register (MSR) | |
static const uint8_t | TCR_REG = 0x06 |
Transmission control register (TCR) when MCR[2] = 1 and EFR[4] = 1. | |
static const uint8_t | SPR_REG = 0x07 |
Scratchpad Register (SPR) - if MCR[2] = 1 and EFR[4] = 1. | |
static const uint8_t | TLR_REG = 0x07 |
Transmission level register (TLR) - if MCR[2] = 1 and EFR[4] = 1. | |
static const uint8_t | TXLVL_REG = 0x08 |
Transmit FIFO Level register. | |
static const uint8_t | RXLVL_REG = 0x09 |
Receive FIFO Level register. | |
static const uint8_t | IODIR_REG = 0x0a |
I/O pin Direction register. | |
static const uint8_t | IOSTATE_REG = 0x0b |
I/O pins State register. | |
static const uint8_t | IOINTENA_REG = 0x0c |
I/O Interrupt Enable register. | |
static const uint8_t | IOCONTROL_REG = 0x0e |
I/O pins Control register. | |
static const uint8_t | EFCR_REG = 0x0f |
Extra Features Control Register. | |
static const uint8_t | LCR_DEFAULT = 0x1D |
Power-on default value of LCR. | |
static const uint8_t | LCR_SPECIAL_ENABLE_DIVISOR_LATCH = 0x80 |
LCR bit to enable setting divisor. | |
static const uint8_t | LCR_ENABLE_ENHANCED_FEATURE_REG = 0xbf |
LCR bit to enable enhanced features. | |
static const uint8_t | DLL_REG = 0x00 |
Divisor Latch LSB (DLL) | |
static const uint8_t | DLH_REG = 0x01 |
Divisor Latch MSB (DLH) | |
static const uint8_t | EFR_REG = 0x02 |
Enhanced Features Register (EFR) | |
static const uint8_t | XON1_REG = 0x04 |
Xon1 word. | |
static const uint8_t | XON2_REG = 0x05 |
Xon2 word. | |
static const uint8_t | XOFF1_REG = 0x06 |
Xoff1 word. | |
static const uint8_t | XOFF2_REG = 0x07 |
Xoff2 word. | |
Static Protected Member Functions inherited from SC16IS7xxInterface | |
static void | threadFunctionStatic (void *param) |
Static thread function, called from FreeRTOS. | |
Protected Attributes inherited from SC16IS7xxPort | |
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. | |
Protected Attributes inherited from SC16IS7xxInterface | |
TwoWire * | wire = nullptr |
When using I2C, the Wire object, typically Wire, but could be Wire1. | |
uint8_t | i2cAddr = 0 |
When using I2C, the I2C address of the SC16IS7xx chip. | |
SPIClass * | spi = nullptr |
When using SPI, the SPI object (typically SPI or SPI1). | |
pin_t | csPin = PIN_INVALID |
When using SPI, the CS pin (required for SPI) | |
pin_t | irqPin = PIN_INVALID |
Hardware IRQ from SC16IS7xx, optional. | |
size_t | irqFifoLevel = 30 |
Number of bytes to trigger IRQ. | |
SPISettings | spiSettings |
When using SPI, the SPISettings (bit rate, bit order, mode). | |
bool | enableGPIO |
Enable GPIO mode. | |
int | oscillatorFreqHz = 1843200 |
Oscillator frequency. Default is 1.8432 MHz, can also be 3072000 (3.072 MHz). | |
Thread * | workerThread = nullptr |
Worker thread, created if registerThreadFunction() is called. | |
std::vector< std::function< void()> > | threadFunctions |
Functions to call from the worker thread, added using registerThreadFunction() | |
Class for SC16IS740, SC16IS750, SC16IS760 single I2C or SPI UART.
SC16IS7x0::SC16IS7x0 | ( | ) |
Default constructor.
You typically allocate one of these per chip as global variables.
|
inlinevirtual |
Since the object is typically a global variable, it is not intended to be deleted.
If you delete this object and are using the worker thread, the device will probably crash since the thread won't be stopped.
|
inline |
Convenience accessor for the port object.
This isn't needed because this class derives from SC16IS7xxPort. However, you may want to use this when accessing the port if you will be supporting both the single and dual versions in your code, since the dual version requires that you specify which port you want to work with.
|
inlinevirtual |
Call callback for each port.
For the SC16IS7x0 there is only one port, but this makes operation consistent across chips.
Implements SC16IS7xxInterface.
|
inline |
Convenience accessor for the port object.
index | The port index, must be 0 (though it's ignored) |
This isn't needed because this class derives from SC16IS7xxPort. However, you may want to use this when accessing the port if you will be supporting both the single and dual versions in your code, since the dual version requires that you specify which port you want to work with.
|
inline |
Chip is connected by I2C.
wire | The I2C port, typically &Wire but could be &Wire1, etc. |
addr | I2C address (see note below) |
A1 A0 Index I2C Address VDD VDD 0 0x48 VDD GND 1 0x49 VDD SCL 2 0x4a VDD SDA 3 0x4b GND VDD 4 0x4c GND GND 5 0x4d GND SCL 6 0x4e GND SDA 7 0x4f SCL VDD 8 0x50 SCL GND 9 0x51 SCL SCL 10 0x52 SCL SDA 11 0x53 SDA VDD 12 0x54 SDA GND 13 0x55 SDA SCL 14 0x56 SDA SDA 15 0x57
You can pass either the index (0 - 15) or the I2C address in the address field. Note that the NXP datasheet addresses must be divided by 2 because they include the R/W bit in the address, and Particle and Arduino do not. That's why the datasheet lists the starting address as 0x90 instead of 0x48.
All models support speeds up to 400 Kbit/sec over I2C.
|
inline |
Chip is connected by SPI.
spi | The SPI port. Typically &SPI but could be &SPI1, etc. |
csPin | The pin used for chip select. This is required. |
speedMHz | The SPI bus speed in MHz. The default is 4 Kbit/sec., which works with all chips. |
The SC16IS740 and SC16IS750 supports SPI speeds up to 4 Mbit/sec. The SC16IS760 supports SPI speeds up to 15 Mbit/sec.