50#ifndef DOXYGEN_PRIVATE
67 int portIndex = ((uint32_t)port - GPIOA_BASE) / GPIO_PERIPHERAL_SIZE;
69 port->
MODER &= ~(0b11 << (2 * pin));
70 port->
MODER |= (config->
mode << (2 * pin));
72 port->
OTYPER &= ~(0b01 << pin);
75 port->
OSPEEDR &= ~(0b11 << (2 * pin));
78 port->
PUPDR &= ~(0b11 << (2 * pin));
79 port->
PUPDR |= (config->
pupd << (2 * pin));
81 volatile uint32_t *afr = (pin <= 7) ? &port->
AFR[0] : &port->AFR[1];
82 *afr &= ~(0b1111 << (4 * (pin & 7)));
83 *afr |= (config->
afr << (4 * (pin & 7)));
144 if (config == NULL) {
145 config = &GPIO_CONFIG_DEFAULT;
152 _GPIOpin_init(gpio->
port, gpio->
pin, config);
GPIO_Speed speed
Pin output speed | (default GPIO_SPEED_HIGH)
GPIO_PUPD pupd
Pin pull-up/pull-down | (default GPIO_PUPD_NONE)
void(* updateConfig)(struct GPIOpin *, GPIO_Config *)
GPIO_Mode mode
Pin I/O direction | (default GPIO_MODE_OUTPUT)
GPIO_AF afr
Pin alternate function | (default GPIO_AF0)
GPIO_TypeDef * port
GPIO port in which the pin is located.
GPIO_Config config
Configuration parameters for the pin.
void(* toggle)(struct GPIOpin *)
GPIO_Type type
Pin output type | (default GPIO_TYPE_PUSHPULL)
GPIO_Pin pin
Actual location of the pin within GPIO port.
void(* set)(struct GPIOpin *)
void(* reset)(struct GPIOpin *)
void GPIOpin_toggle(GPIOpin_t *)
Toggle the selected GPIO pin.
void GPIOpin_updateConfig(GPIOpin_t *, GPIO_Config *)
Update GPIO pin configuration.
GPIOpin_t GPIOpin_init(GPIO_TypeDef *port, GPIO_Pin pin, GPIO_Config *config)
Initialiser for a GPIO peripheral pin interface.
void GPIOpin_set(GPIOpin_t *)
Set the selected GPIO pin.
void GPIOpin_reset(GPIOpin_t *)
Clear the selected GPIO pin.
Struct definition for GPIO configuration.
Struct definition for a GPIO pin.