Simone: a game of visual memory and speed
stm32f4_simone.c File Reference

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

#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <math.h>
#include "port_simone.h"
#include "port_system.h"
#include "stm32f4_system.h"
#include "stm32f4_simone.h"

Functions

static void _timer_simone_setup ()
 Configure the timer that controls the duration of the note. More...
 
void port_simone_set_timer_timeout (uint32_t duration_ms)
 Configure the timer timeout for the Simone game. More...
 
void port_simone_stop_timer (void)
 Stop the timer of the Simone game. More...
 
bool port_simone_get_timeout_status (void)
 Get the timer timeout status of the Simone game. More...
 
void port_simone_set_timeout_status (bool status)
 Set the status of the timer timeout status of the Simone game. More...
 
void port_simone_init ()
 Initialize the Simone game port. More...
 

Variables

stm32f4_simone_hw_t simone_hw
 Array of elements that represents the HW characteristics of the RGB LED of the RGB light systems connected to the STM32F4 platform. More...
 

Detailed Description

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

Author
Sistemas Digitales II
Date
2026-01-01

Function Documentation

◆ _timer_simone_setup()

static void _timer_simone_setup ( )
static

Configure the timer that controls the duration of the note.

This function is called by the port_simone_init() public function to configure the timer that controls the duration of the different events of the game.

TODO alumnos:

✅ 1. Enable the clock source of the timer
    💡 To know if the source clock is APB1 or APB2, check the clock tree in the datasheet (Figure 3. STM32F446xC/E block diagram)
✅ 2. Disable the counter (register CR1) and enable the autoreload preaload (bit ARPE)
✅ 3. Clean the Update Interrupt flag (register SR)
✅ 4. Enable the Update Interrupt (register DIER)
✅ 5. Set the priority and the subpriority of the interrupt
✅ 6. Enable the interrupt in the NVIC

Parameters
buzzer_id

◆ port_simone_get_timeout_status()

bool port_simone_get_timeout_status ( void  )

Get the timer timeout status of the Simone game.

Returns
true
false

◆ port_simone_init()

void port_simone_init ( void  )

Initialize the Simone game port.

This function initializes the HW associated to the Simone game, such as the timer that controls the duration of the different events of the game. It is called from the fsm_simone_init() function to initialize the HW dependencies of the Simone FSM.

TODO alumnos:

✅ 1. Reset the flag of the simone_hw struct.
✅ 2. Configure the timer that controls the duration of the different events of the game by calling the _timer_simone_setup() function.

◆ port_simone_set_timeout_status()

void port_simone_set_timeout_status ( bool  status)

Set the status of the timer timeout status of the Simone game.

Parameters
status

◆ port_simone_set_timer_timeout()

void port_simone_set_timer_timeout ( uint32_t  duration_ms)

Configure the timer timeout for the Simone game.

This function is called to configure the timer that controls the duration of the different events of the game. The duration of the timeout is received as a parameter in milliseconds. When the timer expires, an interrupt is generated and the flag of the simone_hw struct is set to indicate that the time has expired.

TODO alumnos: ✅ 1. Disable the timer by clearing the CEN bit in the CR1 register.
✅ 2. Reset the counter by writing 0 to the CNT register.
✅ 3. Compute the values of the prescaler (PSC) and the auto-reload register (ARR) to match the duration in milliseconds. Use any of the two options explained in the stm32f4_keyboard.c file to compute the values of the prescaler and the auto-reload register.
✅ 4. Load the values of the prescaler and the auto-reload register in the corresponding registers.
✅ 5. The values of the prescaler and the auto-reload register are currently in the preload registers. To load them into the active registers we need an update event. We can do this manually by setting the UG bit in the EGR register.
✅ 6. Clear the pending interrupt flag generated when doing the update event by clearing the UIF bit in the SR register.
✅ 7. Now enable the update interrupt by setting the UIE bit in the DIER register.
✅ 8. Reset the flag of the simone_hw struct to indicate that the time has not expired yet. Important! This must be done after enabling the interrupt to avoid a race condition.
✅ 9. Enable the timer by setting the CEN bit in the CR1 register.

Parameters
duration_ms

◆ port_simone_stop_timer()

void port_simone_stop_timer ( void  )

Stop the timer of the Simone game.

This function is called to stop the timer of the Simone game when the game is over or when the player has won.

Variable Documentation

◆ simone_hw

Array of elements that represents the HW characteristics of the RGB LED of the RGB light systems connected to the STM32F4 platform.

Element that represents the HW characteristics of the Simone game connected to the STM32F4 platform to manage the timers.

  • This is an extern variable that is declared in stm32f4_rgb_light.h. It represents an array of RGB lights.