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(lcd_touch): support trank id (BSP-536) #369

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
2 changes: 1 addition & 1 deletion components/lcd_touch/esp_lcd_touch/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ menu "ESP LCD TOUCH"
range 0 10
default 1

endmenu
endmenu
2 changes: 1 addition & 1 deletion components/lcd_touch/esp_lcd_touch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions components/lcd_touch/esp_lcd_touch/esp_lcd_touch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot change API. We can create another function with similar API.

{
bool touched = false;

Expand All @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion components/lcd_touch/esp_lcd_touch/idf_component.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
17 changes: 9 additions & 8 deletions components/lcd_touch/esp_lcd_touch/include/esp_lcd_touch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot change API. We can create another function with similar API.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be a good name for the new function?

The current function name is static bool esp_lcd_touch_ft5x06_get_xy.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have two options for it:

  1. bool esp_lcd_touch_get_coordinates_track_id(esp_lcd_touch_handle_t tp, uint8_t *track_id);
  2. bool esp_lcd_touch_get_coordinates_track_id(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)

Same for bool (*get_xy)(...) and callback void (*process_coordinates)(...)

Copy link
Author

@lijunru-hub lijunru-hub Aug 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, the touch chip actually supports some additional special features. For example, the FT5x06 can indicate whether a swipe is to the left or right, and whether each touch point is currently being pressed or swiped, among other things. It would be best to address these issues all at once and lay the groundwork for future requirements.

bool esp_lcd_touch_get_coordinates_data(esp_lcd_touch_handle_t tp, void *data)
{
   ft5x06_data_t *ft_data = (ft5x06_data_t *)data// ft_data->x[i]
   // ft_data->trank_id
   //...
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is good idea, but it looks little dangerous use void type and we don't know const count of touches.

We can do something like this:

typedef struct {
   uint16_t x;
   uint16_t y;
   uint16_t strength;
   uint16_t track_id;
   void * user_data;
} esp_lcd_touch_coordinates_data_t;

bool esp_lcd_touch_get_coordinates_data(esp_lcd_touch_handle_t tp, esp_lcd_touch_coordinates_data_t * data, uint8_t *point_num, uint8_t max_point_num);

Usage:

esp_lcd_touch_coordinates_data_t data[4];
uint8_t points = 0;
esp_lcd_touch_get_coordinates_data(tp, data, &points, sizeof(data)/sizeof(esp_lcd_touch_coordinates_data_t));

Note: This structure can be very easily extended in future. And any driver can use user_data for specific strusture. There should be any data type check (I don't know, if it is possible in C - something like compare typeof())

@igrr @tore-espressif What do you think about this solution?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about handling everything within a struct?

typedef struct {
uint16_t x;
uint16_t y;
uint16_t strength;
uint16_t track_id;
} point_data_t;

typedef struct {
esp_lcd_touch_gesture_t gesture_id;
point_data_t *data;
uint32_t num_points;
} esp_lcd_touch_coordinates_data_t;

However, it's important to note that not every chip has all of this information

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you said, some features are not supported in all chips, I think the gestures should be in own function and we can return NOT_SUPPORTED error.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And any driver can use user_data for specific structure. There should be any data type check (I don't know, if it is possible in C - something like compare typeof())

If we want to return device specific data, this should be handled in the specific touch driver eg. esp_lcd_touch_ft5x06 and NOT in esp_lcd_touch base component. C language does not have runtime type information

So there are 2 types of returned data

  1. somewhat common across different touch controllers (eg. track_id). These could be added to base esp_lcd_touch with a function similar to esp_lcd_touch_get_coordinates_data
  2. Specific to the touch driver e.g. gestures. These function should be added to the specific touch driver eg. esp_lcd_touch_ft5x06_gesture()

What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2. Specific to the touch driver e.g. gestures. These function should be added to the specific touch driver eg. esp_lcd_touch_ft5x06_gesture()

Are gestures specific for touch driver? Aren't it more common over lot of drivers?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are gestures specific for touch driver? Aren't it more common over lot of drivers?

🤷‍♂️ :D

If yes, let's make it all common

/*!< User callback called after the touch interrupt occurred */
esp_lcd_touch_interrupt_callback_t interrupt_callback;
/*!< User data passed to callback */
Expand All @@ -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 */
Expand Down Expand Up @@ -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)
/**
Expand All @@ -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
Expand Down Expand Up @@ -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)
/**
Expand Down
11 changes: 8 additions & 3 deletions components/lcd_touch/esp_lcd_touch_ft5x06/esp_lcd_touch_ft5x06.c
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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];
}
Expand All @@ -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);
Expand All @@ -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 */
Expand Down
4 changes: 2 additions & 2 deletions components/lcd_touch/esp_lcd_touch_ft5x06/idf_component.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down Expand Up @@ -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
12 changes: 10 additions & 2 deletions components/lcd_touch/esp_lcd_touch_gt911/esp_lcd_touch_gt911.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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]);
Expand All @@ -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);
Expand All @@ -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 */
Expand Down
4 changes: 2 additions & 2 deletions components/lcd_touch/esp_lcd_touch_gt911/idf_component.yml
Original file line number Diff line number Diff line change
@@ -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
Loading