Gary-Hobson commented on a change in pull request #5736: URL: https://github.com/apache/incubator-nuttx/pull/5736#discussion_r826999233
########## File path: drivers/input/uinput.c ########## @@ -73,30 +154,173 @@ static void uinput_button_enable(FAR const struct btn_lowerhalf_s *lower, FAR void *arg); #endif +#endif /* CONFIG_UINPUT_BUTTONS */ + +#ifdef CONFIG_UINPUT_KEYBOARD + +static ssize_t uinput_keyboard_notify(FAR struct uinput_context_s *ctx, + 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 */ + /**************************************************************************** * Private Functions ****************************************************************************/ -#ifdef CONFIG_INPUT_TOUCHSCREEN +#ifdef CONFIG_UINPUT_RPMSG /**************************************************************************** - * Name: uinput_touch_write + * uinput_rpmsg_ept_cb ****************************************************************************/ -static ssize_t uinput_touch_write(FAR struct touch_lowerhalf_s *lower, - FAR const char *buffer, size_t buflen) +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) { - FAR const struct touch_sample_s *sample; + 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) Review comment: done ########## File path: drivers/input/uinput.c ########## @@ -73,30 +154,173 @@ static void uinput_button_enable(FAR const struct btn_lowerhalf_s *lower, FAR void *arg); #endif +#endif /* CONFIG_UINPUT_BUTTONS */ + +#ifdef CONFIG_UINPUT_KEYBOARD + +static ssize_t uinput_keyboard_notify(FAR struct uinput_context_s *ctx, + 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 */ + /**************************************************************************** * Private Functions ****************************************************************************/ -#ifdef CONFIG_INPUT_TOUCHSCREEN +#ifdef CONFIG_UINPUT_RPMSG /**************************************************************************** - * Name: uinput_touch_write + * uinput_rpmsg_ept_cb ****************************************************************************/ -static ssize_t uinput_touch_write(FAR struct touch_lowerhalf_s *lower, - FAR const char *buffer, size_t buflen) +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) { - FAR const struct touch_sample_s *sample; + 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) + { + ierr("Failed to alloc memory\n"); + return; + } - sample = (FAR const struct touch_sample_s *)buffer; - if (sample == NULL) + ept->ept.priv = ctx; + snprintf(rpmsg_ept_name, RPMSG_NAME_SIZE, + RPMSG_UINPUT_NAME, ctx->name); + ret = rpmsg_create_ept(&ept->ept, rdev, rpmsg_ept_name, + RPMSG_ADDR_ANY, RPMSG_ADDR_ANY, + uinput_rpmsg_ept_cb, NULL); + if (ret < 0) { - return -EINVAL; + 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); + rpmsg_destroy_ept(priv); + 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, + uinput_rpmsg_device_destroy, NULL); +} + +/**************************************************************************** + * Name: uinput_rpmsg_notify + ****************************************************************************/ + +static void uinput_rpmsg_notify(FAR struct uinput_context_s *ctx, + FAR const char *buffer, size_t buflen) +{ + int ret; + FAR struct uinput_rpmsg_ept_s *ept; + + list_for_every_entry(&ctx->eptlist, ept, struct uinput_rpmsg_ept_s, node) + { + if (!is_rpmsg_ept_ready(&ept->ept)) Review comment: done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org