Simone: a game of visual memory and speed
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"

Functions

stm32f4_button_hw_t_stm32f4_button_get (uint8_t button_id)
 Get the button struct with the given ID. More...
 
void port_button_init (uint8_t button_id)
 Configure the HW specifications of a given button. More...
 
bool port_button_get_pressed (uint8_t button_id)
 Return the status of the button (pressed or not). More...
 

Variables

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
2026-01-01

Function Documentation

◆ _stm32f4_button_get()

stm32f4_button_hw_t* _stm32f4_button_get ( uint8_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_get_pressed()

bool port_button_get_pressed ( uint8_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_init()

void port_button_init ( uint8_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

Variable Documentation

◆ buttons_arr

stm32f4_button_hw_t buttons_arr[]

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

Array of elements that represents the HW characteristics of the buttons.

This is an extern variable that is declared in stm32f4_button.h. It represents an array of hardware buttons.