input: add zephyr,lvgl-button-input device binding
Add a pseudo device which can be used to hook into gpio-keys input_events and relay the events to a lv_indev. Signed-off-by: Fabian Blatz <fabianblatz@gmail.com>
This commit is contained in:
parent
116ec2c41c
commit
b296d1152f
4 changed files with 137 additions and 1 deletions
36
dts/bindings/input/zephyr,lvgl-button-input.yaml
Normal file
36
dts/bindings/input/zephyr,lvgl-button-input.yaml
Normal file
|
@ -0,0 +1,36 @@
|
|||
# Copyright 2023 Fabian Blatz <fabianblatz@gmail.com>
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
description: |
|
||||
LVGL button indev pseudo-device
|
||||
|
||||
Listens for button input events and routes the
|
||||
lv_indev_data_t to the underlying button lv_indev_t managed by LVGL.
|
||||
|
||||
Example configuration:
|
||||
|
||||
pointer {
|
||||
compatible = "zephyr,lvgl-button-input";
|
||||
input = <&buttons>;
|
||||
input-codes = <INPUT_KEY_0 INPUT_KEY_1>;
|
||||
coordinates = <120 220>, <150 250>;
|
||||
};
|
||||
|
||||
When the device receives an input_event with code INPUT_KEY_0
|
||||
a click event will be performed at (120,220).
|
||||
|
||||
compatible: "zephyr,lvgl-button-input"
|
||||
|
||||
include: zephyr,lvgl-common-input.yaml
|
||||
|
||||
properties:
|
||||
input-codes:
|
||||
type: array
|
||||
required: true
|
||||
description: |
|
||||
Array of input event key codes (INPUT_KEY_* or INPUT_BTN_*).
|
||||
|
||||
coordinates:
|
||||
type: array
|
||||
description: |
|
||||
Array of points (x,y) the associated input-code is mapped to.
|
|
@ -222,10 +222,11 @@ zephyr_library_sources(
|
|||
zephyr_library_sources_ifdef(CONFIG_LV_Z_USE_FILESYSTEM lvgl_fs.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_LV_Z_MEM_POOL_SYS_HEAP lvgl_mem.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_LV_Z_SHELL lvgl_shell.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_LV_Z_POINTER_KSCAN input/lvgl_kscan_pointer.c)
|
||||
|
||||
zephyr_library_sources(input/lvgl_common_input.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_LV_Z_POINTER_KSCAN input/lvgl_pointer_kscan.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_LV_Z_POINTER_INPUT input/lvgl_pointer_input.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_LV_Z_BUTTON_INPUT input/lvgl_button_input.c)
|
||||
|
||||
zephyr_library_link_libraries(LVGL)
|
||||
target_link_libraries(LVGL INTERFACE zephyr_interface)
|
||||
|
|
|
@ -55,4 +55,17 @@ config LV_Z_POINTER_INPUT_MSGQ_COUNT
|
|||
help
|
||||
Size of the pointer message queue buffering input events.
|
||||
|
||||
config LV_Z_BUTTON_INPUT
|
||||
bool "Input lvgl button"
|
||||
default y
|
||||
depends on INPUT
|
||||
depends on DT_HAS_ZEPHYR_LVGL_BUTTON_INPUT_ENABLED
|
||||
|
||||
config LV_Z_BUTTON_INPUT_MSGQ_COUNT
|
||||
int "Input button queue message count"
|
||||
default 4
|
||||
depends on LV_Z_BUTTON_INPUT
|
||||
help
|
||||
Size of the button message queue buffering input events.
|
||||
|
||||
endmenu
|
||||
|
|
86
modules/lvgl/input/lvgl_button_input.c
Normal file
86
modules/lvgl/input/lvgl_button_input.c
Normal file
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* Copyright 2023 Fabian Blatz <fabianblatz@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#define DT_DRV_COMPAT zephyr_lvgl_button_input
|
||||
|
||||
#include "lvgl_common_input.h"
|
||||
|
||||
#include <zephyr/logging/log.h>
|
||||
|
||||
LOG_MODULE_DECLARE(lvgl);
|
||||
|
||||
struct lvgl_button_input_config {
|
||||
struct lvgl_common_input_config common_config; /* Needs to be first member */
|
||||
const uint16_t *input_codes;
|
||||
uint8_t num_codes;
|
||||
const lv_coord_t *coordinates;
|
||||
};
|
||||
|
||||
static void lvgl_button_process_event(const struct device *dev, struct input_event *evt)
|
||||
{
|
||||
struct lvgl_common_input_data *data = dev->data;
|
||||
const struct lvgl_button_input_config *cfg = dev->config;
|
||||
uint8_t i;
|
||||
|
||||
for (i = 0; i < cfg->num_codes; i++) {
|
||||
if (evt->code == cfg->input_codes[i]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == cfg->num_codes) {
|
||||
LOG_DBG("Ignored input event: %u", evt->code);
|
||||
return;
|
||||
}
|
||||
|
||||
data->pending_event.btn_id = i;
|
||||
data->pending_event.state = evt->value ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
|
||||
|
||||
if (k_msgq_put(cfg->common_config.event_msgq, &data->pending_event, K_NO_WAIT) != 0) {
|
||||
LOG_WRN("Could not put input data into queue");
|
||||
}
|
||||
}
|
||||
|
||||
static int lvgl_button_input_init(const struct device *dev)
|
||||
{
|
||||
struct lvgl_common_input_data *data = dev->data;
|
||||
const struct lvgl_button_input_config *cfg = dev->config;
|
||||
int ret;
|
||||
|
||||
ret = lvgl_input_register_driver(LV_INDEV_TYPE_BUTTON, dev);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
lv_indev_set_button_points(data->indev, (const lv_point_t *)cfg->coordinates);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define ASSERT_PROPERTIES(inst) \
|
||||
BUILD_ASSERT(DT_INST_PROP_LEN(inst, input_codes) * 2 == \
|
||||
DT_INST_PROP_LEN(inst, coordinates), \
|
||||
"Property coordinates must contain one coordinate per input-code.")
|
||||
|
||||
#define LVGL_BUTTON_INPUT_DEFINE(inst) \
|
||||
ASSERT_PROPERTIES(inst); \
|
||||
LVGL_INPUT_DEFINE(inst, button, CONFIG_LV_Z_BUTTON_INPUT_MSGQ_COUNT, \
|
||||
lvgl_button_process_event); \
|
||||
static const uint16_t lvgl_button_input_codes_##inst[] = DT_INST_PROP(inst, input_codes); \
|
||||
static const lv_coord_t lvgl_button_coordinates_##inst[] = \
|
||||
DT_INST_PROP(inst, coordinates); \
|
||||
static const struct lvgl_button_input_config lvgl_button_input_config_##inst = { \
|
||||
.common_config.event_msgq = &LVGL_INPUT_EVENT_MSGQ(inst, button), \
|
||||
.input_codes = lvgl_button_input_codes_##inst, \
|
||||
.num_codes = DT_INST_PROP_LEN(inst, input_codes), \
|
||||
.coordinates = lvgl_button_coordinates_##inst, \
|
||||
}; \
|
||||
static struct lvgl_common_input_data lvgl_common_input_data_##inst; \
|
||||
DEVICE_DT_INST_DEFINE(inst, lvgl_button_input_init, NULL, &lvgl_common_input_data_##inst, \
|
||||
&lvgl_button_input_config_##inst, APPLICATION, \
|
||||
CONFIG_LV_Z_INPUT_INIT_PRIORITY, NULL);
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(LVGL_BUTTON_INPUT_DEFINE)
|
Loading…
Add table
Add a link
Reference in a new issue