4#include "ExtendedIOElement.hpp"
13static bool inRange(T target, T start, T end) {
14 return target >= start && target < end;
19 if (pin < el.getStart())
21 else if (
inRange(pin, el.getStart(), el.getEnd()))
30 F(
"The given pin does not correspond to an Extended IO element."),
47 el->pinMode(pin - el->getStart(), mode);
61 el->digitalWrite(pin - el->getStart(), val);
75 return el->digitalRead(pin - el->getStart());
89 return el->analogRead(pin - el->getStart());
103 el->analogWrite(pin - el->getStart(), val);
123 el->pinModeBuffered(pin - el->getStart(), mode);
134 el->digitalWriteBuffered(pin - el->getStart(), val);
145 return el->digitalReadBuffered(pin - el->getStart());
156 return el->analogReadBuffered(pin - el->getStart());
170 el->analogWriteBuffered(pin - el->getStart(), val);
182 ::shiftOut((
int)dataPin, (
int)clockPin, bitOrder, val);
187 auto dataPinN = dataPin - dataEl->getStart();
189 auto clockPinN = clockPin - clockEl->getStart();
190 for (uint8_t i = 0; i < 8; i++) {
191 uint8_t mask = bitOrder == LSBFIRST ? (1 << i) : (1 << (7 - i));
192 dataEl->digitalWrite(dataPinN, (val & mask) ?
HIGH :
LOW);
193 clockEl->digitalWrite(clockPinN,
HIGH);
194 clockEl->digitalWrite(clockPinN,
LOW);
199 for (uint8_t i = 0; i < 8; i++) {
200 uint8_t mask = bitOrder == LSBFIRST ? (1 << i) : (1 << (7 - i));
212#if UINT16_MAX != UINT_MAX
constexpr PinStatus_t LOW
AH::function_traits< decltype(::digitalWrite)>::argument_t< 0 > ArduinoPin_t
constexpr PinStatus_t HIGH
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 BEGIN_AH_NAMESPACE
#define AH_DIAGNOSTIC_POP()
#define AH_DIAGNOSTIC_WERROR()
An abstract base class for Extended Input/Output elements.
static DoublyLinkedList< ExtendedIOElement > & getAll()
Get the list of all Extended IO elements.
#define FATAL_ERROR(msg, errc)
Print the error message and error code, and stop the execution.
PinStatus_t digitalRead(int pin)
Overload to Arduino digitalRead function.
void analogWriteBuffered(pin_t pin, analog_t val)
A buffered ExtIO version of the Arduino function.
bool isNativePin(pin_t pin)
Check if the given pin number is a real Arduino pin number, and not an ExtIO pin number.
void pinModeBuffered(pin_t pin, PinMode_t mode)
A buffered ExtIO version of the Arduino function.
ExtendedIOElement * getIOElementOfPin(pin_t pin)
Find the IO element of a given extended IO pin number.
void digitalWriteBuffered(pin_t pin, PinStatus_t val)
A buffered ExtIO version of the Arduino function.
void analogWrite(pin_t pin, analog_t val)
An ExtIO version of the Arduino function.
void pinMode(pin_t pin, PinMode_t mode)
An ExtIO version of the Arduino function.
ExtendedIOElement * getIOElementOfPinOrNull(pin_t pin)
Find the IO element of a given extended IO pin number.
PinStatus_t digitalReadBuffered(pin_t pin)
A buffered ExtIO version of the Arduino function.
analog_t analogRead(pin_t pin)
An ExtIO version of the Arduino function.
analog_t analogReadBuffered(pin_t pin)
A buffered ExtIO version of the Arduino function.
PinStatus_t digitalRead(pin_t pin)
An ExtIO version of the Arduino function.
void shiftOut(pin_t dataPin, pin_t clockPin, BitOrder_t bitOrder, uint8_t val)
An ExtIO version of the Arduino function.
analog_t analogRead(int pin)
Overload to Arduino analogRead function.
void digitalWrite(pin_t pin, PinStatus_t val)
An ExtIO version of the Arduino function.
A namespace with alternatives to the standard Arduino IO functions that can be used with extended IO ...
static bool inRange(T target, T start, T end)
ArduinoPin_t arduino_pin_cast(T t)