Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lvgl_port): Add scaling feature for touch #552

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions components/esp_lvgl_port/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 2.6.0

### Features
- Scaling feature in touch

## 2.5.0

### Features (Functional change for button v4 users)
Expand Down
3 changes: 3 additions & 0 deletions components/esp_lvgl_port/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ Add touch input to the LVGL. It can be called more times for adding more touch i
lvgl_port_remove_touch(touch_handle);
```

> [!NOTE]
> 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.

### Add buttons input

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.
Expand Down
10 changes: 7 additions & 3 deletions components/esp_lvgl_port/include/esp_lvgl_port_touch.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -32,8 +32,12 @@ extern "C" {
* @brief Configuration touch structure
*/
typedef struct {
lv_display_t *disp; /*!< LVGL display handle (returned from lvgl_port_add_disp) */
esp_lcd_touch_handle_t handle; /*!< LCD touch IO handle */
lv_display_t *disp; /*!< LVGL display handle (returned from lvgl_port_add_disp) */
esp_lcd_touch_handle_t handle; /*!< LCD touch IO handle */
struct {
float x;
float y;
} scale; /*!< Touch scale */
} lvgl_port_touch_cfg_t;

/**
Expand Down
12 changes: 9 additions & 3 deletions components/esp_lvgl_port/src/lvgl8/esp_lvgl_port_touch.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -19,6 +19,10 @@ static const char *TAG = "LVGL";
typedef struct {
esp_lcd_touch_handle_t handle; /* LCD touch IO handle */
lv_indev_drv_t indev_drv; /* LVGL input device driver */
struct {
float x;
float y;
} scale; /* Touch scale */
} lvgl_port_touch_ctx_t;

/*******************************************************************************
Expand All @@ -44,6 +48,8 @@ lv_indev_t *lvgl_port_add_touch(const lvgl_port_touch_cfg_t *touch_cfg)
return NULL;
}
touch_ctx->handle = touch_cfg->handle;
touch_ctx->scale.x = (touch_cfg->scale.x ? touch_cfg->scale.x : 1);
touch_ctx->scale.y = (touch_cfg->scale.y ? touch_cfg->scale.y : 1);

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

if (touchpad_pressed && touchpad_cnt > 0) {
data->point.x = touchpad_x[0];
data->point.y = touchpad_y[0];
data->point.x = touch_ctx->scale.x * touchpad_x[0];
data->point.y = touch_ctx->scale.y * touchpad_y[0];
data->state = LV_INDEV_STATE_PRESSED;
} else {
data->state = LV_INDEV_STATE_RELEASED;
Expand Down
12 changes: 9 additions & 3 deletions components/esp_lvgl_port/src/lvgl9/esp_lvgl_port_touch.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -19,6 +19,10 @@ static const char *TAG = "LVGL";
typedef struct {
esp_lcd_touch_handle_t handle; /* LCD touch IO handle */
lv_indev_t *indev; /* LVGL input device driver */
struct {
float x;
float y;
} scale; /* Touch scale */
} lvgl_port_touch_ctx_t;

/*******************************************************************************
Expand Down Expand Up @@ -47,6 +51,8 @@ lv_indev_t *lvgl_port_add_touch(const lvgl_port_touch_cfg_t *touch_cfg)
return NULL;
}
touch_ctx->handle = touch_cfg->handle;
touch_ctx->scale.x = (touch_cfg->scale.x ? touch_cfg->scale.x : 1);
touch_ctx->scale.y = (touch_cfg->scale.y ? touch_cfg->scale.y : 1);

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

if (touchpad_pressed && touchpad_cnt > 0) {
data->point.x = touchpad_x[0];
data->point.y = touchpad_y[0];
data->point.x = touch_ctx->scale.x * touchpad_x[0];
data->point.y = touch_ctx->scale.y * touchpad_y[0];
data->state = LV_INDEV_STATE_PRESSED;
} else {
data->state = LV_INDEV_STATE_RELEASED;
Expand Down