driver/uinput: add uinput button support

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
This commit is contained in:
yinshengkai
2021-12-24 16:30:36 +08:00
committed by Xiang Xiao
parent 377c15955e
commit 3bb4e053fe
4 changed files with 201 additions and 2 deletions
+68 -1
View File
@@ -129,6 +129,11 @@ static int btn_ioctl(FAR struct file *filep, int cmd,
static int btn_poll(FAR struct file *filep, FAR struct pollfd *fds,
bool setup);
#ifdef CONFIG_INPUT_UINPUT
static ssize_t btn_write(FAR struct file *filep, FAR const char *buffer,
size_t buflen);
#endif
/****************************************************************************
* Private Data
****************************************************************************/
@@ -138,7 +143,11 @@ static const struct file_operations btn_fops =
btn_open, /* open */
btn_close, /* close */
btn_read, /* read */
#ifdef CONFIG_INPUT_UINPUT
btn_write, /* write */
#else
NULL, /* write */
#endif
NULL, /* seek */
btn_ioctl, /* ioctl */
btn_poll /* poll */
@@ -508,7 +517,7 @@ static ssize_t btn_read(FAR struct file *filep, FAR char *buffer,
if (len < sizeof(btn_buttonset_t))
{
ierr("ERROR: buffer too small: %lu\n", (unsigned long)len);
ierr("ERROR: buffer too small: %zu\n", len);
return -EINVAL;
}
@@ -531,6 +540,64 @@ static ssize_t btn_read(FAR struct file *filep, FAR char *buffer,
return (ssize_t)sizeof(btn_buttonset_t);
}
/****************************************************************************
* Name: btn_write
****************************************************************************/
#ifdef CONFIG_INPUT_UINPUT
static ssize_t btn_write(FAR struct file *filep, FAR const char *buffer,
size_t buflen)
{
FAR struct inode *inode;
FAR struct btn_upperhalf_s *priv;
FAR const struct btn_lowerhalf_s *lower;
int ret;
DEBUGASSERT(filep && filep->f_inode);
inode = filep->f_inode;
DEBUGASSERT(inode->i_private);
priv = (FAR struct btn_upperhalf_s *)inode->i_private;
/* Make sure that the buffer is sufficiently large to hold at least one
* complete sample.
*
* REVISIT: Should also check buffer alignment.
*/
if (buflen < sizeof(btn_buttonset_t))
{
ierr("ERROR: buffer too small: %zu\n", buflen);
return -EINVAL;
}
/* Get exclusive access to the driver structure */
ret = btn_takesem(&priv->bu_exclsem);
if (ret < 0)
{
ierr("ERROR: btn_takesem failed: %d\n", ret);
return ret;
}
/* Write the current state of the buttons */
lower = priv->bu_lower;
DEBUGASSERT(lower);
if (lower->bl_write)
{
ret = lower->bl_write(lower, buffer, buflen);
}
else
{
ret = -ENOSYS;
}
btn_givesem(&priv->bu_exclsem);
return (ssize_t)ret;
}
#endif
/****************************************************************************
* Name: btn_ioctl
****************************************************************************/