Class that manages the SPI or I2C interface.
More...
#include <SC16IS7xxRK.h>
|
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.
|
|
|
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.
|
|
|
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!
|
|
|
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 | SC16IS7xxPort |
| The port object calls the interface object and uses the register contents.
|
|
Class that manages the SPI or I2C interface.
You will not instantiate one of these directly.
◆ SC16IS7xxInterface()
You cannot delete this directly.
This class is not copyable
◆ beginTransaction()
void SC16IS7xxInterface::beginTransaction |
( |
| ) |
|
|
protected |
Begins a SPI or I2C transaction.
A transaction is a group of related calls. Within the transaction other devices are prohibited from accessing the bus, but thread swapping is still enabled.
◆ endTransaction()
void SC16IS7xxInterface::endTransaction |
( |
| ) |
|
|
protected |
Ends a SPI or I2C transaction.
A transaction is a group of related calls. Within the transaction other devices are prohibited from accessing the bus, but thread swapping is still enabled.
◆ forEachPort()
virtual void SC16IS7xxInterface::forEachPort |
( |
std::function< void(SC16IS7xxPort *port)> |
callback | ) |
|
|
pure virtual |
Calls a callback for each port on this chip.
- Parameters
-
Implemented in SC16IS7x0, and SC16IS7x2.
◆ powerOnCheck()
bool SC16IS7xxInterface::powerOnCheck |
( |
| ) |
|
Do a check to see if the device is set to the expected power-on values.
◆ readInternal()
bool SC16IS7xxInterface::readInternal |
( |
uint8_t |
channel, |
|
|
uint8_t * |
buffer, |
|
|
size_t |
size |
|
) |
| |
|
protected |
Internal function to read data.
It can only read 32 bytes at a time, the maximum that will fit in a 32 byte I2C transaction with the register address in the first byte.
◆ readRegister()
uint8_t SC16IS7xxInterface::readRegister |
( |
uint8_t |
channel, |
|
|
uint8_t |
reg |
|
) |
| |
Read a register.
- Parameters
-
channel | The channel (0-3). |
reg | The register number to read. Note that this should be the register 0 - 16, before shifting for channel. |
◆ registerThreadFunction()
void SC16IS7xxInterface::registerThreadFunction |
( |
std::function< void()> |
fn | ) |
|
|
protected |
Adds a new function to be called from the worker thread.
- Parameters
-
fn | The function or lambda to call |
◆ threadFunctionStatic()
void SC16IS7xxInterface::threadFunctionStatic |
( |
void * |
param | ) |
|
|
staticprotected |
Static thread function, called from FreeRTOS.
Note: param must be a pointer to this. threadFunction is called from this function. Never returns!
◆ withEnableGPIO()
Enable GPIO mode on SC16IS750, SC16IS760, SC16IS752, SC16IS762.
This call must be make before any begin() calls. It will have no effect after begin().
◆ withI2C()
SC16IS7xxInterface & SC16IS7xxInterface::withI2C |
( |
TwoWire * |
wire = &Wire , |
|
|
uint8_t |
addr = 0 |
|
) |
| |
Chip is connected by I2C.
- Parameters
-
wire | The I2C port, typically &Wire but could be &Wire1, etc. Default is Wire (primary I2C on D0/D1). |
addr | I2C address (see note below). Default is both 0x48, A0=HIGH, A1=HIGH. |
- Returns
- SC16IS7xxInterface&
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.
The most common scenarios are both high (addr = 0x48 or 0x00) or both low (addr = 0x4d or 0x05)
Because of the way I2C works, the speed is selected per bus and not per I2C slave device like SPI. If all of your I2C devices work at 400 kHz, using Wire.setSpeed(CLOCK_SPEED_400KHZ)
is recommended for better performance.
This call must be make before any begin() calls. It will have no effect after begin().
◆ withIRQ()
SC16IS7xxInterface & SC16IS7xxInterface::withIRQ |
( |
pin_t |
irqPin, |
|
|
PinMode |
mode = INPUT_PULLUP |
|
) |
| |
Sets the pin used for IRQ (hardware interrupts). This is optional.
- Parameters
-
irqPin | Pin to use (D3, D4, ...) |
mode | The pin mode. Default is INPUT_PULLUP. Could be INPUT instead. |
- Returns
- SC16IS7xxInterface&
This call must be make before any begin() calls. It will have no effect after begin().
◆ withOscillatorFrequency()
Set the oscillator frequency for the chip.
- Parameters
-
freqHz | Typically 1843200 (default, 1.8432 MHz), or 3072000 (3.072 MHz). |
- Returns
- * SC16IS7xxInterface&
This call must be make before any begin() calls. It will have no effect after begin().
◆ withSPI()
SC16IS7xxInterface & SC16IS7xxInterface::withSPI |
( |
SPIClass * |
spi, |
|
|
pin_t |
csPin, |
|
|
size_t |
speedMHz |
|
) |
| |
Chip is connected by SPI.
- Parameters
-
spi | The SPI port. Typically &SPI but could be &SPI1, etc. |
csPin | The pin used for chip select |
speedMHz | The SPI bus speed in MHz. |
- Returns
- SC16IS7xxInterface&
This call must be make before any begin() calls. It will have no effect after begin().
◆ writeInternal()
bool SC16IS7xxInterface::writeInternal |
( |
uint8_t |
channel, |
|
|
const uint8_t * |
buffer, |
|
|
size_t |
size |
|
) |
| |
|
protectedvirtual |
Internal function to write data.
It can only write 31 bytes at a time, the maximum that will fit in a 32 byte I2C transaction with the register address in the first byte.
◆ writeRegister()
bool SC16IS7xxInterface::writeRegister |
( |
uint8_t |
channel, |
|
|
uint8_t |
reg, |
|
|
uint8_t |
value |
|
) |
| |
Write a register.
- Parameters
-
channel | The channel (0-3). |
reg | The register number to write. Note that this should be the register 0 - 16, before shifting for channel. |
value | The value to write |
The documentation for this class was generated from the following files: