#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 19 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. More... | |
void | disable () |
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically. More... | |
bool | isEnabled () const |
Check if this updatable is enabled. More... | |
void | moveDown () |
Move down this element in the list. More... | |
static void | enable (UpdatableCRTP *element) |
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically. More... | |
static void | enable (UpdatableCRTP &element) |
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically. More... | |
static void | enable (U(&array)[N]) |
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically. More... | |
static void | disable (UpdatableCRTP *element) |
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically. More... | |
static void | disable (UpdatableCRTP &element) |
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically. More... | |
static void | disable (U(&array)[N]) |
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically. More... | |
Public Member Functions | |
MCP23017 (WireType &wire, uint8_t addressOffset=0, pin_t interruptPin=NO_PIN) | |
Constructor. More... | |
void | pinModeBuffered (pin_t pin, PinMode_t mode) override |
Set the mode of a given pin in the software buffer. More... | |
void | digitalWriteBuffered (pin_t pin, PinStatus_t status) override |
Set the output of a given pin in the software buffer. More... | |
PinStatus_t | digitalReadBuffered (pin_t pin) override |
Read the state of the given pin from the software buffer. More... | |
analog_t | analogReadBuffered (pin_t pin) override |
Read the analog value of the given pin from the software buffer. More... | |
void | analogWriteBuffered (pin_t, analog_t) override |
Write an analog (or PWM) value to the software buffer given pin. More... | |
void | begin () override |
Initialize the extended IO element. More... | |
void | updateBufferedOutputs () override |
Write the internal state to the physical outputs. More... | |
void | updateBufferedInputs () override |
Read the physical state into the input buffers. More... | |
void | updateBufferedPinModes () |
Send the new pin modes to the chip after calling pinModeBuffered . More... | |
pin_t | pinA (pin_t p) |
Get the identifier of the given pin in register A. More... | |
pin_t | pinB (pin_t p) |
Get the identifier of the given pin in register B. More... | |
Array< pin_t, N > | pins () const |
Get an array containing all pins of the element. More... | |
virtual void | pinMode (pin_t pin, PinMode_t mode) |
Set the mode of a given pin. More... | |
virtual void | digitalWrite (pin_t pin, PinStatus_t state) |
Set the output of the given pin to the given state. More... | |
virtual PinStatus_t | digitalRead (pin_t pin) |
Read the state of the given pin. More... | |
virtual void | analogWrite (pin_t pin, analog_t val) |
Write an analog (or PWM) value to the given pin. More... | |
virtual analog_t | analogRead (pin_t pin) |
Read the analog value of the given pin. More... | |
pin_t | pin (pin_t pin) const |
Get the extended IO pin number of a given physical pin of this extended IO element. More... | |
pin_t | operator[] (pin_t pin) const |
Get the extended IO pin number of a given physical pin of this extended IO element. More... | |
pin_t | getLength () const |
Get the number of pins this IO element has. More... | |
pin_t | getEnd () const |
Get the largest global extended IO pin number that belongs to this extended IO element. More... | |
pin_t | getStart () const |
Get the smallest global extended IO pin number that belongs to this extended IO element. More... | |
Static Public Member Functions | |
static constexpr uint16_t | length () |
static void | beginAll () |
Initialize all extended IO elements. More... | |
static void | updateAllBufferedOutputs () |
Write the internal states to the physical outputs for all extended IO elements. More... | |
static void | updateAllBufferedInputs () |
Read the physical state into the input buffers for all extended IO elements. More... | |
static DoublyLinkedList< ExtendedIOElement > & | getAll () |
Get the list of all Extended IO elements. More... | |
Protected Attributes | |
ExtendedIOElement * | next |
ExtendedIOElement * | previous |
Static Protected Attributes | |
static DoublyLinkedList< ExtendedIOElement > | updatables |
Private Member Functions | |
bool | hasInputs () const |
Check if any of the pins are configured as inputs. More... | |
template<size_t N> | |
void | writeI2C (const uint8_t(&values)[N]) |
Write any data to the MCP23017. More... | |
template<class... Args> | |
void | writeI2C (uint8_t addr, Args... values) |
Write any data to the MCP23017. More... | |
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.
|
overridevirtual |
Initialize the extended IO element.
Implements ExtendedIOElement.
Definition at line 80 of file MCP23017.ipp.
|
overridevirtual |
Write the internal state to the physical outputs.
Implements ExtendedIOElement.
Definition at line 97 of file MCP23017.ipp.
|
overridevirtual |
Read the physical state into the input buffers.
Implements ExtendedIOElement.
Definition at line 108 of file MCP23017.ipp.
void updateBufferedPinModes |
Send the new pin modes to the chip after calling pinModeBuffered
.
Definition at line 122 of file MCP23017.ipp.
Get the identifier of the given pin in register A.
p | Pin number in [0, 7] |
Definition at line 58 of file MCP23017.hpp.
Get the identifier of the given pin in register B.
p | Pin number in [0, 7] |
Definition at line 62 of file MCP23017.hpp.
|
private |
Check if any of the pins are configured as inputs.
Definition at line 141 of file MCP23017.ipp.
|
private |
Write any data to the MCP23017.
Definition at line 147 of file MCP23017.ipp.
|
private |
Write any data to the MCP23017.
addr | The address of the register to write to. |
values | The values to write. |
Definition at line 155 of file MCP23017.ipp.
Get an array containing all pins of the element.
Definition at line 27 of file StaticSizeExtendedIOElement.hpp.
|
inlinestaticconstexprinherited |
Definition at line 31 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 100 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 121 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 141 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 161 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 181 of file ExtendedIOElement.hpp.
|
staticinherited |
Initialize all extended IO elements.
Definition at line 20 of file ExtendedIOElement.cpp.
|
staticinherited |
Write the internal states to the physical outputs for all extended IO elements.
Definition at line 24 of file ExtendedIOElement.cpp.
|
staticinherited |
Read the physical state into the input buffers for all extended IO elements.
Definition at line 28 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 32 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 48 of file ExtendedIOElement.cpp.
|
inherited |
Get the number of pins this IO element has.
Definition at line 50 of file ExtendedIOElement.cpp.
|
inherited |
Get the largest global extended IO pin number that belongs to this extended IO element.
Definition at line 52 of file ExtendedIOElement.cpp.
|
inherited |
Get the smallest global extended IO pin number that belongs to this extended IO element.
Definition at line 54 of file ExtendedIOElement.cpp.
|
staticinherited |
Get the list of all Extended IO elements.
Definition at line 56 of file ExtendedIOElement.cpp.
|
inlineinherited |
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.
Definition at line 100 of file Updatable.hpp.
|
inlinestaticinherited |
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.
Definition at line 129 of file Updatable.hpp.
|
inlinestaticinherited |
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.
Definition at line 131 of file Updatable.hpp.
|
inlinestaticinherited |
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.
Definition at line 134 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 110 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 140 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 142 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 145 of file Updatable.hpp.
|
inlineinherited |
Check if this updatable is enabled.
Definition at line 124 of file Updatable.hpp.
|
inlineinherited |
Move down this element in the list.
Definition at line 151 of file Updatable.hpp.
|
staticconstexprprivate |
Definition at line 65 of file MCP23017.hpp.
|
private |
Definition at line 67 of file MCP23017.hpp.
|
private |
Definition at line 68 of file MCP23017.hpp.
|
private |
Definition at line 69 of file MCP23017.hpp.
|
private |
Definition at line 72 of file MCP23017.hpp.
|
private |
Definition at line 73 of file MCP23017.hpp.
|
private |
Definition at line 74 of file MCP23017.hpp.
|
private |
Definition at line 75 of file MCP23017.hpp.
|
private |
Definition at line 76 of file MCP23017.hpp.
|
private |
Definition at line 77 of file MCP23017.hpp.
|
private |
Definition at line 78 of file MCP23017.hpp.
|
privateinherited |
Definition at line 270 of file ExtendedIOElement.hpp.
|
privateinherited |
Definition at line 271 of file ExtendedIOElement.hpp.
|
staticprivateinherited |
Definition at line 272 of file ExtendedIOElement.hpp.
|
staticprotectedinherited |
Definition at line 156 of file Updatable.hpp.
|
protectedinherited |
Definition at line 324 of file LinkedList.hpp.
|
protectedinherited |
Definition at line 325 of file LinkedList.hpp.