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

Conversation

lijunru-hub
Copy link

ESP-BSP Pull Request checklist

Note: For new BSPs create a PR with this link.

  • Version of modified component bumped
  • CI passing

Change description

Please describe your change here

link #358

@CLAassistant
Copy link

CLAassistant commented Aug 13, 2024

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot changed the title feat(lcd_touch): support trank id feat(lcd_touch): support trank id (BSP-536) Aug 13, 2024
@@ -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.

@@ -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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants