FastArduino  v1.8
C++ library to build fast but small Arduino/AVR projects
devices::mcp230xx::MCP23008< MANAGER > Class Template Reference

I2C device driver for Microchip MCP23008 support. More...

#include <fastarduino/devices/mcp23008.h>

Inheritance diagram for devices::mcp230xx::MCP23008< MANAGER >:
Collaboration diagram for devices::mcp230xx::MCP23008< MANAGER >:

Classes

class  BeginFuture
 Create a future to be used by asynchronous method begin(BeginFuture&). More...
 
class  CapturedValuesFuture
 Create a future to be used by asynchronous method captured_values(CapturedValuesFuture&). More...
 
class  ConfigureGPIOFuture
 Create a future to be used by asynchronous method configure_gpio(ConfigureGPIOFuture&). More...
 
class  ConfigureInterruptsFuture
 Create a future to be used by asynchronous method configure_interrupts(ConfigureInterruptsFuture&). More...
 
class  GetValuesFuture
 Create a future to be used by asynchronous method values(GetValuesFuture&). More...
 
class  InterruptFlagsFuture
 Create a future to be used by asynchronous method interrupt_flags(InterruptFlagsFuture&). More...
 
class  SetValuesFuture
 Create a future to be used by asynchronous method values(SetValuesFuture&). More...
 

Public Member Functions

 MCP23008 (MANAGER &manager, uint8_t address)
 Create a new device driver for an MCP23008 chip. More...
 
int begin (PROXY< BeginFuture > future)
 Initialize the chip before operation. More...
 
int configure_gpio (PROXY< ConfigureGPIOFuture > future)
 Configure GPIO on the port of this MCP23008 chip. More...
 
int configure_interrupts (PROXY< ConfigureInterruptsFuture > future)
 Configure interrupts on the port of this MCP23008 chip. More...
 
int values (PROXY< SetValuesFuture > future)
 Set output levels of output pins on the port of this MCP23008 chip. More...
 
int values (PROXY< GetValuesFuture > future)
 Get levels of pins on the port of this MCP23008 chip. More...
 
int interrupt_flags (PROXY< InterruptFlagsFuture > future)
 Get the pins that generated the latest interrupt on the port of the MCP23008 chip. More...
 
int captured_values (PROXY< CapturedValuesFuture > future)
 Get captured levels, at the time an interrupt was triggered, of pins on the port of this MCP23008 chip. More...
 
bool begin (InterruptPolarity interrupt_polarity=InterruptPolarity::ACTIVE_HIGH)
 Initialize the chip before operation. More...
 
bool configure_gpio (uint8_t direction, uint8_t pullup=0, uint8_t polarity=0)
 Configure GPIO on the port of this MCP23008 chip. More...
 
bool configure_interrupts (uint8_t int_pins, uint8_t ref=0, uint8_t compare_ref=0)
 Configure interrupts on the port of this MCP23008 chip. More...
 
bool values (uint8_t value)
 Set output levels of output pins on the port of this MCP23008 chip. More...
 
uint8_t values ()
 Get levels of pins on the port of this MCP23008 chip. More...
 
uint8_t interrupt_flags ()
 Get the pins that generated the latest interrupt on the port of the MCP23008 chip. More...
 
uint8_t captured_values ()
 Get captured levels, at the time an interrupt was triggered, of pins on the port of this MCP23008 chip. More...
 

Additional Inherited Members

- Public Types inherited from i2c::I2CDevice< MANAGER >
using MANAGER = MANAGER
 the type of I2C Manager that can handle this device.
 
- Protected Types inherited from i2c::I2CDevice< MANAGER >
using PROXY = typename MANAGER::template PROXY< T >
 The actual type used for all proxies; may be lifecycle::LightProxy or lifecycle::DirectProxy. More...
 
using ABSTRACT_FUTURE = typename MANAGER::ABSTRACT_FUTURE
 The abstract base class of all futures to be defined for a device. More...
 
using FUTURE = typename MANAGER::template FUTURE< OUT, IN >
 The template base class of all futures to be defined for a device. More...
 
- Protected Member Functions inherited from i2c::I2CDevice< MANAGER >
 I2CDevice (MANAGER &manager, uint8_t device, UNUSED Mode< MODE > mode, bool auto_stop)
 Create a new I2C device. More...
 
 I2CDevice (const I2CDevice &)=delete
 
I2CDeviceoperator= (const I2CDevice &)=delete
 
void set_device (uint8_t device)
 Change the I2C address of this device. More...
 
int launch_commands (PROXY< ABSTRACT_FUTURE > proxy, utils::range< I2CLightCommand > commands)
 Launch execution (asynchronously or synchronously, depending on MANAGER) of a chain of I2CLightCommand items (constructed with read() and write() methods). More...
 
int async_read (PROXY< F > future, bool stop=true)
 Helper method that asynchronously launches I2C commands for a simple Future performing one write followed by one read (typically for device register reading). More...
 
bool sync_read (T &result)
 Helper method that launches I2C commands for a simple Future performing one write followed by one read (typically for device register reading); the method blocks until the end of the I2C transaction. More...
 
int async_write (PROXY< F > future, bool stop=true)
 Helper method that asynchronously launches I2C commands for a simple Future performing only one write (typically for device register writing). More...
 
bool sync_write (const T &value)
 Helper method that launches I2C commands for a simple Future performing only one write (typically for device register writing); the method blocks until the end of the I2C transaction. More...
 
T & resolve (PROXY< T > proxy) const
 Resolve proxy to an actual T (typically a Future). More...
 
- Static Protected Member Functions inherited from i2c::I2CDevice< MANAGER >
static constexpr I2CLightCommand read (uint8_t read_count=0, bool finish_future=false, bool stop=false)
 Build a read I2CLightCommand that can be later pushed to the I2C Manager for proper handling. More...
 
static constexpr I2CLightCommand write (uint8_t write_count=0, bool finish_future=false, bool stop=false)
 Build a write I2CLightCommand that can be later pushed to the I2C Manager for proper handling. More...
 
static PROXY< T > make_proxy (const T &target)
 Create a PROXY from target. More...
 

Detailed Description

template<typename MANAGER>
class devices::mcp230xx::MCP23008< MANAGER >

I2C device driver for Microchip MCP23008 support.

The MCP23008 chip is a 8-Bit I/O Expander with I2C interface.

Template Parameters
MANAGERone of FastArduino available I2C Manager
See also
devices::mcp23017::MCP23017

Definition at line 38 of file mcp23008.h.

Constructor & Destructor Documentation

◆ MCP23008()

template<typename MANAGER >
devices::mcp230xx::MCP23008< MANAGER >::MCP23008 ( MANAGER manager,
uint8_t  address 
)
inline

Create a new device driver for an MCP23008 chip.

The address must match the actual address set for that chip (through pins A0, A1, A3).

Parameters
managerreference to a suitable MANAGER for this device
addressthe address part (0-7) set by A0-3 pins of the chip

Definition at line 63 of file mcp23008.h.

Member Function Documentation

◆ begin() [1/2]

template<typename MANAGER >
int devices::mcp230xx::MCP23008< MANAGER >::begin ( PROXY< BeginFuture future)
inline

Initialize the chip before operation.

Warning
Asynchronous API!
Parameters
futurea BeginFuture passed by the caller, that will be updated once the current I2C action is finished.
Return values
0if no problem occurred during the preparation of I2C transaction
Returns
an error code if something bad happened; for an asynchronous I2C Manager, this typically happens when its queue of I2CCommand is full; for a synchronous I2C Manager, any error on the I2C bus or on the target device will trigger an error here. the list of possible errors is in namespace errors.
See also
BeginFuture
begin(InterruptPolarity)
errors

Definition at line 107 of file mcp23008.h.

◆ configure_gpio() [1/2]

template<typename MANAGER >
int devices::mcp230xx::MCP23008< MANAGER >::configure_gpio ( PROXY< ConfigureGPIOFuture future)
inline

Configure GPIO on the port of this MCP23008 chip.

Warning
Asynchronous API!
Parameters
futurea ConfigureGPIOFuture passed by the caller, that will be updated once the current I2C action is finished.
Return values
0if no problem occurred during the preparation of I2C transaction
Returns
an error code if something bad happened; for an asynchronous I2C Manager, this typically happens when its queue of I2CCommand is full; for a synchronous I2C Manager, any error on the I2C bus or on the target device will trigger an error here. the list of possible errors is in namespace errors.
See also
ConfigureGPIOFuture
configure_gpio(uint8_t, uint8_t, uint8_t)
errors

Definition at line 158 of file mcp23008.h.

◆ configure_interrupts() [1/2]

template<typename MANAGER >
int devices::mcp230xx::MCP23008< MANAGER >::configure_interrupts ( PROXY< ConfigureInterruptsFuture future)
inline

Configure interrupts on the port of this MCP23008 chip.

Warning
Asynchronous API!
Parameters
futurea ConfigureInterruptsFuture passed by the caller, that will be updated once the current I2C action is finished.
Return values
0if no problem occurred during the preparation of I2C transaction
Returns
an error code if something bad happened; for an asynchronous I2C Manager, this typically happens when its queue of I2CCommand is full; for a synchronous I2C Manager, any error on the I2C bus or on the target device will trigger an error here. the list of possible errors is in namespace errors.
See also
ConfigureInterruptsFuture
configure_interrupts(uint8_t, uint8_t, uint8_t)
errors

Definition at line 210 of file mcp23008.h.

◆ values() [1/4]

template<typename MANAGER >
int devices::mcp230xx::MCP23008< MANAGER >::values ( PROXY< SetValuesFuture future)
inline

Set output levels of output pins on the port of this MCP23008 chip.

Warning
Asynchronous API!
Parameters
futurea SetValuesFuture passed by the caller, that will be updated once the current I2C action is finished.
Return values
0if no problem occurred during the preparation of I2C transaction
Returns
an error code if something bad happened; for an asynchronous I2C Manager, this typically happens when its queue of I2CCommand is full; for a synchronous I2C Manager, any error on the I2C bus or on the target device will trigger an error here. the list of possible errors is in namespace errors.
See also
SetValuesFuture
values(uint8_t value)
errors

Definition at line 253 of file mcp23008.h.

◆ values() [2/4]

template<typename MANAGER >
int devices::mcp230xx::MCP23008< MANAGER >::values ( PROXY< GetValuesFuture future)
inline

Get levels of pins on the port of this MCP23008 chip.

Warning
Asynchronous API!
Parameters
futurea GetValuesFuture passed by the caller, that will be updated once the current I2C action is finished.
Return values
0if no problem occurred during the preparation of I2C transaction
Returns
an error code if something bad happened; for an asynchronous I2C Manager, this typically happens when its queue of I2CCommand is full; for a synchronous I2C Manager, any error on the I2C bus or on the target device will trigger an error here. the list of possible errors is in namespace errors.
See also
GetValuesFuture
uint8_t values()
errors

Definition at line 293 of file mcp23008.h.

◆ interrupt_flags() [1/2]

template<typename MANAGER >
int devices::mcp230xx::MCP23008< MANAGER >::interrupt_flags ( PROXY< InterruptFlagsFuture future)
inline

Get the pins that generated the latest interrupt on the port of the MCP23008 chip.

Warning
Asynchronous API!
Parameters
futurea InterruptFlagsFuture passed by the caller, that will be updated once the current I2C action is finished.
Return values
0if no problem occurred during the preparation of I2C transaction
Returns
an error code if something bad happened; for an asynchronous I2C Manager, this typically happens when its queue of I2CCommand is full; for a synchronous I2C Manager, any error on the I2C bus or on the target device will trigger an error here. the list of possible errors is in namespace errors.
See also
InterruptFlagsFuture
uint8_t interrupt_flags()
errors

Definition at line 335 of file mcp23008.h.

◆ captured_values() [1/2]

template<typename MANAGER >
int devices::mcp230xx::MCP23008< MANAGER >::captured_values ( PROXY< CapturedValuesFuture future)
inline

Get captured levels, at the time an interrupt was triggered, of pins on the port of this MCP23008 chip.

This allows to know what generated an interrupt, even if input pins were modified afterwards.

Warning
Asynchronous API!
Parameters
futurea CapturedValuesFuture passed by the caller, that will be updated once the current I2C action is finished.
Return values
0if no problem occurred during the preparation of I2C transaction
Returns
an error code if something bad happened; for an asynchronous I2C Manager, this typically happens when its queue of I2CCommand is full; for a synchronous I2C Manager, any error on the I2C bus or on the target device will trigger an error here. the list of possible errors is in namespace errors.
See also
CapturedValuesFuture
uint8_t captured_values()
errors

Definition at line 379 of file mcp23008.h.

◆ begin() [2/2]

template<typename MANAGER >
bool devices::mcp230xx::MCP23008< MANAGER >::begin ( InterruptPolarity  interrupt_polarity = InterruptPolarity::ACTIVE_HIGH)
inline

Initialize the chip before operation.

Warning
Blocking API!
Parameters
interrupt_polaritythe level triggerred on INTA or INTB pin when an interrupt occurs
Return values
trueif the operation succeeded
falseif the operation failed
See also
begin(BeginFuture&)

Definition at line 397 of file mcp23008.h.

◆ configure_gpio() [2/2]

template<typename MANAGER >
bool devices::mcp230xx::MCP23008< MANAGER >::configure_gpio ( uint8_t  direction,
uint8_t  pullup = 0,
uint8_t  polarity = 0 
)
inline

Configure GPIO on the port of this MCP23008 chip.

Warning
Blocking API!
Parameters
directioneach bit sets the direction of one pin of the selected port; 1 means **I**nput, 0 means **O**utput.
pullupeach bit (only for input pins) sets if a pullup resistor shall be internally connected to the pin; if 1, a pullup is added, if 0, no pullup is added.
polarityeach bit (only for input pins) let you invert polarity of the matching input pin; if 1, polarity is inverted, ie one the level on the input pin is 0, then it is read as 1, and conversely.
Return values
trueif the operation succeeded
falseif the operation failed
See also
configure_gpio(ConfigureGPIOFuture&)

Definition at line 421 of file mcp23008.h.

◆ configure_interrupts() [2/2]

template<typename MANAGER >
bool devices::mcp230xx::MCP23008< MANAGER >::configure_interrupts ( uint8_t  int_pins,
uint8_t  ref = 0,
uint8_t  compare_ref = 0 
)
inline

Configure interrupts on the port of this MCP23008 chip.

Warning
Blocking API!
Parameters
int_pinseach bit sets if the matching pin shall generate interrupts
refcontains the reference value for comparison with the actual input pin; if input differs, then an interrupt will be triggered for that pin, provided that compare_ref for that bit is also 1.
compare_refeach bit indicates the condition for which the matching input pin can generate interrupts; if 0, an interrupt is generated every time the input pin changes level, if 1, an interrupt is generated every time the input pin level changes to be diferent than the matching bit.
Return values
trueif the operation succeeded
falseif the operation failed
See also
configure_interrupts(ConfigureInterruptsFuture&)

Definition at line 445 of file mcp23008.h.

◆ values() [3/4]

template<typename MANAGER >
bool devices::mcp230xx::MCP23008< MANAGER >::values ( uint8_t  value)
inline

Set output levels of output pins on the port of this MCP23008 chip.

Warning
Blocking API!
Parameters
valueeach bit indicates the new level of the matching output pin of the selected port
Return values
trueif the operation succeeded
falseif the operation failed
See also
values(SetValuesFuture&)

Definition at line 463 of file mcp23008.h.

◆ values() [4/4]

template<typename MANAGER >
uint8_t devices::mcp230xx::MCP23008< MANAGER >::values ( )
inline

Get levels of pins on the port of this MCP23008 chip.

Warning
Blocking API!
Returns
a value where each bit indicates the current level of the matching pin of the selected port
See also
values(GetValuesFuture&)

Definition at line 479 of file mcp23008.h.

◆ interrupt_flags() [2/2]

template<typename MANAGER >
uint8_t devices::mcp230xx::MCP23008< MANAGER >::interrupt_flags ( )
inline

Get the pins that generated the latest interrupt on the port of the MCP23008 chip.

Warning
Blocking API!
Returns
a value where each bit indicates if a pin generated the latest interrupt or not
See also
interrupt_flags(InterruptFlagsFuture&)

Definition at line 500 of file mcp23008.h.

◆ captured_values() [2/2]

template<typename MANAGER >
uint8_t devices::mcp230xx::MCP23008< MANAGER >::captured_values ( )
inline

Get captured levels, at the time an interrupt was triggered, of pins on the port of this MCP23008 chip.

This allows to know what generated an interrupt, even if input pins were modified afterwards.

Warning
Blocking API!
Returns
a value where each bit indicates the level of the matching pin, captured at the interrupt time.
See also
captured_values(CapturedValuesFuture&)

Definition at line 523 of file mcp23008.h.


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