Keyboard: Replace uint32_t with keyboard_t
This commit is contained in:
parent
3bb7e2cfd4
commit
efc4820328
|
|
@ -24,7 +24,7 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The following enum provides a set of flags to be used to check whose buttons
|
* The following enum provides a set of flags to be used to check which buttons
|
||||||
* are pressed by bit-masking the uint32_t value returned by kbd_getKeys().
|
* are pressed by bit-masking the uint32_t value returned by kbd_getKeys().
|
||||||
*/
|
*/
|
||||||
enum keys
|
enum keys
|
||||||
|
|
@ -62,6 +62,16 @@ enum keys
|
||||||
KEY_F12 = (1 << 30) /* Function button (device specific) */
|
KEY_F12 = (1 << 30) /* Function button (device specific) */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The status of the keyboard keys is provided as an uint32_t.
|
||||||
|
* To check which buttons are pressed one can bit-mask the
|
||||||
|
* uint32_t value keyboard_t with one of the values defined in keys.
|
||||||
|
* Example:
|
||||||
|
* keyboard_t keys = kbd_getKeys();
|
||||||
|
* if(keys & KEY_ENTER) do_stuff();
|
||||||
|
*/
|
||||||
|
typedef uint32_t keyboard_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function initialises the keyboard subsystem, configuring the GPIOs as
|
* This function initialises the keyboard subsystem, configuring the GPIOs as
|
||||||
* needed.
|
* needed.
|
||||||
|
|
@ -79,6 +89,6 @@ void kbd_terminate();
|
||||||
*
|
*
|
||||||
* @return an uint32_t representing the current keyboard configuration.
|
* @return an uint32_t representing the current keyboard configuration.
|
||||||
*/
|
*/
|
||||||
uint32_t kbd_getKeys();
|
keyboard_t kbd_getKeys();
|
||||||
|
|
||||||
#endif /* KEYBOARD_H */
|
#endif /* KEYBOARD_H */
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ void ui_init();
|
||||||
* @param last_state: A local copy of the previous radio state
|
* @param last_state: A local copy of the previous radio state
|
||||||
* @param keys: A bitmap containing the currently pressed keys
|
* @param keys: A bitmap containing the currently pressed keys
|
||||||
*/
|
*/
|
||||||
void ui_updateFSM(state_t last_state, uint32_t keys);
|
void ui_updateFSM(state_t last_state, keyboard_t keys);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function redraws the GUI based on the last radio state.
|
* This function redraws the GUI based on the last radio state.
|
||||||
|
|
|
||||||
|
|
@ -95,11 +95,11 @@ static void ui_task(void *arg)
|
||||||
state_t last_state = state;
|
state_t last_state = state;
|
||||||
OSMutexPost(&state_mutex, OS_OPT_POST_NONE, &os_err);
|
OSMutexPost(&state_mutex, OS_OPT_POST_NONE, &os_err);
|
||||||
|
|
||||||
uint32_t last_keys = 0;
|
keyboard_t last_keys = 0;
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
uint32_t keys = kbd_getKeys();
|
keyboard_t keys = kbd_getKeys();
|
||||||
if(keys != last_keys)
|
if(keys != last_keys)
|
||||||
{
|
{
|
||||||
last_keys = keys;
|
last_keys = keys;
|
||||||
|
|
|
||||||
|
|
@ -291,7 +291,7 @@ void ui_drawSplashScreen()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui_updateFSM(state_t last_state, uint32_t keys)
|
void ui_updateFSM(state_t last_state, keyboard_t keys)
|
||||||
{
|
{
|
||||||
(void) last_state;
|
(void) last_state;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ void kbd_terminate()
|
||||||
gpio_setMode(KB_ROW3, INPUT);
|
gpio_setMode(KB_ROW3, INPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t kbd_getKeys()
|
keyboard_t kbd_getKeys()
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* First of all, configure the row lines as inputs. Since they are in common
|
* First of all, configure the row lines as inputs. Since they are in common
|
||||||
|
|
@ -73,7 +73,7 @@ uint32_t kbd_getKeys()
|
||||||
* this means that we have to put a small delay before reading the GPIOs to
|
* this means that we have to put a small delay before reading the GPIOs to
|
||||||
* allow voltage to settle.
|
* allow voltage to settle.
|
||||||
*/
|
*/
|
||||||
uint32_t keys = 0;
|
keyboard_t keys = 0;
|
||||||
gpio_setPin(KB_ROW1);
|
gpio_setPin(KB_ROW1);
|
||||||
|
|
||||||
delayUs(1);
|
delayUs(1);
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,9 @@ void kbd_init()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t kbd_getKeys() {
|
keyboard_t kbd_getKeys() {
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
uint32_t keys = 0;
|
keyboard_t keys = 0;
|
||||||
while ((SDL_PollEvent(&event)) != 0) {
|
while ((SDL_PollEvent(&event)) != 0) {
|
||||||
if (event.type == SDL_QUIT)
|
if (event.type == SDL_QUIT)
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ int main(void)
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
state_t state = state_update();
|
state_t state = state_update();
|
||||||
uint32_t keys = kbd_getKeys();
|
keyboard_t keys = kbd_getKeys();
|
||||||
bool renderNeeded = ui_update(state, keys);
|
bool renderNeeded = ui_update(state, keys);
|
||||||
if(renderNeeded)
|
if(renderNeeded)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ int main(void) {
|
||||||
while (1) {
|
while (1) {
|
||||||
gfx_clearScreen();
|
gfx_clearScreen();
|
||||||
gfx_print(title_origin, title_buf, FONT_SIZE_3, TEXT_ALIGN_CENTER, color_red);
|
gfx_print(title_origin, title_buf, FONT_SIZE_3, TEXT_ALIGN_CENTER, color_red);
|
||||||
uint32_t keys = kbd_getKeys();
|
keyboard_t keys = kbd_getKeys();
|
||||||
print_keys(keys);
|
print_keys(keys);
|
||||||
gfx_render();
|
gfx_render();
|
||||||
while (gfx_renderingInProgress());
|
while (gfx_renderingInProgress());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue