FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
Loading...
Searching...
No Matches
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  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...
 

Public Types

using BeginFuture = TWriteRegisterFuture< IOCON, uint8_t, IOCONConverter >
 Create a future to be used by asynchronous method begin(BeginFuture&). More...
 
using SetValuesFuture = TWriteRegisterFuture< GPIO >
 Create a future to be used by asynchronous method values(SetValuesFuture&). More...
 
using GetValuesFuture = TReadRegisterFuture< GPIO >
 Create a future to be used by asynchronous method values(GetValuesFuture&). More...
 
using InterruptFlagsFuture = TReadRegisterFuture< INTF >
 Create a future to be used by asynchronous method interrupt_flags(InterruptFlagsFuture&). More...
 
using CapturedValuesFuture = TReadRegisterFuture< INTCAP >
 Create a future to be used by asynchronous method captured_values(CapturedValuesFuture&). More...
 
- Public Types inherited from i2c::I2CDevice< MANAGER >
using MANAGER = MANAGER
 the type of I2C Manager that can handle this device. More...
 

Public Member Functions

 MCP23008 (MANAGER &manager, uint8_t address)
 Create a new device driver for an MCP23008 chip. More...
 
int begin (BeginFuture &future)
 Initialize the chip before operation. More...
 
int configure_gpio (ConfigureGPIOFuture &future)
 Configure GPIO on the port of this MCP23008 chip. More...
 
int configure_interrupts (ConfigureInterruptsFuture &future)
 Configure interrupts on the port of this MCP23008 chip. More...
 
int values (SetValuesFuture &future)
 Set output levels of output pins on the port of this MCP23008 chip. More...
 
int values (GetValuesFuture &future)
 Get levels of pins on the port of this MCP23008 chip. More...
 
int interrupt_flags (InterruptFlagsFuture &future)
 Get the pins that generated the latest interrupt on the port of the MCP23008 chip. More...
 
int captured_values (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

- Protected Types inherited from i2c::I2CDevice< MANAGER >
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 (ABSTRACT_FUTURE &future, 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 (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 (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...
 
int async_multi_write (F &future, bool stop=true)
 Helper method that asynchronously launches I2C commands for a simple Future performing several register writes. 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...
 
bool sync_write ()
 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...
 
- 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...
 

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 40 of file mcp23008.h.

Member Typedef Documentation

◆ BeginFuture

template<typename MANAGER >
using devices::mcp230xx::MCP23008< MANAGER >::BeginFuture = TWriteRegisterFuture<IOCON, uint8_t, IOCONConverter>

Create a future to be used by asynchronous method begin(BeginFuture&).

This is used by begin() to pass input settings, and it shall be used by the caller to determine when the I2C transaction is finished, hence when you may use other methods.

Parameters
interrupt_polaritythe level triggerred on INT pin when an interrupt occurs
See also
begin(BeginFuture&)

Definition at line 121 of file mcp23008.h.

◆ SetValuesFuture

template<typename MANAGER >
using devices::mcp230xx::MCP23008< MANAGER >::SetValuesFuture = TWriteRegisterFuture<GPIO>

Create a future to be used by asynchronous method values(SetValuesFuture&).

This is used by values() to asynchronously launch the I2C transaction, and it shall be used by the caller to determine when the I2C transaction is finished.

Parameters
valueeach bit indicates the new level of the matching output pin of the selected port
See also
values(SetValuesFuture&)

Definition at line 255 of file mcp23008.h.

◆ GetValuesFuture

template<typename MANAGER >
using devices::mcp230xx::MCP23008< MANAGER >::GetValuesFuture = TReadRegisterFuture<GPIO>

Create a future to be used by asynchronous method values(GetValuesFuture&).

This is used by values() to asynchronously launch the I2C transaction, and it shall be used by the caller to determine when the I2C transaction is finished.

See also
values(GetValuesFuture&)

Definition at line 287 of file mcp23008.h.

◆ InterruptFlagsFuture

template<typename MANAGER >
using devices::mcp230xx::MCP23008< MANAGER >::InterruptFlagsFuture = TReadRegisterFuture<INTF>

Create a future to be used by asynchronous method interrupt_flags(InterruptFlagsFuture&).

This is used by interrupt_flags() to asynchronously launch the I2C transaction, and it shall be used by the caller to determine when the I2C transaction is finished.

See also
interrupt_flags(InterruptFlagsFuture&)

Definition at line 320 of file mcp23008.h.

◆ CapturedValuesFuture

template<typename MANAGER >
using devices::mcp230xx::MCP23008< MANAGER >::CapturedValuesFuture = TReadRegisterFuture<INTCAP>

Create a future to be used by asynchronous method captured_values(CapturedValuesFuture&).

This is used by captured_values() to asynchronously launch the I2C transaction, and it shall be used by the caller to determine when the I2C transaction is finished.

See also
captured_values(CapturedValuesFuture&)

Definition at line 354 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 105 of file mcp23008.h.

Member Function Documentation

◆ begin() [1/2]

template<typename MANAGER >
int devices::mcp230xx::MCP23008< MANAGER >::begin ( 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 140 of file mcp23008.h.

◆ configure_gpio() [1/2]

template<typename MANAGER >
int devices::mcp230xx::MCP23008< MANAGER >::configure_gpio ( 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 189 of file mcp23008.h.

◆ configure_interrupts() [1/2]

template<typename MANAGER >
int devices::mcp230xx::MCP23008< MANAGER >::configure_interrupts ( 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 239 of file mcp23008.h.

◆ values() [1/4]

template<typename MANAGER >
int devices::mcp230xx::MCP23008< MANAGER >::values ( 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 274 of file mcp23008.h.

◆ values() [2/4]

template<typename MANAGER >
int devices::mcp230xx::MCP23008< MANAGER >::values ( 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 306 of file mcp23008.h.

◆ interrupt_flags() [1/2]

template<typename MANAGER >
int devices::mcp230xx::MCP23008< MANAGER >::interrupt_flags ( 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 340 of file mcp23008.h.

◆ captured_values() [1/2]

template<typename MANAGER >
int devices::mcp230xx::MCP23008< MANAGER >::captured_values ( 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 376 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 394 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 416 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 440 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 458 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 472 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 487 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 504 of file mcp23008.h.


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