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 issue 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.
- If the invert-{x,y} property is set the coordinates should only be
  inverted when the state is pressed. This is because the pointer saves the
  coordinates of a previous press event and upon release event it reuses
  them, causing the inversion to be applied twice.

Resolves issue #70539.

Signed-off-by: Fabian Blatz <fabianblatz@gmail.com>
  • Loading branch information
faxe1008 committed Mar 21, 2024
1 parent f0750df commit a0f40e7
Showing 1 changed file with 53 additions and 51 deletions.
104 changes: 53 additions & 51 deletions modules/lvgl/input/lvgl_pointer_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,18 @@ static void lvgl_pointer_process_event(const struct device *dev, struct input_ev

switch (evt->code) {
case INPUT_ABS_X:
point->x = evt->value;
if (cfg->swap_xy) {
point->y = evt->value;
} else {
point->x = evt->value;
}
break;
case INPUT_ABS_Y:
point->y = evt->value;
if (cfg->swap_xy) {
point->x = evt->value;
} else {
point->y = evt->value;
}
break;
case INPUT_BTN_TOUCH:
data->pending_event.state = evt->value ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
Expand All @@ -46,62 +54,56 @@ static void lvgl_pointer_process_event(const struct device *dev, struct input_ev
return;
}

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

tmp = point->x;
point->x = point->y;
point->y = tmp;
}
/* prevent re-inversion of the coordinates on touch release */
if (data->pending_event.state == LV_INDEV_STATE_PR) {
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;
} else {
point->x = cap->y_resolution - point->x;
}
}

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;
} else {
point->x = cap->y_resolution - 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;
} else {
point->y = cap->x_resolution - point->y;
}
}
}

if (cfg->invert_y) {
if (cap->current_orientation == DISPLAY_ORIENTATION_NORMAL ||
cap->current_orientation == DISPLAY_ORIENTATION_ROTATED_180) {
/* 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;
} else if (cap->current_orientation == DISPLAY_ORIENTATION_ROTATED_180) {
point->x = cap->x_resolution - point->x;
point->y = cap->y_resolution - point->y;
} else {
point->y = cap->x_resolution - point->y;
}
}
} else if (cap->current_orientation == DISPLAY_ORIENTATION_ROTATED_270) {
lv_coord_t tmp;

/* 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;
} else if (cap->current_orientation == DISPLAY_ORIENTATION_ROTATED_180) {
point->x = cap->x_resolution - point->x;
point->y = cap->y_resolution - 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;
}
tmp = point->x;
point->x = cap->x_resolution - point->y;
point->y = tmp;
}

/* filter readings within display */
if (point->x <= 0) {
point->x = 0;
} else if (point->x >= cap->x_resolution) {
point->x = cap->x_resolution - 1;
}
/* filter readings within display */
if (point->x <= 0) {
point->x = 0;
} else if (point->x >= cap->x_resolution) {
point->x = cap->x_resolution - 1;
}

if (point->y <= 0) {
point->y = 0;
} else if (point->y >= cap->y_resolution) {
point->y = cap->y_resolution - 1;
if (point->y <= 0) {
point->y = 0;
} else if (point->y >= cap->y_resolution) {
point->y = cap->y_resolution - 1;
}
}

if (k_msgq_put(cfg->common_config.event_msgq, &data->pending_event, K_NO_WAIT) != 0) {
Expand Down

0 comments on commit a0f40e7

Please sign in to comment.