This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 41688a8f135c6d87a0d30d6ad3ed2e465feae030 Author: liuhongchao <liuhongc...@xiaomi.com> AuthorDate: Thu Oct 31 16:24:49 2024 +0800 nuttx: Support for rpmsgdev custom ioctl Signed-off-by: liuhongchao <liuhongc...@xiaomi.com> --- drivers/misc/rpmsgdev.c | 11 ++++++++--- include/nuttx/fs/ioctl.h | 6 +++--- include/nuttx/input/mouse.h | 45 +++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 54 insertions(+), 8 deletions(-) diff --git a/drivers/misc/rpmsgdev.c b/drivers/misc/rpmsgdev.c index 58c8a87e20..15c270aaae 100644 --- a/drivers/misc/rpmsgdev.c +++ b/drivers/misc/rpmsgdev.c @@ -45,6 +45,7 @@ #include <nuttx/net/ioctl.h> #include <nuttx/drivers/rpmsgdev.h> #include <nuttx/power/battery_ioctl.h> +#include <nuttx/input/mouse.h> #include "rpmsgdev.h" @@ -103,7 +104,7 @@ static ssize_t rpmsgdev_write(FAR struct file *filep, FAR const char *buffer, size_t buflen); static off_t rpmsgdev_seek(FAR struct file *filep, off_t offset, int whence); -static ssize_t rpmsgdev_ioctl_arglen(int cmd); +static ssize_t rpmsgdev_ioctl_arglen(int cmd, unsigned long arg); static int rpmsgdev_ioctl(FAR struct file *filep, int cmd, unsigned long arg); static int rpmsgdev_poll(FAR struct file *filep, FAR struct pollfd *fds, @@ -591,6 +592,7 @@ static off_t rpmsgdev_seek(FAR struct file *filep, off_t offset, int whence) * * Parameters: * cmd - the ioctl command + * arg - the ioctl arguments * * Returned Values: * 0 - ioctl command not support @@ -598,7 +600,7 @@ static off_t rpmsgdev_seek(FAR struct file *filep, off_t offset, int whence) * ****************************************************************************/ -static ssize_t rpmsgdev_ioctl_arglen(int cmd) +static ssize_t rpmsgdev_ioctl_arglen(int cmd, unsigned long arg) { switch (cmd) { @@ -622,6 +624,9 @@ static ssize_t rpmsgdev_ioctl_arglen(int cmd) case BATIOC_GET_PROTOCOL: case BATIOC_OPERATE: return sizeof(struct batio_operate_msg_s); + case MSIOC_VENDOR: + return sizeof(struct mouse_vendor_cmd_s) + + ((FAR struct mouse_vendor_cmd_s *)(uintptr_t)arg)->len; default: return -ENOTTY; } @@ -661,7 +666,7 @@ static int rpmsgdev_ioctl(FAR struct file *filep, int cmd, unsigned long arg) /* Call our internal routine to perform the ioctl */ - arglen = rpmsgdev_ioctl_arglen(cmd); + arglen = rpmsgdev_ioctl_arglen(cmd, arg); if (arglen < 0) { return arglen; diff --git a/include/nuttx/fs/ioctl.h b/include/nuttx/fs/ioctl.h index 16bbfcc9d2..67b7304efd 100644 --- a/include/nuttx/fs/ioctl.h +++ b/include/nuttx/fs/ioctl.h @@ -108,7 +108,7 @@ #define _PINCTRLBASE (0x4000) /* Pinctrl driver ioctl commands */ #define _PCIBASE (0x4100) /* Pci ioctl commands */ #define _I3CBASE (0x4200) /* I3C driver ioctl commands */ -#define _MSEIOCBASE (0x4300) /* Mouse ioctl commands */ +#define _MSIOCBASE (0x4300) /* Mouse ioctl commands */ #define _WLIOCBASE (0x8b00) /* Wireless modules ioctl network commands */ /* boardctl() commands share the same number space */ @@ -373,8 +373,8 @@ /* NuttX mouse ioctl definitions (see nuttx/input/mouse.h) ******************/ -#define _MSEIOCVALID(c) (_IOC_TYPE(c)==_MSEIOCBASE) -#define _MSEIOC(nr) _IOC(_MSEIOCBASE,nr) +#define _MSIOCVALID(c) (_IOC_TYPE(c)==_MSIOCBASE) +#define _MSIOC(nr) _IOC(_MSIOCBASE,nr) /* NuttX sensor ioctl definitions (see nuttx/sensor/ioctl.h) ****************/ diff --git a/include/nuttx/input/mouse.h b/include/nuttx/input/mouse.h index 81c60667c6..62426d2461 100644 --- a/include/nuttx/input/mouse.h +++ b/include/nuttx/input/mouse.h @@ -55,8 +55,49 @@ /* Common mouse IOCTL commands */ -#define MSE_FIRST 0x0001 /* First common command */ -#define MSE_NCMDS 1 /* One common commands */ +#define MSIOC_VENDOR _MSIOC(0x0001) /* Vendor-specific commands */ + +#define MSC_FIRST 0x0001 /* First common command */ +#define MSC_NCMDS 1 /* One common commands */ + +/* Vendor-specific command structure + * + * This structure is used to pass vendor-specific commands to the mouse + * driver. The vendor-specific command is identified by the 'cmd' field + * and the length of the data is specified by the 'len' field. The + * data follows the structure in a contiguous block of memory. + * + * The vendor-specific command is defined by the vendor and is not + * standardized. The data format and meaning is defined by the vendor. + * + * The usage is as follows : + * + * struct mse_vendor_data_s + * { + * uint16_t cmd; + * uint16_t len; + * uint16_t data; + * ... ... ... + * }; + * + * struct mse_vendor_data_s cmd_data; + * cmd_data.cmd = VENDOR_CMD_ID; + * cmd_data.data = 12; + * + * struct mouse_vendor_cmd_s *ioctl; + * ioctl = malloc(sizeof(*ioctl) + sizeof(struct mse_vendor_data_s)); + * ioctl->len = sizeof(struct mse_vendor_data_s); + * memcpy(ioctl->data, &cmd_data, sizeof(struct mse_vendor_data_s)); + * + * ioctl(file, MSIOC_VENDOR, ioctl); + * + */ + +struct mouse_vendor_cmd_s +{ + size_t len; + char data[1]; +}; /**************************************************************************** * Public Types