Control Surface pin-t-adl
MIDI Control Surface 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,
40 pin_t interruptPin = NO_PIN);
41
42 void pinModeBuffered(pin_t pin, PinMode_t mode) override;
43 void digitalWriteBuffered(pin_t pin, PinStatus_t status) override;
45 analog_t analogReadBuffered(pin_t pin) override;
46 void analogWriteBuffered(pin_t, analog_t) override;
47
48 void begin() override;
49
50 void updateBufferedOutputs() override;
51 void updateBufferedInputs() override;
53 void updateBufferedPinModes();
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
#define END_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
AH::function_traits< decltype(::pinMode)>::argument_t< 1 > PinMode_t
AH::function_traits< decltype(::digitalWrite)>::argument_t< 1 > PinStatus_t
#define AH_DIAGNOSTIC_POP()
Definition: Warnings.hpp:36
#define AH_DIAGNOSTIC_WERROR()
Definition: Warnings.hpp:35
Class for MCP23017 I²C I/O expanders.
Definition: MCP23017.hpp:19
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
pin_t interruptPin
Definition: MCP23017.hpp:69
BitArray< 16 > bufferedInputs
Definition: MCP23017.hpp:78
WireType * wire
Definition: MCP23017.hpp:67
BitArray< 16 > bufferedOutputs
Definition: MCP23017.hpp:77
pin_t pinB(pin_t p)
Get the identifier of the given pin in register B.
Definition: MCP23017.hpp:62
BitArray< 16 > bufferedPinModes
Definition: MCP23017.hpp:73
uint8_t address
Definition: MCP23017.hpp:68
A class for ExtendedIOElements with a fixed size.
void analogWriteBuffered(pin_t pin, analog_t val)
A buffered ExtIO version of the Arduino function.
void pinModeBuffered(pin_t pin, PinMode_t mode)
A buffered ExtIO version of the Arduino function.
void digitalWriteBuffered(pin_t pin, PinStatus_t val)
A buffered ExtIO version of the Arduino function.
PinStatus_t digitalReadBuffered(pin_t pin)
A buffered ExtIO version of the Arduino function.
analog_t analogReadBuffered(pin_t pin)
A buffered ExtIO version of the Arduino function.
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.
Type for storing pin numbers of Extended Input/Output elements.