#include <AH/Hardware/ExtendedInputOutput/MCP23017.hpp>
Class for MCP23017 I²C I/O expanders.
WireType | The type of the I²C driver to use. |
Definition at line 18 of file MCP23017.hpp.
Enabling and disabling updatables | |
void | enable () |
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically. | |
void | disable () |
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically. | |
bool | isEnabled () const |
Check if this updatable is enabled. | |
void | moveDown () |
Move down this element in the list. | |
static void | enable (UpdatableCRTP *element) |
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically. | |
static void | enable (UpdatableCRTP &element) |
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically. | |
static void | enable (U(&array)[N]) |
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically. | |
static void | disable (UpdatableCRTP *element) |
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically. | |
static void | disable (UpdatableCRTP &element) |
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically. | |
static void | disable (U(&array)[N]) |
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically. | |
Public Member Functions | |
MCP23017 (WireType &wire, uint8_t addressOffset=0, pin_t interruptPin=NO_PIN) | |
Constructor. | |
void | pinModeBuffered (pin_int_t pin, PinMode_t mode) override |
Set the mode of a given pin in the software buffer. | |
void | digitalWriteBuffered (pin_int_t pin, PinStatus_t status) override |
Set the output of a given pin in the software buffer. | |
PinStatus_t | digitalReadBuffered (pin_int_t pin) override |
Read the state of the given pin from the software buffer. | |
analog_t | analogReadBuffered (pin_int_t pin) override |
Read the analog value of the given pin from the software buffer. | |
void | analogWriteBuffered (pin_int_t, analog_t) override |
Write an analog (or PWM) value to the software buffer given pin. | |
void | begin () override |
Initialize the extended IO element. | |
void | updateBufferedOutputs () override |
Write the internal state to the physical outputs. | |
void | updateBufferedInputs () override |
Read the physical state into the input buffers. | |
void | updateBufferedPinModes () |
Send the new pin modes to the chip after calling pinModeBuffered . | |
pin_t | pinA (pin_int_t p) |
Get the identifier of the given pin in register A. | |
pin_t | pinB (pin_int_t p) |
Get the identifier of the given pin in register B. | |
Array< pin_t, N > | pins () const |
Get an array containing all pins of the element. | |
virtual void | pinMode (pin_int_t pin, PinMode_t mode) |
Set the mode of a given pin. | |
virtual void | digitalWrite (pin_int_t pin, PinStatus_t state) |
Set the output of the given pin to the given state. | |
virtual PinStatus_t | digitalRead (pin_int_t pin) |
Read the state of the given pin. | |
virtual void | analogWrite (pin_int_t pin, analog_t val) |
Write an analog (or PWM) value to the given pin. | |
virtual analog_t | analogRead (pin_int_t pin) |
Read the analog value of the given pin. | |
pin_t | pin (pin_int_t pin) const |
Get the extended IO pin number of a given physical pin of this extended IO element. | |
pin_t | operator[] (pin_int_t pin) const |
Get the extended IO pin number of a given physical pin of this extended IO element. | |
pin_int_t | getLength () const |
Get the number of pins this IO element has. | |
pin_t | getEnd () const |
Get the largest global extended IO pin number that belongs to this extended IO element. | |
pin_t | getStart () const |
Get the smallest global extended IO pin number that belongs to this extended IO element. | |
Static Public Member Functions | |
static constexpr uint16_t | length () |
static void | beginAll () |
Initialize all extended IO elements. | |
static void | updateAllBufferedOutputs () |
Write the internal states to the physical outputs for all extended IO elements. | |
static void | updateAllBufferedInputs () |
Read the physical state into the input buffers for all extended IO elements. | |
static DoublyLinkedList< ExtendedIOElement > & | getAll () |
Get the list of all Extended IO elements. | |
Protected Attributes | |
Node * | next = nullptr |
Node * | previous = nullptr |
Static Protected Attributes | |
static DoublyLinkedList< ExtendedIOElement > | updatables |
Private Member Functions | |
bool | hasInputs () const |
Check if any of the pins are configured as inputs. | |
template<size_t N> | |
void | writeI2C (const uint8_t(&values)[N]) |
Write any data to the MCP23017. | |
template<class... Args> | |
void | writeI2C (uint8_t addr, Args... values) |
Write any data to the MCP23017. | |
Private Attributes | |
WireType * | wire |
uint8_t | address |
pin_t | interruptPin |
bool | pinModesDirty = true |
BitArray< 16 > | bufferedPinModes |
bool | pullupsDirty = true |
BitArray< 16 > | bufferedPullups |
bool | outputsDirty = true |
BitArray< 16 > | bufferedOutputs |
BitArray< 16 > | bufferedInputs |
const pin_t | start |
const pin_t | end |
Static Private Attributes | |
static constexpr uint8_t | I2C_BASE_ADDRESS = 0x20 |
static pin_t | offset = NUM_DIGITAL_PINS + NUM_ANALOG_INPUTS |
Constructor.
wire | The Wire/I²C interface to use. |
addressOffset | A number between 0 and 7 reflecting the state of the I2C address pins of the MCP23017. |
interruptPin | The pin connected to the MCP23017 interrupt pin. This doesn't have to be an interrupt pin of the Arduino. The interrupt pin of the MCP23017 is configured as open-drain active-low output, and the interrupt pins of GPIO banks A and B are mirrored/OR'ed together. This means that you only need to connect a single interrupt pin for each MCP23017, and you can connect the interrupt pins of multiple MCP23017s to a single Arduino pin. |
Set the mode of a given pin in the software buffer.
The buffer is written to the ExtIO device when updateBufferedOutputs is called.
pin | The (zero-based) pin of this IO element. |
mode | The mode to set the pin to (e.g. INPUT , OUTPUT or INPUT_PULLUP ). |
Implements ExtendedIOElement.
|
overridevirtual |
Set the output of a given pin in the software buffer.
The buffer is written to the ExtIO device when updateBufferedOutputs is called.
pin | The (zero-based) pin of this IO element. |
state | The new state to set the pin to. |
Implements ExtendedIOElement.
|
overridevirtual |
Read the state of the given pin from the software buffer.
To update the buffer, you have to call updateBufferedInputs first.
pin | The (zero-based) pin of this IO element. |
Implements ExtendedIOElement.
Read the analog value of the given pin from the software buffer.
To update the buffer, you have to call updateBufferedInputs first.
pin | The (zero-based) pin of this IO element. |
Implements ExtendedIOElement.
Write an analog (or PWM) value to the software buffer given pin.
The buffer is written to the ExtIO device when updateBufferedOutputs is called.
pin | The (zero-based) pin of this IO element. |
val | The new analog value to set the pin to. |
Implements ExtendedIOElement.
Initialize the extended IO element.
Implements ExtendedIOElement.
Write the internal state to the physical outputs.
Implements ExtendedIOElement.
Read the physical state into the input buffers.
Implements ExtendedIOElement.
Send the new pin modes to the chip after calling pinModeBuffered
.
Get the identifier of the given pin in register A.
p | Pin number in [0, 7] |
Definition at line 57 of file MCP23017.hpp.
Get the identifier of the given pin in register B.
p | Pin number in [0, 7] |
Definition at line 61 of file MCP23017.hpp.
Check if any of the pins are configured as inputs.
Write any data to the MCP23017.
Write any data to the MCP23017.
addr | The address of the register to write to. |
values | The values to write. |
Get an array containing all pins of the element.
Definition at line 24 of file StaticSizeExtendedIOElement.hpp.
Definition at line 28 of file StaticSizeExtendedIOElement.hpp.
Set the mode of a given pin.
pin | The (zero-based) pin of this IO element. |
mode | The mode to set the pin to (e.g. INPUT , OUTPUT or INPUT_PULLUP ). |
Reimplemented in MAX7219< NumChips, SPIDriver >, and ShiftRegisterOutBase< N >.
Definition at line 95 of file ExtendedIOElement.hpp.
|
inlinevirtualinherited |
Set the output of the given pin to the given state.
pin | The (zero-based) pin of this IO element. |
state | The new state to set the pin to. |
Reimplemented in MAX7219< NumChips, SPIDriver >, and ShiftRegisterOutBase< N >.
Definition at line 116 of file ExtendedIOElement.hpp.
|
inlinevirtualinherited |
Read the state of the given pin.
pin | The (zero-based) pin of this IO element. |
Reimplemented in MAX7219< NumChips, SPIDriver >, and ShiftRegisterOutBase< N >.
Definition at line 136 of file ExtendedIOElement.hpp.
Write an analog (or PWM) value to the given pin.
pin | The (zero-based) pin of this IO element. |
val | The new analog value to set the pin to. |
Reimplemented in MAX7219< NumChips, SPIDriver >, and ShiftRegisterOutBase< N >.
Definition at line 156 of file ExtendedIOElement.hpp.
Read the analog value of the given pin.
pin | The (zero-based) pin of this IO element. |
Reimplemented in MAX7219< NumChips, SPIDriver >, and ShiftRegisterOutBase< N >.
Definition at line 176 of file ExtendedIOElement.hpp.
|
staticinherited |
Initialize all extended IO elements.
Definition at line 17 of file ExtendedIOElement.cpp.
|
staticinherited |
Write the internal states to the physical outputs for all extended IO elements.
Definition at line 21 of file ExtendedIOElement.cpp.
|
staticinherited |
Read the physical state into the input buffers for all extended IO elements.
Definition at line 25 of file ExtendedIOElement.cpp.
Get the extended IO pin number of a given physical pin of this extended IO element.
pin | The zero-based physical pin number of this IO element. |
Definition at line 29 of file ExtendedIOElement.cpp.
Get the extended IO pin number of a given physical pin of this extended IO element.
It is alias for ExtendedIOElement::pin
.
pin | The zero-based physical pin number of this IO element. |
Definition at line 45 of file ExtendedIOElement.cpp.
|
inherited |
Get the number of pins this IO element has.
Definition at line 47 of file ExtendedIOElement.cpp.
|
inherited |
Get the largest global extended IO pin number that belongs to this extended IO element.
Definition at line 49 of file ExtendedIOElement.cpp.
|
inherited |
Get the smallest global extended IO pin number that belongs to this extended IO element.
Definition at line 51 of file ExtendedIOElement.cpp.
|
staticinherited |
Get the list of all Extended IO elements.
Definition at line 53 of file ExtendedIOElement.cpp.
|
inlineinherited |
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.
Definition at line 96 of file Updatable.hpp.
|
inlinestaticinherited |
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.
Definition at line 125 of file Updatable.hpp.
|
inlinestaticinherited |
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.
Definition at line 127 of file Updatable.hpp.
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.
Definition at line 130 of file Updatable.hpp.
|
inlineinherited |
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.
Definition at line 106 of file Updatable.hpp.
|
inlinestaticinherited |
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.
Definition at line 136 of file Updatable.hpp.
|
inlinestaticinherited |
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.
Definition at line 138 of file Updatable.hpp.
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.
Definition at line 141 of file Updatable.hpp.
|
inlineinherited |
Check if this updatable is enabled.
Definition at line 120 of file Updatable.hpp.
|
inlineinherited |
Move down this element in the list.
Definition at line 147 of file Updatable.hpp.
Definition at line 64 of file MCP23017.hpp.
Definition at line 66 of file MCP23017.hpp.
Definition at line 67 of file MCP23017.hpp.
Definition at line 68 of file MCP23017.hpp.
Definition at line 71 of file MCP23017.hpp.
Definition at line 72 of file MCP23017.hpp.
Definition at line 73 of file MCP23017.hpp.
Definition at line 74 of file MCP23017.hpp.
Definition at line 75 of file MCP23017.hpp.
Definition at line 76 of file MCP23017.hpp.
Definition at line 77 of file MCP23017.hpp.
Definition at line 265 of file ExtendedIOElement.hpp.
Definition at line 266 of file ExtendedIOElement.hpp.
|
staticprivateinherited |
Definition at line 267 of file ExtendedIOElement.hpp.
|
staticprotectedinherited |
Definition at line 152 of file Updatable.hpp.
Definition at line 320 of file LinkedList.hpp.
Definition at line 321 of file LinkedList.hpp.