Arduino Filters master
Filter library for Arduino
MCP23017.hpp
Go to the documentation of this file.
1#pragma once
2
4AH_DIAGNOSTIC_WERROR() // Enable errors on warnings
5
6#include "ExtendedInputOutput.hpp"
9
11
18template <class WireType>
20 public:
39 MCP23017(WireType &wire, uint8_t addressOffset = 0,
41
42 void pinModeBuffered(pin_t pin, PinMode_t mode) override;
43 void digitalWriteBuffered(pin_t pin, PinStatus_t status) override;
46 void analogWriteBuffered(pin_t, analog_t) override;
47
48 void begin() override;
49
50 void updateBufferedOutputs() override;
51 void updateBufferedInputs() override;
54
58 pin_t pinA(pin_t p) { return pin(p); }
62 pin_t pinB(pin_t p) { return pin(p + 8); }
63
64 private:
65 constexpr static uint8_t I2C_BASE_ADDRESS = 0x20;
66
67 WireType *wire;
68 uint8_t address;
70
71 private:
72 bool pinModesDirty = true;
74 bool pullupsDirty = true;
76 bool outputsDirty = true;
79
80 private:
82 bool hasInputs() const;
83
85 template <size_t N>
86 void writeI2C(const uint8_t (&values)[N]);
87
96 template <class... Args>
97 void writeI2C(uint8_t addr, Args... values);
98};
99
101
102#include "MCP23017.ipp"
103
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
#define AH_DIAGNOSTIC_POP()
Definition: Warnings.hpp:36
#define AH_DIAGNOSTIC_WERROR()
Definition: Warnings.hpp:35
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:19
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:75
pin_t pinA(pin_t p)
Get the identifier of the given pin in register A.
Definition: MCP23017.hpp:58
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:69
BitArray< 16 > bufferedInputs
Definition: MCP23017.hpp:78
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:65
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:72
WireType * wire
Definition: MCP23017.hpp:67
BitArray< 16 > bufferedOutputs
Definition: MCP23017.hpp:77
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:62
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:74
bool outputsDirty
Definition: MCP23017.hpp:76
BitArray< 16 > bufferedPinModes
Definition: MCP23017.hpp:73
uint8_t address
Definition: MCP23017.hpp:68
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.