From efc4820328f7b36ad14142ef31273afe6d03bac5 Mon Sep 17 00:00:00 2001 From: Federico Amedeo Izzo Date: Sat, 28 Nov 2020 09:51:18 +0100 Subject: [PATCH] Keyboard: Replace uint32_t with keyboard_t --- openrtx/include/interfaces/keyboard.h | 14 ++++++++++++-- openrtx/include/ui.h | 2 +- openrtx/src/threads.c | 4 ++-- openrtx/src/ui.c | 2 +- platform/drivers/keyboard/keyboard_MDx.c | 4 ++-- platform/drivers/keyboard/keyboard_linux.c | 4 ++-- tests/platform/gui_demo.c | 2 +- tests/platform/keyboard_demo.c | 2 +- 8 files changed, 22 insertions(+), 12 deletions(-) diff --git a/openrtx/include/interfaces/keyboard.h b/openrtx/include/interfaces/keyboard.h index 4534eb4d..078ec1ef 100644 --- a/openrtx/include/interfaces/keyboard.h +++ b/openrtx/include/interfaces/keyboard.h @@ -24,7 +24,7 @@ #include /** - * 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(). */ enum keys @@ -62,6 +62,16 @@ enum keys 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 * needed. @@ -79,6 +89,6 @@ void kbd_terminate(); * * @return an uint32_t representing the current keyboard configuration. */ -uint32_t kbd_getKeys(); +keyboard_t kbd_getKeys(); #endif /* KEYBOARD_H */ diff --git a/openrtx/include/ui.h b/openrtx/include/ui.h index ac555c46..bf640cda 100644 --- a/openrtx/include/ui.h +++ b/openrtx/include/ui.h @@ -36,7 +36,7 @@ void ui_init(); * @param last_state: A local copy of the previous radio state * @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. diff --git a/openrtx/src/threads.c b/openrtx/src/threads.c index f827fdb6..e3e5a92f 100644 --- a/openrtx/src/threads.c +++ b/openrtx/src/threads.c @@ -95,11 +95,11 @@ static void ui_task(void *arg) state_t last_state = state; OSMutexPost(&state_mutex, OS_OPT_POST_NONE, &os_err); - uint32_t last_keys = 0; + keyboard_t last_keys = 0; while(1) { - uint32_t keys = kbd_getKeys(); + keyboard_t keys = kbd_getKeys(); if(keys != last_keys) { last_keys = keys; diff --git a/openrtx/src/ui.c b/openrtx/src/ui.c index 32a061a6..b2a21e20 100644 --- a/openrtx/src/ui.c +++ b/openrtx/src/ui.c @@ -291,7 +291,7 @@ void ui_drawSplashScreen() #endif } -void ui_updateFSM(state_t last_state, uint32_t keys) +void ui_updateFSM(state_t last_state, keyboard_t keys) { (void) last_state; diff --git a/platform/drivers/keyboard/keyboard_MDx.c b/platform/drivers/keyboard/keyboard_MDx.c index 17b6229c..870775aa 100644 --- a/platform/drivers/keyboard/keyboard_MDx.c +++ b/platform/drivers/keyboard/keyboard_MDx.c @@ -47,7 +47,7 @@ void kbd_terminate() 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 @@ -73,7 +73,7 @@ uint32_t kbd_getKeys() * this means that we have to put a small delay before reading the GPIOs to * allow voltage to settle. */ - uint32_t keys = 0; + keyboard_t keys = 0; gpio_setPin(KB_ROW1); delayUs(1); diff --git a/platform/drivers/keyboard/keyboard_linux.c b/platform/drivers/keyboard/keyboard_linux.c index 6f101d82..711c6a8b 100644 --- a/platform/drivers/keyboard/keyboard_linux.c +++ b/platform/drivers/keyboard/keyboard_linux.c @@ -27,9 +27,9 @@ void kbd_init() { } -uint32_t kbd_getKeys() { +keyboard_t kbd_getKeys() { SDL_Event event; - uint32_t keys = 0; + keyboard_t keys = 0; while ((SDL_PollEvent(&event)) != 0) { if (event.type == SDL_QUIT) exit(0); diff --git a/tests/platform/gui_demo.c b/tests/platform/gui_demo.c index 26b2ab36..f27bb550 100644 --- a/tests/platform/gui_demo.c +++ b/tests/platform/gui_demo.c @@ -59,7 +59,7 @@ int main(void) while(1) { state_t state = state_update(); - uint32_t keys = kbd_getKeys(); + keyboard_t keys = kbd_getKeys(); bool renderNeeded = ui_update(state, keys); if(renderNeeded) { diff --git a/tests/platform/keyboard_demo.c b/tests/platform/keyboard_demo.c index 5c648a45..37c3bd02 100644 --- a/tests/platform/keyboard_demo.c +++ b/tests/platform/keyboard_demo.c @@ -89,7 +89,7 @@ int main(void) { while (1) { gfx_clearScreen(); 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); gfx_render(); while (gfx_renderingInProgress());