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

Interrupt service routines for the STM32F4 platform. More...

#include "port_system.h"
#include "stm32f4_system.h"
#include "port_button.h"
#include "stm32f4_button.h"
#include "port_keyboard.h"
#include "stm32f4_keyboard.h"
#include "port_simone.h"

Functions

void _check_column_interrupt (uint8_t column_index)
 Check and handle the column interrupt for a given column index. This function is called from the EXTI IRQHandlers for each column. More...
 
void SysTick_Handler (void)
 Interrupt service routine for the System tick timer (SysTick). More...
 
void EXTI15_10_IRQHandler (void)
 This function handles Px10-Px15 global interrupts. More...
 
void EXTI4_IRQHandler (void)
 This function handles EXTI line 4 interrupt. More...
 
void EXTI9_5_IRQHandler (void)
 This function handles EXTI lines [9:5] interrupts. More...
 
void TIM5_IRQHandler (void)
 Interrupt service routine for the TIM5 timer. More...
 
void TIM3_IRQHandler (void)
 Interrupt service routine for the TIM3 timer. More...
 

Detailed Description

Interrupt service routines for the STM32F4 platform.

Author
SDG2. Román Cárdenas (r.car.nosp@m.dena.nosp@m.s@upm.nosp@m..es) and Josué Pagán (j.pag.nosp@m.an@u.nosp@m.pm.es)
Date
2026-12-01

Function Documentation

◆ _check_column_interrupt()

void _check_column_interrupt ( uint8_t  column_index)

Check and handle the column interrupt for a given column index. This function is called from the EXTI IRQHandlers for each column.

TODO alumnos ✅ 1. Get the GPIO port and pin for the given column index from the keyboard struct
✅ 2. Read the GPIO pin state using the stm32f4_system_gpio_read() function
✅ 3. If the pin state is HIGH, it means a key in that column has been pressed. In this case, set the flag_key_pressed field to true. Otherwise, the key has been released and thus, set it to false and store the index of the column that provoked the interrupt in the col_idx_interrupt.
✅ 4. Clear the interrupt pending flag for the column pin by writing '1' to the corresponding bit in the PR register

Parameters
column_indexIndex of the column to check

◆ EXTI15_10_IRQHandler()

void EXTI15_10_IRQHandler ( void  )

This function handles Px10-Px15 global interrupts.

First, this function identifies the line/ pin which has raised the interruption. Then, perform the desired action. Before leaving it cleans the interrupt pending register.

TODO alumnos VERSION 1

✅ 1. Retrieve the values of the GPIO of the user button. Use the PORT_USER_BUTTON_ID index to get the port and pin from the buttons_arr
✅ 2. If the value is HIGH means that the button as been released, therefore set the field flag_pressed to false
✅ 3. If the value is LOW means that the button as been pressed, therefore set the field flag_pressed to true
✅ 4. Clean the corresponding bit of the PR register
    💡 Recommendation: use the macro BIT_POS_TO_MASK
    💡 To clean an interrupt in the Pending Register (PR) we must write '1' in the corresponding bit. Look at the example in section "Ejemplo de interrupción externa" of the reference book. You can also find this out by consulting the reference manual STM32F446xx Advanced ARM-based 32-bit MCUs (See section "10.3.6 Pending register (EXTI_PR)")

TODO alumnos VERSION 2

✅ 1. Check if the interrupt has been generated by the column (column PORT_KEYBOARD_COL_1) of the keyboard. To do so, call the function _check_column_interrupt() with the right column index parameter
*

TODO alumnos VERSION 4

✅ 1. Call the function port_system_systick_resume() to resume the systick timer at the beginning of the ISR

◆ EXTI4_IRQHandler()

void EXTI4_IRQHandler ( void  )

This function handles EXTI line 4 interrupt.

This function is called when a column line (column PORT_KEYBOARD_COL_2) generates an interrupt. It checks if the corresponding GPIO pin is high, indicating that a key in that column has been pressed and released. If a key press is detected, it updates the keyboard state accordingly.

TODO alumnos

✅ 1. Call the function _check_column_interrupt() with the right column index parameter for this ISR (i.e., PORT_KEYBOARD_COL_2)

TODO alumnos VERSION 4

✅ 1. Call the function port_system_systick_resume() to resume the systick timer at the beginning of the ISR

◆ EXTI9_5_IRQHandler()

void EXTI9_5_IRQHandler ( void  )

This function handles EXTI lines [9:5] interrupts.

This function is called when column lines (columns PORT_KEYBOARD_COL_0 and PORT_KEYBOARD_COL_3) generate interrupts. It checks which GPIO pin triggered the interrupt and calls the corresponding handler to process the key press event.

TODO alumnos

✅ 1. For each column (i.e., PORT_KEYBOARD_COL_0 and PORT_KEYBOARD_COL_3), check if the corresponding EXTI line triggered the interrupt by checking the PR register. If it did, call the function _check_column_interrupt() with the right column index parameter

TODO alumnos VERSION 4

✅ 1. Call the function port_system_systick_resume() to resume the systick timer at the beginning of the ISR

◆ SysTick_Handler()

void SysTick_Handler ( void  )

Interrupt service routine for the System tick timer (SysTick).

Note
This ISR is called when the SysTick timer generates an interrupt. The program flow jumps to this ISR and increments the tick counter by one millisecond.

TODO alumnos:

✅ 1. Increment the System tick counter msTicks in 1 count. To do so, use the function port_system_get_millis() and port_system_set_millis().

Warning
The variable msTicks must be declared volatile! Just because it is modified by a call of an ISR, in order to avoid race conditions . Added to the definition after static.

◆ TIM3_IRQHandler()

void TIM3_IRQHandler ( void  )

Interrupt service routine for the TIM3 timer.

This timer controls the different timing events of the Simone game. When the interrupt occurs it means that: a) the time of a color ON has passed, b) the time of the color OFF has passed, c) the time of waiting to a player keyboard pressed has passed.

TODO alumnos

✅ 1. Clear the interrupt flag UIF in the status register SR.
✅ 2. Call the function port_simone_set_timer_status() to set the flag that indicates that the time has expired.

◆ TIM5_IRQHandler()

void TIM5_IRQHandler ( void  )

Interrupt service routine for the TIM5 timer.

This timer controls the duration of the row excitation in the keyboard. When the timer interrupt occurs, it indicates that the duration of the row excitation has expired and a new row can be excited.

TODO alumnos

✅ 1. Clear the interrupt flag UIF in the status register SR.
✅ 2. Set the flag that indicates that the row timeout has occurred.