Simone: a game of visual memory and speed
fsm_keyboard.h File Reference

Header for fsm_keyboard.c file. More...

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

Data Structures

struct  fsm_keyboard_t
 Structure of the Keyboard FSM. More...
 

Enumerations

enum  FSM_KEYBOARD {
  KEYBOARD_RELEASED_WAIT_ROW = 0,
  KEYBOARD_RELEASED_WAIT,
  KEYBOARD_PRESSED,
  KEYBOARD_PRESSED_WAIT
}
 Enumerator for the keyboard finite state machine. More...
 

Functions

fsm_keyboard_tfsm_keyboard_new (uint32_t debounce_time_ms, uint8_t keyboard_id)
 Create a new keyboard FSM. More...
 
void fsm_keyboard_destroy (fsm_keyboard_t *p_fsm)
 Destroy a keyboard FSM. More...
 
void fsm_keyboard_fire (fsm_keyboard_t *p_fsm)
 Fire the keyboard FSM. More...
 
void fsm_keyboard_start_scan (fsm_keyboard_t *p_fsm)
 Start the keyboard scanning. More...
 
void fsm_keyboard_stop_scan (fsm_keyboard_t *p_fsm)
 Stop the keyboard scanning. More...
 
char fsm_keyboard_get_key_value (fsm_keyboard_t *p_fsm)
 Return the key pressed of the last keyboard press. More...
 
bool fsm_keyboard_get_is_valid_key (fsm_keyboard_t *p_fsm)
 Check if the last key pressed is valid. More...
 
void fsm_keyboard_reset_key_value (fsm_keyboard_t *p_fsm)
 Reset the key pressed of the last keyboard press. More...
 
bool fsm_keyboard_check_activity (fsm_keyboard_t *p_fsm)
 Check if the keyboard FSM is active, or not. More...
 

Detailed Description

Header for fsm_keyboard.c file.

Author
Sistemas Digitales II
Date
2026-01-01

Enumeration Type Documentation

◆ FSM_KEYBOARD

Enumerator for the keyboard finite state machine.

This enumerator defines the different states that the keyboard finite state machine can be in. Each state represents a specific condition or step in the keyboard key identification process.

Enumerator
KEYBOARD_RELEASED_WAIT_ROW 

Starting state. State to wait for the row scanning. Also comes here when the keyboard has been released

KEYBOARD_RELEASED_WAIT 

State to perform the anti-debounce mechanism for a rising edge

KEYBOARD_PRESSED 

State while the keyboard is being pressed

KEYBOARD_PRESSED_WAIT 

State to perform the anti-debounce mechanism for a falling edge

Function Documentation

◆ fsm_keyboard_check_activity()

bool fsm_keyboard_check_activity ( fsm_keyboard_t p_fsm)

Check if the keyboard FSM is active, or not.

The keyboard is always inactive because it works with events.

TODO alumnos Version 4:

✅ 1. Return false always.

Parameters
p_fsmPointer to an fsm_keyboard_t struct.
Returns
true
false

◆ fsm_keyboard_destroy()

void fsm_keyboard_destroy ( fsm_keyboard_t p_fsm)

Destroy a keyboard FSM.

This function destroys a keyboard FSM and frees the memory.

Parameters
p_fsmPointer to an fsm_keyboard_t struct.

◆ fsm_keyboard_fire()

void fsm_keyboard_fire ( fsm_keyboard_t p_fsm)

Fire the keyboard FSM.

This function is used to fire the keyboard FSM. It is used to check the transitions and execute the actions of the keyboard FSM.

TODO alumnos:

✅ 1. Call the fsm_fire() function. Pass the address of the fsm_t struct.

Parameters
p_fsmPointer to an fsm_keyboard_t struct.

◆ fsm_keyboard_get_is_valid_key()

bool fsm_keyboard_get_is_valid_key ( fsm_keyboard_t p_fsm)

Check if the last key pressed is valid.

This function checks if the last key pressed is valid by comparing it with the invalid key value.

TODO alumnos:

✅ 1. Return true if the field key_pressed is different from invalid_key, otherwise return false.

Parameters
p_fsmPointer to an fsm_keyboard_t struct.
Returns
true
false

◆ fsm_keyboard_get_key_value()

char fsm_keyboard_get_key_value ( fsm_keyboard_t p_fsm)

Return the key pressed of the last keyboard press.

TODO alumnos:

✅ 1. Retrieve and return the field key_pressed

Parameters
p_fsmPointer to an fsm_keyboard_t struct.
Returns
char Key pressed of the last keyboard press.

◆ fsm_keyboard_new()

fsm_keyboard_t* fsm_keyboard_new ( uint32_t  debounce_time_ms,
uint8_t  keyboard_id 
)

Create a new keyboard FSM.

This function creates a new keyboard FSM with the given debounce time for all keys and keyboard ID.

Parameters
debounce_time_msDebounce time in milliseconds for all keys.
keyboard_idKeyboard ID. Must be unique.
Returns
fsm_keyboard_t* Pointer to the keyboard FSM.

◆ fsm_keyboard_reset_key_value()

void fsm_keyboard_reset_key_value ( fsm_keyboard_t p_fsm)

Reset the key pressed of the last keyboard press.

TODO alumnos:

✅ 1. Set the field key_value to invalid_key

Parameters
p_fsmPointer to an fsm_keyboard_t struct.

◆ fsm_keyboard_start_scan()

void fsm_keyboard_start_scan ( fsm_keyboard_t p_fsm)

Start the keyboard scanning.

This function starts the keyboard scanning by calling the appropriate port function.

TODO alumnos:

✅ 1. Call the appropriate port function passing the keyboard ID

Parameters
p_fsmPointer to an fsm_keyboard_t struct.

◆ fsm_keyboard_stop_scan()

void fsm_keyboard_stop_scan ( fsm_keyboard_t p_fsm)

Stop the keyboard scanning.

This function stops the keyboard scanning by calling the appropriate port function.

TODO alumnos:

✅ 1. Call the appropriate port function passing the keyboard ID

Parameters
p_fsmPointer to an fsm_keyboard_t struct.