From 2b2c4b8ac6040c0cca9a7d63afcc75f9311ae30c Mon Sep 17 00:00:00 2001 From: Li Junru Date: Tue, 13 Aug 2024 20:48:26 +0800 Subject: [PATCH] feat(lcd_touch): support trank id --- components/lcd_touch/esp_lcd_touch/Kconfig | 2 +- components/lcd_touch/esp_lcd_touch/README.md | 2 +- .../lcd_touch/esp_lcd_touch/esp_lcd_touch.c | 6 +++--- .../lcd_touch/esp_lcd_touch/idf_component.yml | 2 +- .../esp_lcd_touch/include/esp_lcd_touch.h | 17 +++++++++-------- .../esp_lcd_touch_ft5x06/esp_lcd_touch_ft5x06.c | 11 ++++++++--- .../esp_lcd_touch_ft5x06/idf_component.yml | 4 ++-- .../include/esp_lcd_touch_ft5x06.h | 3 +-- .../esp_lcd_touch_gt911/esp_lcd_touch_gt911.c | 12 ++++++++++-- .../esp_lcd_touch_gt911/idf_component.yml | 4 ++-- 10 files changed, 38 insertions(+), 25 deletions(-) diff --git a/components/lcd_touch/esp_lcd_touch/Kconfig b/components/lcd_touch/esp_lcd_touch/Kconfig index ed30f44a..136b039b 100644 --- a/components/lcd_touch/esp_lcd_touch/Kconfig +++ b/components/lcd_touch/esp_lcd_touch/Kconfig @@ -10,4 +10,4 @@ menu "ESP LCD TOUCH" range 0 10 default 1 -endmenu \ No newline at end of file +endmenu diff --git a/components/lcd_touch/esp_lcd_touch/README.md b/components/lcd_touch/esp_lcd_touch/README.md index de6e6144..86e54866 100644 --- a/components/lcd_touch/esp_lcd_touch/README.md +++ b/components/lcd_touch/esp_lcd_touch/README.md @@ -2,7 +2,7 @@ [![Component Registry](https://components.espressif.com/components/espressif/esp_lcd_touch/badge.svg)](https://components.espressif.com/components/espressif/esp_lcd_touch) -This componnent is main esp_lcd_touch component which defines main functions and types for easy adding specific touch controller component. +This component is main esp_lcd_touch component which defines main functions and types for easy adding specific touch controller component. ## Supported features diff --git a/components/lcd_touch/esp_lcd_touch/esp_lcd_touch.c b/components/lcd_touch/esp_lcd_touch/esp_lcd_touch.c index 2e6034f7..11730970 100644 --- a/components/lcd_touch/esp_lcd_touch/esp_lcd_touch.c +++ b/components/lcd_touch/esp_lcd_touch/esp_lcd_touch.c @@ -58,7 +58,7 @@ esp_err_t esp_lcd_touch_read_data(esp_lcd_touch_handle_t tp) return tp->read_data(tp); } -bool esp_lcd_touch_get_coordinates(esp_lcd_touch_handle_t tp, uint16_t *x, uint16_t *y, uint16_t *strength, uint8_t *point_num, uint8_t max_point_num) +bool esp_lcd_touch_get_coordinates(esp_lcd_touch_handle_t tp, uint16_t *x, uint16_t *y, uint16_t *strength, uint8_t *track_id, uint8_t *point_num, uint8_t max_point_num) { bool touched = false; @@ -67,14 +67,14 @@ bool esp_lcd_touch_get_coordinates(esp_lcd_touch_handle_t tp, uint16_t *x, uint1 assert(y != NULL); assert(tp->get_xy != NULL); - touched = tp->get_xy(tp, x, y, strength, point_num, max_point_num); + touched = tp->get_xy(tp, x, y, strength, track_id, point_num, max_point_num); if (!touched) { return false; } /* Process coordinates by user */ if (tp->config.process_coordinates != NULL) { - tp->config.process_coordinates(tp, x, y, strength, point_num, max_point_num); + tp->config.process_coordinates(tp, x, y, strength, track_id, point_num, max_point_num); } /* Software coordinates adjustment needed */ diff --git a/components/lcd_touch/esp_lcd_touch/idf_component.yml b/components/lcd_touch/esp_lcd_touch/idf_component.yml index 2441f18f..a0f2be72 100644 --- a/components/lcd_touch/esp_lcd_touch/idf_component.yml +++ b/components/lcd_touch/esp_lcd_touch/idf_component.yml @@ -1,4 +1,4 @@ -version: "1.1.2" +version: "1.2.0" description: ESP LCD Touch - main component for using touch screen controllers url: https://github.com/espressif/esp-bsp/tree/master/components/lcd_touch/esp_lcd_touch dependencies: diff --git a/components/lcd_touch/esp_lcd_touch/include/esp_lcd_touch.h b/components/lcd_touch/esp_lcd_touch/include/esp_lcd_touch.h index d0b26763..fcba8095 100644 --- a/components/lcd_touch/esp_lcd_touch/include/esp_lcd_touch.h +++ b/components/lcd_touch/esp_lcd_touch/include/esp_lcd_touch.h @@ -59,7 +59,7 @@ typedef struct { } flags; /*!< User callback called after get coordinates from touch controller for apply user adjusting */ - void (*process_coordinates)(esp_lcd_touch_handle_t tp, uint16_t *x, uint16_t *y, uint16_t *strength, uint8_t *point_num, uint8_t max_point_num); + void (*process_coordinates)(esp_lcd_touch_handle_t tp, uint16_t *x, uint16_t *y, uint16_t *strength, uint8_t *track_id, uint8_t *point_num, uint8_t max_point_num); /*!< User callback called after the touch interrupt occurred */ esp_lcd_touch_interrupt_callback_t interrupt_callback; /*!< User data passed to callback */ @@ -72,6 +72,7 @@ typedef struct { uint8_t points; /*!< Count of touch points saved */ struct { + uint8_t track_id; /*!< Track ID */ uint16_t x; /*!< X coordinate */ uint16_t y; /*!< Y coordinate */ uint16_t strength; /*!< Strength */ @@ -137,14 +138,14 @@ struct esp_lcd_touch_s { * @param x: Array of X coordinates * @param y: Array of Y coordinates * @param strength: Array of strengths + * @param track_id: Array of track IDs * @param point_num: Count of points touched (equals with count of items in x and y array) * @param max_point_num: Maximum count of touched points to return (equals with max size of x and y array) * * @return - * - Returns true, when touched and coordinates readed. Otherwise returns false. + * - Returns true, when touched and coordinates read. Otherwise returns false. */ - bool (*get_xy)(esp_lcd_touch_handle_t tp, uint16_t *x, uint16_t *y, uint16_t *strength, uint8_t *point_num, uint8_t max_point_num); - + bool (*get_xy)(esp_lcd_touch_handle_t tp, uint16_t *x, uint16_t *y, uint16_t *strength, uint8_t *track_id, uint8_t *point_num, uint8_t max_point_num); #if (CONFIG_ESP_LCD_TOUCH_MAX_BUTTONS > 0) /** @@ -155,7 +156,7 @@ struct esp_lcd_touch_s { * @param state: Button state * * @return - * - Returns true, when touched and coordinates readed. Otherwise returns false. + * - Returns true, when touched and coordinates read. Otherwise returns false. */ esp_err_t (*get_button_state)(esp_lcd_touch_handle_t tp, uint8_t n, uint8_t *state); #endif @@ -278,14 +279,14 @@ esp_err_t esp_lcd_touch_read_data(esp_lcd_touch_handle_t tp); * @param x: Array of X coordinates * @param y: Array of Y coordinates * @param strength: Array of the strengths (can be NULL) + * @param track_id: Array of track IDs (can be NULL) * @param point_num: Count of points touched (equals with count of items in x and y array) * @param max_point_num: Maximum count of touched points to return (equals with max size of x and y array) * * @return - * - Returns true, when touched and coordinates readed. Otherwise returns false. + * - Returns true, when touched and coordinates read. Otherwise returns false. */ -bool esp_lcd_touch_get_coordinates(esp_lcd_touch_handle_t tp, uint16_t *x, uint16_t *y, uint16_t *strength, uint8_t *point_num, uint8_t max_point_num); - +bool esp_lcd_touch_get_coordinates(esp_lcd_touch_handle_t tp, uint16_t *x, uint16_t *y, uint16_t *strength, uint8_t *track_id, uint8_t *point_num, uint8_t max_point_num); #if (CONFIG_ESP_LCD_TOUCH_MAX_BUTTONS > 0) /** diff --git a/components/lcd_touch/esp_lcd_touch_ft5x06/esp_lcd_touch_ft5x06.c b/components/lcd_touch/esp_lcd_touch_ft5x06/esp_lcd_touch_ft5x06.c index 9c2daa80..bca74671 100644 --- a/components/lcd_touch/esp_lcd_touch_ft5x06/esp_lcd_touch_ft5x06.c +++ b/components/lcd_touch/esp_lcd_touch_ft5x06/esp_lcd_touch_ft5x06.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -79,7 +79,7 @@ static const char *TAG = "FT5x06"; * Function definitions *******************************************************************************/ static esp_err_t esp_lcd_touch_ft5x06_read_data(esp_lcd_touch_handle_t tp); -static bool esp_lcd_touch_ft5x06_get_xy(esp_lcd_touch_handle_t tp, uint16_t *x, uint16_t *y, uint16_t *strength, uint8_t *point_num, uint8_t max_point_num); +static bool esp_lcd_touch_ft5x06_get_xy(esp_lcd_touch_handle_t tp, uint16_t *x, uint16_t *y, uint16_t *strength, uint8_t *track_id, uint8_t *point_num, uint8_t max_point_num); static esp_err_t esp_lcd_touch_ft5x06_del(esp_lcd_touch_handle_t tp); /* I2C read */ @@ -196,6 +196,7 @@ static esp_err_t esp_lcd_touch_ft5x06_read_data(esp_lcd_touch_handle_t tp) /* Fill all coordinates */ for (i = 0; i < points; i++) { + tp->data.coords[i].track_id = ((data[(i * 6) + 2] & 0xf0) >> 4); tp->data.coords[i].x = (((uint16_t)data[(i * 6) + 0] & 0x0f) << 8) + data[(i * 6) + 1]; tp->data.coords[i].y = (((uint16_t)data[(i * 6) + 2] & 0x0f) << 8) + data[(i * 6) + 3]; } @@ -205,7 +206,7 @@ static esp_err_t esp_lcd_touch_ft5x06_read_data(esp_lcd_touch_handle_t tp) return ESP_OK; } -static bool esp_lcd_touch_ft5x06_get_xy(esp_lcd_touch_handle_t tp, uint16_t *x, uint16_t *y, uint16_t *strength, uint8_t *point_num, uint8_t max_point_num) +static bool esp_lcd_touch_ft5x06_get_xy(esp_lcd_touch_handle_t tp, uint16_t *x, uint16_t *y, uint16_t *strength, uint8_t *track_id, uint8_t *point_num, uint8_t max_point_num) { assert(tp != NULL); assert(x != NULL); @@ -225,6 +226,10 @@ static bool esp_lcd_touch_ft5x06_get_xy(esp_lcd_touch_handle_t tp, uint16_t *x, if (strength) { strength[i] = tp->data.coords[i].strength; } + + if (track_id) { + track_id[i] = tp->data.coords[i].track_id; + } } /* Invalidate */ diff --git a/components/lcd_touch/esp_lcd_touch_ft5x06/idf_component.yml b/components/lcd_touch/esp_lcd_touch_ft5x06/idf_component.yml index bbd51fcb..3c3f989c 100644 --- a/components/lcd_touch/esp_lcd_touch_ft5x06/idf_component.yml +++ b/components/lcd_touch/esp_lcd_touch_ft5x06/idf_component.yml @@ -1,8 +1,8 @@ -version: "1.0.6" +version: "1.1.0" description: ESP LCD Touch FT5x06 - touch controller FT5x06 url: https://github.com/espressif/esp-bsp/tree/master/components/lcd_touch/esp_lcd_touch_ft5x06 dependencies: idf: ">=4.4.2" esp_lcd_touch: - version: "^1.0.4" + version: "^1.2.0" public: true diff --git a/components/lcd_touch/esp_lcd_touch_ft5x06/include/esp_lcd_touch_ft5x06.h b/components/lcd_touch/esp_lcd_touch_ft5x06/include/esp_lcd_touch_ft5x06.h index e10bbd85..d9ef4df5 100644 --- a/components/lcd_touch/esp_lcd_touch_ft5x06/include/esp_lcd_touch_ft5x06.h +++ b/components/lcd_touch/esp_lcd_touch_ft5x06/include/esp_lcd_touch_ft5x06.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -53,7 +53,6 @@ esp_err_t esp_lcd_touch_new_i2c_ft5x06(const esp_lcd_panel_io_handle_t io, const } \ } - #ifdef __cplusplus } #endif diff --git a/components/lcd_touch/esp_lcd_touch_gt911/esp_lcd_touch_gt911.c b/components/lcd_touch/esp_lcd_touch_gt911/esp_lcd_touch_gt911.c index 5e5e625e..4b3e80b2 100644 --- a/components/lcd_touch/esp_lcd_touch_gt911/esp_lcd_touch_gt911.c +++ b/components/lcd_touch/esp_lcd_touch_gt911/esp_lcd_touch_gt911.c @@ -26,6 +26,7 @@ static const char *TAG = "GT911"; #define ESP_LCD_TOUCH_GT911_CONFIG_REG (0x8047) #define ESP_LCD_TOUCH_GT911_PRODUCT_ID_REG (0x8140) #define ESP_LCD_TOUCH_GT911_ENTER_SLEEP (0x8040) +#define ESP_LCD_TOUCH_GT811_REFRESH_RATE (0x8056) /* GT911 support key num */ #define ESP_GT911_TOUCH_MAX_BUTTONS (4) @@ -34,7 +35,7 @@ static const char *TAG = "GT911"; * Function definitions *******************************************************************************/ static esp_err_t esp_lcd_touch_gt911_read_data(esp_lcd_touch_handle_t tp); -static bool esp_lcd_touch_gt911_get_xy(esp_lcd_touch_handle_t tp, uint16_t *x, uint16_t *y, uint16_t *strength, uint8_t *point_num, uint8_t max_point_num); +static bool esp_lcd_touch_gt911_get_xy(esp_lcd_touch_handle_t tp, uint16_t *x, uint16_t *y, uint16_t *strength, uint8_t *track_id, uint8_t *point_num, uint8_t max_point_num); #if (CONFIG_ESP_LCD_TOUCH_MAX_BUTTONS > 0) static esp_err_t esp_lcd_touch_gt911_get_button_state(esp_lcd_touch_handle_t tp, uint8_t n, uint8_t *state); #endif @@ -159,6 +160,8 @@ esp_err_t esp_lcd_touch_new_i2c_gt911(const esp_lcd_panel_io_handle_t io, const ret = touch_gt911_read_cfg(esp_lcd_touch_gt911); ESP_GOTO_ON_ERROR(ret, err, TAG, "GT911 init failed"); + touch_gt911_i2c_write(esp_lcd_touch_gt911, ESP_LCD_TOUCH_GT811_REFRESH_RATE, 0x00); + err: if (ret != ESP_OK) { ESP_LOGE(TAG, "Error (0x%x)! Touch controller GT911 initialization failed!", ret); @@ -276,6 +279,7 @@ static esp_err_t esp_lcd_touch_gt911_read_data(esp_lcd_touch_handle_t tp) /* Fill all coordinates */ for (i = 0; i < touch_cnt; i++) { + tp->data.coords[i].track_id = buf[(i * 8) + 1]; tp->data.coords[i].x = ((uint16_t)buf[(i * 8) + 3] << 8) + buf[(i * 8) + 2]; tp->data.coords[i].y = (((uint16_t)buf[(i * 8) + 5] << 8) + buf[(i * 8) + 4]); tp->data.coords[i].strength = (((uint16_t)buf[(i * 8) + 7] << 8) + buf[(i * 8) + 6]); @@ -287,7 +291,7 @@ static esp_err_t esp_lcd_touch_gt911_read_data(esp_lcd_touch_handle_t tp) return ESP_OK; } -static bool esp_lcd_touch_gt911_get_xy(esp_lcd_touch_handle_t tp, uint16_t *x, uint16_t *y, uint16_t *strength, uint8_t *point_num, uint8_t max_point_num) +static bool esp_lcd_touch_gt911_get_xy(esp_lcd_touch_handle_t tp, uint16_t *x, uint16_t *y, uint16_t *strength, uint8_t *track_id, uint8_t *point_num, uint8_t max_point_num) { assert(tp != NULL); assert(x != NULL); @@ -307,6 +311,10 @@ static bool esp_lcd_touch_gt911_get_xy(esp_lcd_touch_handle_t tp, uint16_t *x, u if (strength) { strength[i] = tp->data.coords[i].strength; } + + if (track_id) { + track_id[i] = tp->data.coords[i].track_id; + } } /* Invalidate */ diff --git a/components/lcd_touch/esp_lcd_touch_gt911/idf_component.yml b/components/lcd_touch/esp_lcd_touch_gt911/idf_component.yml index 37de956e..109bd7f2 100644 --- a/components/lcd_touch/esp_lcd_touch_gt911/idf_component.yml +++ b/components/lcd_touch/esp_lcd_touch_gt911/idf_component.yml @@ -1,8 +1,8 @@ -version: "1.1.1" +version: "1.2.0" description: ESP LCD Touch GT911 - touch controller GT911 url: https://github.com/espressif/esp-bsp/tree/master/components/lcd_touch/esp_lcd_touch_gt911 dependencies: idf: ">=4.4.2" esp_lcd_touch: - version: "^1.1.0" + version: "^1.2.0" public: true