2021-10-28 08:49:31 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* drivers/input/touchscreen_upper.c
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
#include <sys/types.h>
|
2021-11-29 06:55:17 +01:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <debug.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <poll.h>
|
2021-10-28 08:49:31 +02:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2021-11-29 06:55:17 +01:00
|
|
|
#include <nuttx/input/touchscreen.h>
|
2021-10-28 08:49:31 +02:00
|
|
|
#include <nuttx/kmalloc.h>
|
2022-09-06 08:18:45 +02:00
|
|
|
#include <nuttx/mutex.h>
|
2021-11-29 06:55:17 +01:00
|
|
|
#include <nuttx/list.h>
|
2021-10-28 08:49:31 +02:00
|
|
|
#include <nuttx/mm/circbuf.h>
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-11-29 06:55:17 +01:00
|
|
|
struct touch_openpriv_s
|
|
|
|
{
|
|
|
|
struct circbuf_s circbuf; /* Store touch point data in circle buffer */
|
|
|
|
struct list_node node; /* Opened file buffer linked list node */
|
|
|
|
FAR struct pollfd *fds; /* Polling structure of waiting thread */
|
|
|
|
sem_t waitsem; /* Used to wait for the availability of data */
|
2022-09-06 08:18:45 +02:00
|
|
|
mutex_t lock; /* Manages exclusive access to this structure */
|
2021-11-29 06:55:17 +01:00
|
|
|
};
|
|
|
|
|
2021-10-28 08:49:31 +02:00
|
|
|
/* This structure is for touchscreen upper half driver */
|
|
|
|
|
|
|
|
struct touch_upperhalf_s
|
|
|
|
{
|
2022-03-19 17:10:06 +01:00
|
|
|
uint8_t nums; /* Number of touch point structure */
|
2022-09-06 08:18:45 +02:00
|
|
|
mutex_t lock; /* Manages exclusive access to this structure */
|
2021-11-29 06:55:17 +01:00
|
|
|
struct list_node head; /* Opened file buffer chain header node */
|
|
|
|
FAR struct touch_lowerhalf_s *lower; /* A pointer of lower half instance */
|
2024-07-24 14:09:25 +02:00
|
|
|
FAR struct touch_openpriv_s *grab; /* A pointer of grab file */
|
2021-10-28 08:49:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int touch_open(FAR struct file *filep);
|
|
|
|
static int touch_close(FAR struct file *filep);
|
|
|
|
static ssize_t touch_read(FAR struct file *filep, FAR char *buffer,
|
|
|
|
size_t buflen);
|
2022-03-28 09:36:08 +02:00
|
|
|
static ssize_t touch_write(FAR struct file *filep, FAR const char *buffer,
|
2022-02-26 16:05:03 +01:00
|
|
|
size_t buflen);
|
2021-10-28 08:49:31 +02:00
|
|
|
static int touch_ioctl(FAR struct file *filep, int cmd,
|
|
|
|
unsigned long arg);
|
|
|
|
static int touch_poll(FAR struct file *filep, FAR struct pollfd *fds,
|
|
|
|
bool setup);
|
|
|
|
|
2024-07-24 14:09:25 +02:00
|
|
|
static void touch_event_notify(FAR struct touch_openpriv_s *openpriv,
|
|
|
|
FAR const struct touch_sample_s *sample);
|
|
|
|
|
2021-10-28 08:49:31 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static const struct file_operations g_touch_fops =
|
|
|
|
{
|
2022-01-10 15:51:17 +01:00
|
|
|
touch_open, /* open */
|
|
|
|
touch_close, /* close */
|
|
|
|
touch_read, /* read */
|
2021-11-18 12:44:03 +01:00
|
|
|
touch_write, /* write */
|
2022-01-10 15:51:17 +01:00
|
|
|
NULL, /* seek */
|
|
|
|
touch_ioctl, /* ioctl */
|
2023-01-02 14:02:51 +01:00
|
|
|
NULL, /* mmap */
|
2023-01-02 18:06:12 +01:00
|
|
|
NULL, /* truncate */
|
2022-01-10 15:51:17 +01:00
|
|
|
touch_poll /* poll */
|
2021-10-28 08:49:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: touch_open
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int touch_open(FAR struct file *filep)
|
|
|
|
{
|
2021-11-29 06:55:17 +01:00
|
|
|
FAR struct touch_openpriv_s *openpriv;
|
|
|
|
FAR struct inode *inode = filep->f_inode;
|
2021-10-28 08:49:31 +02:00
|
|
|
FAR struct touch_upperhalf_s *upper = inode->i_private;
|
|
|
|
FAR struct touch_lowerhalf_s *lower = upper->lower;
|
|
|
|
int ret;
|
|
|
|
|
2021-11-29 06:55:17 +01:00
|
|
|
openpriv = kmm_zalloc(sizeof(struct touch_openpriv_s));
|
|
|
|
if (openpriv == NULL)
|
2021-10-28 08:49:31 +02:00
|
|
|
{
|
2021-11-29 06:55:17 +01:00
|
|
|
return -ENOMEM;
|
2021-10-28 08:49:31 +02:00
|
|
|
}
|
|
|
|
|
2021-11-29 06:55:17 +01:00
|
|
|
ret = circbuf_init(&openpriv->circbuf, NULL,
|
|
|
|
upper->nums * SIZEOF_TOUCH_SAMPLE_S(lower->maxpoint));
|
|
|
|
if (ret < 0)
|
2021-10-28 08:49:31 +02:00
|
|
|
{
|
2021-11-29 06:55:17 +01:00
|
|
|
kmm_free(openpriv);
|
|
|
|
return ret;
|
2021-10-28 08:49:31 +02:00
|
|
|
}
|
2021-11-29 06:55:17 +01:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&upper->lock);
|
2021-11-29 06:55:17 +01:00
|
|
|
if (ret < 0)
|
2021-10-28 08:49:31 +02:00
|
|
|
{
|
2021-11-29 06:55:17 +01:00
|
|
|
circbuf_uninit(&openpriv->circbuf);
|
|
|
|
kmm_free(openpriv);
|
|
|
|
return ret;
|
2021-10-28 08:49:31 +02:00
|
|
|
}
|
|
|
|
|
2021-11-29 06:55:17 +01:00
|
|
|
nxsem_init(&openpriv->waitsem, 0, 0);
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_init(&openpriv->lock);
|
2021-11-29 06:55:17 +01:00
|
|
|
list_add_tail(&upper->head, &openpriv->node);
|
|
|
|
|
|
|
|
/* Save the buffer node pointer so that it can be used directly
|
|
|
|
* in the read operation.
|
|
|
|
*/
|
2021-10-28 08:49:31 +02:00
|
|
|
|
2021-11-29 06:55:17 +01:00
|
|
|
filep->f_priv = openpriv;
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&upper->lock);
|
2021-10-28 08:49:31 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: touch_close
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int touch_close(FAR struct file *filep)
|
|
|
|
{
|
2021-11-29 06:55:17 +01:00
|
|
|
FAR struct touch_openpriv_s *openpriv = filep->f_priv;
|
|
|
|
FAR struct inode *inode = filep->f_inode;
|
|
|
|
FAR struct touch_upperhalf_s *upper = inode->i_private;
|
2021-10-28 08:49:31 +02:00
|
|
|
int ret;
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&upper->lock);
|
2021-10-28 08:49:31 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-07-24 14:09:25 +02:00
|
|
|
if (upper->grab == openpriv)
|
|
|
|
{
|
|
|
|
upper->grab = NULL;
|
|
|
|
}
|
|
|
|
|
2021-11-29 06:55:17 +01:00
|
|
|
list_delete(&openpriv->node);
|
|
|
|
circbuf_uninit(&openpriv->circbuf);
|
|
|
|
nxsem_destroy(&openpriv->waitsem);
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_destroy(&openpriv->lock);
|
2021-11-29 06:55:17 +01:00
|
|
|
kmm_free(openpriv);
|
2021-10-28 08:49:31 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&upper->lock);
|
2021-10-28 08:49:31 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-11-18 12:44:03 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: touch_write
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static ssize_t touch_write(FAR struct file *filep, FAR const char *buffer,
|
2022-04-12 12:16:13 +02:00
|
|
|
size_t buflen)
|
2021-11-18 12:44:03 +01:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-10-28 08:49:31 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: touch_read
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-04-12 12:16:13 +02:00
|
|
|
static ssize_t touch_read(FAR struct file *filep, FAR char *buffer,
|
|
|
|
size_t len)
|
2021-10-28 08:49:31 +02:00
|
|
|
{
|
2021-11-29 06:55:17 +01:00
|
|
|
FAR struct touch_openpriv_s *openpriv = filep->f_priv;
|
2021-10-28 08:49:31 +02:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!buffer || !len)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&openpriv->lock);
|
2021-10-28 08:49:31 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-11-29 06:55:17 +01:00
|
|
|
while (circbuf_is_empty(&openpriv->circbuf))
|
2021-10-28 08:49:31 +02:00
|
|
|
{
|
|
|
|
if (filep->f_oflags & O_NONBLOCK)
|
|
|
|
{
|
|
|
|
ret = -EAGAIN;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&openpriv->lock);
|
2021-11-29 06:55:17 +01:00
|
|
|
ret = nxsem_wait_uninterruptible(&openpriv->waitsem);
|
2021-10-28 08:49:31 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&openpriv->lock);
|
2021-10-28 08:49:31 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-29 06:55:17 +01:00
|
|
|
ret = circbuf_read(&openpriv->circbuf, buffer, len);
|
2021-10-28 08:49:31 +02:00
|
|
|
|
|
|
|
out:
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&openpriv->lock);
|
2021-10-28 08:49:31 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-11-30 17:47:59 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: touch_ioctl
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-10-28 08:49:31 +02:00
|
|
|
static int touch_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
|
|
|
{
|
2024-07-24 14:09:25 +02:00
|
|
|
FAR struct touch_openpriv_s *openpriv = filep->f_priv;
|
|
|
|
FAR struct inode *inode = filep->f_inode;
|
|
|
|
FAR struct touch_upperhalf_s *upper = inode->i_private;
|
|
|
|
FAR struct touch_lowerhalf_s *lower = upper->lower;
|
2021-10-28 08:49:31 +02:00
|
|
|
int ret;
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&upper->lock);
|
2021-10-28 08:49:31 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-07-24 14:09:25 +02:00
|
|
|
switch (cmd)
|
2021-10-28 08:49:31 +02:00
|
|
|
{
|
2024-07-24 14:09:25 +02:00
|
|
|
case TSIOC_GRAB:
|
|
|
|
{
|
|
|
|
int enable = (int)arg;
|
|
|
|
ret = OK;
|
|
|
|
if (enable)
|
|
|
|
{
|
|
|
|
if (upper->grab != NULL)
|
|
|
|
{
|
|
|
|
ret = -EBUSY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
upper->grab = openpriv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (upper->grab != openpriv)
|
|
|
|
{
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
upper->grab = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
if (lower->control)
|
|
|
|
{
|
|
|
|
ret = lower->control(lower, cmd, arg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = -ENOTTY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2021-10-28 08:49:31 +02:00
|
|
|
}
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&upper->lock);
|
2021-10-28 08:49:31 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-11-30 17:47:59 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: touch_poll
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-11-29 06:55:17 +01:00
|
|
|
static int touch_poll(FAR struct file *filep, struct pollfd *fds, bool setup)
|
2021-10-28 08:49:31 +02:00
|
|
|
{
|
2021-11-29 06:55:17 +01:00
|
|
|
FAR struct touch_openpriv_s *openpriv = filep->f_priv;
|
2021-10-28 08:49:31 +02:00
|
|
|
pollevent_t eventset = 0;
|
|
|
|
int ret;
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&openpriv->lock);
|
2021-10-28 08:49:31 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setup)
|
|
|
|
{
|
2021-11-29 06:55:17 +01:00
|
|
|
if (openpriv->fds == NULL)
|
2021-10-28 08:49:31 +02:00
|
|
|
{
|
2021-11-29 06:55:17 +01:00
|
|
|
openpriv->fds = fds;
|
|
|
|
fds->priv = &openpriv->fds;
|
2021-10-28 08:49:31 +02:00
|
|
|
}
|
2021-11-29 06:55:17 +01:00
|
|
|
else
|
2021-10-28 08:49:31 +02:00
|
|
|
{
|
2021-11-29 06:55:17 +01:00
|
|
|
ret = -EBUSY;
|
2021-10-28 08:49:31 +02:00
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
2021-11-29 06:55:17 +01:00
|
|
|
if (!circbuf_is_empty(&openpriv->circbuf))
|
2021-10-28 08:49:31 +02:00
|
|
|
{
|
2022-09-19 05:08:57 +02:00
|
|
|
eventset |= POLLIN;
|
2021-10-28 08:49:31 +02:00
|
|
|
}
|
|
|
|
|
2023-11-19 12:19:53 +01:00
|
|
|
poll_notify(&fds, 1, eventset);
|
2021-10-28 08:49:31 +02:00
|
|
|
}
|
|
|
|
else if (fds->priv)
|
|
|
|
{
|
2021-11-29 06:55:17 +01:00
|
|
|
openpriv->fds = NULL;
|
2023-11-19 12:19:53 +01:00
|
|
|
fds->priv = NULL;
|
2021-10-28 08:49:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
errout:
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&openpriv->lock);
|
2021-10-28 08:49:31 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-07-24 14:09:25 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: touch_event_notify
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void touch_event_notify(FAR struct touch_openpriv_s *openpriv,
|
|
|
|
FAR const struct touch_sample_s *sample)
|
|
|
|
{
|
|
|
|
int semcount;
|
|
|
|
|
|
|
|
circbuf_overwrite(&openpriv->circbuf, sample,
|
|
|
|
SIZEOF_TOUCH_SAMPLE_S(sample->npoints));
|
|
|
|
|
|
|
|
nxsem_get_value(&openpriv->waitsem, &semcount);
|
|
|
|
if (semcount < 1)
|
|
|
|
{
|
|
|
|
nxsem_post(&openpriv->waitsem);
|
|
|
|
}
|
|
|
|
|
|
|
|
poll_notify(&openpriv->fds, 1, POLLIN);
|
|
|
|
}
|
|
|
|
|
2021-10-28 08:49:31 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Function
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-11-30 17:47:59 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: touch_event
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-10-28 08:49:31 +02:00
|
|
|
void touch_event(FAR void *priv, FAR const struct touch_sample_s *sample)
|
|
|
|
{
|
|
|
|
FAR struct touch_upperhalf_s *upper = priv;
|
2021-11-29 06:55:17 +01:00
|
|
|
FAR struct touch_openpriv_s *openpriv;
|
2021-10-28 08:49:31 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
if (nxmutex_lock(&upper->lock) < 0)
|
2021-10-28 08:49:31 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-07-24 14:09:25 +02:00
|
|
|
if (upper->grab)
|
2021-10-28 08:49:31 +02:00
|
|
|
{
|
2024-07-24 14:09:25 +02:00
|
|
|
touch_event_notify(upper->grab, sample);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
list_for_every_entry(&upper->head, openpriv,
|
|
|
|
struct touch_openpriv_s, node)
|
2021-11-29 06:55:17 +01:00
|
|
|
{
|
2024-07-24 14:09:25 +02:00
|
|
|
touch_event_notify(openpriv, sample);
|
2021-11-29 06:55:17 +01:00
|
|
|
}
|
2021-10-28 08:49:31 +02:00
|
|
|
}
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&upper->lock);
|
2021-10-28 08:49:31 +02:00
|
|
|
}
|
|
|
|
|
2022-11-30 17:47:59 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: touch_register
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-10-28 08:49:31 +02:00
|
|
|
int touch_register(FAR struct touch_lowerhalf_s *lower,
|
2021-11-29 06:55:17 +01:00
|
|
|
FAR const char *path, uint8_t nums)
|
2021-10-28 08:49:31 +02:00
|
|
|
{
|
|
|
|
FAR struct touch_upperhalf_s *upper;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
iinfo("Registering %s\n", path);
|
|
|
|
|
2021-11-29 06:55:17 +01:00
|
|
|
if (lower == NULL || nums == 0)
|
2021-10-28 08:49:31 +02:00
|
|
|
{
|
|
|
|
ierr("ERROR: invalid touchscreen device\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
upper = kmm_zalloc(sizeof(struct touch_upperhalf_s));
|
|
|
|
if (!upper)
|
|
|
|
{
|
|
|
|
ierr("ERROR: Failed to mem alloc!\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2021-11-29 06:55:17 +01:00
|
|
|
lower->priv = upper;
|
|
|
|
upper->lower = lower;
|
|
|
|
upper->nums = nums;
|
|
|
|
list_initialize(&upper->head);
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_init(&upper->lock);
|
2021-10-28 08:49:31 +02:00
|
|
|
|
|
|
|
ret = register_driver(path, &g_touch_fops, 0666, upper);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_destroy(&upper->lock);
|
2021-11-29 06:55:17 +01:00
|
|
|
kmm_free(upper);
|
|
|
|
return ret;
|
2021-10-28 08:49:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-11-30 17:47:59 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: touch_unregister
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-10-28 08:49:31 +02:00
|
|
|
void touch_unregister(FAR struct touch_lowerhalf_s *lower,
|
|
|
|
FAR const char *path)
|
|
|
|
{
|
|
|
|
FAR struct touch_upperhalf_s *upper;
|
|
|
|
|
|
|
|
DEBUGASSERT(lower != NULL);
|
|
|
|
DEBUGASSERT(lower->priv != NULL);
|
|
|
|
|
|
|
|
upper = lower->priv;
|
|
|
|
iinfo("UnRegistering %s\n", path);
|
|
|
|
unregister_driver(path);
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_destroy(&upper->lock);
|
2021-10-28 08:49:31 +02:00
|
|
|
kmm_free(upper);
|
|
|
|
}
|