30 #if defined(__AVR__) || defined(DOXYGEN)
34 volatile uint8_t*
pin;
35 volatile uint8_t*
ddr;
41 #define GPIO_PIN(reg, bit) {&PIN##reg, &DDR##reg, &PORT##reg, 1 << bit}
44 #include "boards/GpioPinMap.h"
48 __attribute__((error(
"Pin number is too large or not a constant")));
54 void badPinCheck(uint8_t pin)
56 if (!__builtin_constant_p(pin) || pin >= NUM_DIGITAL_PINS) {
66 volatile uint8_t* ddrReg(uint8_t pin)
69 return GpioPinMap[pin].ddr;
77 uint8_t pinMask(uint8_t pin)
80 return GpioPinMap[pin].mask;
88 volatile uint8_t* pinReg(uint8_t pin)
91 return GpioPinMap[pin].pin;
99 volatile uint8_t* portReg(uint8_t pin)
102 return GpioPinMap[pin].port;
111 void fastBitWriteSafe(
volatile uint8_t* address, uint8_t mask,
bool level)
114 if (address >
reinterpret_cast<uint8_t*
>(0X3F)) {
123 if (address >
reinterpret_cast<uint8_t*
>(0X3F)) {
133 bool fastDigitalRead(uint8_t pin)
135 return *pinReg(pin) & pinMask(pin);
145 void fastDigitalToggle(uint8_t pin)
147 if (pinReg(pin) >
reinterpret_cast<uint8_t*
>(0X3F)) {
149 *pinReg(pin) = pinMask(pin);
152 *pinReg(pin) |= pinMask(pin);
161 void fastDigitalWrite(uint8_t pin,
bool level)
163 fastBitWriteSafe(portReg(pin), pinMask(pin), level);
171 void fastDdrWrite(uint8_t pin,
bool level)
173 fastBitWriteSafe(ddrReg(pin), pinMask(pin), level);
184 void fastPinMode(uint8_t pin, uint8_t mode)
186 fastDdrWrite(pin, mode == OUTPUT);
187 if (mode != OUTPUT) {
188 fastDigitalWrite(pin, mode == INPUT_PULLUP);
191 #else // defined(__AVR__)
192 #if defined(CORE_TEENSY)
199 bool fastDigitalRead(uint8_t pin)
201 return *portInputRegister(pin);
209 void fastDigitalWrite(uint8_t pin,
bool value)
212 *portSetRegister(pin) = 1;
214 *portClearRegister(pin) = 1;
217 #elif defined(__SAM3X8E__) || defined(__SAM3X8H__)
224 bool fastDigitalRead(uint8_t pin)
226 return g_APinDescription[pin].pPort->PIO_PDSR & g_APinDescription[pin].ulPin;
234 void fastDigitalWrite(uint8_t pin,
bool value)
237 g_APinDescription[pin].pPort->PIO_SODR = g_APinDescription[pin].ulPin;
239 g_APinDescription[pin].pPort->PIO_CODR = g_APinDescription[pin].ulPin;
242 #elif defined(ESP8266)
249 void fastDigitalWrite(uint8_t pin, uint8_t val)
257 }
else if (pin == 16) {
271 bool fastDigitalRead(uint8_t pin)
275 }
else if (pin == 16) {
282 inline void fastDigitalWrite(uint8_t pin,
bool value)
284 digitalWrite(pin, value);
287 inline bool fastDigitalRead(uint8_t pin)
289 return digitalRead(pin);
291 #endif // CORE_TEENSY
293 inline void fastDigitalToggle(uint8_t pin)
295 fastDigitalWrite(pin, !fastDigitalRead(pin));
298 inline void fastPinMode(uint8_t pin, uint8_t mode)
310 #define fastPinConfig(pin, mode, level)\
311 {fastPinMode(pin, mode); fastDigitalWrite(pin, level);}
317 template<u
int8_t PinNumber>
351 void config(uint8_t mode,
bool level)
382 void mode(uint8_t mode)
384 fastPinMode(PinNumber, mode);
391 return fastDigitalRead(PinNumber);
402 fastDigitalToggle(PinNumber);
410 void write(
bool value)
412 fastDigitalWrite(PinNumber, value);
415 #endif // DigitalPin_h