From 79b3bf1265fe6310f4ea26913efb9a9cf4805ba5 Mon Sep 17 00:00:00 2001 From: jianglianfang <132983613+jianglianfang@users.noreply.github.com> Date: Wed, 16 Oct 2024 17:40:54 +0800 Subject: [PATCH] feat(nuttx): add indev cursor display (#7021) Signed-off-by: jianglianfang --- Kconfig | 7 ++++++ lv_conf_template.h | 3 +++ src/drivers/nuttx/lv_nuttx_touchscreen.c | 31 +++++++++++++++++++++++- src/indev/lv_indev.c | 6 +++++ src/indev/lv_indev.h | 7 ++++++ src/lv_conf_internal.h | 9 +++++++ 6 files changed, 62 insertions(+), 1 deletion(-) diff --git a/Kconfig b/Kconfig index 810481f66..0d81fa7e4 100644 --- a/Kconfig +++ b/Kconfig @@ -1829,6 +1829,13 @@ menu "LVGL configuration" depends on LV_USE_NUTTX default n + config LV_NUTTX_TOUCHSCREEN_CURSOR_SIZE + int "Touchscreen cursor size in pixels" + depends on LV_USE_NUTTX_TOUCHSCREEN + default 0 + help + Set to 0 to disable cursor, or set to a value greater than 0 to set the cursor size in pixels. + config LV_USE_LINUX_DRM bool "Use Linux DRM device" default n diff --git a/lv_conf_template.h b/lv_conf_template.h index d647c37ec..1acf79073 100644 --- a/lv_conf_template.h +++ b/lv_conf_template.h @@ -1126,6 +1126,9 @@ /** Driver for /dev/input */ #define LV_USE_NUTTX_TOUCHSCREEN 0 + + /*Touchscreen cursor size in pixels(<=0: disable cursor)*/ + #define LV_NUTTX_TOUCHSCREEN_CURSOR_SIZE 0 #endif /** Driver for /dev/dri/card */ diff --git a/src/drivers/nuttx/lv_nuttx_touchscreen.c b/src/drivers/nuttx/lv_nuttx_touchscreen.c index d49f765a3..b34e71021 100644 --- a/src/drivers/nuttx/lv_nuttx_touchscreen.c +++ b/src/drivers/nuttx/lv_nuttx_touchscreen.c @@ -43,6 +43,7 @@ typedef struct { /********************** * STATIC PROTOTYPES **********************/ +static void indev_set_cursor(lv_indev_t * indev, int32_t size); static void touchscreen_read(lv_indev_t * drv, lv_indev_data_t * data); static void touchscreen_delete_cb(lv_event_t * e); static lv_indev_t * touchscreen_init(int fd); @@ -80,6 +81,8 @@ lv_indev_t * lv_nuttx_touchscreen_create(const char * dev_path) close(fd); } + indev_set_cursor(indev, LV_NUTTX_TOUCHSCREEN_CURSOR_SIZE); + return indev; } @@ -87,6 +90,32 @@ lv_indev_t * lv_nuttx_touchscreen_create(const char * dev_path) * STATIC FUNCTIONS **********************/ +static void indev_set_cursor(lv_indev_t * indev, int32_t size) +{ + lv_obj_t * cursor_obj = lv_indev_get_cursor(indev); + if(size <= 0) { + if(cursor_obj) { + lv_obj_delete(cursor_obj); + lv_indev_set_cursor(indev, NULL); + } + } + else { + if(cursor_obj == NULL) { + cursor_obj = lv_obj_create(lv_layer_sys()); + lv_obj_remove_style_all(cursor_obj); + lv_obj_set_style_radius(cursor_obj, LV_RADIUS_CIRCLE, 0); + lv_obj_set_style_bg_opa(cursor_obj, LV_OPA_50, 0); + lv_obj_set_style_bg_color(cursor_obj, lv_color_black(), 0); + lv_obj_set_style_border_width(cursor_obj, 2, 0); + lv_obj_set_style_border_color(cursor_obj, lv_palette_main(LV_PALETTE_GREY), 0); + } + lv_obj_set_size(cursor_obj, size, size); + lv_obj_set_style_translate_x(cursor_obj, -size / 2, 0); + lv_obj_set_style_translate_y(cursor_obj, -size / 2, 0); + lv_indev_set_cursor(indev, cursor_obj); + } +} + static void conv_touch_sample(lv_indev_t * drv, lv_indev_data_t * data, struct touch_sample_s * sample) @@ -163,7 +192,7 @@ static void touchscreen_delete_cb(lv_event_t * e) if(touchscreen) { lv_indev_set_driver_data(indev, NULL); lv_indev_set_read_cb(indev, NULL); - + indev_set_cursor(indev, -1); if(touchscreen->fd >= 0) { close(touchscreen->fd); touchscreen->fd = -1; diff --git a/src/indev/lv_indev.c b/src/indev/lv_indev.c index 4dec48092..cad96151f 100644 --- a/src/indev/lv_indev.c +++ b/src/indev/lv_indev.c @@ -519,6 +519,12 @@ void lv_indev_get_vect(const lv_indev_t * indev, lv_point_t * point) } } +lv_obj_t * lv_indev_get_cursor(lv_indev_t * indev) +{ + if(indev == NULL) return NULL; + return indev->cursor; +} + void lv_indev_wait_release(lv_indev_t * indev) { if(indev == NULL)return; diff --git a/src/indev/lv_indev.h b/src/indev/lv_indev.h index bee5ec1a9..6c3cc727e 100644 --- a/src/indev/lv_indev.h +++ b/src/indev/lv_indev.h @@ -319,6 +319,13 @@ lv_obj_t * lv_indev_get_scroll_obj(const lv_indev_t * indev); */ void lv_indev_get_vect(const lv_indev_t * indev, lv_point_t * point); +/** + * Get the cursor object of an input device (for LV_INDEV_TYPE_POINTER only) + * @param indev pointer to an input device + * @return pointer to the cursor object + */ +lv_obj_t * lv_indev_get_cursor(lv_indev_t * indev); + /** * Do nothing until the next release * @param indev pointer to an input device diff --git a/src/lv_conf_internal.h b/src/lv_conf_internal.h index a8e28b155..3c2d347df 100644 --- a/src/lv_conf_internal.h +++ b/src/lv_conf_internal.h @@ -3655,6 +3655,15 @@ #define LV_USE_NUTTX_TOUCHSCREEN 0 #endif #endif + + /*Touchscreen cursor size in pixels(<=0: disable cursor)*/ + #ifndef LV_NUTTX_TOUCHSCREEN_CURSOR_SIZE + #ifdef CONFIG_LV_NUTTX_TOUCHSCREEN_CURSOR_SIZE + #define LV_NUTTX_TOUCHSCREEN_CURSOR_SIZE CONFIG_LV_NUTTX_TOUCHSCREEN_CURSOR_SIZE + #else + #define LV_NUTTX_TOUCHSCREEN_CURSOR_SIZE 0 + #endif + #endif #endif /** Driver for /dev/dri/card */