Urbanite: Parking aid system
stm32f4_button.c File Reference

Portable functions to interact with the button FSM library. All portable functions must be implemented in this file. More...

#include <stdio.h>
#include "port_button.h"
#include "port_system.h"
#include "stm32f4_system.h"
#include "stm32f4_button.h"

Data Structures

struct  stm32f4_button_hw_t
 Structure to define the HW dependencies of a button status. More...
 

Functions

stm32f4_button_hw_t_stm32f4_button_get (uint32_t button_id)
 Get the button struct with the given ID. More...
 
void port_button_init (uint32_t button_id)
 Configure the HW specifications of a given button. More...
 
bool port_button_get_value (uint32_t button_id)
 Get the value of the GPIO connected to the button. More...
 
bool port_button_get_pressed (uint32_t button_id)
 Return the status of the button (pressed or not). More...
 
void port_button_set_pressed (uint32_t button_id, bool pressed)
 Set the status of the button (pressed or not). More...
 
bool port_button_get_pending_interrupt (uint32_t button_id)
 Get the status of the interrupt line connected to the button. More...
 
void port_button_clear_pending_interrupt (uint32_t button_id)
 Clear the pending interrupt of the button. More...
 
void port_button_disable_interrupts (uint32_t button_id)
 Disable the interrupts of the button. More...
 
void stm32f4_button_set_new_gpio (uint32_t button_id, GPIO_TypeDef *p_port, uint8_t pin)
 Auxiliary function to change the GPIO and pin of a button. This function is used for testing purposes mainly although it can be used in the final implementation if needed. More...
 

Variables

static stm32f4_button_hw_t buttons_arr []
 Array of elements that represents the HW characteristics of the buttons connected to the STM32F4 platform. More...
 

Detailed Description

Portable functions to interact with the button FSM library. All portable functions must be implemented in this file.

Author
Sistemas Digitales II
Date
2025-01-01

Function Documentation

◆ _stm32f4_button_get()

stm32f4_button_hw_t* _stm32f4_button_get ( uint32_t  button_id)

Get the button struct with the given ID.

Parameters
button_idButton ID.
Returns
Pointer to the button struct.
NULL If the button ID is not valid.

◆ port_button_clear_pending_interrupt()

void port_button_clear_pending_interrupt ( uint32_t  button_id)

Clear the pending interrupt of the button.

This function is used to clear the pending interrupt of the button. It is called from the ISR to avoid unwanted interrupts.

TODO alumnos:

✅ 1. Get the button configuration struct calling _stm32f4_button_get()
✅ 2. Get the pin of the button
✅ 3. Clear the corresponding bit of the PR register of the EXTI peripheral associated with the button pin

Parameters
button_idButton ID. This index is used to get the correct button struct of the buttons_arr[] array.

◆ port_button_disable_interrupts()

void port_button_disable_interrupts ( uint32_t  button_id)

Disable the interrupts of the button.

This function is used to disable the interrupts of the button. It is used in the unit tests to avoid unwanted interrupts.

TODO alumnos:

✅ 1. Get the button configuration struct calling _stm32f4_button_get()
✅ 2. Get the pin of the button
✅ 3. Disable the EXTI line associated with the button pin by calling the function stm32f4_system_gpio_exti_disable()

Parameters
button_idButton ID. This index is used to get the correct button struct of the buttons_arr[] array.

◆ port_button_get_pending_interrupt()

bool port_button_get_pending_interrupt ( uint32_t  button_id)

Get the status of the interrupt line connected to the button.

This function is used to check if the interrupt line of the button is pending. It is called from the ISR to check if the button has been pressed.

TODO alumnos:

✅ 1. Get the button configuration struct calling _stm32f4_button_get()
✅ 2. Get the pin of the button
✅ 3. Read the value of the PR register of the EXTI peripheral associated with the button pin
✅ 4. Return the value.

Parameters
button_idButton ID. This index is used to get the correct button struct of the buttons_arr[] array.
Returns
true
false

◆ port_button_get_pressed()

bool port_button_get_pressed ( uint32_t  button_id)

Return the status of the button (pressed or not).

TODO alumnos:

✅ 1. Return the value of the field flag_pressed. Call the function _stm32f4_button_get() to get the button struct.

Parameters
button_idButton ID. This index is used to get the correct button status struct.
Returns
true If the button has been pressed
false If the button has not been pressed

◆ port_button_get_value()

bool port_button_get_value ( uint32_t  button_id)

Get the value of the GPIO connected to the button.

TODO alumnos:

✅ 1. Call function stm32f4_system_gpio_read() with the right arguments to get the value of the button. Call the function _stm32f4_button_get() to get the button struct.

Parameters
button_idButton ID. This index is used to select the element of the buttons_arr[] array
Returns
true
false

◆ port_button_init()

void port_button_init ( uint32_t  button_id)

Configure the HW specifications of a given button.

Assuming we are using an STM32F4-based platform, this function must call the following functions:

TODO alumnos: ✅ 1. Retrieve the button configuration struct calling _stm32f4_button_get()
✅ 2. Call function stm32f4_system_gpio_config() with the right arguments to configure the button as input and no pull up neither pull down connection
✅ 3. Call function stm32f4_system_gpio_config_exti() with the right arguments to configure interruption mode in both rising and falling edges, and enable the interrupt request
✅ 4. Call function stm32f4_system_gpio_exti_enable() with the right parameters to enable the interrupt line and set the priority level to 1 and the subpriority level to 0

Parameters
button_idButton ID. This index is used to select the element of the buttons_arr[] array

◆ port_button_set_pressed()

void port_button_set_pressed ( uint32_t  button_id,
bool  pressed 
)

Set the status of the button (pressed or not).

This function is used to force the status of the button. It is used to simulate the button press in the tests.

TODO alumnos:

✅ 1. Set the value of the field flag_pressed. Call the function _stm32f4_button_get() to get the button struct.

Parameters
button_idButton ID. This index is used to get the correct button struct of the buttons_arr[] array.
pressedStatus of the button.

◆ stm32f4_button_set_new_gpio()

void stm32f4_button_set_new_gpio ( uint32_t  button_id,
GPIO_TypeDef *  p_port,
uint8_t  pin 
)

Auxiliary function to change the GPIO and pin of a button. This function is used for testing purposes mainly although it can be used in the final implementation if needed.

Parameters
button_idID of the button to change.
p_portNew GPIO port for the button.
pinNew GPIO pin for the button.

Variable Documentation

◆ buttons_arr

stm32f4_button_hw_t buttons_arr[]
static

Array of elements that represents the HW characteristics of the buttons connected to the STM32F4 platform.

This must be hidden from the user, so it is declared as static. To access the elements of this array, use the function _stm32f4_button_get().