MIDI Control Surface library for Arduino
|
Go to the documentation of this file.
9 #include <AH/Arduino-Wrapper.h>
12 #include <AH/Hardware/ExtendedInputOutput/ExtendedInputOutput.hpp>
13 #include <AH/STL/type_traits>
56 template <
class WireType,
class EncoderPositionType = int32_t,
57 bool InterruptSafe =
false>
61 typename std::conditional<InterruptSafe,
volatile EncoderPositionType,
62 EncoderPositionType>::type;
64 typename std::conditional<InterruptSafe,
volatile uint16_t,
67 constexpr
static uint8_t I2C_BASE_ADDRESS = 0x20;
80 this->wire->beginTransmission(address);
81 this->wire->write(values, N);
82 this->wire->endTransmission();
93 template <
class... Args>
95 const uint8_t v[] = {addr,
static_cast<uint8_t
>(values)...};
111 this->wire->requestFrom(address, uint8_t(2));
112 uint8_t a = this->wire->read();
113 uint16_t b = this->wire->read();
138 : wire(&wire), address(I2C_BASE_ADDRESS | addr_offset),
139 interrupt_pin(interrupt_pin) {}
186 if (interrupt_pin !=
NO_PIN)
211 if (interrupt_pin !=
NO_PIN &&
215 uint16_t newstate = readGPIO();
216 uint16_t oldstate = state;
219 if (newstate == oldstate)
229 for (uint8_t i = 0; i < 8; ++i) {
231 uint8_t(newstate) & 0b11;
234 uint8_t(oldstate) & 0b11;
238 positions[i] += delta;
255 EncoderPositionType
read(uint8_t idx)
const {
258 EncoderPositionType ret = positions[idx];
262 return positions[idx];
279 EncoderPositionType ret = positions[idx];
284 EncoderPositionType ret = positions[idx];
300 void write(uint8_t idx, EncoderPositionType pos) {
303 positions[idx] = pos;
306 positions[idx] = pos;
322 : position(position) {}
327 EncoderPositionType
read()
const {
330 EncoderPositionType ret = *position;
343 EncoderPositionType ret = *position;
348 EncoderPositionType ret = *position;
356 void write(EncoderPositionType pos) {
377 return &positions[index];
int digitalRead(pin_t pin)
An ExtIO version of the Arduino function.
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
EncoderPositionType readAndReset(uint8_t idx)
Read the position of the given encoder and reset it to zero.
void writeI2C(uint8_t addr, Args... values)
Write any data to the MCP23017.
typename std::conditional< InterruptSafe, volatile EncoderPositionType, EncoderPositionType >::type EncoderPositionStorageType
#define AH_DIAGNOSTIC_POP()
uint16_t readGPIO()
Read the state of all GPIO pins.
typename std::conditional< InterruptSafe, volatile uint16_t, uint16_t >::type StateStorageType
EncoderPositionType readAndReset()
Read the position of the encoder and reset it to zero.
MCP23017Encoders(WireType &wire, uint8_t addr_offset=0, pin_t interrupt_pin=NO_PIN)
Constructor.
void writeI2C(const uint8_t(&values)[N])
Write any data to the MCP23017.
MCP23017Encoder operator[](uint8_t index)
Get a proxy to one of the encoders managed by this MCP23017.
EncoderPositionStorageType * position
A pointer to the position value inside of the MCP23017Encoders class.
void update()
If the state of the MCP23017's GPIO changed, read the new state and update the encoder positions.
EncoderPositionType read() const
Read the position of the encoder.
void write(EncoderPositionType pos)
Set the position of the encoder.
Proxy to access a single encoder of the 8 encoders managed by MCP23017Encoders.
constexpr pin_t NO_PIN
A special pin number that indicates an unused or invalid pin.
#define AH_DIAGNOSTIC_EXTERNAL_HEADER()
constexpr static int8_t MCP23017Encoders_lut[16]
MCP23017Encoder(EncoderPositionStorageType *position)
Class for reading 8 rotary encoders using a MCP23017 I²C port expander.
void pinMode(pin_t pin, PinMode_t mode)
An ExtIO version of the Arduino function.
void begin()
Initialize the MCP23017.
#define AH_DIAGNOSTIC_WERROR()
#define BEGIN_AH_NAMESPACE
void write(uint8_t idx, EncoderPositionType pos)
Set the position of the given encoder.
EncoderPositionType read(uint8_t idx) const
Read the position of the given encoder.