From 03cf1d1a0c5bd6d905675ab8bf27ee38873252d3 Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Wed, 24 Jan 2024 14:38:18 +0100 Subject: [PATCH] feat(fbdev): add docs and allow forcing refresh (#5444) --- docs/integration/driver/display/fbdev.rst | 41 +++++++++++++++++++++++ docs/integration/driver/display/index.rst | 3 ++ src/display/lv_display.c | 1 + src/drivers/display/fb/lv_linux_fbdev.c | 14 ++++++++ src/drivers/display/fb/lv_linux_fbdev.h | 6 ++++ 5 files changed, 65 insertions(+) create mode 100644 docs/integration/driver/display/fbdev.rst diff --git a/docs/integration/driver/display/fbdev.rst b/docs/integration/driver/display/fbdev.rst new file mode 100644 index 000000000..89dd6499d --- /dev/null +++ b/docs/integration/driver/display/fbdev.rst @@ -0,0 +1,41 @@ +======================== +Linux Framebuffer Driver +======================== + +Overview +------------- + +The Linux framebuffer (fbdev) is a linux subsystem used to display graphics. It is a hardware-independent API that gives user space software +access to the framebuffer (the part of a computer's video memory containing a current video frame) using only the Linux kernel's own basic +facilities and its device file system interface, avoiding the need for libraries that implement video drivers in user space. + +Prerequisites +------------- + +Your system has a framebuffer device configured (usually under ``/dev/fb0``). + +Configuring the driver +---------------------- + +Enable the framebuffer driver support in lv_conf.h, by cmake compiler define or by KConfig. Additionally you may configure the rendering +mode. + +.. code:: c + + #define LV_USE_LINUX_FBDEV 1 + #define LV_LINUX_FBDEV_RENDER_MODE LV_DISPLAY_RENDER_MODE_PARTIAL + +Usage +----- + +To set up a framebuffer-based display, first create a display with ``lv_linux_fbdev_create``. Afterwards set the framebuffer device +node on the display (usually this is ``/dev/fb0``). + +.. code:: c + + lv_display_t *disp = lv_linux_fbdev_create(); + lv_linux_fbdev_set_file(disp, "/dev/fb0"); + +If your screen stays black or only draws partially, you can try enabling direct rendering via ``LV_DISPLAY_RENDER_MODE_DIRECT``. Additionally, +you can activate a force refresh mode with ``lv_linux_fbdev_set_force_refresh(true)``. This usually has a performance impact though and shouldn't +be enabled unless really needed. diff --git a/docs/integration/driver/display/index.rst b/docs/integration/driver/display/index.rst index 04c0d2986..ad1a8760c 100644 --- a/docs/integration/driver/display/index.rst +++ b/docs/integration/driver/display/index.rst @@ -5,7 +5,10 @@ Display .. toctree:: :maxdepth: 2 + fbdev + gen_mipi ili9341 + lcd_stm32_hal st7735 st7789 st7796 diff --git a/src/display/lv_display.c b/src/display/lv_display.c index 313602a3a..36c482f8f 100644 --- a/src/display/lv_display.c +++ b/src/display/lv_display.c @@ -84,6 +84,7 @@ lv_display_t * lv_display_create(int32_t hor_res, int32_t ver_res) disp->layer_head->color_format = disp->color_format; disp->inv_en_cnt = 1; + disp->last_activity_time = lv_tick_get(); _lv_ll_init(&disp->sync_areas, sizeof(lv_area_t)); diff --git a/src/drivers/display/fb/lv_linux_fbdev.c b/src/drivers/display/fb/lv_linux_fbdev.c index c835efa80..0a4deb54a 100644 --- a/src/drivers/display/fb/lv_linux_fbdev.c +++ b/src/drivers/display/fb/lv_linux_fbdev.c @@ -59,6 +59,7 @@ typedef struct { char * fbp; long int screensize; int fbfd; + bool force_refresh; } lv_linux_fb_t; /********************** @@ -238,6 +239,12 @@ void lv_linux_fbdev_set_file(lv_display_t * disp, const char * file) hor_res, ver_res, lv_display_get_dpi(disp)); } +void lv_linux_fbdev_set_force_refresh(lv_display_t * disp, bool enabled) +{ + lv_linux_fb_t * dsc = lv_display_get_driver_data(disp); + dsc->force_refresh = enabled; +} + /********************** * STATIC FUNCTIONS **********************/ @@ -275,6 +282,13 @@ static void flush_cb(lv_display_t * disp, const lv_area_t * area, uint8_t * colo } } + if(dsc->force_refresh) { + dsc->vinfo.activate |= FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE; + if(ioctl(dsc->fbfd, FBIOPUT_VSCREENINFO, &(dsc->vinfo)) == -1) { + perror("Error setting var screen info"); + } + } + lv_display_flush_ready(disp); } diff --git a/src/drivers/display/fb/lv_linux_fbdev.h b/src/drivers/display/fb/lv_linux_fbdev.h index b94723c9f..c14e9734c 100644 --- a/src/drivers/display/fb/lv_linux_fbdev.h +++ b/src/drivers/display/fb/lv_linux_fbdev.h @@ -33,6 +33,12 @@ lv_display_t * lv_linux_fbdev_create(void); void lv_linux_fbdev_set_file(lv_display_t * disp, const char * file); +/** + * Force the display to be refreshed on every change. + * Expected to be used with LV_DISPLAY_RENDER_MODE_DIRECT or LV_DISPLAY_RENDER_MODE_FULL. + */ +void lv_linux_fbdev_set_force_refresh(lv_display_t * disp, bool enabled); + /********************** * MACROS **********************/