tests: platform: updated keyboard test

This commit is contained in:
Silvano Seva 2025-07-29 22:16:43 +02:00
parent fa9134e106
commit 6881c2430b
1 changed files with 40 additions and 51 deletions

View File

@ -21,71 +21,60 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <os.h> #include <hwconfig.h>
#include <interfaces/gpio.h> #include <graphics.h>
#include <interfaces/graphics.h>
#include "hwconfig.h"
#include <interfaces/platform.h> #include <interfaces/platform.h>
#include "state.h"
#include <interfaces/keyboard.h> #include <interfaces/keyboard.h>
#include "ui.h" #include <interfaces/display.h>
#include <interfaces/delays.h>
color_t color_yellow_fab413 = {250, 180, 19};
color_t color_red = {255, 0, 0};
color_t color_green = {0, 255, 0};
char *keys_list[] = { char *keys_list[] = {
" ", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "*", "#", "ENTER", "ESC", "UP", "DOWN", "LEFT", "RIGHT", " ", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"*", "#", "ENTER", "ESC", "UP", "DOWN", "LEFT", "RIGHT",
"MONI", "F1" "MONI", "F1"
}; };
void *print_keys(keyboard_t keys) { int main(void)
point_t origin = {0, SCREEN_HEIGHT / 4}; {
//count set bits to check how many keys are being pressed platform_init();
gfx_init();
kbd_init();
gfx_clearScreen();
gfx_render();
display_setBacklightLevel(255);
while (1) {
gfx_clearScreen();
color_t color_white = {255, 255, 255, 255};
color_t color_green = {0, 255, 0, 255};
point_t origin = {5, 10};
gfx_print(origin, FONT_SIZE_6PT, TEXT_ALIGN_LEFT, color_green,
"Keyboard test");
keyboard_t keys = kbd_getKeys();
int i = __builtin_popcount(keys); int i = __builtin_popcount(keys);
while (i > 0) { while (i > 0) {
//position of the first set bit //position of the first set bit
int pos = __builtin_ctz(keys); int pos = __builtin_ctz(keys);
gfx_print(origin, FONT_SIZE_8PT, TEXT_ALIGN_LEFT,
color_green, "Pressed: %s", keys_list[pos + 1]); origin.y += 10;
origin.y += 9; gfx_print(origin, FONT_SIZE_6PT, TEXT_ALIGN_LEFT, color_white,
"Pressed: %s", keys_list[pos + 1]);
//unset the bit we already handled //unset the bit we already handled
keys &= ~(1 << pos); keys &= ~(1 << pos);
i--; i--;
} }
gfx_render(); gfx_render();
while (gfx_renderingInProgress()); sleepFor(0, 100u);
}
int main(void) {
OS_ERR os_err;
// Initialize platform drivers
platform_init();
// Initialize graphics driver
gfx_init();
// Clear screen
gfx_clearScreen();
gfx_render();
while (gfx_renderingInProgress());
platform_setBacklightLevel(255);
// Initialize keyboard driver
kbd_init();
point_t title_origin = {0, SCREEN_HEIGHT / 9};
// UI update infinite loop
while (1) {
gfx_clearScreen();
gfx_print(title_origin, FONT_SIZE_8PT, TEXT_ALIGN_CENTER,
color_red, "Keyboard demo");
keyboard_t keys = kbd_getKeys();
if (keys != 0)
print_keys(keys);
OSTimeDlyHMSM(0u, 0u, 0u, 100u, OS_OPT_TIME_HMSM_STRICT, &os_err);
} }
return 0;
} }