Arduino Helpers master
Utility library for Arduino
MCP23017.hpp
Go to the documentation of this file.
1#pragma once
2
6
8
17template <class WireType>
19 public:
38 MCP23017(WireType &wire, uint8_t addressOffset = 0,
40
41 void pinModeBuffered(pin_t pin, PinMode_t mode) override;
42 void digitalWriteBuffered(pin_t pin, PinStatus_t status) override;
45 void analogWriteBuffered(pin_t, analog_t) override;
46
47 void begin() override;
48
49 void updateBufferedOutputs() override;
50 void updateBufferedInputs() override;
53
57 pin_t pinA(pin_t p) { return pin(p); }
61 pin_t pinB(pin_t p) { return pin(p + 8); }
62
63 private:
64 constexpr static uint8_t I2C_BASE_ADDRESS = 0x20;
65
66 WireType *wire;
67 uint8_t address;
69
70 private:
71 bool pinModesDirty = true;
73 bool pullupsDirty = true;
75 bool outputsDirty = true;
78
79 private:
81 bool hasInputs() const;
82
84 template <size_t N>
85 void writeI2C(const uint8_t (&values)[N]);
86
95 template <class... Args>
96 void writeI2C(uint8_t addr, Args... values);
97};
98
100
101#include "MCP23017.ipp"
AH::function_traits< decltype(::pinMode)>::argument_t< 1 > PinMode_t
AH::function_traits< decltype(::digitalWrite)>::argument_t< 1 > PinStatus_t
uint16_t analog_t
The type returned from analogRead and similar functions.
constexpr pin_t NO_PIN
A special pin number that indicates an unused or invalid pin.
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
#define END_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
pin_t pin(pin_t pin) const
Get the extended IO pin number of a given physical pin of this extended IO element.
Class for MCP23017 I²C I/O expanders.
Definition: MCP23017.hpp:18
MCP23017(WireType &wire, uint8_t addressOffset=0, pin_t interruptPin=NO_PIN)
Constructor.
Definition: MCP23017.ipp:30
void updateBufferedPinModes()
Send the new pin modes to the chip after calling pinModeBuffered.
Definition: MCP23017.ipp:122
void updateBufferedOutputs() override
Write the internal state to the physical outputs.
Definition: MCP23017.ipp:97
BitArray< 16 > bufferedPullups
Definition: MCP23017.hpp:74
pin_t pinA(pin_t p)
Get the identifier of the given pin in register A.
Definition: MCP23017.hpp:57
void analogWriteBuffered(pin_t, analog_t) override
Write an analog (or PWM) value to the software buffer given pin.
Definition: MCP23017.ipp:75
PinStatus_t digitalReadBuffered(pin_t pin) override
Read the state of the given pin from the software buffer.
Definition: MCP23017.ipp:65
void pinModeBuffered(pin_t pin, PinMode_t mode) override
Set the mode of a given pin in the software buffer.
Definition: MCP23017.ipp:40
pin_t interruptPin
Definition: MCP23017.hpp:68
BitArray< 16 > bufferedInputs
Definition: MCP23017.hpp:77
void updateBufferedInputs() override
Read the physical state into the input buffers.
Definition: MCP23017.ipp:108
void begin() override
Initialize the extended IO element.
Definition: MCP23017.ipp:80
static constexpr uint8_t I2C_BASE_ADDRESS
Definition: MCP23017.hpp:64
analog_t analogReadBuffered(pin_t pin) override
Read the analog value of the given pin from the software buffer.
Definition: MCP23017.ipp:70
bool pinModesDirty
Definition: MCP23017.hpp:71
WireType * wire
Definition: MCP23017.hpp:66
BitArray< 16 > bufferedOutputs
Definition: MCP23017.hpp:76
bool hasInputs() const
Check if any of the pins are configured as inputs.
Definition: MCP23017.ipp:141
pin_t pinB(pin_t p)
Get the identifier of the given pin in register B.
Definition: MCP23017.hpp:61
void digitalWriteBuffered(pin_t pin, PinStatus_t status) override
Set the output of a given pin in the software buffer.
Definition: MCP23017.ipp:58
bool pullupsDirty
Definition: MCP23017.hpp:73
bool outputsDirty
Definition: MCP23017.hpp:75
BitArray< 16 > bufferedPinModes
Definition: MCP23017.hpp:72
uint8_t address
Definition: MCP23017.hpp:67
void writeI2C(const uint8_t(&values)[N])
Write any data to the MCP23017.
Definition: MCP23017.ipp:147
A class for ExtendedIOElements with a fixed size.