Skip to content

Commit a70bf0e

Browse files
glenn-andrewscarlescufi
authored andcommitted
modules: lvgl: Fix inverting x/y if screen is rotated
#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 <[email protected]>
1 parent 7abb9d7 commit a70bf0e

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

modules/lvgl/input/lvgl_pointer_input.c

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,37 +61,49 @@ static void lvgl_pointer_process_event(const struct device *dev, struct input_ev
6161
return;
6262
}
6363

64-
point->x = data->point_x;
65-
point->y = data->point_y;
64+
lv_point_t tmp_point = {
65+
.x = data->point_x,
66+
.y = data->point_y,
67+
};
6668

6769
if (cfg->invert_x) {
6870
if (cap->current_orientation == DISPLAY_ORIENTATION_NORMAL ||
6971
cap->current_orientation == DISPLAY_ORIENTATION_ROTATED_180) {
70-
point->x = cap->x_resolution - data->point_x;
72+
tmp_point.x = cap->x_resolution - tmp_point.x;
7173
} else {
72-
point->x = cap->y_resolution - data->point_x;
74+
tmp_point.x = cap->y_resolution - tmp_point.x;
7375
}
7476
}
7577

7678
if (cfg->invert_y) {
7779
if (cap->current_orientation == DISPLAY_ORIENTATION_NORMAL ||
7880
cap->current_orientation == DISPLAY_ORIENTATION_ROTATED_180) {
79-
point->y = cap->y_resolution - data->point_y;
81+
tmp_point.y = cap->y_resolution - tmp_point.y;
8082
} else {
81-
point->y = cap->x_resolution - data->point_y;
83+
tmp_point.y = cap->x_resolution - tmp_point.y;
8284
}
8385
}
8486

8587
/* rotate touch point to match display rotation */
86-
if (cap->current_orientation == DISPLAY_ORIENTATION_ROTATED_90) {
87-
point->x = data->point_y;
88-
point->y = cap->y_resolution - data->point_x;
89-
} else if (cap->current_orientation == DISPLAY_ORIENTATION_ROTATED_180) {
90-
point->x = cap->x_resolution - data->point_x;
91-
point->y = cap->y_resolution - data->point_y;
92-
} else if (cap->current_orientation == DISPLAY_ORIENTATION_ROTATED_270) {
93-
point->x = cap->x_resolution - data->point_y;
94-
point->y = data->point_x;
88+
switch (cap->current_orientation) {
89+
case DISPLAY_ORIENTATION_NORMAL:
90+
point->x = tmp_point.x;
91+
point->y = tmp_point.y;
92+
case DISPLAY_ORIENTATION_ROTATED_90:
93+
point->x = tmp_point.y;
94+
point->y = cap->y_resolution - tmp_point.x;
95+
break;
96+
case DISPLAY_ORIENTATION_ROTATED_180:
97+
point->x = cap->x_resolution - tmp_point.x;
98+
point->y = cap->y_resolution - tmp_point.y;
99+
break;
100+
case DISPLAY_ORIENTATION_ROTATED_270:
101+
point->x = cap->x_resolution - tmp_point.y;
102+
point->y = tmp_point.x;
103+
break;
104+
default:
105+
LOG_ERR("Invalid display orientation");
106+
break;
95107
}
96108

97109
/* filter readings within display */

0 commit comments

Comments
 (0)