1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00

feat(nuttx): add indev cursor display (#7021)

Signed-off-by: jianglianfang <jianglianfang@xiaomi.com>
This commit is contained in:
jianglianfang 2024-10-16 17:40:54 +08:00 committed by GitHub
parent 55876d4f1e
commit 79b3bf1265
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 62 additions and 1 deletions

View File

@ -1829,6 +1829,13 @@ menu "LVGL configuration"
depends on LV_USE_NUTTX depends on LV_USE_NUTTX
default n 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 config LV_USE_LINUX_DRM
bool "Use Linux DRM device" bool "Use Linux DRM device"
default n default n

View File

@ -1126,6 +1126,9 @@
/** Driver for /dev/input */ /** Driver for /dev/input */
#define LV_USE_NUTTX_TOUCHSCREEN 0 #define LV_USE_NUTTX_TOUCHSCREEN 0
/*Touchscreen cursor size in pixels(<=0: disable cursor)*/
#define LV_NUTTX_TOUCHSCREEN_CURSOR_SIZE 0
#endif #endif
/** Driver for /dev/dri/card */ /** Driver for /dev/dri/card */

View File

@ -43,6 +43,7 @@ typedef struct {
/********************** /**********************
* STATIC PROTOTYPES * 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_read(lv_indev_t * drv, lv_indev_data_t * data);
static void touchscreen_delete_cb(lv_event_t * e); static void touchscreen_delete_cb(lv_event_t * e);
static lv_indev_t * touchscreen_init(int fd); 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); close(fd);
} }
indev_set_cursor(indev, LV_NUTTX_TOUCHSCREEN_CURSOR_SIZE);
return indev; return indev;
} }
@ -87,6 +90,32 @@ lv_indev_t * lv_nuttx_touchscreen_create(const char * dev_path)
* STATIC FUNCTIONS * 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, static void conv_touch_sample(lv_indev_t * drv,
lv_indev_data_t * data, lv_indev_data_t * data,
struct touch_sample_s * sample) struct touch_sample_s * sample)
@ -163,7 +192,7 @@ static void touchscreen_delete_cb(lv_event_t * e)
if(touchscreen) { if(touchscreen) {
lv_indev_set_driver_data(indev, NULL); lv_indev_set_driver_data(indev, NULL);
lv_indev_set_read_cb(indev, NULL); lv_indev_set_read_cb(indev, NULL);
indev_set_cursor(indev, -1);
if(touchscreen->fd >= 0) { if(touchscreen->fd >= 0) {
close(touchscreen->fd); close(touchscreen->fd);
touchscreen->fd = -1; touchscreen->fd = -1;

View File

@ -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) void lv_indev_wait_release(lv_indev_t * indev)
{ {
if(indev == NULL)return; if(indev == NULL)return;

View File

@ -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); 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 * Do nothing until the next release
* @param indev pointer to an input device * @param indev pointer to an input device

View File

@ -3655,6 +3655,15 @@
#define LV_USE_NUTTX_TOUCHSCREEN 0 #define LV_USE_NUTTX_TOUCHSCREEN 0
#endif #endif
#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 #endif
/** Driver for /dev/dri/card */ /** Driver for /dev/dri/card */