Skip to content

Commit

Permalink
modules: lvgl: Fix coordinate handling for invert-{x,y} and swap-xy
Browse files Browse the repository at this point in the history
This patch fixes two issues in the coordinate handling of the
`zephyr,lvgl-pointer-input` compatible:
- If the swap-xy flag is set the coordinates need to be swapped even
  before the sync event is received.
- The coordinates are stored into an additional variable instead of the
  pending_event. This is done to prevent the double inversion for touch
  release events.

Resolves issue zephyrproject-rtos#70539.

Signed-off-by: Fabian Blatz <fabianblatz@gmail.com>
  • Loading branch information
faxe1008 committed Apr 30, 2024
1 parent f0750df commit 0f3266b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 34 deletions.
3 changes: 1 addition & 2 deletions modules/lvgl/input/lvgl_keypad_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ static void lvgl_keypad_process_event(const struct device *dev, struct input_eve
}

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) {
if (k_msgq_put(cfg->common_config.event_msgq, &data->pending_event, K_NO_WAIT) != 0) {
LOG_WRN("Could not put input data into keypad queue");
}
}
Expand Down
68 changes: 36 additions & 32 deletions modules/lvgl/input/lvgl_pointer_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,74 +21,77 @@ struct lvgl_pointer_input_config {
bool invert_y;
};

struct lvgl_pointer_input_data {
struct lvgl_common_input_data common_data;
uint32_t point_x;
uint32_t point_y;
};

static void lvgl_pointer_process_event(const struct device *dev, struct input_event *evt)
{
const struct lvgl_pointer_input_config *cfg = dev->config;
struct lvgl_common_input_data *data = dev->data;
struct lvgl_pointer_input_data *data = dev->data;
lv_disp_t *disp = lv_disp_get_default();
struct lvgl_disp_data *disp_data = disp->driver->user_data;
struct display_capabilities *cap = &disp_data->cap;
lv_point_t *point = &data->pending_event.point;
lv_point_t *point = &data->common_data.pending_event.point;

switch (evt->code) {
case INPUT_ABS_X:
point->x = evt->value;
if (cfg->swap_xy) {
data->point_y = evt->value;
} else {
data->point_x = evt->value;
}
break;
case INPUT_ABS_Y:
point->y = evt->value;
if (cfg->swap_xy) {
data->point_x = evt->value;
} else {
data->point_y = evt->value;
}
break;
case INPUT_BTN_TOUCH:
data->pending_event.state = evt->value ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
data->common_data.pending_event.state =
evt->value ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
break;
}

if (!evt->sync) {
return;
}

/* adjust coordinates */
if (cfg->swap_xy) {
lv_coord_t tmp;

tmp = point->x;
point->x = point->y;
point->y = tmp;
}
point->x = data->point_x;
point->y = data->point_y;

if (cfg->invert_x) {
if (cap->current_orientation == DISPLAY_ORIENTATION_NORMAL ||
cap->current_orientation == DISPLAY_ORIENTATION_ROTATED_180) {
point->x = cap->x_resolution - point->x;
point->x = cap->x_resolution - data->point_x;
} else {
point->x = cap->y_resolution - point->x;
point->x = cap->y_resolution - data->point_x;
}
}

if (cfg->invert_y) {
if (cap->current_orientation == DISPLAY_ORIENTATION_NORMAL ||
cap->current_orientation == DISPLAY_ORIENTATION_ROTATED_180) {
point->y = cap->y_resolution - point->y;
point->y = cap->y_resolution - data->point_y;
} else {
point->y = cap->x_resolution - point->y;
point->y = cap->x_resolution - data->point_y;
}
}

/* rotate touch point to match display rotation */
if (cap->current_orientation == DISPLAY_ORIENTATION_ROTATED_90) {
lv_coord_t tmp;

tmp = point->x;
point->x = point->y;
point->y = cap->y_resolution - tmp;
point->x = data->point_y;
point->y = cap->y_resolution - data->point_x;
} else if (cap->current_orientation == DISPLAY_ORIENTATION_ROTATED_180) {
point->x = cap->x_resolution - point->x;
point->y = cap->y_resolution - point->y;
point->x = cap->x_resolution - data->point_x;
point->y = cap->y_resolution - data->point_y;
} else if (cap->current_orientation == DISPLAY_ORIENTATION_ROTATED_270) {
lv_coord_t tmp;

tmp = point->x;
point->x = cap->x_resolution - point->y;
point->y = tmp;
point->x = cap->x_resolution - data->point_y;
point->y = data->point_x;
}

/* filter readings within display */
Expand All @@ -104,7 +107,8 @@ static void lvgl_pointer_process_event(const struct device *dev, struct input_ev
point->y = cap->y_resolution - 1;
}

if (k_msgq_put(cfg->common_config.event_msgq, &data->pending_event, K_NO_WAIT) != 0) {
if (k_msgq_put(cfg->common_config.event_msgq, &data->common_data.pending_event,
K_NO_WAIT) != 0) {
LOG_WRN("Could not put input data into queue");
}
}
Expand All @@ -123,8 +127,8 @@ int lvgl_pointer_input_init(const struct device *dev)
.invert_x = DT_INST_PROP(inst, invert_x), \
.invert_y = DT_INST_PROP(inst, invert_y), \
}; \
static struct lvgl_common_input_data lvgl_common_input_data_##inst; \
DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &lvgl_common_input_data_##inst, \
static struct lvgl_pointer_input_data lvgl_pointer_input_data_##inst; \
DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &lvgl_pointer_input_data_##inst, \
&lvgl_pointer_input_config_##inst, POST_KERNEL, \
CONFIG_INPUT_INIT_PRIORITY, NULL);

Expand Down

0 comments on commit 0f3266b

Please sign in to comment.