nuttx: Support for the mouse ioctl interface

Signed-off-by: liuhongchao <liuhongchao@xiaomi.com>
This commit is contained in:
liuhongchao 2024-10-29 10:45:01 +08:00
parent 7036098d23
commit 97b30a6e5b
3 changed files with 66 additions and 1 deletions

View file

@ -68,6 +68,8 @@ static int mouse_open(FAR struct file *filep);
static int mouse_close(FAR struct file *filep); static int mouse_close(FAR struct file *filep);
static ssize_t mouse_read(FAR struct file *filep, FAR char *buffer, static ssize_t mouse_read(FAR struct file *filep, FAR char *buffer,
size_t buflen); size_t buflen);
static int mouse_ioctl(FAR struct file *filep, int cmd,
unsigned long arg);
static int mouse_poll(FAR struct file *filep, FAR struct pollfd *fds, static int mouse_poll(FAR struct file *filep, FAR struct pollfd *fds,
bool setup); bool setup);
@ -82,7 +84,7 @@ static const struct file_operations g_mouse_fops =
mouse_read, /* read */ mouse_read, /* read */
NULL, /* write */ NULL, /* write */
NULL, /* seek */ NULL, /* seek */
NULL, /* ioctl */ mouse_ioctl, /* ioctl */
NULL, /* mmap */ NULL, /* mmap */
NULL, /* truncate */ NULL, /* truncate */
mouse_poll /* poll */ mouse_poll /* poll */
@ -217,6 +219,36 @@ out:
return ret; return ret;
} }
/****************************************************************************
* Name: mouse_ioctl
****************************************************************************/
static int mouse_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
{
FAR struct inode *inode = filep->f_inode;
FAR struct mouse_upperhalf_s *upper = inode->i_private;
FAR struct mouse_lowerhalf_s *lower = upper->lower;
int ret;
ret = nxmutex_lock(&upper->lock);
if (ret < 0)
{
return ret;
}
if (lower->control)
{
ret = lower->control(lower, cmd, arg);
}
else
{
ret = -ENOTTY;
}
nxmutex_unlock(&upper->lock);
return ret;
}
/**************************************************************************** /****************************************************************************
* Name: mouse_poll * Name: mouse_poll
****************************************************************************/ ****************************************************************************/

View file

@ -108,6 +108,7 @@
#define _PINCTRLBASE (0x4000) /* Pinctrl driver ioctl commands */ #define _PINCTRLBASE (0x4000) /* Pinctrl driver ioctl commands */
#define _PCIBASE (0x4100) /* Pci ioctl commands */ #define _PCIBASE (0x4100) /* Pci ioctl commands */
#define _I3CBASE (0x4200) /* I3C driver ioctl commands */ #define _I3CBASE (0x4200) /* I3C driver ioctl commands */
#define _MSEIOCBASE (0x4300) /* Mouse ioctl commands */
#define _WLIOCBASE (0x8b00) /* Wireless modules ioctl network commands */ #define _WLIOCBASE (0x8b00) /* Wireless modules ioctl network commands */
/* boardctl() commands share the same number space */ /* boardctl() commands share the same number space */
@ -370,6 +371,11 @@
#define _TSIOCVALID(c) (_IOC_TYPE(c)==_TSIOCBASE) #define _TSIOCVALID(c) (_IOC_TYPE(c)==_TSIOCBASE)
#define _TSIOC(nr) _IOC(_TSIOCBASE,nr) #define _TSIOC(nr) _IOC(_TSIOCBASE,nr)
/* NuttX mouse ioctl definitions (see nuttx/input/mouse.h) ******************/
#define _MSEIOCVALID(c) (_IOC_TYPE(c)==_MSEIOCBASE)
#define _MSEIOC(nr) _IOC(_MSEIOCBASE,nr)
/* NuttX sensor ioctl definitions (see nuttx/sensor/ioctl.h) ****************/ /* NuttX sensor ioctl definitions (see nuttx/sensor/ioctl.h) ****************/
#define _SNIOCVALID(c) (_IOC_TYPE(c)==_SNIOCBASE) #define _SNIOCVALID(c) (_IOC_TYPE(c)==_SNIOCBASE)

View file

@ -37,6 +37,7 @@
****************************************************************************/ ****************************************************************************/
#include <nuttx/config.h> #include <nuttx/config.h>
#include <nuttx/fs/ioctl.h>
/**************************************************************************** /****************************************************************************
* Pre-processor Definitions * Pre-processor Definitions
@ -50,6 +51,13 @@
#define MOUSE_BUTTON_2 (1 << 1) /* True: Right mouse button pressed */ #define MOUSE_BUTTON_2 (1 << 1) /* True: Right mouse button pressed */
#define MOUSE_BUTTON_3 (1 << 2) /* True: Middle mouse button pressed */ #define MOUSE_BUTTON_3 (1 << 2) /* True: Middle mouse button pressed */
/* IOCTL Commands ***********************************************************/
/* Common mouse IOCTL commands */
#define MSE_FIRST 0x0001 /* First common command */
#define MSE_NCMDS 1 /* One common commands */
/**************************************************************************** /****************************************************************************
* Public Types * Public Types
****************************************************************************/ ****************************************************************************/
@ -75,6 +83,25 @@ struct mouse_report_s
struct mouse_lowerhalf_s struct mouse_lowerhalf_s
{ {
FAR void *priv; /* Save the upper half pointer */ FAR void *priv; /* Save the upper half pointer */
/**************************************************************************
* Name: control
*
* Description:
* Users can use this interface to implement custom IOCTL.
*
* Arguments:
* lower - The instance of lower half of mouse device.
* cmd - User defined specific command.
* arg - Argument of the specific command.
*
* Return Value:
* Zero(OK) on success; a negated errno value on failure.
* -ENOTTY - The command is not supported.
**************************************************************************/
CODE int (*control)(FAR struct mouse_lowerhalf_s *lower,
int cmd, unsigned long arg);
}; };
/**************************************************************************** /****************************************************************************