Skip to content

Commit faf7736

Browse files
gmarullMaureenHelm
authored andcommitted
lib: gui: lvgl: fix touch point rotation equations
When rotation is 90 or 270 degrees X and Y resolution values will also be swapped, so we need to take that into account. Signed-off-by: Gerard Marull-Paretas <[email protected]>
1 parent fc4fe09 commit faf7736

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

lib/gui/lvgl/lvgl.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,29 +225,39 @@ static bool lvgl_pointer_kscan_read(lv_indev_drv_t *drv, lv_indev_data_t *data)
225225
}
226226

227227
if (IS_ENABLED(CONFIG_LVGL_POINTER_KSCAN_INVERT_X)) {
228-
prev.point.x = cap.x_resolution - prev.point.x;
228+
if (cap.current_orientation == DISPLAY_ORIENTATION_NORMAL ||
229+
cap.current_orientation == DISPLAY_ORIENTATION_ROTATED_180) {
230+
prev.point.x = cap.x_resolution - prev.point.x;
231+
} else {
232+
prev.point.x = cap.y_resolution - prev.point.x;
233+
}
229234
}
230235

231236
if (IS_ENABLED(CONFIG_LVGL_POINTER_KSCAN_INVERT_Y)) {
232-
prev.point.y = cap.y_resolution - prev.point.y;
237+
if (cap.current_orientation == DISPLAY_ORIENTATION_NORMAL ||
238+
cap.current_orientation == DISPLAY_ORIENTATION_ROTATED_180) {
239+
prev.point.y = cap.y_resolution - prev.point.y;
240+
} else {
241+
prev.point.y = cap.x_resolution - prev.point.y;
242+
}
233243
}
234244

235245
/* rotate touch point to match display rotation */
236246
if (cap.current_orientation == DISPLAY_ORIENTATION_ROTATED_90) {
237247
lv_coord_t x;
238248

239249
x = prev.point.x;
240-
prev.point.x = cap.y_resolution - prev.point.y;
241-
prev.point.y = x;
250+
prev.point.x = prev.point.y;
251+
prev.point.y = cap.y_resolution - x;
242252
} else if (cap.current_orientation == DISPLAY_ORIENTATION_ROTATED_180) {
243253
prev.point.x = cap.x_resolution - prev.point.x;
244254
prev.point.y = cap.y_resolution - prev.point.y;
245255
} else if (cap.current_orientation == DISPLAY_ORIENTATION_ROTATED_270) {
246256
lv_coord_t x;
247257

248258
x = prev.point.x;
249-
prev.point.x = prev.point.y;
250-
prev.point.y = cap.x_resolution - x;
259+
prev.point.x = cap.x_resolution - prev.point.y;
260+
prev.point.y = x;
251261
}
252262

253263
*data = prev;

0 commit comments

Comments
 (0)