Add keypad support

This commit is contained in:
Rafał Kołucki 2026-05-26 19:58:49 +02:00
parent 332694aa10
commit fb7fe32bf4
2 changed files with 74 additions and 2 deletions

View file

@ -24,11 +24,13 @@
**********************/
static void touchpad_read(lv_indev_t * indev, lv_indev_data_t * data);
static void keypad_read(lv_indev_t * indev, lv_indev_data_t * data);
/**********************
* STATIC VARIABLES
**********************/
lv_indev_t * indev_touchpad;
lv_indev_t * indev_keypad;
/**********************
* MACROS
@ -45,12 +47,27 @@ void lv_ctr_indev_init(void)
lv_indev_set_type(indev_touchpad, LV_INDEV_TYPE_POINTER);
lv_indev_set_read_cb(indev_touchpad, touchpad_read);
/*Register a keypad input device*/
indev_keypad = lv_indev_create();
lv_indev_set_type(indev_keypad, LV_INDEV_TYPE_KEYPAD);
lv_indev_set_read_cb(indev_keypad, keypad_read);
/*Later you should create group(s) with `lv_group_t * group = lv_group_create()`,
*add objects to the group with `lv_group_add_obj(group, obj)`
*and assign this input device to group to navigate in it:
*`lv_indev_set_group(indev_keypad, group);`*/
}
lv_indev_t * lv_ctr_indev_get_touchpad(void)
{
return indev_touchpad;
}
lv_indev_t * lv_ctr_indev_get_keypad(void)
{
return indev_keypad;
}
/**********************
* STATIC FUNCTIONS
**********************/
@ -64,8 +81,6 @@ static void touchpad_read(lv_indev_t * indev_drv, lv_indev_data_t * data)
static int32_t last_x = 0;
static int32_t last_y = 0;
touchPosition touch;
hidScanInput();
/*Save the pressed coordinates and the state*/
if(hidKeysHeld() & KEY_TOUCH) {
@ -83,6 +98,61 @@ static void touchpad_read(lv_indev_t * indev_drv, lv_indev_data_t * data)
data->point.y = last_y;
}
/*------------------
* Keypad
* -----------------*/
/* What do you mean you can't handle more than one button at the same time!? */
static void keypad_read(lv_indev_t * indev_drv, lv_indev_data_t * data)
{
static uint32_t last_key = 0;
bool key_pressed = false;
u32 kDown = hidKeysDown();
u32 kHeld = hidKeysHeld();
u32 kUp = hidKeysUp();
if (kHeld & KEY_UP) {
last_key = LV_KEY_UP;
key_pressed = true;
}
else if (kHeld & KEY_DOWN) {
last_key = LV_KEY_DOWN;
key_pressed = true;
}
else if (kHeld & KEY_LEFT) {
last_key = LV_KEY_LEFT;
key_pressed = true;
}
else if (kHeld & KEY_RIGHT) {
last_key = LV_KEY_RIGHT;
key_pressed = true;
}
else if (kHeld & KEY_A) {
last_key = LV_KEY_ENTER;
key_pressed = true;
}
else if (kHeld & KEY_B) {
last_key = LV_KEY_ESC;
key_pressed = true;
}
else if (kHeld & KEY_L) {
last_key = LV_KEY_PREV;
key_pressed = true;
}
else if (kHeld & KEY_R) {
last_key = LV_KEY_NEXT;
key_pressed = true;
}
data->key = last_key;
if (key_pressed)
data->state = LV_INDEV_STATE_PRESSED;
else
data->state = LV_INDEV_STATE_RELEASED;
}
#else /*Enable this file at the top*/
/*This dummy typedef exists purely to silence -Wpedantic.*/