From d1575891ed63e829db761012080bd8f77a0bdb09 Mon Sep 17 00:00:00 2001 From: liuhongchao Date: Tue, 5 Nov 2024 10:55:46 +0800 Subject: [PATCH] nuxxt: add open and close callback functions for the mouse. --- drivers/input/mouse_upper.c | 12 ++++++++++++ include/nuttx/input/mouse.h | 39 +++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/drivers/input/mouse_upper.c b/drivers/input/mouse_upper.c index e23a9664a28..f63118180d9 100644 --- a/drivers/input/mouse_upper.c +++ b/drivers/input/mouse_upper.c @@ -101,6 +101,7 @@ static int mouse_open(FAR struct file *filep) FAR struct mouse_openpriv_s *openpriv; 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); @@ -129,6 +130,11 @@ static int mouse_open(FAR struct file *filep) nxmutex_init(&openpriv->lock); list_add_tail(&upper->head, &openpriv->node); + if (lower->open && list_is_singular(&openpriv->node)) + { + ret = lower->open(lower); + } + /* Save the buffer node pointer so that it can be used directly * in the read operation. */ @@ -147,6 +153,7 @@ static int mouse_close(FAR struct file *filep) FAR struct mouse_openpriv_s *openpriv = filep->f_priv; 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); @@ -155,6 +162,11 @@ static int mouse_close(FAR struct file *filep) return ret; } + if (lower->close && list_is_singular(&openpriv->node)) + { + ret = lower->close(lower); + } + list_delete(&openpriv->node); circbuf_uninit(&openpriv->circbuf); nxsem_destroy(&openpriv->waitsem); diff --git a/include/nuttx/input/mouse.h b/include/nuttx/input/mouse.h index 62426d2461e..19970cce8f1 100644 --- a/include/nuttx/input/mouse.h +++ b/include/nuttx/input/mouse.h @@ -143,6 +143,45 @@ struct mouse_lowerhalf_s CODE int (*control)(FAR struct mouse_lowerhalf_s *lower, int cmd, unsigned long arg); + + /************************************************************************** + * Name: open + * + * Description: + * This function pointer is used to open a connection to the mouse driver + * instance. It initializes the mouse and prepares it for subsequent + * interactions with the user. This function typically sets up the state + * of the driver and allocates any necessary resources. + * + * Input Parameters: + * lower - A pointer to the instance of the lower half mouse driver. + * filep - A pointer to the file structure representing the user. + * + * Returned Value: + * It returns zero (OK) on success; a negative errno value on failure. + **************************************************************************/ + + CODE int (*open)(FAR struct mouse_lowerhalf_s *lower); + + /************************************************************************** + * Name: close + * + * Description: + * This function pointer is used to close the connection to the mouse + * driver instance. It performs any necessary cleanup operations, such as + * releasing resources and resetting the state of the mouse driver, + * before ending theinteraction with the user. + * + * Input Parameters: + * lower - A pointer to the instance of the lower half mouse driver. + * filep - A pointer to the file structure representing the user closing + * the mouse connection. + * + * Returned Value: + * Returns zero (OK) on success; a negative errno value on failure. + **************************************************************************/ + + CODE int (*close)(FAR struct mouse_lowerhalf_s *lower); }; /****************************************************************************