49 #define _FG_SBI(mem_addr, bit) asm volatile("sbi %0, %1\n" : \ 50 : "I" (mem_addr - __SFR_OFFSET), "I" (bit)) 51 #define _FG_CBI(mem_addr, bit) asm volatile("cbi %0, %1\n" : \ 52 : "I" (mem_addr - __SFR_OFFSET), "I" (bit)) 53 #define _FG_PIN(port, bit) { _SFR_MEM_ADDR(PIN##port), _SFR_MEM_ADDR(PORT##port), \ 54 _SFR_MEM_ADDR(DDR##port), bit } 65 typedef struct IOStruct
72 volatile uint8_t * pin()
const 74 return (
volatile uint8_t *)(uint16_t)pinAddr;
77 volatile uint8_t * port()
const 79 return (
volatile uint8_t *)(uint16_t)portAddr;
82 volatile uint8_t * ddr()
const 84 return (
volatile uint8_t *)(uint16_t)ddrAddr;
89 #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__) 91 const IOStruct pinStructs[] = {
139 #elif defined(__AVR_ATmega32U4__) 141 const IOStruct pinStructs[] = {
214 #error FastGPIO does not support this board. 217 template<u
int8_t pin>
class Pin 228 _FG_CBI(pinStructs[pin].portAddr, pinStructs[pin].bit);
229 _FG_SBI(pinStructs[pin].ddrAddr, pinStructs[pin].bit);
240 _FG_SBI(pinStructs[pin].portAddr, pinStructs[pin].bit);
241 _FG_SBI(pinStructs[pin].ddrAddr, pinStructs[pin].bit);
248 setOutputValueToggle();
249 _FG_SBI(pinStructs[pin].ddrAddr, pinStructs[pin].bit);
260 static inline void setOutput(
bool value) __attribute__((always_inline))
262 setOutputValue(value);
263 _FG_SBI(pinStructs[pin].ddrAddr, pinStructs[pin].bit);
276 _FG_CBI(pinStructs[pin].portAddr, pinStructs[pin].bit);
289 _FG_SBI(pinStructs[pin].portAddr, pinStructs[pin].bit);
304 _FG_SBI(pinStructs[pin].pinAddr, pinStructs[pin].bit);
322 _FG_SBI(pinStructs[pin].portAddr, pinStructs[pin].bit);
326 _FG_CBI(pinStructs[pin].portAddr, pinStructs[pin].bit);
333 static inline void setInput() __attribute__((always_inline))
335 _FG_CBI(pinStructs[pin].ddrAddr, pinStructs[pin].bit);
336 _FG_CBI(pinStructs[pin].portAddr, pinStructs[pin].bit);
344 _FG_CBI(pinStructs[pin].ddrAddr, pinStructs[pin].bit);
345 _FG_SBI(pinStructs[pin].portAddr, pinStructs[pin].bit);
354 return *pinStructs[pin].pin() >> pinStructs[pin].bit & 1;
374 static inline bool isOutput() __attribute__((always_inline))
376 return *pinStructs[pin].ddr() >> pinStructs[pin].bit & 1;
387 return *pinStructs[pin].port() >> pinStructs[pin].bit & 1;
406 :
"I" (pinStructs[pin].bit),
407 "I" (pinStructs[pin].portAddr - __SFR_OFFSET),
408 "I" (pinStructs[pin].ddrAddr - __SFR_OFFSET));
444 "I" (pinStructs[pin].bit),
445 "I" (pinStructs[pin].portAddr - __SFR_OFFSET),
446 "I" (pinStructs[pin].ddrAddr - __SFR_OFFSET));
uint8_t state
The state of the pin as returned from FastGPIO::Pin::getState.
static bool isInputHigh() __attribute__((always_inline))
Reads the input value of the pin.
static void setOutputToggle() __attribute__((always_inline))
Configures the pin to be an output and toggles it.
static void setOutput(bool value) __attribute__((always_inline))
Sets the pin as an output.
static void setOutputValueLow() __attribute__((always_inline))
Sets the output value of the pin to 0.
static void setInput() __attribute__((always_inline))
Sets a pin to be a digital input with the internal pull-up resistor disabled.
static bool isOutputValueHigh() __attribute__((always_inline))
Returns the output value of the pin.
static void setState(uint8_t state)
Sets the full 2-bit state of the pin.
static void setOutputValueHigh() __attribute__((always_inline))
Sets the output value of the pin to 1.
static bool isOutput() __attribute__((always_inline))
Returns 1 if the pin is configured as an output.
static void setOutputValueToggle() __attribute__((always_inline))
Toggles the output value of the pin.
static void setOutputHigh() __attribute__((always_inline))
Configures the pin to be an output driving high.
static void setInputPulledUp() __attribute__((always_inline))
Sets a pin to be a digital input with the internal pull-up resistor enabled.
static void setOutputValue(bool value) __attribute__((always_inline))
Sets the output value of the pin.
static void setOutputLow() __attribute__((always_inline))
Configures the pin to be an output driving low.
static uint8_t getState()
Returns the full 2-bit state of the pin.