|
Simone: a game of visual memory and speed
|
Keyboard FSM main file. More...
#include <stdlib.h>#include <stdio.h>#include "port_system.h"#include "port_keyboard.h"#include "fsm.h"#include "fsm_keyboard.h"#include "keyboards.h"Functions | |
| static bool | check_row_timeout (fsm_t *p_this) |
| Check if the timeout to activate a new row and scan columns has passed. More... | |
| static bool | check_keyboard_pressed (fsm_t *p_this) |
| Check if the keyboard has been pressed. More... | |
| static bool | check_keyboard_released (fsm_t *p_this) |
| Check if the keyboard has been released. More... | |
| static bool | check_timeout (fsm_t *p_this) |
| Check if the debounce-time has passed. More... | |
| void | do_excite_next_row (fsm_t *p_this) |
| Clean the row timeout flag and update the row to be excited. More... | |
| static void | do_store_tick_pressed (fsm_t *p_this) |
| Store the system tick when the keyboard was pressed. More... | |
| static void | do_set_key_value (fsm_t *p_this) |
| Store the key value of the keyboard press. More... | |
| static void | fsm_keyboard_init (fsm_keyboard_t *p_fsm_keyboard, uint32_t debounce_time, uint8_t keyboard_id) |
| Initialize a keyboard FSM. More... | |
| fsm_keyboard_t * | fsm_keyboard_new (uint32_t debounce_time, 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... | |
Variables | |
| static fsm_trans_t | fsm_trans_keyboard [] |
| Array representing the transitions table of the FSM keyboard. More... | |
Keyboard FSM main file.
|
static |
Check if the keyboard has been pressed.
TODO alumnos:
✅ 1. Call function
port_keyboard_get_key_pressed_status()and retrieve the status
✅ 2. Return the status
| p_this | Pointer to an fsm_t struct than contains an fsm_keyboard_t. |
|
static |
Check if the keyboard has been released.
TODO alumnos:
✅ 1. Call function
port_keyboard_get_key_pressed_status()and retrieve the status
✅ 2. Return the inverse of the status
| p_this | Pointer to an fsm_t struct than contains an fsm_keyboard_t. |
|
static |
Check if the timeout to activate a new row and scan columns has passed.
TODO alumnos:
✅ 1. Return the value of the field
flag_row_timeout
| p_this | Pointer to an fsm_t struct than contains an fsm_keyboard_t. |
|
static |
Check if the debounce-time has passed.
TODO alumnos:
✅ 1. Call function
port_system_get_millis()and retrieve the current system tick
✅ 2. Check if the current system tick is higher than the fieldnext_timeout
✅ 3. Returntrueif it is higher, otherwise returnfalse
| p_this | Pointer to an fsm_t struct than contains an fsm_keyboard_t. |
| void do_excite_next_row | ( | fsm_t * | p_this | ) |
Clean the row timeout flag and update the row to be excited.
TODO alumnos:
✅ 1. Clear the flag that indicates the row timeout with
port_keyboard_set_row_timeout_status().
✅ 2. Excite the the next row by callingport_keyboard_excite_next_row()function.
| p_this | Pointer to an fsm_t struct than contains an fsm_keyboard_t. |
|
static |
Store the key value of the keyboard press.
TODO alumnos:
✅ 1. Call function
port_system_get_millis()and retrieve the current system tick
✅ 2. Update the fieldnext_timeoutconsidering the current tick and the fielddebounce_time_ms
✅ 3. Save thekey_valueof key pressed calling the appropriate port function.
| p_this | Pointer to an fsm_t struct than contains an fsm_keyboard_t. |
|
static |
Store the system tick when the keyboard was pressed.
TODO alumnos:
✅ 1. Call function
port_system_get_millis()and retrieve the current system tick
✅ 2. Store it in the fieldtick_pressed
✅ 3. Update the fieldnext_timeoutconsidering the current tick and the fielddebounce_time_ms
| p_this | Pointer to an fsm_t struct than contains an fsm_keyboard_t. |
| 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
falsealways.
| p_fsm | Pointer to an fsm_keyboard_t struct. |
| void fsm_keyboard_destroy | ( | fsm_keyboard_t * | p_fsm | ) |
Destroy a keyboard FSM.
This function destroys a keyboard FSM and frees the memory.
| p_fsm | Pointer to an fsm_keyboard_t struct. |
| 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 thefsm_tstruct.
| p_fsm | Pointer to an fsm_keyboard_t struct. |
| 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_pressedis different frominvalid_key, otherwise return false.
| p_fsm | Pointer to an fsm_keyboard_t struct. |
| 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
| p_fsm | Pointer to an fsm_keyboard_t struct. |
|
static |
Initialize a keyboard FSM.
This function initializes the default values of the FSM struct and calls to the port to initialize the associated HW given the ID.
This FSM implements an anti-debounce mechanism. Debounces (or very fast keyboard presses) lasting less than the debounce_time_ms are filtered out.
The FSM stores the key_value of the last keyboard press. The user should ask for it using the function fsm_keyboard_get_key_value().
At start and reset, the key value value must be 0 ms. A value of 0 ms means that there has not been a new keyboard press.
fsm_keyboard_reset_key_value() must be called.In other words, the status flag of this FSM is the variable key_value. A key_value of null key means that no new keyboard has been pressed, a value other than null key means that it has been pressed and the value is the key pressed, so it is the user's responsibility to clear this status flag.
The FSM contains information of the keyboard ID. This ID is a unique identifier that is managed by the user in the port. That is where the user provides identifiers and HW information for all the keyboards on his system. The FSM does not have to know anything of the underlying HW.
TODO alumnos:
✅ 1. Call the
fsm_init()to initialize the FSM. Pass the address of thefsm_tstruct and the transition table
✅ 2. Initialize the fieldsdebounce_time_ms,keyboard_idofp_fsm_keyboardwith the received values
✅ 3. Initialize the fieldstick_pressedandinvalid_keyofp_fsm_keyboardproperly. Initialize the ID as well.
✅ 4. Call the functionport_keyboard_init()✅ 5. Call the functionport_keyboard_get_invalid_key_value()to get the null key value of the keyboard and store it in the fieldinvalid_keyandkey_valueas initial value.
| p_fsm_keyboard | Pointer to the keyboard FSM. |
| debounce_time | Anti-debounce time in milliseconds |
| keyboard_id | Unique keyboard identifier number |
| 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.
| debounce_time_ms | Debounce time in milliseconds for all keys. |
| keyboard_id | Keyboard ID. Must be unique. |
| 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_valuetoinvalid_key
| p_fsm | Pointer to an fsm_keyboard_t struct. |
| 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
| p_fsm | Pointer to an fsm_keyboard_t struct. |
| 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
| p_fsm | Pointer to an fsm_keyboard_t struct. |
|
static |
Array representing the transitions table of the FSM keyboard.