I2Cexpander - A collection of I2C I/O devices
Another SPCoast Library
|
#include <I2Cexpander.h>
Public Types | |
enum | IOSize { B_UNKNOWN = 0, B4 = 4, B6 = 6, B8 = 8, B16 = 16, B32 = 32 } |
enum | ExpanderType { IGNORE = 0, I2CLCD = 0, BUILTIN = 1, BIT, BYTE, FIRSTI2C, PCA9555 = FIRSTI2C, MCP23016, MCP23017, PCF8574, PCF8574A, PCF8591, MAX731x, MAX7311 = MAX731x, MAX7312 = MAX731x, MAX7313 = MAX731x, PCA9685, ARDIO_A, ARDIO_B, ARDIO_C, ARDIO_D, PHOTON_A, PHOTON_B, PHOTON_C, WEMOS_A, WEMOS_B, WEMOS_C, WEMOS_MATRIX, CPNODE_LOW, CPNODE_HIGH } |
Public Member Functions | |
I2Cexpander (void) | |
I2Cexpander class Constructor. No arguments so that it can be either statically initialized OR dynamic. | |
I2Cexpander (ExpanderType device_type, size_t address, boolean debounce=false) | |
void | init (size_t address, uint16_t device_type, uint16_t config, boolean debounce=false) |
Initialize the I2C expander device. Usually called in the setup() routine for a one-time initialization. More... | |
void | init (uint16_t config) |
Initialize the I2C expander device. Usually called in the setup() routine for a one-time initialization. More... | |
void | digitalWrite (uint8_t dataPin, uint8_t val) |
Arduino compatibility routine. Write a bit to an expander. Updates current cached state and writes data to the device. More... | |
uint8_t | digitalRead (uint8_t dataPin) |
Arduino compatibility routine. Read from an expander, update the cached state and return the bit value. More... | |
uint32_t | read (void) |
Read data from an expander, update the cached state and return the data. More... | |
uint32_t | get (void) |
wrapper for read(). More... | |
void | write (uint32_t data) |
Write data to an expander. More... | |
void | put (uint32_t data) |
wrapper for write(data). More... | |
void | put (void) |
wrapper for write(this->next). | |
void | write (void) |
wrapper for write(this->next). | |
uint16_t | getSize (void) |
How many bits does this expander read/write? More... | |
uint32_t | current () |
Cached data - the last read from the device. More... | |
uint32_t | last () |
Cached data - the last write to the device. More... | |
uint16_t | config () |
Configuration initialization info. More... | |
uint16_t | chip () |
Device Type. More... | |
uint8_t | i2caddr () |
Real I2C Address. More... | |
bool | changed () |
Have any INPUT bits changed since the last "read()"? More... | |
void | printString (const char *tag) |
Public Attributes | |
uint32_t | next |
byte | debugflag |
Static Public Attributes | |
static const char * | version = "2.0.3" |
enum I2Cexpander::IOSize |
The devices understood by this library.
Enumerator | |
---|---|
IGNORE |
device is managed outside of this library... |
I2CLCD |
... handled elsewhere |
BUILTIN |
Used by CMRI autoconf routines. |
BIT |
Also used by autoconf routines, not by I2Cexpander... |
BYTE |
Also used by autoconf routines, not by I2Cexpander... |
PCA9555 |
Bits 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16. |
MCP23016 |
Bits 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16. |
MCP23017 |
Bits 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16. |
PCF8574 |
Bits 0 1 2 3 4 5 6 7 8. |
PCF8574A |
Bits 0 1 2 3 4 5 6 7 8. |
PCF8591 |
4 A-D converters, 1 D-A |
MAX731x |
Bits 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16. |
PCA9685 |
16 bit PWM controller |
ARDIO_A |
4x Bits D2 D3 D4 D5 - low digital |
ARDIO_B |
4x Bits D6 D9 D10 D11 - high digital |
ARDIO_C |
4x Bits D12 D13 A0 A1 - mixed, digital and analog |
ARDIO_D |
4x Bits A2 A3 A6 A7 - analog (A6 & A7 are input only) |
PHOTON_A |
4x Bits D2, D3, D4, D5, – – – – |
PHOTON_B |
4x Bits D6, D7, A0, A1, – – – – |
PHOTON_C |
4x Bits A2, A3, DAC, WKP, – – – – |
WEMOS_A |
4x Bits GPIO 4, 0, 2, 14 Pins D2 D3 D4 D5 |
WEMOS_B |
4x Bits GPIO 12, 13, 3, 1 Pins D6 D7 RX TX |
WEMOS_C |
4x Bits GPIO 16, 13, 3, 1 Pins D0 D7 RX TX |
WEMOS_MATRIX |
4x Bits GPIO 4, 2, 14, 12 Pins D3 [D4 D5 D6] used by LEDCONTROL |
CPNODE_LOW |
8x Bits GPIO 4, 5, 6, 7, 8, 9, 10, 11 |
CPNODE_HIGH |
8x Bits GPIO 12, 13, A0, A1, A2, A3, A4, A5 |
I2Cexpander::I2Cexpander | ( | I2Cexpander::ExpanderType | device_type, |
size_t | address, | ||
boolean | debounce = false |
||
) |
Initialize what we can without knowing details of bit configuration
address | Either a zero-based chip sequence number OR the real I2C address Instead of remembering the address ranges used by the various I2C devices, the library can do it for you, and will calculate the I2C address based on this value. For example, an 8-bit 8574 starts at I2C address 0x20, bit the -A version starts at 0x38. In either case, here you would simply pass [0,1,2,3,4,5,6,7] to the init function and it will translate depending on the device type. The code uses a heuristic: if given address < device_base_address, add the base... |
device_type | The manufacturer's name for the device [MCP23016, PCF8574, MAX7311, ...] or a virtual name for the onboard MCU pins [ARDIO_A, WEMOS_C, ...] The special type "IGNORE" can be used to document I2C addresses used elsewhere. |
debounce | For bit-I/O, ensure that 2x readings are the same before noting a pin change. |
void I2Cexpander::init | ( | size_t | address, |
uint16_t | device_type, | ||
uint16_t | config, | ||
boolean | debounce = false |
||
) |
Initialize the I2C expander device. Usually called in the setup() routine for a one-time initialization.
address | Either a zero-based chip sequence number OR the real I2C address Instead of remembering the address ranges used by the various I2C devices, the library can do it for you, and will calculate the I2C address based on this value. For example, an 8-bit 8574 starts at I2C address 0x20, bit the -A version starts at 0x38. In either case, here you would simply pass [0,1,2,3,4,5,6,7] to the init function and it will translate depending on the device type. The code uses a heuristic: if given address < device_base_address, add the base... |
device_type | The manufacturer's name for the device [MCP23016, PCF8574, MAX7311, ...] or a virtual name for the onboard MCU pins [ARDIO_A, WEMOS_C, ...] The special type "IGNORE" can be used to document I2C addresses used elsewhere. |
config | Usually, the Input-vs-Output pin direction settings, used on a device-by-device basis for device specific configuration. |
debounce | For bit-I/O, ensure that 2x readings are the same before noting a pin change. |
void I2Cexpander::init | ( | uint16_t | config | ) |
Initialize the I2C expander device. Usually called in the setup() routine for a one-time initialization.
config | Usually, the Input-vs-Output pin direction settings, used on a device-by-device basis for device specific configuration. |
void I2Cexpander::digitalWrite | ( | uint8_t | dataPin, |
uint8_t | val | ||
) |
Arduino compatibility routine. Write a bit to an expander. Updates current cached state and writes data to the device.
dataPin | which bit in the I/O device's control [0..7 or 0..15, etc]. |
val | HIGH, 1, LOW, 0 |
uint8_t I2Cexpander::digitalRead | ( | uint8_t | dataPin | ) |
Arduino compatibility routine. Read from an expander, update the cached state and return the bit value.
dataPin | which bit in the I/O device's control [0..7 or 0..15, etc]. |
uint32_t I2Cexpander::read | ( | void | ) |
Read data from an expander, update the cached state and return the data.
|
inline |
wrapper for read().
void I2Cexpander::write | ( | uint32_t | data | ) |
Write data to an expander.
data | (1,4,8, 16 or 32 bits, per the device type) |
|
inline |
wrapper for write(data).
data | (1,4,8, 16 or 32 bits, per the device type) |
|
inline |
How many bits does this expander read/write?
|
inline |
Cached data - the last read from the device.
|
inline |
Cached data - the last write to the device.
|
inline |
Configuration initialization info.
|
inline |
Device Type.
|
inline |
Real I2C Address.
bool I2Cexpander::changed | ( | ) |
Have any INPUT bits changed since the last "read()"?
void I2Cexpander::printString | ( | const char * | tag | ) |
Internal debugging helper - print info about device along with some tag string...
tag |
|
static |
Library version
uint32_t I2Cexpander::next |
collection point for bits to-be-written
byte I2Cexpander::debugflag |
enable debugging if compiled in...