31 #include <libopencm3/stm32/gpio.h>
32 #include <libopencm3/stm32/rcc.h>
38 rcc_periph_clock_enable(RCC_GPIOA);
41 rcc_periph_clock_enable(RCC_GPIOB);
44 rcc_periph_clock_enable(RCC_GPIOC);
47 rcc_periph_clock_enable(RCC_GPIOD);
51 rcc_periph_clock_enable(RCC_GPIOE);
56 rcc_periph_clock_enable(RCC_GPIOF);
61 rcc_periph_clock_enable(RCC_GPIOG);
66 rcc_periph_clock_enable(RCC_GPIOH);
71 rcc_periph_clock_enable(RCC_GPIOI);
83 gpio_set_mode(port, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, gpios);
89 gpio_set_mode(port, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, gpios);
96 gpio_set_mode(port, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, gpios);
103 gpio_set_mode(port, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, gpios);
111 rcc_periph_clock_enable(RCC_AFIO);
115 gpio_set_mode(port, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, pin);
117 gpio_set_mode(port, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, pin);
124 gpio_set_mode(port, GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, pin);
127 #elif defined STM32F4
132 gpio_mode_setup(port, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, gpios);
138 gpio_mode_setup(port, GPIO_MODE_INPUT, GPIO_PUPD_NONE, gpios);
144 gpio_mode_setup(port, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, gpios);
150 gpio_mode_setup(port, GPIO_MODE_INPUT, GPIO_PUPD_PULLDOWN, gpios);
156 gpio_set_af(port, af, pin);
157 gpio_mode_setup(port, GPIO_MODE_AF, GPIO_PUPD_NONE, pin);
163 gpio_mode_setup(port, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, pin);
void gpio_setup_input_pullup(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as inputs with pull up resistor enabled.
void gpio_setup_input_pulldown(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as inputs with pull down resistors enabled.
void gpio_setup_pin_af(ioportid_t port, uint16_t pin, uint8_t af, bool is_output)
Setup a gpio for input or output with alternate function.
void gpio_setup_output(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as outputs.
void gpio_setup_input(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as inputs.
void gpio_setup_pin_analog(ioportid_t port, uint16_t pin)
Setup a gpio for analog use.
Some architecture independent helper functions for GPIOs.
void gpio_set(uint32_t port, uint16_t pin)
Set a gpio output to high level.
void gpio_clear(uint32_t port, uint16_t pin)
Clear a gpio output to low level.
void gpio_enable_clock(uint32_t port)
Enable the relevant clock.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.