I2Cexpander - A collection of I2C I/O devices
Another SPCoast Library
Public Types | Public Member Functions | Public Attributes | Static Public Attributes | List of all members
I2Cexpander Class Reference

#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"
 

Detailed Description

A collection of I2C expanders with a simple API: init() read() / get() write() / put()

Member Enumeration Documentation

The number of bits managed by an expander device.

Enumerator
B_UNKNOWN 

Usually an error...

B4 

4-bit - Virtual expanders (aka MCU pins)

B6 

6-bit - potentially used for some virtual expanders

B8 

8-bit values

B16 

16-bit

B32 

32 bit

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

Constructor & Destructor Documentation

I2Cexpander::I2Cexpander ( I2Cexpander::ExpanderType  device_type,
size_t  address,
boolean  debounce = false 
)

Initialize what we can without knowing details of bit configuration

Parameters
addressEither 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_typeThe 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.
debounceFor bit-I/O, ensure that 2x readings are the same before noting a pin change.

Member Function Documentation

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.

Parameters
addressEither 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_typeThe 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.
configUsually, the Input-vs-Output pin direction settings, used on a device-by-device basis for device specific configuration.
debounceFor 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.

Parameters
configUsually, 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.

Parameters
dataPinwhich bit in the I/O device's control [0..7 or 0..15, etc].
valHIGH, 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.

Parameters
dataPinwhich bit in the I/O device's control [0..7 or 0..15, etc].
Returns
the value of the bit - HIGH, 1 or LOW, 0
uint32_t I2Cexpander::read ( void  )

Read data from an expander, update the cached state and return the data.

Returns
the data from the device (1,4,8, 16 or 32 bits, per the device type)
uint32_t I2Cexpander::get ( void  )
inline

wrapper for read().

Returns
the data from the device (1,4,8, 16 or 32 bits, per the device type)
void I2Cexpander::write ( uint32_t  data)

Write data to an expander.

Parameters
data(1,4,8, 16 or 32 bits, per the device type)
void I2Cexpander::put ( uint32_t  data)
inline

wrapper for write(data).

Parameters
data(1,4,8, 16 or 32 bits, per the device type)
uint16_t I2Cexpander::getSize ( void  )
inline

How many bits does this expander read/write?

Returns
(1,4,8, 16 or 32 bits, per the device type)
uint32_t I2Cexpander::current ( )
inline

Cached data - the last read from the device.

Returns
the same value as the last "read()"
uint32_t I2Cexpander::last ( )
inline

Cached data - the last write to the device.

Returns
the previous "write()" value.
uint16_t I2Cexpander::config ( )
inline

Configuration initialization info.

Returns
the "config" value sent to the "init()" function.
uint16_t I2Cexpander::chip ( )
inline

Device Type.

Returns
the "device_type" value sent to the "init()" function.
uint8_t I2Cexpander::i2caddr ( )
inline

Real I2C Address.

Returns
the device's I2C address (the sequence "address" + device_address_base).
bool I2Cexpander::changed ( )

Have any INPUT bits changed since the last "read()"?

Returns
TRUE if something changed.
void I2Cexpander::printString ( const char *  tag)

Internal debugging helper - print info about device along with some tag string...

Parameters
tag

Member Data Documentation

const char * I2Cexpander::version = "2.0.3"
static

Library version

uint32_t I2Cexpander::next

collection point for bits to-be-written

byte I2Cexpander::debugflag

enable debugging if compiled in...


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