FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
|
I2C device driver for Microchip MCP23008 support. More...
#include <fastarduino/devices/mcp23008.h>
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 | |
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 MCP23008 support.
The MCP23008 chip is a 8-Bit I/O Expander with I2C interface.
MANAGER | one of FastArduino available I2C Manager |
Definition at line 40 of file mcp23008.h.
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.
interrupt_polarity | the level triggerred on INT pin when an interrupt occurs |
Definition at line 121 of file mcp23008.h.
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.
value | each bit indicates the new level of the matching output pin of the selected port |
Definition at line 255 of file mcp23008.h.
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.
Definition at line 287 of file mcp23008.h.
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.
Definition at line 320 of file mcp23008.h.
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.
Definition at line 354 of file mcp23008.h.
|
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).
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 105 of file mcp23008.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 140 of file mcp23008.h.
|
inline |
Configure GPIO on the port of this MCP23008 chip.
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 189 of file mcp23008.h.
|
inline |
Configure interrupts on the port of this MCP23008 chip.
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 239 of file mcp23008.h.
|
inline |
Set output levels of output pins on the port of this MCP23008 chip.
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 274 of file mcp23008.h.
|
inline |
Get levels of pins on the port of this MCP23008 chip.
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 306 of file mcp23008.h.
|
inline |
Get the pins that generated the latest interrupt on the port of the MCP23008 chip.
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 340 of file mcp23008.h.
|
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.
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 376 of file mcp23008.h.
|
inline |
Initialize the chip before operation.
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 394 of file mcp23008.h.
|
inline |
Configure GPIO on the port of this MCP23008 chip.
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 416 of file mcp23008.h.
|
inline |
Configure interrupts on the port of this MCP23008 chip.
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 440 of file mcp23008.h.
|
inline |
Set output levels of output pins on the port of this MCP23008 chip.
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 458 of file mcp23008.h.
|
inline |
Get levels of pins on the port of this MCP23008 chip.
Definition at line 472 of file mcp23008.h.
|
inline |
Get the pins that generated the latest interrupt on the port of the MCP23008 chip.
Definition at line 487 of file mcp23008.h.
|
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.
Definition at line 504 of file mcp23008.h.