From 17d0f568c87ad715a386fdbe494fa347712db37b Mon Sep 17 00:00:00 2001 From: bjsylvia Date: Wed, 11 Oct 2023 12:38:36 +0800 Subject: [PATCH] feat(nuttx): refactor Nuttx porting layer (#4634) Signed-off-by: YanXiaowei Co-authored-by: YanXiaowei --- Kconfig | 19 ++- lv_conf_template.h | 12 +- lvgl.h | 7 +- src/dev/nuttx/lv_nuttx_entry.c | 129 ++++++++++++++++++ src/dev/nuttx/lv_nuttx_entry.h | 59 ++++++++ .../{display/fb => nuttx}/lv_nuttx_fbdev.c | 7 +- .../{display/fb => nuttx}/lv_nuttx_fbdev.h | 6 +- src/dev/{display/lcd => nuttx}/lv_nuttx_lcd.c | 3 +- src/dev/{display/lcd => nuttx}/lv_nuttx_lcd.h | 2 +- .../lv_nuttx_touchscreen.c | 4 +- .../lv_nuttx_touchscreen.h | 2 +- src/lv_conf_internal.h | 36 +++-- 12 files changed, 249 insertions(+), 37 deletions(-) create mode 100644 src/dev/nuttx/lv_nuttx_entry.c create mode 100644 src/dev/nuttx/lv_nuttx_entry.h rename src/dev/{display/fb => nuttx}/lv_nuttx_fbdev.c (98%) rename src/dev/{display/fb => nuttx}/lv_nuttx_fbdev.h (87%) rename src/dev/{display/lcd => nuttx}/lv_nuttx_lcd.c (99%) rename src/dev/{display/lcd => nuttx}/lv_nuttx_lcd.h (94%) rename src/dev/{input/touchscreen => nuttx}/lv_nuttx_touchscreen.c (97%) rename src/dev/{input/touchscreen => nuttx}/lv_nuttx_touchscreen.h (95%) diff --git a/Kconfig b/Kconfig index 1d2d19c7b..a068211d6 100644 --- a/Kconfig +++ b/Kconfig @@ -1236,12 +1236,18 @@ menu "LVGL configuration" depends on LV_USE_LINUX_FBDEV && LV_LINUX_FBDEV_CUSTOM_BUFFER default 60 - config LV_USE_NUTTX_FBDEV - bool "Use Nuttx framebuffer device" + config LV_USE_NUTTX + bool "Use Nuttx to open window and handle touchscreen" + default n + + config LV_USE_NUTTX_CUSTOM_INIT + bool "Use Custom Nuttx init API to open window and handle touchscreen" + depends on LV_USE_NUTTX default n config LV_USE_NUTTX_LCD bool "Use NuttX LCD device" + depends on LV_USE_NUTTX default n choice @@ -1272,6 +1278,11 @@ menu "LVGL configuration" depends on LV_USE_NUTTX_LCD && LV_NUTTX_LCD_CUSTOM_BUFFER default 60 + config LV_USE_NUTTX_TOUCHSCREEN + bool "Use NuttX touchscreen driver" + depends on LV_USE_NUTTX + default n + config LV_USE_LINUX_DRM bool "Use Linux DRM device" default n @@ -1279,10 +1290,6 @@ menu "LVGL configuration" config LV_USE_TFT_ESPI bool "Use TFT_eSPI driver" default n - - config LV_USE_NUTTX_TOUCHSCREEN - bool "Use NuttX touchscreen driver" - default n endmenu menu "Examples" diff --git a/lv_conf_template.h b/lv_conf_template.h index a6661de8e..8d36d4235 100644 --- a/lv_conf_template.h +++ b/lv_conf_template.h @@ -754,7 +754,11 @@ #define LV_LINUX_FBDEV_BUFFER_SIZE 60 #endif -#define LV_USE_NUTTX_FBDEV 0 +/*Use Nuttx to open window and handle touchscreen*/ +#define LV_USE_NUTTX 0 + +/*Use Nuttx custom init API to open window and handle touchscreen*/ +#define LV_USE_NUTTX_CUSTOM_INIT 0 /*Driver for /dev/lcd*/ #define LV_USE_NUTTX_LCD 0 @@ -763,15 +767,15 @@ #define LV_NUTTX_LCD_BUFFER_SIZE 60 #endif +/*Driver for /dev/input*/ +#define LV_USE_NUTTX_TOUCHSCREEN 0 + /*Driver for /dev/dri/card*/ #define LV_USE_LINUX_DRM 0 /*Interface for TFT_eSPI*/ #define LV_USE_TFT_ESPI 0 -/*Driver for /dev/input*/ -#define LV_USE_NUTTX_TOUCHSCREEN 0 - /*================== * EXAMPLES *==================*/ diff --git a/lvgl.h b/lvgl.h index f09b334b0..e815e0c68 100644 --- a/lvgl.h +++ b/lvgl.h @@ -118,10 +118,11 @@ extern "C" { #include "src/dev/display/drm/lv_linux_drm.h" #include "src/dev/display/fb/lv_linux_fbdev.h" -#include "src/dev/display/fb/lv_nuttx_fbdev.h" -#include "src/dev/display/lcd/lv_nuttx_lcd.h" -#include "src/dev/input/touchscreen/lv_nuttx_touchscreen.h" +#include "src/dev/nuttx/lv_nuttx_entry.h" +#include "src/dev/nuttx/lv_nuttx_fbdev.h" +#include "src/dev/nuttx/lv_nuttx_touchscreen.h" +#include "src/dev/nuttx/lv_nuttx_lcd.h" #include "src/core/lv_global.h" /********************* diff --git a/src/dev/nuttx/lv_nuttx_entry.c b/src/dev/nuttx/lv_nuttx_entry.c new file mode 100644 index 000000000..50f86877f --- /dev/null +++ b/src/dev/nuttx/lv_nuttx_entry.c @@ -0,0 +1,129 @@ +/** + * @file lv_nuttx_entry.h + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_nuttx_entry.h" + +#if LV_USE_NUTTX + +#include +#include + +#include + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +static uint32_t millis(void); + +/********************** + * STATIC VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +#if LV_ENABLE_GLOBAL_CUSTOM + +/**************************************************************************** + * Name: lv_global_free + ****************************************************************************/ + +static void lv_global_free(void * data) +{ + if(data) { + free(data); + } +} + +/**************************************************************************** + * Name: lv_global_default + ****************************************************************************/ + +lv_global_t * lv_global_default(void) +{ + static int index = -1; + lv_global_t * data; + + if(index < 0) { + index = task_tls_alloc(lv_global_free); + } + + if(index >= 0) { + data = (lv_global_t *)task_tls_get_value(index); + if(data == NULL) { + data = (lv_global_t *)calloc(1, sizeof(lv_global_t)); + task_tls_set_value(index, (uintptr_t)data); + } + } + return data; +} +#endif + +lv_display_t * lv_nuttx_init(lv_nuttx_t * info) +{ + lv_display_t * disp = NULL; + +#if !LV_USE_NUTTX_CUSTOM_INIT + + if(info && info->fb_path) { +#if LV_USE_NUTTX_LCD + disp = lv_nuttx_lcd_create(info->fb_path); +#else + disp = lv_nuttx_fbdev_create(); + if(lv_nuttx_fbdev_set_file(disp, info->fb_path) != 0) { + lv_display_remove(disp); + disp = NULL; + } +#endif + } + + if(info && info->input_path) { +#if LV_USE_NUTTX_TOUCHSCREEN + lv_nuttx_touchscreen_create(info->input_path); +#endif + } + +#else + + disp = lv_nuttx_init_custom(info); +#endif + + lv_tick_set_cb(millis); + + return disp; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +static uint32_t millis(void) +{ + struct timespec ts; + + clock_gettime(CLOCK_MONOTONIC, &ts); + uint32_t tick = ts.tv_sec * 1000 + ts.tv_nsec / 1000000; + + return tick; +} + +#endif /*LV_USE_NUTTX*/ diff --git a/src/dev/nuttx/lv_nuttx_entry.h b/src/dev/nuttx/lv_nuttx_entry.h new file mode 100644 index 000000000..302a0e7a0 --- /dev/null +++ b/src/dev/nuttx/lv_nuttx_entry.h @@ -0,0 +1,59 @@ +/** + * @file lv_nuttx_entry.h + * + */ + +/********************* + * INCLUDES + *********************/ + +#ifndef LV_NUTTX_ENTRY_H +#define LV_NUTTX_ENTRY_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +#include "../../display/lv_display.h" +#include "../../indev/lv_indev.h" + +#if LV_USE_NUTTX + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +typedef struct { + const char * fb_path; + const char * input_path; + bool need_wait_vsync; +} lv_nuttx_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +lv_display_t * lv_nuttx_init(lv_nuttx_t * info); + +#if LV_USE_NUTTX_CUSTOM_INIT +lv_display_t * lv_nuttx_init_custom(lv_nuttx_t * info); +#endif + +/********************** + * MACROS + **********************/ + +#endif /* LV_USE_NUTTX*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* LV_NUTTX_ENTRY_H */ diff --git a/src/dev/display/fb/lv_nuttx_fbdev.c b/src/dev/nuttx/lv_nuttx_fbdev.c similarity index 98% rename from src/dev/display/fb/lv_nuttx_fbdev.c rename to src/dev/nuttx/lv_nuttx_fbdev.c index d595e2a3b..63285150b 100644 --- a/src/dev/display/fb/lv_nuttx_fbdev.c +++ b/src/dev/nuttx/lv_nuttx_fbdev.c @@ -7,7 +7,7 @@ * INCLUDES *********************/ #include "lv_nuttx_fbdev.h" -#if LV_USE_NUTTX_FBDEV +#if LV_USE_NUTTX #include #include @@ -18,8 +18,9 @@ #include #include #include + #include -#include "../../../lvgl_private.h" +#include "../../lvgl_private.h" /********************* * DEFINES @@ -286,4 +287,4 @@ static int fbdev_init_mem2(lv_nuttx_fb_t * dsc) return 0; } -#endif /*LV_USE_NUTTX_FBDEV*/ +#endif /*LV_USE_NUTTX*/ diff --git a/src/dev/display/fb/lv_nuttx_fbdev.h b/src/dev/nuttx/lv_nuttx_fbdev.h similarity index 87% rename from src/dev/display/fb/lv_nuttx_fbdev.h rename to src/dev/nuttx/lv_nuttx_fbdev.h index 873552977..e6b8be39c 100644 --- a/src/dev/display/fb/lv_nuttx_fbdev.h +++ b/src/dev/nuttx/lv_nuttx_fbdev.h @@ -14,9 +14,9 @@ extern "C" { * INCLUDES *********************/ -#include "../../../display/lv_display.h" +#include "lv_nuttx_entry.h" -#if LV_USE_NUTTX_FBDEV +#if LV_USE_NUTTX /********************* * DEFINES @@ -37,7 +37,7 @@ int lv_nuttx_fbdev_set_file(lv_display_t * disp, const char * file); * MACROS **********************/ -#endif /* LV_USE_NUTTX_FBDEV */ +#endif /* LV_USE_NUTTX */ #ifdef __cplusplus } /* extern "C" */ diff --git a/src/dev/display/lcd/lv_nuttx_lcd.c b/src/dev/nuttx/lv_nuttx_lcd.c similarity index 99% rename from src/dev/display/lcd/lv_nuttx_lcd.c rename to src/dev/nuttx/lv_nuttx_lcd.c index 50beb6222..7624d052c 100644 --- a/src/dev/display/lcd/lv_nuttx_lcd.c +++ b/src/dev/nuttx/lv_nuttx_lcd.c @@ -8,6 +8,7 @@ *********************/ #include "lv_nuttx_lcd.h" + #if LV_USE_NUTTX_LCD #include @@ -20,7 +21,7 @@ #include #include -#include "../../../lvgl_private.h" +#include "../../lvgl_private.h" /********************* * DEFINES diff --git a/src/dev/display/lcd/lv_nuttx_lcd.h b/src/dev/nuttx/lv_nuttx_lcd.h similarity index 94% rename from src/dev/display/lcd/lv_nuttx_lcd.h rename to src/dev/nuttx/lv_nuttx_lcd.h index 1e4f1b72a..93c4290a9 100644 --- a/src/dev/display/lcd/lv_nuttx_lcd.h +++ b/src/dev/nuttx/lv_nuttx_lcd.h @@ -14,7 +14,7 @@ extern "C" { * INCLUDES *********************/ -#include "../../../display/lv_display.h" +#include "lv_nuttx_entry.h" #if LV_USE_NUTTX_LCD diff --git a/src/dev/input/touchscreen/lv_nuttx_touchscreen.c b/src/dev/nuttx/lv_nuttx_touchscreen.c similarity index 97% rename from src/dev/input/touchscreen/lv_nuttx_touchscreen.c rename to src/dev/nuttx/lv_nuttx_touchscreen.c index 19ac1bf73..1c0d19883 100644 --- a/src/dev/input/touchscreen/lv_nuttx_touchscreen.c +++ b/src/dev/nuttx/lv_nuttx_touchscreen.c @@ -18,7 +18,7 @@ #include #include #include -#include "../../../lvgl_private.h" +#include "../../lvgl_private.h" /********************* * DEFINES @@ -137,4 +137,4 @@ static lv_indev_t * touchscreen_init(int fd) return touchscreen->indev_drv; } -#endif /*LV_USE_NUTTX_SCREEN*/ +#endif /*LV_USE_NUTTX_TOUCHSCREEN*/ diff --git a/src/dev/input/touchscreen/lv_nuttx_touchscreen.h b/src/dev/nuttx/lv_nuttx_touchscreen.h similarity index 95% rename from src/dev/input/touchscreen/lv_nuttx_touchscreen.h rename to src/dev/nuttx/lv_nuttx_touchscreen.h index 5f4e4c82c..803853b2a 100644 --- a/src/dev/input/touchscreen/lv_nuttx_touchscreen.h +++ b/src/dev/nuttx/lv_nuttx_touchscreen.h @@ -18,7 +18,7 @@ extern "C" { * INCLUDES *********************/ -#include "../../../indev/lv_indev.h" +#include "lv_nuttx_entry.h" #if LV_USE_NUTTX_TOUCHSCREEN diff --git a/src/lv_conf_internal.h b/src/lv_conf_internal.h index 907fe48ed..a9bc1ddfc 100644 --- a/src/lv_conf_internal.h +++ b/src/lv_conf_internal.h @@ -2478,11 +2478,21 @@ #endif #endif -#ifndef LV_USE_NUTTX_FBDEV - #ifdef CONFIG_LV_USE_NUTTX_FBDEV - #define LV_USE_NUTTX_FBDEV CONFIG_LV_USE_NUTTX_FBDEV +/*Use Nuttx to open window and handle touchscreen*/ +#ifndef LV_USE_NUTTX + #ifdef CONFIG_LV_USE_NUTTX + #define LV_USE_NUTTX CONFIG_LV_USE_NUTTX #else - #define LV_USE_NUTTX_FBDEV 0 + #define LV_USE_NUTTX 0 + #endif +#endif + +/*Use Nuttx custom init API to open window and handle touchscreen*/ +#ifndef LV_USE_NUTTX_CUSTOM_INIT + #ifdef CONFIG_LV_USE_NUTTX_CUSTOM_INIT + #define LV_USE_NUTTX_CUSTOM_INIT CONFIG_LV_USE_NUTTX_CUSTOM_INIT + #else + #define LV_USE_NUTTX_CUSTOM_INIT 0 #endif #endif @@ -2511,6 +2521,15 @@ #endif #endif +/*Driver for /dev/input*/ +#ifndef LV_USE_NUTTX_TOUCHSCREEN + #ifdef CONFIG_LV_USE_NUTTX_TOUCHSCREEN + #define LV_USE_NUTTX_TOUCHSCREEN CONFIG_LV_USE_NUTTX_TOUCHSCREEN + #else + #define LV_USE_NUTTX_TOUCHSCREEN 0 + #endif +#endif + /*Driver for /dev/dri/card*/ #ifndef LV_USE_LINUX_DRM #ifdef CONFIG_LV_USE_LINUX_DRM @@ -2529,15 +2548,6 @@ #endif #endif -/*Driver for /dev/input*/ -#ifndef LV_USE_NUTTX_TOUCHSCREEN - #ifdef CONFIG_LV_USE_NUTTX_TOUCHSCREEN - #define LV_USE_NUTTX_TOUCHSCREEN CONFIG_LV_USE_NUTTX_TOUCHSCREEN - #else - #define LV_USE_NUTTX_TOUCHSCREEN 0 - #endif -#endif - /*================== * EXAMPLES *==================*/