modules: lvgl: retain last event for button/pointer device

Adds saving of the last lv_indev_data_t for button and pointer type
devices. This is needed because there is currently no way to tell LVGL in
the read callback that no event is pending. Preservation of the last state
is expected to happen in the port layer for the input devices.
This resolves issue #62512.

Signed-off-by: Fabian Blatz <fabianblatz@gmail.com>
This commit is contained in:
Fabian Blatz 2023-09-18 06:20:40 +02:00 committed by Fabio Baltieri
commit 2ea2d37d60
2 changed files with 12 additions and 1 deletions

View file

@ -23,6 +23,7 @@ struct lvgl_common_input_data {
lv_indev_drv_t indev_drv;
lv_indev_t *indev;
lv_indev_data_t pending_event;
lv_indev_data_t previous_event;
};
int lvgl_input_register_driver(lv_indev_type_t indev_type, const struct device *dev);

View file

@ -26,8 +26,18 @@ static void lvgl_input_read_cb(lv_indev_drv_t *drv, lv_indev_data_t *data)
{
const struct device *dev = drv->user_data;
const struct lvgl_common_input_config *cfg = dev->config;
struct lvgl_common_input_data *common_data = dev->data;
k_msgq_get(cfg->event_msgq, data, K_NO_WAIT);
if (k_msgq_get(cfg->event_msgq, data, K_NO_WAIT) != 0) {
memcpy(data, &common_data->previous_event, sizeof(lv_indev_data_t));
if (drv->type == LV_INDEV_TYPE_ENCODER) {
data->enc_diff = 0; /* For encoders, clear last movement */
}
data->continue_reading = false;
return;
}
memcpy(&common_data->previous_event, data, sizeof(lv_indev_data_t));
data->continue_reading = k_msgq_num_used_get(cfg->event_msgq) > 0;
}