driver/touchscreen: Add support for write operations

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
This commit is contained in:
yinshengkai 2021-11-18 19:44:03 +08:00 committed by Xiang Xiao
parent ec54c4e30d
commit 676b735c4a
2 changed files with 49 additions and 0 deletions

View File

@ -81,6 +81,11 @@ static int touch_ioctl(FAR struct file *filep, int cmd,
static int touch_poll(FAR struct file *filep, FAR struct pollfd *fds,
bool setup);
#ifdef CONFIG_INPUT_UINPUT
static ssize_t touch_write(FAR struct file *filep, FAR const char *buffer,
size_t buflen);
#endif
/****************************************************************************
* Private Data
****************************************************************************/
@ -90,7 +95,11 @@ static const struct file_operations g_touch_fops =
touch_open, /* open */
touch_close, /* close */
touch_read, /* read */
#ifdef CONFIG_INPUT_UINPUT
touch_write, /* write */
#else
NULL, /* write */
#endif
NULL, /* seek */
touch_ioctl, /* ioctl */
touch_poll /* poll */
@ -197,6 +206,27 @@ static int touch_close(FAR struct file *filep)
return ret;
}
/****************************************************************************
* Name: touch_write
****************************************************************************/
#ifdef CONFIG_INPUT_UINPUT
static ssize_t touch_write(FAR struct file *filep, FAR const char *buffer,
size_t buflen)
{
FAR struct inode *inode = filep->f_inode;
FAR struct touch_upperhalf_s *upper = inode->i_private;
FAR struct touch_lowerhalf_s *lower = upper->lower;
if (!lower->write)
{
return -ENOSYS;
}
return lower->write(lower, buffer, buflen);
}
#endif
/****************************************************************************
* Name: touch_read
****************************************************************************/

View File

@ -175,6 +175,25 @@ struct touch_lowerhalf_s
CODE int (*control)(FAR struct touch_lowerhalf_s *lower,
int cmd, unsigned long arg);
/**************************************************************************
* Name: write
*
* Description:
* Users can use this interface to implement custom write.
*
* Arguments:
* lower - The instance of lower half of touchscreen device.
* buffer - User defined specific buffer.
* buflen - User defined specific buffer size.
*
* Return Value:
* Number of bytes writtena negated errno value on failure.
*
**************************************************************************/
CODE ssize_t (*write)(FAR struct touch_lowerhalf_s *lower,
FAR const char *buffer, size_t buflen);
};
/****************************************************************************