Skip to content

Commit 33d7fad

Browse files
authored
Merge pull request #552 from espressif/feat/lvgl_port_touch_scale
feat(lvgl_port): Add scaling feature for touch
2 parents 5e90db3 + 7ae11d6 commit 33d7fad

File tree

5 files changed

+33
-9
lines changed

5 files changed

+33
-9
lines changed

components/esp_lvgl_port/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 2.6.0
4+
5+
### Features
6+
- Scaling feature in touch
7+
38
## 2.5.0
49

510
### Features (Functional change for button v4 users)

components/esp_lvgl_port/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ Add touch input to the LVGL. It can be called more times for adding more touch i
108108
lvgl_port_remove_touch(touch_handle);
109109
```
110110

111+
> [!NOTE]
112+
> If the screen has another resolution than the touch resolution, you can use scaling by add `.scale.x` or `.scale.y` into `lvgl_port_touch_cfg_t` configuration structure.
113+
111114
### Add buttons input
112115

113116
Add buttons input to the LVGL. It can be called more times for adding more buttons inputs for different displays. This feature is available only when the component `espressif/button` was added into the project.

components/esp_lvgl_port/include/esp_lvgl_port_touch.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -32,8 +32,12 @@ extern "C" {
3232
* @brief Configuration touch structure
3333
*/
3434
typedef struct {
35-
lv_display_t *disp; /*!< LVGL display handle (returned from lvgl_port_add_disp) */
36-
esp_lcd_touch_handle_t handle; /*!< LCD touch IO handle */
35+
lv_display_t *disp; /*!< LVGL display handle (returned from lvgl_port_add_disp) */
36+
esp_lcd_touch_handle_t handle; /*!< LCD touch IO handle */
37+
struct {
38+
float x;
39+
float y;
40+
} scale; /*!< Touch scale */
3741
} lvgl_port_touch_cfg_t;
3842

3943
/**

components/esp_lvgl_port/src/lvgl8/esp_lvgl_port_touch.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -19,6 +19,10 @@ static const char *TAG = "LVGL";
1919
typedef struct {
2020
esp_lcd_touch_handle_t handle; /* LCD touch IO handle */
2121
lv_indev_drv_t indev_drv; /* LVGL input device driver */
22+
struct {
23+
float x;
24+
float y;
25+
} scale; /* Touch scale */
2226
} lvgl_port_touch_ctx_t;
2327

2428
/*******************************************************************************
@@ -44,6 +48,8 @@ lv_indev_t *lvgl_port_add_touch(const lvgl_port_touch_cfg_t *touch_cfg)
4448
return NULL;
4549
}
4650
touch_ctx->handle = touch_cfg->handle;
51+
touch_ctx->scale.x = (touch_cfg->scale.x ? touch_cfg->scale.x : 1);
52+
touch_ctx->scale.y = (touch_cfg->scale.y ? touch_cfg->scale.y : 1);
4753

4854
/* Register a touchpad input device */
4955
lv_indev_drv_init(&touch_ctx->indev_drv);
@@ -92,8 +98,8 @@ static void lvgl_port_touchpad_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *
9298
bool touchpad_pressed = esp_lcd_touch_get_coordinates(touch_ctx->handle, touchpad_x, touchpad_y, NULL, &touchpad_cnt, 1);
9399

94100
if (touchpad_pressed && touchpad_cnt > 0) {
95-
data->point.x = touchpad_x[0];
96-
data->point.y = touchpad_y[0];
101+
data->point.x = touch_ctx->scale.x * touchpad_x[0];
102+
data->point.y = touch_ctx->scale.y * touchpad_y[0];
97103
data->state = LV_INDEV_STATE_PRESSED;
98104
} else {
99105
data->state = LV_INDEV_STATE_RELEASED;

components/esp_lvgl_port/src/lvgl9/esp_lvgl_port_touch.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -19,6 +19,10 @@ static const char *TAG = "LVGL";
1919
typedef struct {
2020
esp_lcd_touch_handle_t handle; /* LCD touch IO handle */
2121
lv_indev_t *indev; /* LVGL input device driver */
22+
struct {
23+
float x;
24+
float y;
25+
} scale; /* Touch scale */
2226
} lvgl_port_touch_ctx_t;
2327

2428
/*******************************************************************************
@@ -47,6 +51,8 @@ lv_indev_t *lvgl_port_add_touch(const lvgl_port_touch_cfg_t *touch_cfg)
4751
return NULL;
4852
}
4953
touch_ctx->handle = touch_cfg->handle;
54+
touch_ctx->scale.x = (touch_cfg->scale.x ? touch_cfg->scale.x : 1);
55+
touch_ctx->scale.y = (touch_cfg->scale.y ? touch_cfg->scale.y : 1);
5056

5157
if (touch_ctx->handle->config.int_gpio_num != GPIO_NUM_NC) {
5258
/* Register touch interrupt callback */
@@ -122,8 +128,8 @@ static void lvgl_port_touchpad_read(lv_indev_t *indev_drv, lv_indev_data_t *data
122128
bool touchpad_pressed = esp_lcd_touch_get_coordinates(touch_ctx->handle, touchpad_x, touchpad_y, NULL, &touchpad_cnt, 1);
123129

124130
if (touchpad_pressed && touchpad_cnt > 0) {
125-
data->point.x = touchpad_x[0];
126-
data->point.y = touchpad_y[0];
131+
data->point.x = touch_ctx->scale.x * touchpad_x[0];
132+
data->point.y = touch_ctx->scale.y * touchpad_y[0];
127133
data->state = LV_INDEV_STATE_PRESSED;
128134
} else {
129135
data->state = LV_INDEV_STATE_RELEASED;

0 commit comments

Comments
 (0)