Skip to content

Mapping by lv_display_rotate_point incorrect for rotations of 90° and 270° #10052

@nwholloway

Description

@nwholloway

LVGL version

9.5.0

Platform

Using Cheap Yellow Display (CYD) with Touchscreen.

Development uses PlatformIO extension to Visual Studio Code on Linux.

What happened?

When LVGL is set to rotation of 90° or 270°, the touchscreen pointer events coordinates are diagonally opposite the correct point.

How to reproduce?

I created an example project https://github.com/nwholloway/lvgl-rotation with buttons in each corner, and a central button to set LVGLs rotation.

I believe the problem is in lv_display_rotate_point, where the switch cases for LV_DISPLAY_ROTATION_90 and LV_DISPLAY_ROTATION_270 are swapped.

Making the following change locally rectified it for me.

diff --git a/src/display/lv_display.c b/src/display/lv_display.c
index 63555da77..0d4cc57d7 100644
--- a/src/display/lv_display.c
+++ b/src/display/lv_display.c
@@ -1256,16 +1256,16 @@ void lv_display_rotate_point(lv_display_t * disp, lv_point_t * point)
 
     switch(rotation) {
         case LV_DISPLAY_ROTATION_90:
-            point->x = disp->ver_res - y - 1;
-            point->y = x;
+            point->x = y;
+            point->y = disp->hor_res - x - 1;
             break;
         case LV_DISPLAY_ROTATION_180:
             point->x = disp->hor_res - x - 1;
             point->y = disp->ver_res - y - 1;
             break;
         case LV_DISPLAY_ROTATION_270:
-            point->x = y;
-            point->y = disp->hor_res - x - 1;
+            point->x = disp->ver_res - y - 1;
+            point->y = x;
             break;
         default:
             break;

I haven't created a PR, as I haven't investigated getting unit tests running (which would need updating to match).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions