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

os/drivers/input/: Add callback functionality to notify touch interrupt to application for touch driver ist415, touch HAL layer #6539

Merged
merged 2 commits into from
Dec 5, 2024

Conversation

abhinav-s235
Copy link
Contributor

Touch Driver provides a mechanism to notify application whenever a touch event occur.
Register a callback function with touch input driver using TSIOC_SETAPPNOTIFY IOCTL Call. THis function will be automatically called whenever a touch event(Press ,Hold/Move, Release) is detected.
When a touch event occurs , the registered callback function is triggered by the touch interrupt handler function. The driver provides details such as touch coordinate and type directly to this callback. Whenever there is a touch interrupt a new task is created to get the touch data and it eventually call the callback function.

int ret = ioctl(touch_fd, TSIOC_SETAPPNOTIFY, &touch_set_callback);
if (ret != OK) {
printf("ERROR: Touch callback register from application to touch driver failed\n");
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

close(touch_fd) before return

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed


#elif CONFIG_TOUCH_CALLBACK

touch_set_callback.touch_points = (struct touch_sample_s *)malloc(sizeof(struct touch_sample_s));
Copy link
Contributor

Choose a reason for hiding this comment

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

Should free it when task end or operation below failed

@abhinav-s235 abhinav-s235 marked this pull request as draft November 28, 2024 04:58
@@ -85,7 +85,9 @@
#define TSIOC_GETFREQUENCY _TSIOC(0x0004) /* arg: Pointer to uint32_t frequency value */
#define TSIOC_DISABLE _TSIOC(0x0005) /* Disable touch interrupt */
#define TSIOC_ENABLE _TSIOC(0x0006) /* Enable touch interrupt */

#ifdef CONFIG_TOUCH_CALLBACK
#define TSIOC_SETAPPNOTIFY _TSIOC(0x0008) /* arg: Pointer to struct touch_set_callback_s */
Copy link
Contributor

Choose a reason for hiding this comment

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

address will be 0x0007

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -446,8 +510,15 @@ int lcd_test_main(int argc, char *argv[])
}
test_fps();
close(fd);
errout:
Copy link
Contributor

Choose a reason for hiding this comment

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

it will not always errout case
this line could execute in OK case also.
change the name errout

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

free(touch_set_callback.touch_points);
return;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

remove all extra lines in # ifdefines

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -370,6 +374,9 @@ static void test_fps(void)
}

#ifdef CONFIG_TOUCH

Copy link
Contributor

Choose a reason for hiding this comment

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

remove the extra line

@@ -370,6 +374,9 @@ static void test_fps(void)
}

#ifdef CONFIG_TOUCH

#ifdef CONFIG_TOUCH_POLL

Copy link
Contributor

Choose a reason for hiding this comment

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

remove the extra line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -85,6 +85,10 @@ static int yres;
#define EXAMPLE_LCD_FPS_TEST 5000
#endif

#if defined(CONFIG_TOUCH) && defined(CONFIG_TOUCH_CALLBACK)
Copy link
Contributor

Choose a reason for hiding this comment

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

You can keep defined(CONFIG_TOUCH_CALLBACK) only. Because it can be enabled only when the CONFIG_TOUCH is enabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -408,6 +415,37 @@ static void touch_test(void)
}
close(fd);
}

#elif CONFIG_TOUCH_CALLBACK
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be #elif defined(CONFIG_...). This is wrong usage of the config.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

touch_set_callback.touch_points = (struct touch_sample_s *)malloc(sizeof(struct touch_sample_s));
if (!touch_set_callback.touch_points) {
printf("Error: Touch point buffer memory allocation failed\n");
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

This function return type is int, not void. So you should return -1 or something else.
Same as other returns in the function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

prompt "choose TOUCH DEVICE app notification type"
default TOUCH_POLL
---help---
Polling based notification to application
Copy link
Contributor

Choose a reason for hiding this comment

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

This help sentence is for TOUCH_POLL, not for the choice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -135,6 +147,12 @@ static int ist415_get_touch_data(struct ist415_dev_s *dev, FAR void *buf)
}
touchvdbg("touch_point %d\n", touch_point + 1);

#ifdef CONFIG_TOUCH_CALLBACK
Copy link
Contributor

Choose a reason for hiding this comment

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

line 156 is not in this conditional. Do we need to add this conditional here only?
This new code looks not releated with callback config.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In case of TOUCH_POLL we have handle buffer NULL condition inside function touch read()
but in case of TOUCH_CALLBACK this function is getting directly called from here (

int ret = ist415_get_touch_data(priv, upper->app_touch_point_buffer);
). So we have to explicitly handle this condition.

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. The touch_read does not check whether the buffer is null or not.
  2. What you linked is https://github.com/Samsung/TizenRT/blob/e5d7ef9b8629882448210d8615255e70fc591db4/os/drivers/input/ist415.c#L259C13-L259C27. This is for callback, not poll case.

Could you check it again?
And even it is really checking like that, I suggest to do the same thing at the same location.
For the same purpose, if we do different location for each, it's not good to maintain.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is the platform code, it should be easy-maintain and common.

Copy link
Contributor

Choose a reason for hiding this comment

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

@anjana348 I left the same comment on @namanjain7 's PR. Let's concern this point for all.
Same purpose, same location regardless of the config difference as possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It has been fixed.
Now buffer NULL condition is getting checked at same location for both the cases.

Comment on lines +259 to +274
static void get_touch_data(struct ist415_dev_s *priv)
{
FAR struct touchscreen_s *upper = priv->upper;

struct touch_sample_s touch_points;

if (!upper->app_touch_point_buffer) {
touchdbg("ERROR: application buffer touch data is NULL\n");
if (upper->is_touch_detected) {
upper->is_touch_detected(-EINVAL);
return;
}
}
int ret = ist415_get_touch_data(priv, upper->app_touch_point_buffer);

if (upper->is_touch_detected) {
upper->is_touch_detected(ret);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I don't know how to give the data to app. Could you explain working flow?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are registering callback function is_touch_detected and buffer to driver using IOCTL call TSIOC_SETAPPNOTIFY
When there is an touch interrupt a new thread will be created which will execute function get_touch_data() and this function will call function ist415_get_touch_data() by passing buffer as a parameter(this buffer was register to driver using IOCTL call).
Function ist415_get_touch_data() copy data related to touch inside the passed buffer and after completion of this function the callback function will be called from here
Now callback fuction use the buffer(which was passed to driver) to acces the touch data.

@@ -85,7 +85,9 @@
#define TSIOC_GETFREQUENCY _TSIOC(0x0004) /* arg: Pointer to uint32_t frequency value */
#define TSIOC_DISABLE _TSIOC(0x0005) /* Disable touch interrupt */
#define TSIOC_ENABLE _TSIOC(0x0006) /* Enable touch interrupt */

#ifdef CONFIG_TOUCH_CALLBACK
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add this without conditional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't understood the query.
Could you please elaborate it more

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's remove #ifdef CONFIG_TOUCH_CALLBACK and #endif.
Just add new definition without #ifdef.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@abhinav-s235 abhinav-s235 force-pushed the callback_1 branch 3 times, most recently from e5d7ef9 to 9dacc47 Compare November 29, 2024 10:59
@abhinav-s235 abhinav-s235 marked this pull request as ready for review December 4, 2024 09:18
…pt to application for touch driver ist415, touch HAL layer

    Register a callback function with touch input driver using TSIOC_SETAPPNOTIFY IOCTL Call. This function will be automatically called whenever a touch event(Press ,Hold/Move, Release) is detected.
    When a touch event occurs , the registered callback function is triggered by the touch interrupt handler function. The driver provides details such as touch coordinate and type directly to this
    callback. Whenever there is a touch interrupt a new task is created to get the touch data and it eventually call the callback function.
…ctionality

    Touch hold/move event
    Total touch points 3
    TOUCH COORDINATES id: 0, x : 313 y : 162 touch type: 2
    Touch hold/move event
    TOUCH COORDINATES id: 1, x : 398 y : 282 touch type: 2
    Touch hold/move event
    TOUCH COORDINATES id: 2, x : 561 y : 321 touch type: 2
    Touch hold/move event
    Total touch points 3
    TOUCH COORDINATES id: 0, x : 313 y : 162 touch type: 2
    Touch hold/move event
@sunghan-chang sunghan-chang merged commit f40de0b into Samsung:master Dec 5, 2024
11 checks passed
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.

5 participants