Line data Source code
1 : /* ✔ */ 2 : 3 : #pragma once 4 : 5 : #include <AH/Hardware/Arduino-Hardware-Types.hpp> 6 : #include <AH/STL/climits> 7 : #include <AH/Settings/NamespaceSettings.hpp> 8 : #include <AH/Settings/Warnings.hpp> 9 : 10 : AH_DIAGNOSTIC_WERROR() // Enable errors on warnings 11 : 12 : BEGIN_AH_NAMESPACE 13 : 14 : class ExtendedIOElement; 15 : 16 : /** 17 : * @brief A namespace with alternatives to the standard Arduino IO functions 18 : * that can be used with extended IO pin numbers. 19 : */ 20 : namespace ExtIO { 21 : 22 : /// @addtogroup AH_ExtIO 23 : /// @{ 24 : 25 : /// Check if the given pin number is a real Arduino pin number, and not an ExtIO 26 : /// pin number. 27 849 : inline bool isNativePin(pin_t pin) { 28 849 : return pin.pin < NUM_DIGITAL_PINS + NUM_ANALOG_INPUTS; 29 : } 30 : 31 : /** 32 : * @brief Find the IO element of a given extended IO pin number. 33 : * 34 : * @param pin 35 : * The extended IO pin number to find the IO element of. 36 : * @return A pointer to the extended IO element that the given pin belongs to. 37 : */ 38 : ExtendedIOElement *getIOElementOfPinOrNull(pin_t pin); 39 : /// @copydoc getIOElementOfPinOrNull 40 : /// Throws an error if the element was not found. 41 : ExtendedIOElement *getIOElementOfPin(pin_t pin); 42 : 43 : /// An ExtIO version of the Arduino function 44 : /// @see ExtendedIOElement::pinMode 45 : void pinMode(pin_t pin, PinMode_t mode); 46 : /// Overload to Arduino pinMode function. 47 : void pinMode(int pin, PinMode_t mode); 48 : /// An ExtIO version of the Arduino function 49 : /// @see ExtendedIOElement::digitalWrite 50 : void digitalWrite(pin_t pin, PinStatus_t val); 51 : /// Overload to Arduino digitalWrite function. 52 : void digitalWrite(int pin, PinStatus_t val); 53 : /// An ExtIO version of the Arduino function 54 : /// @see ExtendedIOElement::digitalRead 55 : PinStatus_t digitalRead(pin_t pin); 56 : /// Overload to Arduino digitalRead function. 57 : PinStatus_t digitalRead(int pin); 58 : 59 : /// An ExtIO version of the Arduino function 60 : /// @see ExtendedIOElement::analogRead 61 : analog_t analogRead(pin_t pin); 62 : /// Overload to Arduino analogRead function. 63 : analog_t analogRead(int pin); 64 : /// An ExtIO version of the Arduino function 65 : /// @see ExtendedIOElement::analogWrite 66 : void analogWrite(pin_t pin, analog_t val); 67 : /// An ExtIO version of the Arduino function 68 : /// @see ExtendedIOElement::analogWrite 69 : void analogWrite(pin_t pin, int val); 70 : #ifndef ESP32 71 : /// Overload to Arduino analogWrite function. 72 : void analogWrite(int pin, analog_t val); 73 : /// Overload to Arduino analogWrite function. 74 : void analogWrite(int pin, int val); 75 : #endif 76 : 77 : /// An ExtIO version of the Arduino function 78 : void shiftOut(pin_t dataPin, pin_t clockPin, BitOrder_t bitOrder, uint8_t val); 79 : /// Overload to Arduino shiftOut function 80 : void shiftOut(int dataPin, int clockPin, BitOrder_t bitOrder, uint8_t val); 81 : 82 : /// A buffered ExtIO version of the Arduino function 83 : /// @see ExtendedIOElement::pinModeBuffered 84 : void pinModeBuffered(pin_t pin, PinMode_t mode); 85 : /// A buffered ExtIO version of the Arduino function 86 : /// @see ExtendedIOElement::digitalWriteBuffered 87 : void digitalWriteBuffered(pin_t pin, PinStatus_t val); 88 : /// A buffered ExtIO version of the Arduino function 89 : /// @see ExtendedIOElement::digitalReadBuffered 90 : PinStatus_t digitalReadBuffered(pin_t pin); 91 : 92 : /// A buffered ExtIO version of the Arduino function 93 : /// @see ExtendedIOElement::analogReadBuffered 94 : analog_t analogReadBuffered(pin_t pin); 95 : /// A buffered ExtIO version of the Arduino function 96 : /// @see ExtendedIOElement::analogWriteBuffered 97 : void analogWriteBuffered(pin_t pin, analog_t val); 98 : /// A buffered ExtIO version of the Arduino function 99 : /// @see ExtendedIOElement::analogWriteBuffered 100 : void analogWriteBuffered(pin_t pin, int val); 101 : 102 : #if UINT16_MAX != UINT_MAX 103 : /// Overload to Arduino pinMode function. 104 : void pinMode(unsigned int pin, PinMode_t mode); 105 : /// Overload to Arduino digitalWrite function. 106 : void digitalWrite(unsigned int pin, PinStatus_t val); 107 : /// Overload to Arduino digitalRead function. 108 : PinStatus_t digitalRead(unsigned int pin); 109 : 110 : /// Overload to Arduino analogRead function. 111 : analog_t analogRead(unsigned int pin); 112 : #ifndef ESP32 113 : /// Overload to Arduino analogWrite function. 114 : void analogWrite(unsigned int pin, analog_t val); 115 : /// Overload to Arduino analogWrite function. 116 : void analogWrite(unsigned int pin, int val); 117 : #endif 118 : 119 : /// Overload to Arduino shiftOut function 120 : void shiftOut(unsigned int dataPin, unsigned int clockPin, BitOrder_t bitOrder, 121 : uint8_t val); 122 : #endif 123 : 124 : /// @} 125 : 126 : } // namespace ExtIO 127 : 128 : END_AH_NAMESPACE 129 : 130 : AH_DIAGNOSTIC_POP()