Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
ExtendedIOElement.cpp
Go to the documentation of this file.
2#include <AH/Error/Error.hpp>
3#include <AH/STL/type_traits> // is_unsigned
4
6
7ExtendedIOElement::ExtendedIOElement(pin_int_t length)
8 : length(length), start(offset), end(offset + length) {
9 if (end > NO_PIN)
10 FATAL_ERROR(F("ExtIO ran out of pin numbers. "
11 "Dynamically creating new ExtendedIOElements is not "
12 "recommended."),
13 0x00FF);
14 offset = end;
15}
16
18 ExtendedIOElement::applyToAll(&ExtendedIOElement::begin);
19}
20
24
28
30 if (p >= length) {
31 static_assert(!std::is_integral<pin_t>::value ||
32 std::is_unsigned<pin_t>::value,
33 "Error: pin_t should be an unsigned integer type");
34 ERROR(F("Error: the pin number (")
35 << p
36 << F(") is greater than the number of pins of this "
37 "ExtendedIOElement (")
38 << length << ')',
39 0x4567);
40 return end - 1; // LCOV_EXCL_LINE
41 }
42 return p + start;
43}
44
46
48
50
52
56
58
#define END_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
#define ERROR(msg, errc)
Definition Error.hpp:19
pin_t getStart() const
Get the smallest global extended IO pin number that belongs to this extended IO element.
virtual void updateBufferedInputs()=0
Read the physical state into the input buffers.
virtual void updateBufferedOutputs()=0
Write the internal state to the physical outputs.
pin_int_t getLength() const
Get the number of pins this IO element has.
virtual void begin()=0
Initialize the extended IO element.
static DoublyLinkedList< ExtendedIOElement > & getAll()
Get the list of all Extended IO elements.
static void updateAllBufferedOutputs()
Write the internal states to the physical outputs for all extended IO elements.
pin_t getEnd() const
Get the largest global extended IO pin number that belongs to this extended IO element.
static void beginAll()
Initialize all extended IO elements.
pin_t operator[](pin_int_t pin) const
Get the extended IO pin number of a given physical pin of this extended IO element.
pin_t pin(pin_int_t pin) const
Get the extended IO pin number of a given physical pin of this extended IO element.
static void updateAllBufferedInputs()
Read the physical state into the input buffers for all extended IO elements.
A class for serial-in/parallel-out shift registers, like the 74HC595 that are connected to the SPI bu...
static DoublyLinkedList< ExtendedIOElement > updatables
#define FATAL_ERROR(msg, errc)
Print the error message and error code, and stop the execution.
Definition Error.hpp:57
uint_fast16_t pin_int_t
Integer type used internally to store the index of (extended) GPIO pins.
Type for storing pin numbers of Extended Input/Output elements.