2021-11-19 06:24:06 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* drivers/input/uinput.c
|
|
|
|
*
|
|
|
|
* Licensed 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>
|
|
|
|
|
2022-02-18 08:21:36 +01:00
|
|
|
#include <assert.h>
|
|
|
|
#include <debug.h>
|
2021-11-19 06:24:06 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
nuttx/list: rename container_of to list_container_of from public header
Use private naming to avoid conflicts with user applications
In file included from libuv/src/unix/internal.h:25,
from libuv/src/unix/udp.c:23:
libuv/src/uv-common.h:57: warning: "container_of" redefined
57 | #define container_of(ptr, type, member) \
|
In file included from nuttx/include/nuttx/list.h:47,
from nuttx/include/nuttx/tls.h:40,
from nuttx/include/nuttx/sched.h:48,
from nuttx/include/nuttx/arch.h:87,
from nuttx/include/nuttx/userspace.h:35,
from nuttx/include/nuttx/mm/mm.h:30,
from nuttx/include/nuttx/kmalloc.h:34,
from nuttx/include/nuttx/lib/lib.h:31,
from nuttx/include/stdio.h:35,
from apps/system/libuv/libuv/include/uv.h:59,
from libuv/src/unix/udp.c:22:
nuttx/include/nuttx/nuttx.h:48: note: this is the location of the previous definition
48 | #define container_of(ptr, type, member) \
|
Signed-off-by: chao an <anchao@lixiang.com>
2024-02-29 03:19:49 +01:00
|
|
|
#include <nuttx/nuttx.h>
|
2021-12-24 09:30:36 +01:00
|
|
|
#include <nuttx/input/buttons.h>
|
2022-02-18 14:36:43 +01:00
|
|
|
#include <nuttx/input/keyboard.h>
|
2021-11-19 06:24:06 +01:00
|
|
|
#include <nuttx/input/touchscreen.h>
|
|
|
|
#include <nuttx/input/uinput.h>
|
2021-12-24 09:30:36 +01:00
|
|
|
#include <nuttx/kmalloc.h>
|
2022-02-18 08:21:36 +01:00
|
|
|
#include <nuttx/list.h>
|
|
|
|
|
|
|
|
#ifdef CONFIG_UINPUT_RPMSG
|
|
|
|
# include <nuttx/rptun/openamp.h>
|
|
|
|
#endif
|
2021-11-19 06:24:06 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-03-19 16:58:19 +01:00
|
|
|
#define UINPUT_NAME_SIZE 16
|
|
|
|
#define UINPUT_NAME_RPMSG "rpmsg-uinput-%s"
|
|
|
|
|
|
|
|
#define UINPUT_NAME_TOUCH "utouch"
|
|
|
|
#define UINPUT_NAME_KEYBOARD "ukeyboard"
|
|
|
|
#define UINPUT_NAME_BUTTON "ubutton"
|
2021-11-19 06:24:06 +01:00
|
|
|
|
2021-12-24 09:30:36 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-02-18 08:21:36 +01:00
|
|
|
#ifdef CONFIG_UINPUT_RPMSG
|
|
|
|
|
|
|
|
struct uinput_rpmsg_ept_s
|
|
|
|
{
|
|
|
|
struct rpmsg_endpoint ept;
|
|
|
|
struct rpmsg_device *rdev;
|
|
|
|
struct list_node node;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct uinput_context_s
|
|
|
|
{
|
|
|
|
char name[UINPUT_NAME_SIZE];
|
|
|
|
struct list_node eptlist;
|
|
|
|
ssize_t (*notify)(FAR void *uinput_lower,
|
|
|
|
FAR const char *buffer,
|
|
|
|
size_t buflen);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* CONFIG_UINPUT_RPMSG */
|
|
|
|
|
2023-01-11 16:24:05 +01:00
|
|
|
#ifdef CONFIG_UINPUT_TOUCH
|
2022-02-18 08:21:36 +01:00
|
|
|
struct uinput_touch_lowerhalf_s
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_UINPUT_RPMSG
|
|
|
|
struct uinput_context_s ctx;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct touch_lowerhalf_s lower;
|
|
|
|
};
|
2023-01-11 16:24:05 +01:00
|
|
|
#endif
|
2022-02-18 08:21:36 +01:00
|
|
|
|
2023-01-11 16:24:05 +01:00
|
|
|
#ifdef CONFIG_UINPUT_BUTTONS
|
2021-12-24 09:30:36 +01:00
|
|
|
struct uinput_button_lowerhalf_s
|
|
|
|
{
|
2022-02-18 08:21:36 +01:00
|
|
|
#ifdef CONFIG_UINPUT_RPMSG
|
|
|
|
struct uinput_context_s ctx;
|
|
|
|
#endif
|
|
|
|
|
2021-12-24 09:30:36 +01:00
|
|
|
struct btn_lowerhalf_s lower;
|
|
|
|
btn_buttonset_t buttons;
|
|
|
|
btn_handler_t handler;
|
|
|
|
FAR void *arg;
|
|
|
|
};
|
2023-01-11 16:24:05 +01:00
|
|
|
#endif
|
2021-12-24 09:30:36 +01:00
|
|
|
|
2023-01-11 16:24:05 +01:00
|
|
|
#ifdef CONFIG_UINPUT_KEYBOARD
|
2022-02-18 14:36:43 +01:00
|
|
|
struct uinput_keyboard_lowerhalf_s
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_UINPUT_RPMSG
|
|
|
|
struct uinput_context_s ctx;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct keyboard_lowerhalf_s lower;
|
|
|
|
};
|
2023-01-11 16:24:05 +01:00
|
|
|
#endif
|
2022-02-18 14:36:43 +01:00
|
|
|
|
2021-11-19 06:24:06 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-02-18 08:21:36 +01:00
|
|
|
#ifdef CONFIG_UINPUT_RPMSG
|
|
|
|
|
|
|
|
static int uinput_rpmsg_ept_cb(FAR struct rpmsg_endpoint *ept,
|
|
|
|
FAR void *data, size_t len,
|
|
|
|
uint32_t src, FAR void *priv);
|
|
|
|
|
|
|
|
static void uinput_rpmsg_device_created(FAR struct rpmsg_device *rdev,
|
|
|
|
FAR void *priv);
|
|
|
|
|
|
|
|
static void uinput_rpmsg_device_destroy(FAR struct rpmsg_device *rdev,
|
|
|
|
FAR void *priv);
|
|
|
|
|
|
|
|
static int uinput_rpmsg_initialize(FAR struct uinput_context_s *ctx,
|
|
|
|
FAR const char *name);
|
|
|
|
|
|
|
|
static void uinput_rpmsg_notify(FAR struct uinput_context_s *ctx,
|
|
|
|
FAR const char *buffer, size_t buflen);
|
|
|
|
|
|
|
|
#endif /* CONFIG_UINPUT_RPMSG */
|
|
|
|
|
2022-03-19 17:36:35 +01:00
|
|
|
#ifdef CONFIG_UINPUT_TOUCH
|
2022-02-17 04:00:03 +01:00
|
|
|
|
2022-02-18 08:21:36 +01:00
|
|
|
static ssize_t uinput_touch_notify(FAR void *uinput_lower,
|
|
|
|
FAR const char *buffer, size_t buflen);
|
|
|
|
|
2021-11-19 06:24:06 +01:00
|
|
|
static ssize_t uinput_touch_write(FAR struct touch_lowerhalf_s *lower,
|
|
|
|
FAR const char *buffer, size_t buflen);
|
2021-12-24 09:30:36 +01:00
|
|
|
|
2022-03-19 17:36:35 +01:00
|
|
|
#endif /* CONFIG_UINPUT_TOUCH */
|
2022-02-17 04:00:03 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_UINPUT_BUTTONS
|
|
|
|
|
2022-02-18 08:21:36 +01:00
|
|
|
static ssize_t uinput_button_notify(FAR void *uinput_lower,
|
|
|
|
FAR const char *buffer, size_t buflen);
|
|
|
|
|
2021-12-24 09:30:36 +01:00
|
|
|
static ssize_t uinput_button_write(FAR const struct btn_lowerhalf_s *lower,
|
|
|
|
FAR const char *buffer, size_t buflen);
|
|
|
|
|
|
|
|
static btn_buttonset_t uinput_button_supported(FAR const struct
|
|
|
|
btn_lowerhalf_s *lower);
|
|
|
|
|
|
|
|
static btn_buttonset_t uinput_button_buttons(FAR const struct
|
|
|
|
btn_lowerhalf_s *lower);
|
|
|
|
|
|
|
|
static void uinput_button_enable(FAR const struct btn_lowerhalf_s *lower,
|
|
|
|
btn_buttonset_t press,
|
|
|
|
btn_buttonset_t release,
|
|
|
|
btn_handler_t handler,
|
|
|
|
FAR void *arg);
|
2022-02-17 04:00:03 +01:00
|
|
|
|
|
|
|
#endif /* CONFIG_UINPUT_BUTTONS */
|
2021-11-19 06:24:06 +01:00
|
|
|
|
2022-02-18 14:36:43 +01:00
|
|
|
#ifdef CONFIG_UINPUT_KEYBOARD
|
|
|
|
|
|
|
|
static ssize_t uinput_keyboard_notify(FAR void *uinput_lower,
|
|
|
|
FAR const char *buffer, size_t buflen);
|
|
|
|
|
|
|
|
static ssize_t uinput_keyboard_write(FAR struct keyboard_lowerhalf_s *lower,
|
|
|
|
FAR const char *buffer, size_t buflen);
|
|
|
|
|
|
|
|
#endif /* CONFIG_UINPUT_KEYBOARD */
|
|
|
|
|
2021-11-19 06:24:06 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-02-18 08:21:36 +01:00
|
|
|
#ifdef CONFIG_UINPUT_RPMSG
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* uinput_rpmsg_ept_cb
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int uinput_rpmsg_ept_cb(FAR struct rpmsg_endpoint *ept,
|
|
|
|
FAR void *data, size_t len,
|
|
|
|
uint32_t src, FAR void *priv)
|
|
|
|
{
|
|
|
|
FAR struct uinput_context_s *ctx = priv;
|
|
|
|
|
|
|
|
ctx->notify(ctx, data, len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* uinput_rpmsg_device_created
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void uinput_rpmsg_device_created(FAR struct rpmsg_device *rdev,
|
|
|
|
FAR void *priv)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
char rpmsg_ept_name[RPMSG_NAME_SIZE];
|
|
|
|
FAR struct uinput_rpmsg_ept_s *ept;
|
|
|
|
FAR struct uinput_context_s *ctx = (FAR struct uinput_context_s *)priv;
|
|
|
|
FAR struct list_node *list = &ctx->eptlist;
|
|
|
|
|
|
|
|
ept = kmm_zalloc(sizeof(struct uinput_rpmsg_ept_s));
|
|
|
|
if (ept == NULL)
|
|
|
|
{
|
|
|
|
ierr("Failed to alloc memory\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ept->ept.priv = ctx;
|
|
|
|
snprintf(rpmsg_ept_name, sizeof(rpmsg_ept_name),
|
2022-03-19 16:58:19 +01:00
|
|
|
UINPUT_NAME_RPMSG, ctx->name);
|
2022-02-18 08:21:36 +01:00
|
|
|
ret = rpmsg_create_ept(&ept->ept, rdev, rpmsg_ept_name,
|
|
|
|
RPMSG_ADDR_ANY, RPMSG_ADDR_ANY,
|
|
|
|
uinput_rpmsg_ept_cb, NULL);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
ierr("uinput rpmsg create failure, %s\n", rpmsg_get_cpuname(rdev));
|
|
|
|
kmm_free(ept);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ept->rdev = rdev;
|
|
|
|
list_add_tail(list, &ept->node);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* uinput_rpmsg_device_destroy
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void uinput_rpmsg_device_destroy(FAR struct rpmsg_device *rdev,
|
|
|
|
FAR void *priv)
|
|
|
|
{
|
|
|
|
FAR struct uinput_context_s *ctx = (FAR struct uinput_context_s *)priv;
|
|
|
|
FAR struct list_node *list = &ctx->eptlist;
|
|
|
|
FAR struct uinput_rpmsg_ept_s *ept;
|
|
|
|
|
|
|
|
list_for_every_entry(list, ept, struct uinput_rpmsg_ept_s, node)
|
|
|
|
{
|
|
|
|
if (ept->rdev == rdev)
|
|
|
|
{
|
|
|
|
list_delete(&ept->node);
|
2023-08-07 15:49:49 +02:00
|
|
|
rpmsg_destroy_ept(&ept->ept);
|
2022-02-18 08:21:36 +01:00
|
|
|
kmm_free(ept);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: uinput_rpmsg_initialize
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int uinput_rpmsg_initialize(FAR struct uinput_context_s *ctx,
|
|
|
|
FAR const char *name)
|
|
|
|
{
|
|
|
|
list_initialize(&ctx->eptlist);
|
|
|
|
strlcpy(ctx->name, name, UINPUT_NAME_SIZE);
|
|
|
|
return rpmsg_register_callback(ctx, uinput_rpmsg_device_created,
|
2022-06-06 10:38:11 +02:00
|
|
|
uinput_rpmsg_device_destroy, NULL, NULL);
|
2022-02-18 08:21:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: uinput_rpmsg_notify
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void uinput_rpmsg_notify(FAR struct uinput_context_s *ctx,
|
|
|
|
FAR const char *buffer, size_t buflen)
|
|
|
|
{
|
|
|
|
FAR struct uinput_rpmsg_ept_s *ept;
|
|
|
|
|
|
|
|
list_for_every_entry(&ctx->eptlist, ept, struct uinput_rpmsg_ept_s, node)
|
|
|
|
{
|
2022-04-06 11:09:16 +02:00
|
|
|
if (is_rpmsg_ept_ready(&ept->ept))
|
2022-02-18 08:21:36 +01:00
|
|
|
{
|
|
|
|
if (rpmsg_send(&ept->ept, buffer, buflen) < 0)
|
|
|
|
{
|
|
|
|
ierr("uinput rpmsg send failed, cpu : %s\n",
|
|
|
|
rpmsg_get_cpuname(ept->rdev));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_UINPUT_RPMSG */
|
|
|
|
|
2022-03-19 17:36:35 +01:00
|
|
|
#ifdef CONFIG_UINPUT_TOUCH
|
2021-12-24 09:30:36 +01:00
|
|
|
|
2022-02-18 08:21:36 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: uinput_touch_notify
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static ssize_t uinput_touch_notify(FAR void *uinput_lower,
|
|
|
|
FAR const char *buffer, size_t buflen)
|
|
|
|
{
|
|
|
|
FAR struct uinput_touch_lowerhalf_s *utcs_lower =
|
|
|
|
(FAR struct uinput_touch_lowerhalf_s *)uinput_lower;
|
|
|
|
FAR const struct touch_sample_s *sample =
|
|
|
|
(FAR const struct touch_sample_s *)buffer;
|
|
|
|
|
|
|
|
touch_event(utcs_lower->lower.priv, sample);
|
|
|
|
return buflen;
|
|
|
|
}
|
|
|
|
|
2021-11-19 06:24:06 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: uinput_touch_write
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static ssize_t uinput_touch_write(FAR struct touch_lowerhalf_s *lower,
|
|
|
|
FAR const char *buffer, size_t buflen)
|
|
|
|
{
|
2022-02-18 08:21:36 +01:00
|
|
|
FAR struct uinput_touch_lowerhalf_s *utcs_lower =
|
|
|
|
container_of(lower, struct uinput_touch_lowerhalf_s, lower);
|
2021-11-19 06:24:06 +01:00
|
|
|
|
2022-02-18 08:21:36 +01:00
|
|
|
#ifdef CONFIG_UINPUT_RPMSG
|
|
|
|
uinput_rpmsg_notify(&utcs_lower->ctx, buffer, buflen);
|
|
|
|
#endif
|
2021-11-19 06:24:06 +01:00
|
|
|
|
2022-02-18 08:21:36 +01:00
|
|
|
return uinput_touch_notify(utcs_lower, buffer, buflen);
|
2021-11-19 06:24:06 +01:00
|
|
|
}
|
2021-12-24 09:30:36 +01:00
|
|
|
|
2022-03-19 17:36:35 +01:00
|
|
|
#endif /* CONFIG_UINPUT_TOUCH */
|
2021-12-24 09:30:36 +01:00
|
|
|
|
2022-02-17 04:00:03 +01:00
|
|
|
#ifdef CONFIG_UINPUT_BUTTONS
|
2022-01-24 05:43:13 +01:00
|
|
|
|
2021-12-24 09:30:36 +01:00
|
|
|
/****************************************************************************
|
2022-02-18 08:21:36 +01:00
|
|
|
* Name: uinput_button_notify
|
2021-12-24 09:30:36 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2022-02-18 08:21:36 +01:00
|
|
|
static ssize_t uinput_button_notify(FAR void *uinput_lower,
|
|
|
|
FAR const char *buffer, size_t buflen)
|
2021-12-24 09:30:36 +01:00
|
|
|
{
|
|
|
|
FAR struct uinput_button_lowerhalf_s *ubtn_lower =
|
2022-02-18 08:21:36 +01:00
|
|
|
(FAR struct uinput_button_lowerhalf_s *)uinput_lower;
|
2021-12-24 09:30:36 +01:00
|
|
|
|
|
|
|
if (buflen != sizeof(btn_buttonset_t))
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ubtn_lower->buttons = *(btn_buttonset_t *)buffer;
|
2022-02-18 08:21:36 +01:00
|
|
|
if (ubtn_lower->handler != NULL)
|
|
|
|
{
|
|
|
|
ubtn_lower->handler(&ubtn_lower->lower, ubtn_lower->arg);
|
|
|
|
}
|
2021-12-24 09:30:36 +01:00
|
|
|
|
|
|
|
return buflen;
|
|
|
|
}
|
|
|
|
|
2022-02-18 08:21:36 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: uinput_button_write
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static ssize_t uinput_button_write(FAR const struct btn_lowerhalf_s *lower,
|
|
|
|
FAR const char *buffer, size_t buflen)
|
|
|
|
{
|
|
|
|
FAR struct uinput_button_lowerhalf_s *ubtn_lower =
|
|
|
|
container_of(lower, struct uinput_button_lowerhalf_s, lower);
|
|
|
|
|
|
|
|
#ifdef CONFIG_UINPUT_RPMSG
|
|
|
|
uinput_rpmsg_notify(&ubtn_lower->ctx, buffer, buflen);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return uinput_button_notify(ubtn_lower, buffer, buflen);
|
|
|
|
}
|
|
|
|
|
2021-12-24 09:30:36 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: uinput_button_supported
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-02-18 08:21:36 +01:00
|
|
|
static btn_buttonset_t
|
|
|
|
uinput_button_supported(FAR const struct btn_lowerhalf_s *lower)
|
2021-12-24 09:30:36 +01:00
|
|
|
{
|
|
|
|
return ~0u;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: uinput_button_buttons
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static btn_buttonset_t
|
|
|
|
uinput_button_buttons(FAR const struct btn_lowerhalf_s *lower)
|
|
|
|
{
|
|
|
|
FAR struct uinput_button_lowerhalf_s *ubtn_lower =
|
2022-02-18 08:21:36 +01:00
|
|
|
container_of(lower, struct uinput_button_lowerhalf_s, lower);
|
2021-12-24 09:30:36 +01:00
|
|
|
return ubtn_lower->buttons;
|
|
|
|
}
|
|
|
|
|
2022-01-24 05:43:13 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: uinput_button_enable
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-12-24 09:30:36 +01:00
|
|
|
static void uinput_button_enable(FAR const struct btn_lowerhalf_s *lower,
|
|
|
|
btn_buttonset_t press,
|
|
|
|
btn_buttonset_t release,
|
|
|
|
btn_handler_t handler, FAR void *arg)
|
|
|
|
{
|
|
|
|
FAR struct uinput_button_lowerhalf_s *ubtn_lower =
|
2022-02-18 08:21:36 +01:00
|
|
|
container_of(lower, struct uinput_button_lowerhalf_s, lower);
|
2021-12-24 09:30:36 +01:00
|
|
|
ubtn_lower->arg = arg;
|
|
|
|
ubtn_lower->handler = handler;
|
|
|
|
}
|
|
|
|
|
2022-02-17 04:00:03 +01:00
|
|
|
#endif /* CONFIG_UINPUT_BUTTONS */
|
2021-11-19 06:24:06 +01:00
|
|
|
|
2022-02-18 14:36:43 +01:00
|
|
|
#ifdef CONFIG_UINPUT_KEYBOARD
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: uinput_keyboard_notify
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static ssize_t uinput_keyboard_notify(FAR void *uinput_lower,
|
|
|
|
FAR const char *buffer, size_t buflen)
|
|
|
|
{
|
|
|
|
FAR struct uinput_keyboard_lowerhalf_s *ukbd_lower =
|
|
|
|
(FAR struct uinput_keyboard_lowerhalf_s *)uinput_lower;
|
|
|
|
FAR struct keyboard_event_s *key = (FAR struct keyboard_event_s *)buffer;
|
|
|
|
|
|
|
|
keyboard_event(&ukbd_lower->lower, key->code, key->type);
|
|
|
|
return buflen;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: uinput_keyboard_write
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static ssize_t uinput_keyboard_write(FAR struct keyboard_lowerhalf_s *lower,
|
|
|
|
FAR const char *buffer, size_t buflen)
|
|
|
|
{
|
|
|
|
FAR struct keyboard_event_s *key = (FAR struct keyboard_event_s *)buffer;
|
|
|
|
FAR struct uinput_keyboard_lowerhalf_s *ukbd_lower =
|
|
|
|
container_of(lower, struct uinput_keyboard_lowerhalf_s, lower);
|
|
|
|
|
|
|
|
if (key == NULL || buflen != sizeof(struct keyboard_event_s))
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_UINPUT_RPMSG
|
|
|
|
uinput_rpmsg_notify(&ukbd_lower->ctx, buffer, buflen);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return uinput_keyboard_notify(ukbd_lower, buffer, buflen);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_UINPUT_KEYBOARD */
|
|
|
|
|
2021-11-19 06:24:06 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: uinput_touch_initialize
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Initialized the uinput touchscreen device
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2022-03-19 16:58:19 +01:00
|
|
|
* None
|
2021-11-19 06:24:06 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero is returned on success. Otherwise, a negated errno value is
|
|
|
|
* returned to indicate the nature of the failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-03-19 17:36:35 +01:00
|
|
|
#ifdef CONFIG_UINPUT_TOUCH
|
2022-02-17 04:00:03 +01:00
|
|
|
|
2022-03-19 16:58:19 +01:00
|
|
|
int uinput_touch_initialize(void)
|
2021-11-19 06:24:06 +01:00
|
|
|
{
|
2022-02-18 08:21:36 +01:00
|
|
|
FAR struct uinput_touch_lowerhalf_s *utcs_lower;
|
2022-01-24 05:43:13 +01:00
|
|
|
int ret;
|
2021-11-19 06:24:06 +01:00
|
|
|
|
2022-02-18 08:21:36 +01:00
|
|
|
utcs_lower = kmm_zalloc(sizeof(struct uinput_touch_lowerhalf_s));
|
|
|
|
if (utcs_lower == NULL)
|
2021-11-19 06:24:06 +01:00
|
|
|
{
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2022-02-18 08:21:36 +01:00
|
|
|
utcs_lower->lower.write = uinput_touch_write;
|
2022-03-19 16:58:19 +01:00
|
|
|
utcs_lower->lower.maxpoint = CONFIG_UINPUT_TOUCH_MAXPOINT;
|
2022-02-18 08:21:36 +01:00
|
|
|
#ifdef CONFIG_UINPUT_RPMSG
|
|
|
|
utcs_lower->ctx.notify = uinput_touch_notify;
|
|
|
|
#endif
|
2021-11-19 06:24:06 +01:00
|
|
|
|
2022-02-18 08:21:36 +01:00
|
|
|
/* Regiest Touchscreen device */
|
2022-01-24 05:43:13 +01:00
|
|
|
|
2022-03-19 16:58:19 +01:00
|
|
|
ret = touch_register(&utcs_lower->lower,
|
|
|
|
"/dev/" UINPUT_NAME_TOUCH,
|
|
|
|
CONFIG_UINPUT_TOUCH_BUFNUMBER);
|
2022-01-24 05:43:13 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2022-02-18 08:21:36 +01:00
|
|
|
kmm_free(utcs_lower);
|
|
|
|
return ret;
|
2022-01-24 05:43:13 +01:00
|
|
|
}
|
2021-11-19 06:24:06 +01:00
|
|
|
|
2022-02-18 08:21:36 +01:00
|
|
|
#ifdef CONFIG_UINPUT_RPMSG
|
2022-03-19 16:58:19 +01:00
|
|
|
uinput_rpmsg_initialize(&utcs_lower->ctx, UINPUT_NAME_TOUCH);
|
2022-02-18 08:21:36 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
2021-11-19 06:24:06 +01:00
|
|
|
}
|
2022-02-17 04:00:03 +01:00
|
|
|
|
2022-03-19 17:36:35 +01:00
|
|
|
#endif /* CONFIG_UINPUT_TOUCH */
|
2022-01-24 05:43:13 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: uinput_button_initialize
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Initialized the uinput button device
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2022-03-19 16:58:19 +01:00
|
|
|
* None
|
2022-01-24 05:43:13 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero is returned on success. Otherwise, a negated errno value is
|
|
|
|
* returned to indicate the nature of the failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2021-12-24 09:30:36 +01:00
|
|
|
|
2022-02-17 04:00:03 +01:00
|
|
|
#ifdef CONFIG_UINPUT_BUTTONS
|
|
|
|
|
2022-03-19 16:58:19 +01:00
|
|
|
int uinput_button_initialize(void)
|
2021-12-24 09:30:36 +01:00
|
|
|
{
|
|
|
|
FAR struct uinput_button_lowerhalf_s *ubtn_lower;
|
2022-01-24 05:43:13 +01:00
|
|
|
int ret;
|
2021-12-24 09:30:36 +01:00
|
|
|
|
|
|
|
ubtn_lower = kmm_zalloc(sizeof(struct uinput_button_lowerhalf_s));
|
|
|
|
ubtn_lower->lower.bl_buttons = uinput_button_buttons;
|
|
|
|
ubtn_lower->lower.bl_enable = uinput_button_enable;
|
|
|
|
ubtn_lower->lower.bl_supported = uinput_button_supported;
|
|
|
|
ubtn_lower->lower.bl_write = uinput_button_write;
|
2022-02-18 08:21:36 +01:00
|
|
|
#ifdef CONFIG_UINPUT_RPMSG
|
|
|
|
ubtn_lower->ctx.notify = uinput_button_notify;
|
|
|
|
#endif
|
2021-12-24 09:30:36 +01:00
|
|
|
|
2022-03-19 16:58:19 +01:00
|
|
|
ret = btn_register("/dev/" UINPUT_NAME_BUTTON, &ubtn_lower->lower);
|
2022-01-24 05:43:13 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
kmm_free(ubtn_lower);
|
2022-02-18 08:21:36 +01:00
|
|
|
ierr("ERROR: uinput button initialize failed\n");
|
|
|
|
return ret;
|
2022-01-24 05:43:13 +01:00
|
|
|
}
|
|
|
|
|
2022-02-18 08:21:36 +01:00
|
|
|
#ifdef CONFIG_UINPUT_RPMSG
|
2022-03-19 16:58:19 +01:00
|
|
|
uinput_rpmsg_initialize(&ubtn_lower->ctx, UINPUT_NAME_BUTTON);
|
2022-02-18 08:21:36 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
2021-12-24 09:30:36 +01:00
|
|
|
}
|
2022-02-17 04:00:03 +01:00
|
|
|
|
|
|
|
#endif /* CONFIG_UINPUT_BUTTONS */
|
2022-02-18 14:36:43 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: uinput_keyboard_initialize
|
|
|
|
*
|
|
|
|
* Description:
|
2022-03-19 16:58:19 +01:00
|
|
|
* None
|
2022-02-18 14:36:43 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* name: keyboard devices name
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero is returned on success. Otherwise, a negated errno value is
|
|
|
|
* returned to indicate the nature of the failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_UINPUT_KEYBOARD
|
|
|
|
|
2022-03-19 16:58:19 +01:00
|
|
|
int uinput_keyboard_initialize(void)
|
2022-02-18 14:36:43 +01:00
|
|
|
{
|
|
|
|
FAR struct uinput_keyboard_lowerhalf_s *ukbd_lower;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ukbd_lower = kmm_zalloc(sizeof(struct uinput_keyboard_lowerhalf_s));
|
|
|
|
if (ukbd_lower == NULL)
|
|
|
|
{
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
ukbd_lower->lower.write = uinput_keyboard_write;
|
|
|
|
|
|
|
|
#ifdef CONFIG_UINPUT_RPMSG
|
|
|
|
ukbd_lower->ctx.notify = uinput_keyboard_notify;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Regiest Touchscreen device */
|
|
|
|
|
2022-03-19 17:06:52 +01:00
|
|
|
ret = keyboard_register(&ukbd_lower->lower,
|
|
|
|
"/dev/" UINPUT_NAME_KEYBOARD,
|
|
|
|
CONFIG_UINPUT_KEYBOARD_BUFNUMBER);
|
2022-02-18 14:36:43 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
kmm_free(ukbd_lower);
|
|
|
|
ierr("ERROR: uinput keyboard initialize failed\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_UINPUT_RPMSG
|
2022-03-19 16:58:19 +01:00
|
|
|
uinput_rpmsg_initialize(&ukbd_lower->ctx, UINPUT_NAME_KEYBOARD);
|
2022-02-18 14:36:43 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_UINPUT_KEYBOARD */
|