FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
|
I2C device driver for Microchip MCP23017 support. More...
#include <fastarduino/devices/mcp23017.h>
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 | |
I2CDevice & | operator= (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... | |
I2C device driver for Microchip MCP23017 support.
The MCP23017 chip is a 16-Bit I/O Expander with I2C interface.
MANAGER | one of FastArduino available I2C Manager |
Definition at line 102 of file mcp23017.h.
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.
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. |
value | each bit indicates the new level of the matching output pin of the selected port |
Definition at line 358 of file mcp23017.h.
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.
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. |
Definition at line 399 of file mcp23017.h.
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.
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. |
Definition at line 440 of file mcp23017.h.
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.
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. |
Definition at line 483 of file mcp23017.h.
|
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).
manager | reference to a suitable MANAGER for this device |
address | the address part (0-7) set by A0-3 pins of the chip |
Definition at line 172 of file mcp23017.h.
|
inline |
Initialize the chip before operation.
future | a BeginFuture passed by the caller, that will be updated once the current I2C action is finished. |
0 | if no problem occurred during the preparation of I2C transaction |
errors
.Definition at line 222 of file mcp23017.h.
|
inline |
Configure GPIO on one or both ports of this MCP23017 chip.
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. |
future | a ConfigureGPIOFuture passed by the caller, that will be updated once the current I2C action is finished. |
0 | if no problem occurred during the preparation of I2C transaction |
errors
.Definition at line 279 of file mcp23017.h.
|
inline |
Configure interrupts on one or both ports of this MCP23017 chip.
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. |
future | a ConfigureInterruptsFuture passed by the caller, that will be updated once the current I2C action is finished. |
0 | if no problem occurred during the preparation of I2C transaction |
errors
.Definition at line 338 of file mcp23017.h.
|
inline |
Set output levels of output pins on one or both ports of this MCP23017 chip.
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. |
future | a SetValuesFuture passed by the caller, that will be updated once the current I2C action is finished. |
0 | if no problem occurred during the preparation of I2C transaction |
errors
.Definition at line 381 of file mcp23017.h.
|
inline |
Get levels of pins on one or both ports of this MCP23017 chip.
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. |
future | a GetValuesFuture passed by the caller, that will be updated once the current I2C action is finished. |
0 | if no problem occurred during the preparation of I2C transaction |
errors
.Definition at line 421 of file mcp23017.h.
|
inline |
Get the pins that generated the latest interrupt on one or both ports of the MCP23017 chip.
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. |
future | a InterruptFlagsFuture passed by the caller, that will be updated once the current I2C action is finished. |
0 | if no problem occurred during the preparation of I2C transaction |
errors
.Definition at line 464 of file mcp23017.h.
|
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.
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. |
future | a CapturedValuesFuture passed by the caller, that will be updated once the current I2C action is finished. |
0 | if no problem occurred during the preparation of I2C transaction |
errors
.Definition at line 509 of file mcp23017.h.
|
inline |
Initialize the chip before operation.
mirror_interrupts | if 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_polarity | the level triggerred on INTA or INTB pin when an interrupt occurs |
true | if the operation succeeded |
false | if the operation failed |
Definition at line 531 of file mcp23017.h.
|
inline |
Configure GPIO on one or both ports of this MCP23017 chip.
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. |
direction | each bit sets the direction of one pin of the selected port; 1 means **I**nput, 0 means **O**utput. |
pullup | each 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. |
polarity | each 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. |
true | if the operation succeeded |
false | if the operation failed |
Definition at line 559 of file mcp23017.h.
|
inline |
Configure interrupts on one or both ports of this MCP23017 chip.
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. |
int_pins | each bit sets if the matching pin shall generate interrupts |
ref | contains 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_ref | each 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. |
true | if the operation succeeded |
false | if the operation failed |
Definition at line 587 of file mcp23017.h.
|
inline |
Set output levels of output pins on one or both ports of this MCP23017 chip.
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. |
value | each bit indicates the new level of the matching output pin of the selected port |
true | if the operation succeeded |
false | if the operation failed |
Definition at line 608 of file mcp23017.h.
|
inline |
Get levels of pins on one or both ports of this MCP23017 chip.
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. |
Definition at line 625 of file mcp23017.h.
|
inline |
Get the pins that generated the latest interrupt on one or both ports of the MCP23017 chip.
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. |
Definition at line 643 of file mcp23017.h.
|
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.
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. |
Definition at line 663 of file mcp23017.h.