Urbanite: Parking aid system
|
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... | |
Portable functions to interact with the button FSM library. All portable functions must be implemented in this file.
stm32f4_button_hw_t* _stm32f4_button_get | ( | uint32_t | button_id | ) |
Get the button struct with the given ID.
button_id | Button ID. |
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
button_id | Button ID. This index is used to get the correct button struct of the buttons_arr[] array. |
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 functionstm32f4_system_gpio_exti_disable()
button_id | Button ID. This index is used to get the correct button struct of the buttons_arr[] array. |
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.
button_id | Button ID. This index is used to get the correct button struct of the buttons_arr[] array. |
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.
button_id | Button ID. This index is used to get the correct button status struct. |
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.
button_id | Button ID. This index is used to select the element of the buttons_arr[] array |
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 functionstm32f4_system_gpio_config()
with the right arguments to configure the button as input and no pull up neither pull down connection
✅ 3. Call functionstm32f4_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 functionstm32f4_system_gpio_exti_enable()
with the right parameters to enable the interrupt line and set the priority level to1
and the subpriority level to0
button_id | Button ID. This index is used to select the element of the buttons_arr[] array |
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.
button_id | Button ID. This index is used to get the correct button struct of the buttons_arr[] array. |
pressed | Status of the button. |
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.
button_id | ID of the button to change. |
p_port | New GPIO port for the button. |
pin | New GPIO pin for the button. |
|
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()
.