Skip to content

Commit 460b467

Browse files
authored
Merge pull request #198 from baba-dev/codex/update-lvgl_read_cb-for-display-rotation
fix: align GT911 touches with display rotation
2 parents 9d37acb + f4bfadc commit 460b467

2 files changed

Lines changed: 118 additions & 8 deletions

File tree

platforms/tab5/components/m5stack_tab5/m5stack_tab5.c

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,10 +1587,66 @@ static void lvgl_read_cb(lv_indev_t* indev, lv_indev_data_t* data)
15871587

15881588
if (!touchpad_pressed) {
15891589
data->state = LV_INDEV_STATE_REL;
1590-
} else {
1591-
data->state = LV_INDEV_STATE_PR;
1592-
data->point.x = touch_x[0];
1593-
data->point.y = touch_y[0];
1590+
return;
1591+
}
1592+
1593+
lv_display_t* disp = lv_indev_get_display(indev);
1594+
lv_display_rotation_t rotation = LV_DISPLAY_ROTATION_0;
1595+
lv_coord_t raw_w = BSP_LCD_H_RES;
1596+
lv_coord_t raw_h = BSP_LCD_V_RES;
1597+
static bool logged_right_edge_ok = false;
1598+
1599+
if (disp != NULL)
1600+
{
1601+
rotation = lv_display_get_rotation(disp);
1602+
1603+
lv_coord_t phys_w = lv_display_get_physical_horizontal_resolution(disp);
1604+
lv_coord_t phys_h = lv_display_get_physical_vertical_resolution(disp);
1605+
if (phys_w > 0)
1606+
{
1607+
raw_w = phys_w;
1608+
}
1609+
if (phys_h > 0)
1610+
{
1611+
raw_h = phys_h;
1612+
}
1613+
}
1614+
1615+
lv_coord_t transformed_x = touch_x[0];
1616+
lv_coord_t transformed_y = touch_y[0];
1617+
1618+
switch (rotation)
1619+
{
1620+
case LV_DISPLAY_ROTATION_90:
1621+
transformed_x = touch_y[0];
1622+
transformed_y = raw_w - 1 - touch_x[0];
1623+
break;
1624+
case LV_DISPLAY_ROTATION_180:
1625+
transformed_x = raw_w - 1 - touch_x[0];
1626+
transformed_y = raw_h - 1 - touch_y[0];
1627+
break;
1628+
case LV_DISPLAY_ROTATION_270:
1629+
transformed_x = raw_h - 1 - touch_y[0];
1630+
transformed_y = touch_x[0];
1631+
break;
1632+
case LV_DISPLAY_ROTATION_0:
1633+
default:
1634+
break;
1635+
}
1636+
1637+
data->state = LV_INDEV_STATE_PR;
1638+
data->point.x = transformed_x;
1639+
data->point.y = transformed_y;
1640+
1641+
lv_coord_t right_edge_threshold = LV_MAX(raw_h - 5, 0);
1642+
if (!logged_right_edge_ok && rotation == LV_DISPLAY_ROTATION_90
1643+
&& transformed_x >= right_edge_threshold)
1644+
{
1645+
ESP_LOGI(TAG,
1646+
"Touch rotation check: right edge press mapped to (%d,%d)",
1647+
transformed_x,
1648+
transformed_y);
1649+
logged_right_edge_ok = true;
15941650
}
15951651
}
15961652

platforms/tab5/main/hal/hal_esp32.cpp

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,66 @@ static void lvgl_read_cb(lv_indev_t* indev, lv_indev_data_t* data)
4242
if (!touchpad_pressed)
4343
{
4444
data->state = LV_INDEV_STATE_REL;
45+
return;
4546
}
46-
else
47+
48+
lv_display_t* disp = lv_indev_get_display(indev);
49+
lv_display_rotation_t rotation = LV_DISPLAY_ROTATION_0;
50+
lv_coord_t raw_w = BSP_LCD_H_RES;
51+
lv_coord_t raw_h = BSP_LCD_V_RES;
52+
static bool logged_right_edge_ok = false;
53+
54+
if (disp != nullptr)
55+
{
56+
rotation = lv_display_get_rotation(disp);
57+
58+
lv_coord_t phys_w = lv_display_get_physical_horizontal_resolution(disp);
59+
lv_coord_t phys_h = lv_display_get_physical_vertical_resolution(disp);
60+
if (phys_w > 0)
61+
{
62+
raw_w = phys_w;
63+
}
64+
if (phys_h > 0)
65+
{
66+
raw_h = phys_h;
67+
}
68+
}
69+
70+
lv_coord_t transformed_x = touch_x[0];
71+
lv_coord_t transformed_y = touch_y[0];
72+
73+
switch (rotation)
74+
{
75+
case LV_DISPLAY_ROTATION_90:
76+
transformed_x = touch_y[0];
77+
transformed_y = raw_w - 1 - touch_x[0];
78+
break;
79+
case LV_DISPLAY_ROTATION_180:
80+
transformed_x = raw_w - 1 - touch_x[0];
81+
transformed_y = raw_h - 1 - touch_y[0];
82+
break;
83+
case LV_DISPLAY_ROTATION_270:
84+
transformed_x = raw_h - 1 - touch_y[0];
85+
transformed_y = touch_x[0];
86+
break;
87+
case LV_DISPLAY_ROTATION_0:
88+
default:
89+
break;
90+
}
91+
92+
data->state = LV_INDEV_STATE_PR;
93+
data->point.x = transformed_x;
94+
data->point.y = transformed_y;
95+
96+
lv_coord_t right_edge_threshold = LV_MAX(raw_h - 5, 0);
97+
if (!logged_right_edge_ok && rotation == LV_DISPLAY_ROTATION_90
98+
&& transformed_x >= right_edge_threshold)
4799
{
48-
data->state = LV_INDEV_STATE_PR;
49-
data->point.x = touch_x[0];
50-
data->point.y = touch_y[0];
100+
mclog::tagInfo(_tag,
101+
"Touch rotation check: right edge press mapped to ({}, {})",
102+
static_cast<int>(transformed_x),
103+
static_cast<int>(transformed_y));
104+
logged_right_edge_ok = true;
51105
}
52106
}
53107

0 commit comments

Comments
 (0)