This is an automated email from the ASF dual-hosted git repository. jerzy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 7b48320ce6df9e5da0e14e3beeb983c1d15af070 Author: Jerzy Kasenberg <[email protected]> AuthorDate: Mon Sep 11 09:29:52 2023 +0200 lvgl: Display driver optimizations This adds several syscfg values that tweak LVGL build. LV_DISP_DRAW_BUF_LINES (default 10) specifies buffer size in lines. Increasing this number can reduce drawing time but uses more memory. LV_DISP_DOUBLE_BUFFER - when set, allows display driver to draw pixel asynchronously (with DMA). Currently no driver utilizes this. LV_DISP_X_ALIGN/LV_DISP_Y_ALIGN - can specify minimum pixel alignment required by display driver. Currently only DA1469X LCD driver requires LV_DISP_X_ALIGN to be 1. Increasing this number forces LVGL to draw more pixels that library needs. Signed-off-by: Jerzy Kasenberg <[email protected]> --- hw/drivers/display/lvgl/default/lv_conf.h | 4 ++-- hw/drivers/display/lvgl/src/mynewt_lvgl.c | 38 ++++++++++++++++++++++++++++--- hw/drivers/display/lvgl/syscfg.yml | 32 ++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 5 deletions(-) diff --git a/hw/drivers/display/lvgl/default/lv_conf.h b/hw/drivers/display/lvgl/default/lv_conf.h index 4284b00a2..902ba77f2 100644 --- a/hw/drivers/display/lvgl/default/lv_conf.h +++ b/hw/drivers/display/lvgl/default/lv_conf.h @@ -40,10 +40,10 @@ *=========================*/ /*1: use custom malloc/free, 0: use the built-in `lv_mem_alloc()` and `lv_mem_free()`*/ -#define LV_MEM_CUSTOM 0 +#define LV_MEM_CUSTOM MYNEWT_VAL(LV_MEM_CUSTOM) #if LV_MEM_CUSTOM == 0 /*Size of the memory available for `lv_mem_alloc()` in bytes (>= 2kB)*/ - #define LV_MEM_SIZE (48U * 1024U) /*[bytes]*/ + #define LV_MEM_SIZE (MYNEWT_VAL(LV_MEM_SIZE)) /*[bytes]*/ /*Set an address for the memory pool instead of allocating it as a normal array. Can be in external SRAM too.*/ #define LV_MEM_ADR 0 /*0: unused*/ diff --git a/hw/drivers/display/lvgl/src/mynewt_lvgl.c b/hw/drivers/display/lvgl/src/mynewt_lvgl.c index 5c68a42c4..067556063 100644 --- a/hw/drivers/display/lvgl/src/mynewt_lvgl.c +++ b/hw/drivers/display/lvgl/src/mynewt_lvgl.c @@ -50,6 +50,7 @@ init_lv_timer(void) os_callout_reset(&lv_callout, lv_timer_period); } +#define DISP_DRAW_BUF_LINES MYNEWT_VAL(LV_DISP_DRAW_BUF_LINES) /* A static or global variable to store the buffers */ static lv_disp_draw_buf_t disp_buf; /* A variable to hold the drivers. Must be static or global. */ @@ -57,8 +58,36 @@ static lv_disp_drv_t disp_drv; #define DISP_HOR_RES MYNEWT_VAL(LVGL_DISPLAY_HORIZONTAL_RESOLUTION) #define DISP_VERT_RES MYNEWT_VAL(LVGL_DISPLAY_VERTICAL_RESOLUTION) /* Static or global buffer(s). The second buffer is optional */ -static lv_color_t buf_1[DISP_HOR_RES * 10]; -static lv_color_t buf_2[DISP_HOR_RES * 10]; +static lv_color_t buf_1[DISP_HOR_RES * DISP_DRAW_BUF_LINES]; +#if MYNEWT_VAL(LV_DISP_DOUBLE_BUFFER) +static lv_color_t buf_2[DISP_HOR_RES * DISP_DRAW_BUF_LINES]; +#else +#define buf_2 NULL +#endif + +/** Extend the invalidated areas to match with the display drivers requirements + * E.g. round `y` to, 8, 16 ..) on a monochrome display*/ +static void +mynewt_lv_rounder(struct _lv_disp_drv_t *driver, lv_area_t *area) +{ + (void)driver; + uint32_t mask; + + if (MYNEWT_VAL(LV_DISP_X_ALIGN)) { + mask = (1 << MYNEWT_VAL(LV_DISP_X_ALIGN)) - 1; + /* Clear left side bits */ + area->x1 &= ~mask; + /* Set right side bits */ + area->x2 |= mask; + } + if (MYNEWT_VAL(LV_DISP_Y_ALIGN)) { + mask = (1 << MYNEWT_VAL(LV_DISP_Y_ALIGN)) - 1; + /* Clear top side bits */ + area->y1 &= ~mask; + /* Set bottom side bits */ + area->y2 |= mask; + } +} void mynewt_lv_init(void) @@ -70,11 +99,14 @@ mynewt_lv_init(void) lv_init(); /*Initialize `disp_buf` with the buffer(s). With only one buffer use NULL instead buf_2 */ - lv_disp_draw_buf_init(&disp_buf, buf_1, buf_2, DISP_HOR_RES * 10); + lv_disp_draw_buf_init(&disp_buf, buf_1, buf_2, DISP_HOR_RES * DISP_DRAW_BUF_LINES); lv_disp_drv_init(&disp_drv); /* Basic initialization */ disp_drv.draw_buf = &disp_buf; /* Set an initialized buffer */ disp_drv.hor_res = DISP_HOR_RES; /* Set the horizontal resolution in pixels */ disp_drv.ver_res = DISP_VERT_RES; /* Set the vertical resolution in pixels */ + if (MYNEWT_VAL(LV_DISP_X_ALIGN) || MYNEWT_VAL(LV_DISP_Y_ALIGN)) { + disp_drv.rounder_cb = mynewt_lv_rounder; + } mynewt_lv_drv_init(&disp_drv); diff --git a/hw/drivers/display/lvgl/syscfg.yml b/hw/drivers/display/lvgl/syscfg.yml index 6dec4222e..194e8fedf 100644 --- a/hw/drivers/display/lvgl/syscfg.yml +++ b/hw/drivers/display/lvgl/syscfg.yml @@ -164,3 +164,35 @@ syscfg.defs: LV_USE_DEMO_WIDGETS: description: Enable Widgets demo. value: 1 + + LV_MEM_CUSTOM: + description: > + If set to 1 malloc/free/realloc is used by lvgl library instead of + lv_mem_free/lv_mem_alloc. + value: 0 + LV_MEM_SIZE: + description: > + Size of the memory available for `lv_malloc()` in bytes. + value: 49152 + LV_DISP_DRAW_BUF_LINES: + description: > + Number of line for buffer usd for drawing portion of the screen. + value: 10 + LV_DISP_DOUBLE_BUFFER: + description: > + Enable double buffer when LCD interface has asynchronous write more. + It should be set to 1 one DMA is used for transferring color data to + display. + value: 0 + LV_DISP_X_ALIGN: + description: > + Display driver X alignment requirement in bits. + If set to 0 display driver can draw pixels at any point. + If set to value grater than 0 X pixel coordinates will be rounded. + value: 0 + LV_DISP_Y_ALIGN: + description: > + Display driver Y alignment requirement in bits. + If set to 0 display driver can draw pixels at any point. + If set to value grater than 0 X pixel coordinates will be rounded. + value: 0
