Skip to content

Commit

Permalink
modules: lvgl: Fix inverting x/y if screen is rotated
Browse files Browse the repository at this point in the history
#70541 has an
issue where if the screen has been rotated, values calculated if
invert-x or invert-y are set will be overwritten.

This breaks the adafruit_2_8_tft_touch_v2 touchscreen as the
display is rotated by 90 degrees but uses invert-x and invert-y.

This change makes the invert-x and invert-y options independent
of screen rotation.

Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
  • Loading branch information
glenn-andrews committed May 26, 2024
1 parent ea29ef3 commit 631eda5
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions modules/lvgl/input/lvgl_pointer_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,37 +61,47 @@ static void lvgl_pointer_process_event(const struct device *dev, struct input_ev
return;
}

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

/* rotate touch point to match display rotation */
if (cap->current_orientation == DISPLAY_ORIENTATION_ROTATED_90) {
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 - data->point_x;
point->y = cap->y_resolution - data->point_y;
} else if (cap->current_orientation == DISPLAY_ORIENTATION_ROTATED_270) {
point->x = cap->x_resolution - data->point_y;
point->y = data->point_x;
switch (cap->current_orientation) {
case DISPLAY_ORIENTATION_NORMAL:
point->x = point_x;
point->y = point_y;
case DISPLAY_ORIENTATION_ROTATED_90:
point->x = point_y;
point->y = cap->y_resolution - point_x;
break;
case DISPLAY_ORIENTATION_ROTATED_180:
point->x = cap->x_resolution - point_x;
point->y = cap->y_resolution - point_y;
break;
case DISPLAY_ORIENTATION_ROTATED_270:
point->x = cap->x_resolution - point_y;
point->y = point_x;
break;
default:
LOG_ERR("Invalid display orientation");
break;
}

/* filter readings within display */
Expand Down

0 comments on commit 631eda5

Please sign in to comment.