46 uint32_t afr_index = gpio_cfg->
pin >> 3;
47 uint32_t afr_shift = (gpio_cfg->
pin & 0x7) * 4;
49 gpio_cfg->
port->
GPIO_AFR[afr_index] &= ~(0xFu << afr_shift);
59 RCC->RCC_APB2ENR |= (0b1 << 14);
62 if(gpio_cfg->
pin < 4) {
63 SYSCFG->SYSCFG_EXTICR1 &= ~(0b1111 << gpio_cfg->
pin * 4);
66 else if(gpio_cfg->
pin < 8) {
67 SYSCFG->SYSCFG_EXTICR2 &= ~(0b1111 << (gpio_cfg->
pin - 4) * 4);
70 else if(gpio_cfg->
pin < 12) {
71 SYSCFG->SYSCFG_EXTICR3 &= ~(0b1111 << (gpio_cfg->
pin - 8) * 4);
75 SYSCFG->SYSCFG_EXTICR4 &= ~(0b1111 << (gpio_cfg->
pin - 12) * 4);
80 EXTI->EXTI_IMR |= 0b1 << gpio_cfg->
pin;
85 EXTI->EXTI_RTSR |= 0b1 << gpio_cfg->
pin;
88 EXTI->EXTI_FTSR |= 0b1 << gpio_cfg->
pin;
91 EXTI->EXTI_RTSR |= 0b1 << gpio_cfg->
pin;
92 EXTI->EXTI_FTSR |= 0b1 << gpio_cfg->
pin;
104 if(gpio_port ==
GPIOA) {
107 else if(gpio_port ==
GPIOB) {
110 else if(gpio_port ==
GPIOC) {
113 else if(gpio_port ==
GPIOD) {
116 else if(gpio_port ==
GPIOE) {
119 else if(gpio_port ==
GPIOH) {
130 gpio_port->
GPIO_ODR |= (0x1 << gpio_pin);
133 gpio_port->
GPIO_ODR &= ~(0x1 << gpio_pin);
146 EXTI->EXTI_PR = 0x1 << exti_line;
151 const char gpio[] =
"GPIO";
153 uint8_t pos_counter = 0;
155 while(pos_counter < gpio_len) {
156 name[pos_counter] = gpio[pos_counter];
160 if(gpio_port ==
GPIOA) name[pos_counter] =
'A';
161 else if(gpio_port ==
GPIOB) name[pos_counter] =
'B';
162 else if(gpio_port ==
GPIOC) name[pos_counter] =
'C';
163 else if(gpio_port ==
GPIOD) name[pos_counter] =
'D';
164 else if(gpio_port ==
GPIOE) name[pos_counter] =
'E';
165 else if(gpio_port ==
GPIOH) name[pos_counter] =
'H';
168 name[pos_counter] =
'\0';
189 if(gpio_port ==
GPIOA) {
192 else if(gpio_port ==
GPIOB) {
195 else if(gpio_port ==
GPIOC) {
198 else if(gpio_port ==
GPIOD) {
201 else if(gpio_port ==
GPIOE) {
204 else if(gpio_port ==
GPIOH) {
222 if(gpio_port ==
GPIOA)
return PA;
223 else if(gpio_port ==
GPIOB)
return PB;
224 else if(gpio_port ==
GPIOC)
return PC;
225 else if(gpio_port ==
GPIOD)
return PD;
226 else if(gpio_port ==
GPIOE)
return PE;
Arm Cortex-M4 NVIC driver public API.
Common utility module public API.
uint32_t get_str_len(char const *str)
Returns the length of a string, excluding the null terminator.
PIN_STATUS_te
Represents the logical level of a GPIO pin.
EN_STATUS_te
Represents an enabled or disabled state.
void nvic_set_interrupt(IRQn_te interrupt_line, EN_STATUS_te en_status)
Enables or disables an interrupt line in the NVIC.
static PORT_CODES_ts get_syscfg_code(GPIO_REGDEF_ts const *port)
Returns the SYSCFG port code for a GPIO port instance.
static uint8_t get_exti_position(GPIO_CFG_ts const *gpio_cfg)
Returns the IRQ number for the EXTI line corresponding to a GPIO pin.
static void gpio_set_pclk(GPIO_REGDEF_ts const *gpio_port, EN_STATUS_te en_status)
Enables or disables the peripheral clock for a GPIO port.
PIN_STATUS_te gpio_read(GPIO_REGDEF_ts const *gpio_port, uint8_t gpio_pin)
Reads the current logic level of a GPIO input pin.
void gpio_write(GPIO_REGDEF_ts *gpio_port, uint8_t gpio_pin, PIN_STATUS_te pin_status)
Drives a GPIO output pin high or low.
void gpio_deinit(GPIO_REGDEF_ts const *gpio_port)
Deinitializes a GPIO port by resetting its registers to reset values.
void gpio_get_name(GPIO_REGDEF_ts const *gpio_port, char *name)
Returns the name string of a GPIO port.
void gpio_init(GPIO_CFG_ts *gpio_cfg)
Initializes a GPIO pin according to the given configuration.
void gpio_clear_interrupt(EXTI_LINES_te exti_line)
Clears the EXTI pending flag for the given interrupt line.
@ GPIO_INTERRUPT_TRIGGER_RE
@ GPIO_INTERRUPT_TRIGGER_RFE
@ GPIO_INTERRUPT_TRIGGER_FE
void rcc_set_pclk_ahb1(RCC_AHB1ENR_te periph_position, EN_STATUS_te en_status)
Enables or disables the peripheral clock for an AHB1 peripheral.
void rcc_reset_periph_ahb1(RCC_AHB1RSTR_te periph_position)
Resets an AHB1 peripheral via RCC_AHB1RSTR.
PORT_CODES_ts
SYSCFG port codes for EXTICRx routing.
EXTI_LINES_te
EXTI line numbers.
STM32F401RE MCU-specific peripheral register definitions and bit position enumerations.
STM32F401RE GPIO driver public API.
STM32F401RE RCC driver public API.
Configuration structure for initializing a GPIO pin.
GPIO_PULL_MODE_te pull_mode
GPIO_ALTERNATE_FUNCTION_te alternate_function
GPIO_INTERRUPT_TRIGGER_te interrupt_trigger
GPIO_OUTPUT_TYPE_te output_type
GPIO_OUTPUT_SPEED_te output_speed
GPIO peripheral register map.
uint32_t volatile GPIO_IDR
uint32_t volatile GPIO_ODR
uint32_t volatile GPIO_PUPDR
uint32_t volatile GPIO_OTYPER
uint32_t volatile GPIO_AFR[2]
uint32_t volatile GPIO_MODER
uint32_t volatile GPIO_OSPEEDR