Urbanite: Parking aid system
port_button.h File Reference

Header for the portable functions to interact with the HW of the buttons. The functions must be implemented in the platform-specific code. More...

#include <stdint.h>
#include <stdbool.h>

Macros

#define PORT_PARKING_BUTTON_ID
 
#define PORT_PARKING_BUTTON_DEBOUNCE_TIME_MS
 

Functions

void port_button_init (uint32_t button_id)
 Configure the HW specifications of a given button. More...
 
bool port_button_get_pressed (uint32_t button_id)
 Return the status of the button (pressed or not). More...
 
bool port_button_get_value (uint32_t button_id)
 Get the value of the GPIO connected to the button. 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...
 

Detailed Description

Header for the portable functions to interact with the HW of the buttons. The functions must be implemented in the platform-specific code.

Author
Sistemas Digitales II
Date
2025-01-01

Macro Definition Documentation

◆ PORT_PARKING_BUTTON_DEBOUNCE_TIME_MS

#define PORT_PARKING_BUTTON_DEBOUNCE_TIME_MS

Button debounce time in milliseconds

◆ PORT_PARKING_BUTTON_ID

#define PORT_PARKING_BUTTON_ID

User button identifier that represents the rear button (activation of the parking aid system)

Function Documentation

◆ 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.