FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
Loading...
Searching...
No Matches
devices::mcp230xx::MCP23017< MANAGER > Class Template Reference

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

#include <fastarduino/devices/mcp23017.h>

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

Classes

class  BeginFuture
 Create a future to be used by asynchronous method begin(BeginFuture&). 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<P_>&). More...
 

Public Types

template<MCP23017Port P_>
using SetValuesFuture = TWriteRegisterFuture< P_, GPIO_A >
 Create a future to be used by asynchronous method values(SetValuesFuture<P_>&). More...
 
template<MCP23017Port P_>
using GetValuesFuture = TReadRegisterFuture< P_, GPIO_A >
 Create a future to be used by asynchronous method values(GetValuesFuture<P_>&). More...
 
template<MCP23017Port P_>
using InterruptFlagsFuture = TReadRegisterFuture< P_, INTF_A >
 Create a future to be used by asynchronous method interrupt_flags(InterruptFlagsFuture<P_>&). More...
 
template<MCP23017Port P_>
using CapturedValuesFuture = TReadRegisterFuture< P_, INTCAP_A >
 Create a future to be used by asynchronous method captured_values(CapturedValuesFuture<P_>&). 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

 MCP23017 (MANAGER &manager, uint8_t address)
 Create a new device driver for an MCP23017 chip. More...
 
int begin (BeginFuture &future)
 Initialize the chip before operation. More...
 
template<MCP23017Port P_>
int configure_gpio (ConfigureGPIOFuture< P_ > &future)
 Configure GPIO on one or both ports of this MCP23017 chip. More...
 
template<MCP23017Port P_>
int configure_interrupts (ConfigureInterruptsFuture< P_ > &future)
 Configure interrupts on one or both ports of this MCP23017 chip. More...
 
template<MCP23017Port P_>
int values (SetValuesFuture< P_ > &future)
 Set output levels of output pins on one or both ports of this MCP23017 chip. More...
 
template<MCP23017Port P_>
int values (GetValuesFuture< P_ > &future)
 Get levels of pins on one or both ports of this MCP23017 chip. More...
 
template<MCP23017Port P_>
int interrupt_flags (InterruptFlagsFuture< P_ > &future)
 Get the pins that generated the latest interrupt on one or both ports of the MCP23017 chip. More...
 
template<MCP23017Port P_>
int captured_values (CapturedValuesFuture< P_ > &future)
 Get captured levels, at the time an interrupt was triggered, of pins on one or both ports of this MCP23017 chip. More...
 
bool begin (bool mirror_interrupts=false, InterruptPolarity interrupt_polarity=InterruptPolarity::ACTIVE_HIGH)
 Initialize the chip before operation. More...
 
template<MCP23017Port P_>
bool configure_gpio (T< P_ > direction, T< P_ > pullup=T< P_ >{}, T< P_ > polarity=T< P_ >{})
 Configure GPIO on one or both ports of this MCP23017 chip. More...
 
template<MCP23017Port P_>
bool configure_interrupts (T< P_ > int_pins, T< P_ > ref=T< P_ >{}, T< P_ > compare_ref=T< P_ >{})
 Configure interrupts on one or both ports of this MCP23017 chip. More...
 
template<MCP23017Port P_>
bool values (T< P_ > value)
 Set output levels of output pins on one or both ports of this MCP23017 chip. More...
 
template<MCP23017Port P_>
T< P_ > values ()
 Get levels of pins on one or both ports of this MCP23017 chip. More...
 
template<MCP23017Port P_>
T< P_ > interrupt_flags ()
 Get the pins that generated the latest interrupt on one or both ports of the MCP23017 chip. More...
 
template<MCP23017Port P_>
T< P_ > captured_values ()
 Get captured levels, at the time an interrupt was triggered, of pins on one or both ports of this MCP23017 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::MCP23017< MANAGER >

I2C device driver for Microchip MCP23017 support.

The MCP23017 chip is a 16-Bit I/O Expander with I2C interface.

Template Parameters
MANAGERone of FastArduino available I2C Manager

Definition at line 102 of file mcp23017.h.

Member Typedef Documentation

◆ SetValuesFuture

template<typename MANAGER >
template<MCP23017Port P_>
using devices::mcp230xx::MCP23017< MANAGER >::SetValuesFuture = TWriteRegisterFuture<P_, GPIO_A>

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

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.

Template Parameters
P_which port to configure, may be A, B or both; if both, then all arguments will be uint16_t, with low byte for port A configuration, and high byte for port B.
Parameters
valueeach bit indicates the new level of the matching output pin of the selected port
See also
values(SetValuesFuture<P_>&)

Definition at line 358 of file mcp23017.h.

◆ GetValuesFuture

template<typename MANAGER >
template<MCP23017Port P_>
using devices::mcp230xx::MCP23017< MANAGER >::GetValuesFuture = TReadRegisterFuture<P_, GPIO_A>

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

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.

Template Parameters
P_which port to configure, may be A, B or both; if both, then all arguments will be uint16_t, with low byte for port A configuration, and high byte for port B.
See also
values(GetValuesFuture<P_>&)

Definition at line 399 of file mcp23017.h.

◆ InterruptFlagsFuture

template<typename MANAGER >
template<MCP23017Port P_>
using devices::mcp230xx::MCP23017< MANAGER >::InterruptFlagsFuture = TReadRegisterFuture<P_, INTF_A>

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

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.

Template Parameters
P_which port to read from, may be A, B or both; if both, then the return type will be uint16_t, with low byte for port A, and high byte for port B.
See also
interrupt_flags(InterruptFlagsFuture<P_>&)

Definition at line 440 of file mcp23017.h.

◆ CapturedValuesFuture

template<typename MANAGER >
template<MCP23017Port P_>
using devices::mcp230xx::MCP23017< MANAGER >::CapturedValuesFuture = TReadRegisterFuture<P_, INTCAP_A>

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

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.

Template Parameters
P_which port to read from, may be A, B or both; if both, then the return type will be uint16_t, with low byte for port A, and high byte for port B.
See also
captured_values(CapturedValuesFuture<P_>&)

Definition at line 483 of file mcp23017.h.

Constructor & Destructor Documentation

◆ MCP23017()

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

Create a new device driver for an MCP23017 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 172 of file mcp23017.h.

Member Function Documentation

◆ begin() [1/2]

template<typename MANAGER >
int devices::mcp230xx::MCP23017< 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(bool, InterruptPolarity)
errors

Definition at line 222 of file mcp23017.h.

◆ configure_gpio() [1/2]

template<typename MANAGER >
template<MCP23017Port P_>
int devices::mcp230xx::MCP23017< MANAGER >::configure_gpio ( ConfigureGPIOFuture< P_ > &  future)
inline

Configure GPIO on one or both ports of this MCP23017 chip.

Warning
Asynchronous API!
Template Parameters
P_which port to configure, may be A, B or both; if both, then all arguments will be uint16_t, with low byte for port A configuration, and high byte for port B.
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<P_>
configure_gpio(T<P_>, T<P_>, T<P_>)
errors

Definition at line 279 of file mcp23017.h.

◆ configure_interrupts() [1/2]

template<typename MANAGER >
template<MCP23017Port P_>
int devices::mcp230xx::MCP23017< MANAGER >::configure_interrupts ( ConfigureInterruptsFuture< P_ > &  future)
inline

Configure interrupts on one or both ports of this MCP23017 chip.

Warning
Asynchronous API!
Template Parameters
P_which port to configure, may be A, B or both; if both, then all arguments will be uint16_t, with low byte for port A configuration, and high byte for port B.
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<P_>
configure_interrupts(T<P_>, T<P_>, T<P_>)
errors

Definition at line 338 of file mcp23017.h.

◆ values() [1/4]

template<typename MANAGER >
template<MCP23017Port P_>
int devices::mcp230xx::MCP23017< MANAGER >::values ( SetValuesFuture< P_ > &  future)
inline

Set output levels of output pins on one or both ports of this MCP23017 chip.

Warning
Asynchronous API!
Template Parameters
P_which port to write to, may be A, B or both; if both, then all arguments will be uint16_t, with low byte for port A, and high byte for port B.
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<P_>
values(T<P_> value)
errors

Definition at line 381 of file mcp23017.h.

◆ values() [2/4]

template<typename MANAGER >
template<MCP23017Port P_>
int devices::mcp230xx::MCP23017< MANAGER >::values ( GetValuesFuture< P_ > &  future)
inline

Get levels of pins on one or both ports of this MCP23017 chip.

Warning
Asynchronous API!
Template Parameters
P_which port to read from, may be A, B or both; if both, then the return type will be uint16_t, with low byte for port A, and high byte for port B.
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<P_>
T<P_> values()
errors

Definition at line 421 of file mcp23017.h.

◆ interrupt_flags() [1/2]

template<typename MANAGER >
template<MCP23017Port P_>
int devices::mcp230xx::MCP23017< MANAGER >::interrupt_flags ( InterruptFlagsFuture< P_ > &  future)
inline

Get the pins that generated the latest interrupt on one or both ports of the MCP23017 chip.

Warning
Asynchronous API!
Template Parameters
P_which port to read from, may be A, B or both; if both, then the return type will be uint16_t, with low byte for port A, and high byte for port B.
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<P_>
T<P_> interrupt_flags()
errors

Definition at line 464 of file mcp23017.h.

◆ captured_values() [1/2]

template<typename MANAGER >
template<MCP23017Port P_>
int devices::mcp230xx::MCP23017< MANAGER >::captured_values ( CapturedValuesFuture< P_ > &  future)
inline

Get captured levels, at the time an interrupt was triggered, of pins on one or both ports of this MCP23017 chip.

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

Warning
Asynchronous API!
Template Parameters
P_which port to read from, may be A, B or both; if both, then the return type will be uint16_t, with low byte for port A, and high byte for port B.
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<P_>
T<P_> captured_values()
errors

Definition at line 509 of file mcp23017.h.

◆ begin() [2/2]

template<typename MANAGER >
bool devices::mcp230xx::MCP23017< MANAGER >::begin ( bool  mirror_interrupts = false,
InterruptPolarity  interrupt_polarity = InterruptPolarity::ACTIVE_HIGH 
)
inline

Initialize the chip before operation.

Warning
Blocking API!
Parameters
mirror_interruptsif true then INTA and INTB are mirrored, hence any interrupt occurring on A or B port will generate a level change on both pins; hence you can connect any pin to only one interrupt pin on Arduino if you are lacking available pins.
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 531 of file mcp23017.h.

◆ configure_gpio() [2/2]

template<typename MANAGER >
template<MCP23017Port P_>
bool devices::mcp230xx::MCP23017< MANAGER >::configure_gpio ( T< P_ >  direction,
T< P_ >  pullup = T<P_>{},
T< P_ >  polarity = T<P_>{} 
)
inline

Configure GPIO on one or both ports of this MCP23017 chip.

Warning
Blocking API!
Template Parameters
P_which port to configure, may be A, B or both; if both, then all arguments will be uint16_t, with low byte for port A configuration, and high byte for port B.
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<P_>&)

Definition at line 559 of file mcp23017.h.

◆ configure_interrupts() [2/2]

template<typename MANAGER >
template<MCP23017Port P_>
bool devices::mcp230xx::MCP23017< MANAGER >::configure_interrupts ( T< P_ >  int_pins,
T< P_ >  ref = T<P_>{},
T< P_ >  compare_ref = T<P_>{} 
)
inline

Configure interrupts on one or both ports of this MCP23017 chip.

Warning
Blocking API!
Template Parameters
P_which port to configure, may be A, B or both; if both, then all arguments will be uint16_t, with low byte for port A configuration, and high byte for port B.
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<P_>&)

Definition at line 587 of file mcp23017.h.

◆ values() [3/4]

template<typename MANAGER >
template<MCP23017Port P_>
bool devices::mcp230xx::MCP23017< MANAGER >::values ( T< P_ >  value)
inline

Set output levels of output pins on one or both ports of this MCP23017 chip.

Warning
Blocking API!
Template Parameters
P_which port to write to, may be A, B or both; if both, then all arguments will be uint16_t, with low byte for port A, and high byte for port B.
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<P_>&)

Definition at line 608 of file mcp23017.h.

◆ values() [4/4]

template<typename MANAGER >
template<MCP23017Port P_>
T< P_ > devices::mcp230xx::MCP23017< MANAGER >::values ( )
inline

Get levels of pins on one or both ports of this MCP23017 chip.

Warning
Blocking API!
Template Parameters
P_which port to read from, may be A, B or both; if both, then the return type will be uint16_t, with low byte for port A, and high byte for port B.
Returns
a value where each bit indicates the current level of the matching pin of the selected port
See also
values(GetValuesFuture<P_>&)

Definition at line 625 of file mcp23017.h.

◆ interrupt_flags() [2/2]

template<typename MANAGER >
template<MCP23017Port P_>
T< P_ > devices::mcp230xx::MCP23017< MANAGER >::interrupt_flags ( )
inline

Get the pins that generated the latest interrupt on one or both ports of the MCP23017 chip.

Warning
Blocking API!
Template Parameters
P_which port to read from, may be A, B or both; if both, then the return type will be uint16_t, with low byte for port A, and high byte for port B.
Returns
a value where each bit indicates if a pin generated the latest interrupt or not
See also
interrupt_flags(InterruptFlagsFuture<P_>&)

Definition at line 643 of file mcp23017.h.

◆ captured_values() [2/2]

template<typename MANAGER >
template<MCP23017Port P_>
T< P_ > devices::mcp230xx::MCP23017< MANAGER >::captured_values ( )
inline

Get captured levels, at the time an interrupt was triggered, of pins on one or both ports of this MCP23017 chip.

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

Warning
Blocking API!
Template Parameters
P_which port to read from, may be A, B or both; if both, then the return type will be uint16_t, with low byte for port A, and high byte for port B.
Returns
a value where each bit indicates the level of the matching pin, captured at the interrupt time.
See also
captured_values(CapturedValuesFuture<P_>&)

Definition at line 663 of file mcp23017.h.


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