LCC Fusion Project 1.0
LCC Automation
Loading...
Searching...
No Matches
LccNodeI2c Class Reference

class for I2C connection to I2C enabled devices acting as 'slave' devices.
More...

#include <LccNodeI2c.h>

Inherits openlcb::Polling.

Public Member Functions

bool begin (const uint8_t bus, const uint8_t addressOffset)
 begin Invoked to begin I2C connection, based on the specfied bus and offset. More...
 
bool begin (const uint8_t bus, const uint8_t addressOffset, Adafruit_MCP23017 *pMcp)
 begin Invoked to begin an MCP (over I2C) connection, based on the specfied bus and offset. More...
 
bool begin (const uint8_t bus, const uint8_t addressOffset, FaBoPWM *pPwm)
 begin Invoked to begin an PWM (over I2C) connection, based on the specfied bus and offset. More...
 
bool send (char *message)
 send invoked to send a 'message' to an I2C enabled device, based the I2C bus and address previously configured. More...
 
bool get (char *message, const size_t messageLength)
 receives character data from I2C enabled device, based the I2C bus and address previously configured. More...
 
template<typename T >
bool get (T &out)
 receives integer data from I2C enabled device, based the I2C bus and address previously configured. More...
 
Polling * polling ()
 

Static Private Member Functions

static bool _isConnected (const uint8_t bus, const uint8_t address, TwoWire *pWire=nullptr)
 Check if an I2C device at the given address responds. More...
 
static TwoWire * _selectWire (uint8_t bus, TwoWire *pWire=nullptr)
 Selects the appropriate TwoWire instance for the given bus. More...
 
static bool _initWire (const uint8_t bus, const uint8_t address, TwoWire **ppWire)
 begin Invoked to begin an I2C connection, based on the specfied bus and offset. More...
 

Detailed Description

class for I2C connection to I2C enabled devices acting as 'slave' devices.


Note
The Node hardware device acts as an I2C 'master' device, connecting to one or more slave devices.

Uses Wire.h library to create an I2C connection on hardware bus 0 or 1. Requires an I2C base address to be configured in LccNodeConfig.h and an optional offset to be specified (has to match the offset being used by the I2C enabled device).

Parameters
addressBaseThe I2C device's base address. All I2C devices are idenitified by their base + offset addresses. begin() provides the address offset to be added to the base address. Defaults to 0x20 used by MCP23017 IC.

Definition at line 65 of file LccNodeI2c.h.

Member Function Documentation

◆ _initWire()

static bool LccNodeI2c::_initWire ( const uint8_t  bus,
const uint8_t  address,
TwoWire **  ppWire 
)
inlinestaticprivate

begin Invoked to begin an I2C connection, based on the specfied bus and offset.


Note
can be invoked multiple times if the I2C bus and/or offset changes.
Parameters
busis the I2C bus number (0 or 1)
addressis the offset from the base I2C address (passed in on the constuctor)
ppWireis the TwoWire instance pointer to be published to the caller
Note
I2C devices typically have DIP switches to enable setting the devices address offset value. If not available offset should = 0. This value must match the offset value for the specific device to connect too.

Definition at line 506 of file LccNodeI2c.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _isConnected()

static bool LccNodeI2c::_isConnected ( const uint8_t  bus,
const uint8_t  address,
TwoWire *  pWire = nullptr 
)
inlinestaticprivate

Check if an I2C device at the given address responds.

Parameters
busThe I2C bus number (0 or 1).
addressThe 7-bit I2C device address.
pWireOptional pointer to a TwoWire instance. If nullptr, the default bus will be used.
Returns
True if the device acknowledges, false otherwise.

Definition at line 460 of file LccNodeI2c.h.

Here is the caller graph for this function:

◆ _selectWire()

static TwoWire * LccNodeI2c::_selectWire ( uint8_t  bus,
TwoWire *  pWire = nullptr 
)
inlinestaticprivate

Selects the appropriate TwoWire instance for the given bus.

  • If a non-null pointer is provided, it is returned directly.
  • Otherwise, bus 0 returns &Wire and bus 1 returns &Wire1.
Parameters
busI²C bus index (0 or 1)
pWireOptional pointer supplied by the caller
Returns
Pointer to the chosen TwoWire instance

Definition at line 487 of file LccNodeI2c.h.

Here is the caller graph for this function:

◆ begin() [1/3]

bool LccNodeI2c::begin ( const uint8_t  bus,
const uint8_t  addressOffset 
)
inline

begin Invoked to begin I2C connection, based on the specfied bus and offset.


Note
can be invoked multiple times if the I2C bus and/or offset changes.
Parameters
busis the I2C bus number (0 or 1)
addressOffsetis the I2C offset (0-7) set by PCB Dip switches, added to base I2C address (MCP23017 uses 0x20, passed in on the constuctor
Returns
true if successful connection to device
Note
For LCC Fusion, I2C devices typically have DIP switches to enable setting the devices address offset value. If not available offset should = 0. This value must match the offset value for the specific device to connect too.
addressBase_ is assigned by the constructor, defaults to MCP's base address of x020

Definition at line 84 of file LccNodeI2c.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ begin() [2/3]

bool LccNodeI2c::begin ( const uint8_t  bus,
const uint8_t  addressOffset,
Adafruit_MCP23017 *  pMcp 
)
inline

begin Invoked to begin an MCP (over I2C) connection, based on the specfied bus and offset.


Note
can be invoked multiple times if the I2C bus and/or offset changes.
Parameters
busis the I2C bus number (0 or 1)
addressOffsetis the I2C offset (0-7) set by PCB Dip switches, added to base I2C address (MCP23017 uses 0x20, passed in on the constuctor
pMcpis the Adafruit_MCP23017 object
Returns
true if successful connection to device
Note
I2C/MCP devices typically have DIP switches to enable setting the devices address offset value. If not available offset should = 0. This value must match the offset value for the specific device to connect too.

Definition at line 103 of file LccNodeI2c.h.

Here is the call graph for this function:

◆ begin() [3/3]

bool LccNodeI2c::begin ( const uint8_t  bus,
const uint8_t  addressOffset,
FaBoPWM *  pPwm 
)
inline

begin Invoked to begin an PWM (over I2C) connection, based on the specfied bus and offset.


Note
can be invoked multiple times if the I2C bus and/or offset changes.
Parameters
busis the I2C bus number (0 or 1)
addressOffsetis the I2C offset (0-7) set by PCB Dip switches, added to base I2C address (PCA9685 uses 0x40, passed in on the constuctor
pPwmis the FaBoPWM object
Returns
true if successful connection to device
Note
I2C/PWM devices typically have DIP switches to enable setting the devices address offset value. If not available offset should = 0. This value must match the offset value for the specific device to connect too.

Definition at line 122 of file LccNodeI2c.h.

Here is the call graph for this function:

◆ get() [1/2]

bool LccNodeI2c::get ( char *  message,
const size_t  messageLength 
)
inline

receives character data from I2C enabled device, based the I2C bus and address previously configured.


Parameters
[in,out]messageis updated with bytes received from the I2C slave using requestFrom(address, numBytes)
messageLengthis the size of the message buffer (or # bytes expected from slave, which is less than size of buffer)
Returns
true if number of bytes received matches size of in/out message buffer

Definition at line 309 of file LccNodeI2c.h.

Here is the caller graph for this function:

◆ get() [2/2]

template<typename T >
bool LccNodeI2c::get ( T &  out)
inline

receives integer data from I2C enabled device, based the I2C bus and address previously configured.


Parameters
[in,out]outis an integer or char that is updated with bytes received from the I2C slave using requestFrom(address, numBytes)
Note
data types include; char, all sizes of signed/unsigned integers, float, long, double, enum, and struct/classes
Returns
true if number of bytes received matches size of in/out message buffer

Definition at line 327 of file LccNodeI2c.h.

◆ polling()

Polling * LccNodeI2c::polling ( )
inline
Returns
the instance to give to the RefreshLoop object.

Definition at line 344 of file LccNodeI2c.h.

◆ send()

bool LccNodeI2c::send ( char *  message)
inline

send invoked to send a 'message' to an I2C enabled device, based the I2C bus and address previously configured.


Note
assumes the message was delivered.
Parameters
messageis the text message to send
Note
max data length is 32 bytes

Definition at line 293 of file LccNodeI2c.h.

Here is the caller graph for this function:

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