Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
Hardware-Types.hpp
Go to the documentation of this file.
1/* ✔ */
2
3#pragma once
4
7#include <AH/STL/limits>
9#include <stdint.h> // uint8_t
10
12
21 (std::numeric_limits<pin_int_t>::max() >> 1) + 1;
22
23namespace ExtIO {
25struct pin_t {
27 constexpr pin_t() = default;
29 constexpr pin_t(pin_int_t pin) : pin(pin) {}
30
33
34 static_assert(std::is_unsigned<decltype(pin)>::value,
35 "Error: pin_t should be an unsigned integer type");
36
38 this->pin += b;
39 return *this;
40 }
42 ++pin;
43 return *this;
44 }
46 pin_t t = *this;
47 ++pin;
48 return t;
49 }
50
52 this->pin -= b;
53 return *this;
54 }
56 --pin;
57 return *this;
58 }
60 pin_t t = *this;
61 --pin;
62 return t;
63 }
64};
65constexpr inline bool operator==(pin_t a, pin_t b) { return a.pin == b.pin; }
66constexpr inline bool operator<(pin_t a, pin_t b) { return a.pin < b.pin; }
67constexpr inline bool operator<=(pin_t a, pin_t b) { return a.pin <= b.pin; }
68constexpr inline bool operator>(pin_t a, pin_t b) { return a.pin > b.pin; }
69constexpr inline bool operator>=(pin_t a, pin_t b) { return a.pin >= b.pin; }
70constexpr inline bool operator!=(pin_t a, pin_t b) { return !(a == b); }
71constexpr inline pin_int_t operator-(pin_t a, pin_t b) { return a.pin - b.pin; }
72constexpr inline pin_t operator-(pin_t a, pin_int_t b) { return a.pin - b; }
73constexpr inline pin_t operator+(pin_t a, pin_int_t b) { return a.pin + b; }
74constexpr inline pin_t operator+(pin_int_t a, pin_t b) { return a + b.pin; }
75constexpr inline pin_t operator*(pin_t a, pin_int_t b) { return a.pin * b; }
76constexpr inline pin_t operator*(pin_int_t a, pin_t b) { return a * b.pin; }
77inline Print &operator<<(Print &os, pin_t p) {
78 using AH::operator<<;
79 return os << +p.pin;
80}
81#ifndef ARDUINO
82inline std::ostream &operator<<(std::ostream &os, pin_t p) {
83 return os << +p.pin;
84}
85#endif
86} // namespace ExtIO
87
89using ExtIO::pin_t;
90
91#ifdef NO_PIN // Fix for FastLED: https://github.com/FastLED/FastLED/issues/893
92#undef NO_PIN
93#endif
94
96constexpr pin_t NO_PIN {};
97
99template <size_t N>
101
#define END_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
Print & operator<<(Print &os, Cable c)
Definition Cable.cpp:6
pin_t pin(pin_int_t pin) const
Get the extended IO pin number of a given physical pin of this extended IO element.
A class for serial-in/parallel-out shift registers, like the 74HC595 that are connected to the SPI bu...
constexpr bool operator==(pin_t a, pin_t b)
constexpr pin_t operator*(pin_t a, pin_int_t b)
constexpr bool operator!=(pin_t a, pin_t b)
constexpr pin_t operator+(pin_t a, pin_int_t b)
constexpr bool operator>(pin_t a, pin_t b)
constexpr pin_int_t operator-(pin_t a, pin_t b)
constexpr bool operator>=(pin_t a, pin_t b)
constexpr pin_int_t NO_PIN_INT
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.
constexpr pin_t()=default
Default constructor (NO_PIN).
pin_t & operator+=(pin_int_t b)
pin_int_t pin
The actual underlying pin number.
constexpr pin_t(pin_int_t pin)
Constructor from integer.
pin_t & operator-=(pin_int_t b)