7 #include <util/atomic.h>
9 #define ATOMIC_BLOCK(x)
18 volatile uint8_t PINx;
19 volatile uint8_t DDRx;
20 volatile uint8_t PORTx;
23 enum class Mode : uint8_t {
28 enum class Pull : uint8_t {
34 enum class Level : uint8_t {
58 __attribute__((always_inline))
inline void WritePin(
const GPIO_pin portPin, Level level) {
59 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
60 if (level == Level::high)
61 portPin.port->PORTx |= (1 << portPin.pin);
63 portPin.port->PORTx &= ~(1 << portPin.pin);
67 __attribute__((always_inline))
inline Level ReadPin(
const GPIO_pin portPin) {
69 return (Level)((portPin.port->PINx & (1 << portPin.pin)) != 0);
72 return (Level)((portPin.port->PORTx & (1 << portPin.pin)) != 0);
76 __attribute__((always_inline))
inline void TogglePin(
const GPIO_pin portPin) {
79 portPin.port->PINx = (1 << portPin.pin);
81 WritePin(portPin, (Level)(ReadPin(portPin) != Level::high));
85 __attribute__((always_inline))
inline void Init(
const GPIO_pin portPin, GPIO_InitTypeDef GPIO_Init) {
86 if (GPIO_Init.mode == Mode::output) {
87 WritePin(portPin, GPIO_Init.level);
88 portPin.port->DDRx |= (1 << portPin.pin);
90 portPin.port->DDRx &= ~(1 << portPin.pin);
91 WritePin(portPin, (Level)GPIO_Init.pull);
99 #define GPIOA ((hal::gpio::GPIO_TypeDef *)&PINA)
100 #define GPIOB ((hal::gpio::GPIO_TypeDef *)&PINB)
101 #define GPIOC ((hal::gpio::GPIO_TypeDef *)&PINC)
102 #define GPIOD ((hal::gpio::GPIO_TypeDef *)&PIND)
103 #define GPIOE ((hal::gpio::GPIO_TypeDef *)&PINE)
104 #define GPIOF ((hal::gpio::GPIO_TypeDef *)&PINF)
105 #define GPIOG ((hal::gpio::GPIO_TypeDef *)&PING)
106 #define GPIOH ((hal::gpio::GPIO_TypeDef *)&PINH)
107 #define GPIOJ ((hal::gpio::GPIO_TypeDef *)&PINJ)
108 #define GPIOK ((hal::gpio::GPIO_TypeDef *)&PINK)
109 #define GPIOL ((hal::gpio::GPIO_TypeDef *)&PINL)
125 #define GPIOA (&::_GPIOA)
126 #define GPIOB (&::_GPIOB)
127 #define GPIOC (&::_GPIOC)
128 #define GPIOD (&::_GPIOD)
129 #define GPIOE (&::_GPIOE)
130 #define GPIOF (&::_GPIOF)
131 #define GPIOG (&::_GPIOG)
132 #define GPIOH (&::_GPIOH)
133 #define GPIOJ (&::_GPIOJ)
134 #define GPIOK (&::_GPIOK)
135 #define GPIOL (&::_GPIOL)
void Init()
ADC access routines.
Definition: adc.cpp:8