From c20d5d81f28b78b450610c223402681e7a435183 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Mon, 11 Jan 2021 07:38:17 -0600 Subject: [PATCH 1/7] Minor fix found in Kconfig (#2005) * Trim trailing whitespace from Kconfig * Replace all tab to space in Kconfig * Add more dependence between opions to Kconfig * Add LV_USE_FONT_SUBPX for LV_FONT_SUBPX_BGR in Kconfig * Fix typo error(LV_USE_DROPBOX->LV_USE_DROPDOWN) in Kconfig * Remove LV_THEME_MATERIAL dependence from the child of LV_THEME_DEFAULT_FLAG since LV_THEME_DEFAULT_FLAG already depends on LV_THEME_MATERIAL * Rename LV_MEM_SIZE_BYTES to LV_MEM_SIZE_KILOBYTES since this opion use KiB as the unit --- Kconfig | 129 +++++++++++++++++++++++++----------------- src/lv_conf_kconfig.h | 4 +- 2 files changed, 80 insertions(+), 53 deletions(-) diff --git a/Kconfig b/Kconfig index f306fe790..865c42e47 100644 --- a/Kconfig +++ b/Kconfig @@ -1,7 +1,7 @@ # Kconfig file for LVGL v7.8.1 menu "LVGL configuration" - + config LV_ATTRIBUTE_FAST_MEM_USE_IRAM bool "Set IRAM as LV_ATTRIBUTE_FAST_MEM" help @@ -47,12 +47,14 @@ menu "LVGL configuration" default 8 if LV_COLOR_DEPTH_8 default 16 if LV_COLOR_DEPTH_16 default 32 if LV_COLOR_DEPTH_32 - + config LV_COLOR_16_SWAP bool "Swap the 2 bytes of RGB565 color. Useful if the display has a 8 bit interface (e.g. SPI)." + depends on LV_COLOR_DEPTH_16 config LV_COLOR_SCREEN_TRANSP bool "Enable screen transparency." + depends on LV_COLOR_DEPTH_32 help Useful for OSD or other overlapping GUIs. Requires `LV_COLOR_DEPTH = 32` colors and the screen's style @@ -95,7 +97,7 @@ menu "LVGL configuration" According to the width of the display (hor. res. / dpi) the displays fall in 4 categories. This is the upper limit for medium displays. - + config LV_DISP_LARGE_LIMIT int "Large display limit" default 70 @@ -103,11 +105,11 @@ menu "LVGL configuration" According to the width of the display (hor. res. / dpi) the displays fall in 4 categories. This is the upper limit for large displays. - + menu "Memory manager settings" config LV_MEM_CUSTOM - bool - prompt "If true use custom malloc/free, otherwise use the built-in `lv_mem_alloc` and `lv_mem_free`" + bool + prompt "If true use custom malloc/free, otherwise use the built-in `lv_mem_alloc` and `lv_mem_free`" config LV_MEM_CUSTOM_INCLUDE string @@ -118,19 +120,19 @@ menu "LVGL configuration" config LV_MEM_CUSTOM_ALLOC string prompt "Wrapper to malloc" - default "malloc" + default "malloc" depends on LV_MEM_CUSTOM config LV_MEM_CUSTOM_FREE string prompt "Wrapper to free" - default "free" + default "free" depends on LV_MEM_CUSTOM - config LV_MEM_SIZE_BYTES - int - prompt "Size of the memory used by `lv_mem_alloc` in kilobytes (>= 2kB)" - range 2 128 + config LV_MEM_SIZE_KILOBYTES + int + prompt "Size of the memory used by `lv_mem_alloc` in kilobytes (>= 2kB)" + range 2 128 default 32 depends on !LV_MEM_CUSTOM @@ -138,7 +140,7 @@ menu "LVGL configuration" bool prompt "Use the standard memcpy and memset instead of LVGL's own functions" endmenu - + menu "Indev device settings" config LV_INDEV_DEF_READ_PERIOD int "Input device read period [ms]." @@ -163,7 +165,7 @@ menu "LVGL configuration" default 3 endmenu - + menu "Feature usage" config LV_USE_ANIMATION bool "Enable the Animations." @@ -208,6 +210,7 @@ menu "LVGL configuration" bool "Enable STM32 DMA2D." config LV_GPU_DMA2D_CMSIS_INCLUDE string "include path of CMSIS header of target processor" + depends on LV_USE_GPU_STM32_DMA2D default "" help e.g. "stm32f769xx.h" or "stm32f429xx.h" @@ -215,6 +218,7 @@ menu "LVGL configuration" bool "Use PXP for CPU off-load on NXP RTxxx platforms." config LV_USE_GPU_NXP_PXP_AUTO_INIT bool "Call lv_gpu_nxp_pxp_init() automatically or manually." + depends on LV_USE_GPU_NXP_PXP help 1: Add default bare metal and FreeRTOS interrupt handling routines for PXP (lv_gpu_nxp_pxp_osa.c) and call @@ -251,7 +255,7 @@ menu "LVGL configuration" bool "Use the functions and types from the older (v7) API if possible." default y if !LV_CONF_MINIMAL endmenu - + menu "Image decoder and cache" config LV_IMG_CF_INDEXED bool "Enable indexed (pallete) images." @@ -280,7 +284,7 @@ menu "LVGL configuration" menu "HAL Settings" config LV_TICK_CUSTOM - bool + bool prompt "Use a custom tick source" config LV_TICK_CUSTOM_INCLUDE @@ -308,13 +312,13 @@ menu "LVGL configuration" config LV_LOG_LEVEL_TRACE bool "Trace - Detailed information" - config LV_LOG_LEVEL_INFO + config LV_LOG_LEVEL_INFO bool "Info - Log important events" - config LV_LOG_LEVEL_WARN + config LV_LOG_LEVEL_WARN bool "Warn - Log if something unwanted happened" config LV_LOG_LEVEL_ERROR bool "Error - Only critical issues" - config LV_LOG_LEVEL_NONE + config LV_LOG_LEVEL_NONE bool "None - Do not log anything" endchoice @@ -330,15 +334,15 @@ menu "LVGL configuration" config LV_LOG_PRINTF bool "Print the log with 'printf'" if LV_USE_LOG help - Use printf for log output. + Use printf for log output. If not set the user needs to register a callback with `lv_log_register_print_cb`. endmenu - + menu "Debug Settings" config LV_USE_DEBUG bool "Enable Debug" - + config LV_USE_ASSERT_NULL bool "Check if the parameter is NULL. (Quite fast)" default y if !LV_CONF_MINIMAL @@ -349,21 +353,21 @@ menu "LVGL configuration" config LV_USE_ASSERT_MEM_INTEGRITY bool "Check the integrity of `lv_mem` after critical operations. (Slow)" - + config LV_USE_ASSERT_STR bool "Search for NULL, very long strings, invalid characters, and unnatural repetitions. (Slow)" - help + help If disabled `LV_USE_ASSERT_NULL` will be performed instead (if it's enabled). - + config LV_USE_ASSERT_OBJ bool "Check NULL, the object's type and existence (e.g. not deleted). (Quite slow)." - help + help If disabled `LV_USE_ASSERT_NULL` will be performed instead (if it's enabled) - + config LV_USE_ASSERT_STYLE bool "Check if the styles are properly initialized. (Fast)" endmenu - + menu "Font usage" config LV_FONT_FMT_TXT_LARGE bool "Enable it if you have fonts with a lot of characters." @@ -372,13 +376,17 @@ menu "LVGL configuration" but with > 10,000 characters if you see issues probably you need to enable it. + config LV_USE_FONT_SUBPX + bool "Enable subpixel rendering." + config LV_FONT_SUBPX_BGR bool "Use BGR instead RGB for sub-pixel rendering." + depends on LV_USE_FONT_SUBPX help Set the pixel order of the display. Important only if "subpx fonts" are used. With "normal" font it doesn't matter. - + menu "Enable built-in fonts" config LV_FONT_MONTSERRAT_8 bool "Enable Montserrat 8" @@ -527,7 +535,7 @@ menu "LVGL configuration" bool "Simsun 16 CJK" select LV_FONT_SIMSUN_16_CJK endchoice - + choice LV_FONT_DEFAULT_NORMAL prompt "Select theme default normal font" default LV_FONT_DEFAULT_NORMAL_MONTSERRAT_16 if !LV_CONF_MINIMAL @@ -617,7 +625,7 @@ menu "LVGL configuration" bool "Simsun 16 CJK" select LV_FONT_SIMSUN_16_CJK endchoice - + choice LV_FONT_DEFAULT_SUBTITLE prompt "Select theme default subtitle font" default LV_FONT_DEFAULT_SUBTITLE_MONTSERRAT_16 if !LV_CONF_MINIMAL @@ -707,7 +715,7 @@ menu "LVGL configuration" bool "Simsun 16 CJK" select LV_FONT_SIMSUN_16_CJK endchoice - + choice LV_FONT_DEFAULT_TITLE prompt "Select theme default title font" default LV_FONT_DEFAULT_TITLE_MONTSERRAT_16 if !LV_CONF_MINIMAL @@ -797,7 +805,7 @@ menu "LVGL configuration" endmenu menu "Theme usage" - menu "Enable theme usage, always enable at least one theme" + menu "Enable theme usage, always enable at least one theme" config LV_THEME_EMPTY bool "Empty: No theme, you can apply your styles as you need." default y if LV_CONF_MINIMAL @@ -808,7 +816,7 @@ menu "LVGL configuration" default y if !LV_CONF_MINIMAL config LV_THEME_MONO bool "Mono: Mono-color theme for monochrome displays" - endmenu + endmenu choice LV_THEME_DEFAULT_INIT prompt "Select theme default init" @@ -830,7 +838,7 @@ menu "LVGL configuration" bool "Default init for mono theme" select LV_THEME_MONO endchoice - + config LV_THEME_DEFAULT_COLOR_PRIMARY hex "Select theme default primary color" range 0x000000 0xFFFFFF @@ -849,7 +857,7 @@ menu "LVGL configuration" choice LV_THEME_DEFAULT_FLAG depends on LV_THEME_MATERIAL - + prompt "Select theme default flag" default LV_THEME_DEFAULT_FLAG_LIGHT help @@ -857,10 +865,8 @@ menu "LVGL configuration" config LV_THEME_DEFAULT_FLAG_LIGHT bool "Light theme" - depends on LV_THEME_MATERIAL config LV_THEME_DEFAULT_FLAG_DARK bool "Dark theme" - depends on LV_THEME_MATERIAL endchoice endmenu @@ -882,39 +888,39 @@ menu "LVGL configuration" config LV_TXT_BREAK_CHARS string "Can break (wrap) texts on these chars" default " ,.;:-_" - + config LV_TXT_LINE_BREAK_LONG_LEN int "Line break long length" default 0 help - If a word is at least this long, will break wherever 'prettiest'. + If a word is at least this long, will break wherever 'prettiest'. To disable, set to a value <= 0. - + config LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN int "Min num chars before break" default 3 + depends on LV_TXT_LINE_BREAK_LONG_LEN > 0 help Minimum number of characters in a long word to put on a line before a break. - Depends on LV_TXT_LINE_BREAK_LONG_LEN - + config LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN int "Min num chars after break" default 3 + depends on LV_TXT_LINE_BREAK_LONG_LEN > 0 help Minimum number of characters in a long word to put on a line after a break. - Depends on LV_TXT_LINE_BREAK_LONG_LEN - + config LV_TXT_COLOR_CMD string "The control character to use for signalling text recoloring" default "#" config LV_USE_BIDI bool "Support bidirectional texts" - help + help Allows mixing Left-to-Right and Right-to-Left texts. The direction will be processed according to the Unicode Bidirectional Algorithm: https://www.w3.org/International/articles/inline-bidi-markup/uba-basics - + choice prompt "Set the default BIDI direction" default LV_BIDI_DIR_AUTO @@ -930,7 +936,7 @@ menu "LVGL configuration" config LV_USE_ARABIC_PERSIAN_CHARS bool "Enable Arabic/Persian processing" - help + help In these languages characters should be replaced with an other form based on their position in the text. @@ -938,14 +944,14 @@ menu "LVGL configuration" bool "Change the built-in (v)snprintf functions" config LV_SPRINTF_DISABLE_FLOAT - bool "Disable float in built-in (v)snprintf functions" if !LV_SPRINTF_CUSTOM + bool "Disable float in built-in (v)snprintf functions" if !LV_SPRINTF_CUSTOM endmenu menu "Widgets" config LV_USE_OBJ_REALIGN bool "Enable `lv_obj_realign()` based on `lv_obj_align()` parameters." default y if !LV_CONF_MINIMAL - + choice prompt "Enable to make the object clickable on a larger area." default LV_USE_EXT_CLICK_AREA_TINY @@ -976,6 +982,7 @@ menu "LVGL configuration" default y if !LV_CONF_MINIMAL config LV_CALENDAR_WEEK_STARTS_MONDAY bool "Calendar week starts monday." + depends on LV_USE_CALENDAR config LV_USE_CANVAS bool "Canvas. Dependencies: lv_img." select LV_USE_IMG @@ -1005,7 +1012,7 @@ menu "LVGL configuration" default y if !LV_CONF_MINIMAL config LV_DROPDOWN_DEF_ANIM_TIME int "Drop down animation time. 0: no animation." - depends on LV_USE_DROPBOX + depends on LV_USE_DROPDOWN default 200 config LV_USE_GAUGE bool "Gauge. Dependencies: lv_bar, lv_linemeter." @@ -1033,13 +1040,17 @@ menu "LVGL configuration" config LV_LABEL_DEF_SCROLL_SPEED int "Hor. or ver. scroll speed [px/sec] in LV_LABEL_LONG_ROLL/ROLL_CIRC mode." default 25 + depends on LV_USE_LABEL config LV_LABEL_WAIT_CHAR_COUNT int "Waiting period at beginning/end of animation cycle." default 3 + depends on LV_USE_LABEL config LV_LABEL_TEXT_SEL bool "Enable selecting text of the label." + depends on LV_USE_LABEL config LV_LABEL_LONG_TXT_HINT bool "Store extra some info in labels (12 bytes) to speed up drawing of very long texts." + depends on LV_USE_LABEL config LV_USE_LED bool "LED." default y if !LV_CONF_MINIMAL @@ -1047,10 +1058,12 @@ menu "LVGL configuration" int "LED minimal brightness." range 0 255 default 120 + depends on LV_USE_LED config LV_LED_BRIGHT_MAX int "LED maximal brightness." range 0 255 default 255 + depends on LV_USE_LED config LV_USE_LINE bool "Line." default y if !LV_CONF_MINIMAL @@ -1064,12 +1077,14 @@ menu "LVGL configuration" config LV_LIST_DEF_ANIM_TIME int "List default animation time of focusing to a list element [ms]. 0: no animation." default 100 + depends on LV_USE_LIST config LV_USE_LINEMETER bool "Line meter." default y if !LV_CONF_MINIMAL choice prompt "Draw line more precisely at cost of performance." default LV_LINEMETER_PRECISE_NO_EXTRA_PRECISION + depends on LV_USE_LINEMETER config LV_LINEMETER_PRECISE_NO_EXTRA_PRECISION bool "0: No extra precision." config LV_LINEMETER_PRECISE_SOME_EXTRA_PRECISION @@ -1093,6 +1108,7 @@ menu "LVGL configuration" config LV_PAGE_DEF_ANIM_TIME int "Focus default animation time [ms]. 0: No animation." default 100 + depends on LV_USE_PAGE config LV_USE_SPINNER bool "Spinner. Dependencies: lv_arc, lv_anim." select LV_USE_ARC @@ -1101,12 +1117,15 @@ menu "LVGL configuration" config LV_SPINNER_DEF_ARC_LENGTH int "Spinner def. arc length [deg]." default 60 + depends on LV_USE_SPINNER config LV_SPINNER_DEF_SPIN_TIME int "Spinner def. spin time [ms]." default 1000 + depends on LV_USE_SPINNER choice prompt "Type of spinner (animation type)." default LV_SPINNER_TYPE_SPINNING_ARC + depends on LV_USE_SPINNER config LV_SPINNER_TYPE_SPINNING_ARC bool "0: Spinner type spinning arc." config LV_SPINNER_TYPE_FILLSPIN_ARC @@ -1121,9 +1140,11 @@ menu "LVGL configuration" config LV_ROLLER_DEF_ANIM_TIME int "Focus animation time [ms]. 0: no animation." default 200 + depends on LV_USE_ROLLER config LV_ROLLER_INF_PAGES int "Number of extra 'pages' when the controller is infinite." default 7 + depends on LV_USE_ROLLER config LV_USE_SLIDER bool "Slider. Dependencies: lv_bar." select LV_USE_BAR @@ -1144,9 +1165,11 @@ menu "LVGL configuration" config LV_TEXTAREA_DEF_CURSOR_BLINK_TIME int "Text area def. cursor blink time [ms]." default 400 + depends on LV_USE_TEXTAREA config LV_TEXTAREA_DEF_PWN_SHOW_TIME int "Text area def. pwn show time [ms]." default 1500 + depends on LV_USE_TEXTAREA config LV_USE_TABLE bool "Table. Dependencies: lv_label." select LV_USE_LABEL @@ -1154,9 +1177,11 @@ menu "LVGL configuration" config LV_TABLE_COL_MAX int "Table col max." default 12 + depends on LV_USE_TABLE config LV_TABLE_CELL_STYLE_CNT int "Table cell style count." default 4 + depends on LV_USE_TABLE config LV_USE_TABVIEW bool "Tab. Dependencies: lv_page, lv_btnm." select LV_USE_PAGE @@ -1165,6 +1190,7 @@ menu "LVGL configuration" config LV_TABVIEW_DEF_ANIM_TIME int "Time of slide animation [ms]. 0: No animation." default 300 + depends on LV_USE_TABVIEW config LV_USE_TILEVIEW bool "Tileview. Dependencies: lv_page." select LV_USE_PAGE @@ -1172,6 +1198,7 @@ menu "LVGL configuration" config LV_TILEVIEW_DEF_ANIM_TIME int "Time of slide animation [ms]. 0: No animation." default 300 + depends on LV_USE_TILEVIEW config LV_USE_WIN bool "Window. Dependencies: lv_cont, lv_btn, lv_label, lv_img, lv_page." select LV_USE_CONT diff --git a/src/lv_conf_kconfig.h b/src/lv_conf_kconfig.h index 648edfa0e..3c88c6011 100644 --- a/src/lv_conf_kconfig.h +++ b/src/lv_conf_kconfig.h @@ -30,8 +30,8 @@ extern "C" { *******************/ #ifndef LV_MEM_SIZE -#if defined (CONFIG_LV_MEM_SIZE_BYTES) -#define CONFIG_LV_MEM_SIZE (CONFIG_LV_MEM_SIZE_BYTES * 1024U) +#if defined (CONFIG_LV_MEM_SIZE_KILOBYTES) +#define CONFIG_LV_MEM_SIZE (CONFIG_LV_MEM_SIZE_KILOBYTES * 1024U) #endif #endif From 138fcfec7955c1f37a5bf2372a25bc08cbcb0dc5 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Tue, 12 Jan 2021 05:00:20 -0600 Subject: [PATCH 2/7] fix(math): Correct the function argument type declaration (#2013) 1.all argument of _lv_bezier3 should be uint32_t since the input and output are unsigned 2.the return type of _lv_map should be int32_t since the type of output range is int32_t 3.remove the unnecessary cast --- src/lv_misc/lv_math.c | 18 +++++++++--------- src/lv_misc/lv_math.h | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/lv_misc/lv_math.c b/src/lv_misc/lv_math.c index b66f75002..45b82cd50 100644 --- a/src/lv_misc/lv_math.c +++ b/src/lv_misc/lv_math.c @@ -83,7 +83,7 @@ LV_ATTRIBUTE_FAST_MEM int16_t _lv_trigo_sin(int16_t angle) * @param u3 end values in range of [0..LV_BEZIER_VAL_MAX] * @return the value calculated from the given parameters in range of [0..LV_BEZIER_VAL_MAX] */ -int32_t _lv_bezier3(uint32_t t, int32_t u0, int32_t u1, int32_t u2, int32_t u3) +uint32_t _lv_bezier3(uint32_t t, uint32_t u0, uint32_t u1, uint32_t u2, uint32_t u3) { uint32_t t_rem = 1024 - t; uint32_t t_rem2 = (t_rem * t_rem) >> 10; @@ -91,10 +91,10 @@ int32_t _lv_bezier3(uint32_t t, int32_t u0, int32_t u1, int32_t u2, int32_t u3) uint32_t t2 = (t * t) >> 10; uint32_t t3 = (t2 * t) >> 10; - uint32_t v1 = ((uint32_t)t_rem3 * u0) >> 10; - uint32_t v2 = ((uint32_t)3 * t_rem2 * t * u1) >> 20; - uint32_t v3 = ((uint32_t)3 * t_rem * t2 * u2) >> 20; - uint32_t v4 = ((uint32_t)t3 * u3) >> 10; + uint32_t v1 = (t_rem3 * u0) >> 10; + uint32_t v2 = (3 * t_rem2 * t * u1) >> 20; + uint32_t v3 = (3 * t_rem * t2 * u2) >> 20; + uint32_t v4 = (t3 * u3) >> 10; return v1 + v2 + v3 + v4; } @@ -118,12 +118,12 @@ LV_ATTRIBUTE_FAST_MEM void _lv_sqrt(uint32_t x, lv_sqrt_res_t * q, uint32_t mask // http://ww1.microchip.com/...en/AppNotes/91040a.pdf do { trial = root + mask; - if((uint32_t)trial * trial <= x) root = trial; + if(trial * trial <= x) root = trial; mask = mask >> 1; } while(mask); - q->i = (uint32_t) root >> 4; - q->f = (uint32_t)(root & 0xf) << 4; + q->i = root >> 4; + q->f = (root & 0xf) << 4; } /** @@ -238,7 +238,7 @@ int64_t _lv_pow(int64_t base, int8_t exp) * @param max_out max output range * @return the mapped number */ -int16_t _lv_map(int32_t x, int32_t min_in, int32_t max_in, int32_t min_out, int32_t max_out) +int32_t _lv_map(int32_t x, int32_t min_in, int32_t max_in, int32_t min_out, int32_t max_out) { if(x <= min_in) return min_out; if(x >= max_in) return max_out; diff --git a/src/lv_misc/lv_math.h b/src/lv_misc/lv_math.h index f734f7b44..1730b4311 100644 --- a/src/lv_misc/lv_math.h +++ b/src/lv_misc/lv_math.h @@ -1,5 +1,5 @@ /** - * @file math_base.h + * @file lv_math.h * */ @@ -74,7 +74,7 @@ LV_ATTRIBUTE_FAST_MEM int16_t _lv_trigo_sin(int16_t angle); * @param u3 end values in range of [0..LV_BEZIER_VAL_MAX] * @return the value calculated from the given parameters in range of [0..LV_BEZIER_VAL_MAX] */ -int32_t _lv_bezier3(uint32_t t, int32_t u0, int32_t u1, int32_t u2, int32_t u3); +uint32_t _lv_bezier3(uint32_t t, uint32_t u0, uint32_t u1, uint32_t u2, uint32_t u3); /** * Calculate the atan2 of a vector. @@ -117,7 +117,7 @@ int64_t _lv_pow(int64_t base, int8_t exp); * @param max_out max output range * @return the mapped number */ -int16_t _lv_map(int32_t x, int32_t min_in, int32_t max_in, int32_t min, int32_t max); +int32_t _lv_map(int32_t x, int32_t min_in, int32_t max_in, int32_t min, int32_t max); /********************** * MACROS From c083d19b52a3f6b9460cb919b15e4e6ad37de1f5 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Tue, 12 Jan 2021 05:07:00 -0600 Subject: [PATCH 3/7] Minor fix found in async module (#2015) * fix(async): Move lv_async_info_t from lv_async.h to lv_async.c since the user don't need know the implementation detail * fix(async): Don't set user_data again since lv_task_create already save it for us --- src/lv_misc/lv_async.c | 7 +++++-- src/lv_misc/lv_async.h | 7 ------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/lv_misc/lv_async.c b/src/lv_misc/lv_async.c index 4336ff09a..41ec144a5 100644 --- a/src/lv_misc/lv_async.c +++ b/src/lv_misc/lv_async.c @@ -17,6 +17,11 @@ * TYPEDEFS **********************/ +typedef struct _lv_async_info_t { + lv_async_cb_t cb; + void * user_data; +} lv_async_info_t; + /********************** * STATIC PROTOTYPES **********************/ @@ -55,8 +60,6 @@ lv_res_t lv_async_call(lv_async_cb_t async_xcb, void * user_data) info->cb = async_xcb; info->user_data = user_data; - /* Set the task's user data */ - task->user_data = info; lv_task_set_repeat_count(task, 1); return LV_RES_OK; } diff --git a/src/lv_misc/lv_async.h b/src/lv_misc/lv_async.h index dafa2fc1a..a3a9330b5 100644 --- a/src/lv_misc/lv_async.h +++ b/src/lv_misc/lv_async.h @@ -30,13 +30,6 @@ extern "C" { */ typedef void (*lv_async_cb_t)(void *); -typedef struct _lv_async_info_t { - lv_async_cb_t cb; - void * user_data; -} lv_async_info_t; - -struct _lv_obj_t; - /********************** * GLOBAL PROTOTYPES **********************/ From 486053012dd970211315efbe9e7f56d77935725c Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Tue, 12 Jan 2021 05:16:02 -0600 Subject: [PATCH 4/7] Various fs module fix and improvement (#2019) * fix(fs): Check driver ready in lv_fs_dir_open and lv_fs_free_space * fix(fs): Avoid the memory leak in lv_fs_open and lv_fs_dir_open * fix(fs): Fix typo error in lv_fs_trunc(tell_cb should be trunc_cb) * fix(fs): Make lv_fs_dir_close same as lv_fs_close when dir_close_cb equals NULL * fix(fs): Handle the struct cleanup correctly * improve(fs): Don't allocate memory when file_size or rddir_size equal zero pass the address of file_d or dir_d to open_cb or dir_open_cb instead, so implementor can point file_d/dir_d to other location. In many cases(POSIX), file system will allocate the context for us, this improvement could avoid we allocate the 4/8 bytes intermediate space. --- src/lv_misc/lv_fs.c | 95 ++++++++++++++++++++++++++++----------------- 1 file changed, 60 insertions(+), 35 deletions(-) diff --git a/src/lv_misc/lv_fs.c b/src/lv_misc/lv_fs.c index 6b9a1e129..e1641eb2b 100644 --- a/src/lv_misc/lv_fs.c +++ b/src/lv_misc/lv_fs.c @@ -95,18 +95,28 @@ lv_fs_res_t lv_fs_open(lv_fs_file_t * file_p, const char * path, lv_fs_mode_t mo file_p->drv = lv_fs_get_drv(letter); if(file_p->drv == NULL) { - file_p->file_d = NULL; return LV_FS_RES_NOT_EX; } if(file_p->drv->ready_cb != NULL) { if(file_p->drv->ready_cb(file_p->drv) == false) { - file_p->drv = NULL; - file_p->file_d = NULL; + file_p->drv = NULL; return LV_FS_RES_HW_ERR; } } + if(file_p->drv->open_cb == NULL) { + file_p->drv = NULL; + return LV_FS_RES_NOT_IMP; + } + + const char * real_path = lv_fs_get_real_path(path); + + if (file_p->drv->file_size == 0) { /*Is file_d zero size?*/ + /*Pass file_d's address to open_cb, so the implementor can allocate memory byself*/ + return file_p->drv->open_cb(file_p->drv, &file_p->file_d, real_path, mode); + } + file_p->file_d = lv_mem_alloc(file_p->drv->file_size); LV_ASSERT_MEM(file_p->file_d); if(file_p->file_d == NULL) { @@ -114,12 +124,7 @@ lv_fs_res_t lv_fs_open(lv_fs_file_t * file_p, const char * path, lv_fs_mode_t mo return LV_FS_RES_OUT_OF_MEM; /* Out of memory */ } - if(file_p->drv->open_cb == NULL) { - return LV_FS_RES_NOT_IMP; - } - - const char * real_path = lv_fs_get_real_path(path); - lv_fs_res_t res = file_p->drv->open_cb(file_p->drv, file_p->file_d, real_path, mode); + lv_fs_res_t res = file_p->drv->open_cb(file_p->drv, file_p->file_d, real_path, mode); if(res != LV_FS_RES_OK) { lv_mem_free(file_p->file_d); @@ -150,7 +155,6 @@ lv_fs_res_t lv_fs_close(lv_fs_file_t * file_p) lv_mem_free(file_p->file_d); /*Clean up*/ file_p->file_d = NULL; file_p->drv = NULL; - file_p->file_d = NULL; return res; } @@ -258,12 +262,12 @@ lv_fs_res_t lv_fs_seek(lv_fs_file_t * file_p, uint32_t pos) lv_fs_res_t lv_fs_tell(lv_fs_file_t * file_p, uint32_t * pos) { if(file_p->drv == NULL) { - pos = 0; + *pos = 0; return LV_FS_RES_INV_PARAM; } if(file_p->drv->tell_cb == NULL) { - pos = 0; + *pos = 0; return LV_FS_RES_NOT_IMP; } @@ -284,7 +288,7 @@ lv_fs_res_t lv_fs_trunc(lv_fs_file_t * file_p) return LV_FS_RES_INV_PARAM; } - if(file_p->drv->tell_cb == NULL) { + if(file_p->drv->trunc_cb == NULL) { return LV_FS_RES_NOT_IMP; } @@ -355,6 +359,9 @@ lv_fs_res_t lv_fs_rename(const char * oldname, const char * newname) */ lv_fs_res_t lv_fs_dir_open(lv_fs_dir_t * rddir_p, const char * path) { + rddir_p->drv = NULL; + rddir_p->dir_d = NULL; + if(path == NULL) return LV_FS_RES_INV_PARAM; char letter = path[0]; @@ -362,25 +369,43 @@ lv_fs_res_t lv_fs_dir_open(lv_fs_dir_t * rddir_p, const char * path) rddir_p->drv = lv_fs_get_drv(letter); if(rddir_p->drv == NULL) { - rddir_p->dir_d = NULL; return LV_FS_RES_NOT_EX; } - rddir_p->dir_d = lv_mem_alloc(rddir_p->drv->rddir_size); - LV_ASSERT_MEM(rddir_p->dir_d); - if(rddir_p->dir_d == NULL) { - rddir_p->dir_d = NULL; - return LV_FS_RES_OUT_OF_MEM; /* Out of memory */ + if(rddir_p->drv->ready_cb != NULL) { + if(rddir_p->drv->ready_cb(rddir_p->drv) == false) { + rddir_p->drv = NULL; + return LV_FS_RES_HW_ERR; + } } if(rddir_p->drv->dir_open_cb == NULL) { + rddir_p->drv = NULL; return LV_FS_RES_NOT_IMP; } const char * real_path = lv_fs_get_real_path(path); + if (rddir_p->drv->rddir_size == 0) { /*Is dir_d zero size?*/ + /*Pass dir_d's address to dir_open_cb, so the implementor can allocate memory byself*/ + return rddir_p->drv->dir_open_cb(rddir_p->drv, &rddir_p->dir_d, real_path); + } + + rddir_p->dir_d = lv_mem_alloc(rddir_p->drv->rddir_size); + LV_ASSERT_MEM(rddir_p->dir_d); + if(rddir_p->dir_d == NULL) { + rddir_p->drv = NULL; + return LV_FS_RES_OUT_OF_MEM; /* Out of memory */ + } + lv_fs_res_t res = rddir_p->drv->dir_open_cb(rddir_p->drv, rddir_p->dir_d, real_path); + if(res != LV_FS_RES_OK) { + lv_mem_free(rddir_p->dir_d); + rddir_p->dir_d = NULL; + rddir_p->drv = NULL; + } + return res; } @@ -399,6 +424,7 @@ lv_fs_res_t lv_fs_dir_read(lv_fs_dir_t * rddir_p, char * fn) } if(rddir_p->drv->dir_read_cb == NULL) { + fn[0] = '\0'; return LV_FS_RES_NOT_IMP; } @@ -418,19 +444,15 @@ lv_fs_res_t lv_fs_dir_close(lv_fs_dir_t * rddir_p) return LV_FS_RES_INV_PARAM; } - lv_fs_res_t res; - if(rddir_p->drv->dir_close_cb == NULL) { - res = LV_FS_RES_NOT_IMP; - } - else { - res = rddir_p->drv->dir_close_cb(rddir_p->drv, rddir_p->dir_d); + return LV_FS_RES_NOT_IMP; } + lv_fs_res_t res = rddir_p->drv->dir_close_cb(rddir_p->drv, rddir_p->dir_d); + lv_mem_free(rddir_p->dir_d); /*Clean up*/ rddir_p->dir_d = NULL; rddir_p->drv = NULL; - rddir_p->dir_d = NULL; return res; } @@ -450,19 +472,22 @@ lv_fs_res_t lv_fs_free_space(char letter, uint32_t * total_p, uint32_t * free_p) return LV_FS_RES_INV_PARAM; } - lv_fs_res_t res; + if(drv->ready_cb != NULL) { + if(drv->ready_cb(drv) == false) { + return LV_FS_RES_HW_ERR; + } + } if(drv->free_space_cb == NULL) { - res = LV_FS_RES_NOT_IMP; + return LV_FS_RES_NOT_IMP; } - else { - uint32_t total_tmp = 0; - uint32_t free_tmp = 0; - res = drv->free_space_cb(drv, &total_tmp, &free_tmp); - if(total_p != NULL) *total_p = total_tmp; - if(free_p != NULL) *free_p = free_tmp; - } + uint32_t total_tmp = 0; + uint32_t free_tmp = 0; + lv_fs_res_t res = drv->free_space_cb(drv, &total_tmp, &free_tmp); + + if(total_p != NULL) *total_p = total_tmp; + if(free_p != NULL) *free_p = free_tmp; return res; } From d6ca15a74923f2e86ce1e4ee6ee83bb2bbc887b8 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Tue, 12 Jan 2021 09:13:41 -0600 Subject: [PATCH 5/7] Move LV_GC_INCLUDE to the common place(gc.h) (#2010) * Move LV_GC_INCLUDE to the common place(gc.h) to avoid the duplication in many source files * fix(theme template): Always initialize _lv_theme_material_styles just like what other theme do --- src/lv_core/lv_group.c | 4 ---- src/lv_core/lv_obj.c | 4 ---- src/lv_core/lv_refr.c | 4 ---- src/lv_draw/lv_draw_mask.c | 4 ---- src/lv_draw/lv_img_cache.c | 3 --- src/lv_draw/lv_img_decoder.c | 4 ---- src/lv_font/lv_font_fmt_txt.c | 4 ---- src/lv_hal/lv_hal_disp.c | 4 ---- src/lv_hal/lv_hal_indev.c | 4 ---- src/lv_misc/lv_anim.c | 4 ---- src/lv_misc/lv_fs.c | 4 ---- src/lv_misc/lv_gc.c | 4 ---- src/lv_misc/lv_gc.h | 1 + src/lv_misc/lv_mem.c | 4 ---- src/lv_misc/lv_task.c | 4 ---- src/lv_themes/lv_theme_empty.c | 4 ---- src/lv_themes/lv_theme_material.c | 4 ---- src/lv_themes/lv_theme_mono.c | 4 ---- src/lv_themes/lv_theme_template.c | 9 --------- 19 files changed, 1 insertion(+), 76 deletions(-) diff --git a/src/lv_core/lv_group.c b/src/lv_core/lv_group.c index 9f2f554dc..ca91a3968 100644 --- a/src/lv_core/lv_group.c +++ b/src/lv_core/lv_group.c @@ -13,10 +13,6 @@ #include "../lv_themes/lv_theme.h" #include "../lv_misc/lv_gc.h" -#if defined(LV_GC_INCLUDE) - #include LV_GC_INCLUDE -#endif /* LV_ENABLE_GC */ - /********************* * DEFINES *********************/ diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index fb409ea16..a03e5cdab 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -30,10 +30,6 @@ #include "../lv_gpu/lv_gpu_nxp_pxp_osa.h" #endif -#if defined(LV_GC_INCLUDE) - #include LV_GC_INCLUDE -#endif /* LV_ENABLE_GC */ - #if defined(LV_USER_DATA_FREE_INCLUDE) #include LV_USER_DATA_FREE_INCLUDE #endif /* LV_USE_USER_DATA_FREE */ diff --git a/src/lv_core/lv_refr.c b/src/lv_core/lv_refr.c index 7572412e4..e8502431b 100644 --- a/src/lv_core/lv_refr.c +++ b/src/lv_core/lv_refr.c @@ -23,10 +23,6 @@ #include "../lv_widgets/lv_label.h" #endif -#if defined(LV_GC_INCLUDE) - #include LV_GC_INCLUDE -#endif /* LV_ENABLE_GC */ - /********************* * DEFINES *********************/ diff --git a/src/lv_draw/lv_draw_mask.c b/src/lv_draw/lv_draw_mask.c index 130c449f0..b74f2b4b2 100644 --- a/src/lv_draw/lv_draw_mask.c +++ b/src/lv_draw/lv_draw_mask.c @@ -12,10 +12,6 @@ #include "../lv_misc/lv_debug.h" #include "../lv_misc/lv_gc.h" -#if defined(LV_GC_INCLUDE) - #include LV_GC_INCLUDE -#endif /* LV_ENABLE_GC */ - /********************* * DEFINES *********************/ diff --git a/src/lv_draw/lv_img_cache.c b/src/lv_draw/lv_img_cache.c index 087d36c27..f5dc99d3c 100644 --- a/src/lv_draw/lv_img_cache.c +++ b/src/lv_draw/lv_img_cache.c @@ -13,9 +13,6 @@ #include "../lv_hal/lv_hal_tick.h" #include "../lv_misc/lv_gc.h" -#if defined(LV_GC_INCLUDE) - #include LV_GC_INCLUDE -#endif /* LV_ENABLE_GC */ /********************* * DEFINES *********************/ diff --git a/src/lv_draw/lv_img_decoder.c b/src/lv_draw/lv_img_decoder.c index c70f32fbe..190edb252 100644 --- a/src/lv_draw/lv_img_decoder.c +++ b/src/lv_draw/lv_img_decoder.c @@ -13,10 +13,6 @@ #include "../lv_misc/lv_color.h" #include "../lv_misc/lv_gc.h" -#if defined(LV_GC_INCLUDE) - #include LV_GC_INCLUDE -#endif /* LV_ENABLE_GC */ - /********************* * DEFINES *********************/ diff --git a/src/lv_font/lv_font_fmt_txt.c b/src/lv_font/lv_font_fmt_txt.c index 75a084772..e6852baec 100644 --- a/src/lv_font/lv_font_fmt_txt.c +++ b/src/lv_font/lv_font_fmt_txt.c @@ -16,10 +16,6 @@ #include "../lv_misc/lv_utils.h" #include "../lv_misc/lv_mem.h" -#if defined(LV_GC_INCLUDE) - #include LV_GC_INCLUDE -#endif /* LV_ENABLE_GC */ - /********************* * DEFINES *********************/ diff --git a/src/lv_hal/lv_hal_disp.c b/src/lv_hal/lv_hal_disp.c index a79987cb6..007fdc367 100644 --- a/src/lv_hal/lv_hal_disp.c +++ b/src/lv_hal/lv_hal_disp.c @@ -19,10 +19,6 @@ #include "../lv_core/lv_refr.h" #include "../lv_themes/lv_theme.h" -#if defined(LV_GC_INCLUDE) - #include LV_GC_INCLUDE -#endif /* LV_ENABLE_GC */ - /********************* * DEFINES *********************/ diff --git a/src/lv_hal/lv_hal_indev.c b/src/lv_hal/lv_hal_indev.c index 2dd402c94..2c088f7e4 100644 --- a/src/lv_hal/lv_hal_indev.c +++ b/src/lv_hal/lv_hal_indev.c @@ -15,10 +15,6 @@ #include "../lv_misc/lv_gc.h" #include "lv_hal_disp.h" -#if defined(LV_GC_INCLUDE) - #include LV_GC_INCLUDE -#endif /* LV_ENABLE_GC */ - /********************* * DEFINES *********************/ diff --git a/src/lv_misc/lv_anim.c b/src/lv_misc/lv_anim.c index ed54cf635..e22487aa5 100644 --- a/src/lv_misc/lv_anim.c +++ b/src/lv_misc/lv_anim.c @@ -17,10 +17,6 @@ #include "lv_math.h" #include "lv_gc.h" -#if defined(LV_GC_INCLUDE) - #include LV_GC_INCLUDE -#endif /* LV_ENABLE_GC */ - /********************* * DEFINES *********************/ diff --git a/src/lv_misc/lv_fs.c b/src/lv_misc/lv_fs.c index e1641eb2b..772f1468b 100644 --- a/src/lv_misc/lv_fs.c +++ b/src/lv_misc/lv_fs.c @@ -14,10 +14,6 @@ #include #include "lv_gc.h" -#if defined(LV_GC_INCLUDE) - #include LV_GC_INCLUDE -#endif /* LV_ENABLE_GC */ - /********************* * DEFINES *********************/ diff --git a/src/lv_misc/lv_gc.c b/src/lv_misc/lv_gc.c index a9b355861..3a37a48c2 100644 --- a/src/lv_misc/lv_gc.c +++ b/src/lv_misc/lv_gc.c @@ -10,10 +10,6 @@ #include "lv_gc.h" #include "string.h" -#if defined(LV_GC_INCLUDE) - #include LV_GC_INCLUDE -#endif /* LV_ENABLE_GC */ - /********************* * DEFINES *********************/ diff --git a/src/lv_misc/lv_gc.h b/src/lv_misc/lv_gc.h index e1d7f4526..2236ab66d 100644 --- a/src/lv_misc/lv_gc.h +++ b/src/lv_misc/lv_gc.h @@ -52,6 +52,7 @@ extern "C" { #if LV_MEM_CUSTOM != 1 #error "GC requires CUSTOM_MEM" #endif /* LV_MEM_CUSTOM */ +#include LV_GC_INCLUDE #else /* LV_ENABLE_GC */ #define LV_GC_ROOT(x) x #define LV_EXTERN_ROOT(root_type, root_name) extern root_type root_name; diff --git a/src/lv_misc/lv_mem.c b/src/lv_misc/lv_mem.c index 33539391b..119ffadc5 100644 --- a/src/lv_misc/lv_mem.c +++ b/src/lv_misc/lv_mem.c @@ -16,10 +16,6 @@ #include LV_MEM_CUSTOM_INCLUDE #endif -#if defined(LV_GC_INCLUDE) - #include LV_GC_INCLUDE -#endif /* LV_ENABLE_GC */ - /********************* * DEFINES *********************/ diff --git a/src/lv_misc/lv_task.c b/src/lv_misc/lv_task.c index 04a240b88..2c2223f5c 100644 --- a/src/lv_misc/lv_task.c +++ b/src/lv_misc/lv_task.c @@ -13,10 +13,6 @@ #include "../lv_hal/lv_hal_tick.h" #include "lv_gc.h" -#if defined(LV_GC_INCLUDE) - #include LV_GC_INCLUDE -#endif /* LV_ENABLE_GC */ - /********************* * DEFINES *********************/ diff --git a/src/lv_themes/lv_theme_empty.c b/src/lv_themes/lv_theme_empty.c index 7d565e475..1d34ee3a4 100644 --- a/src/lv_themes/lv_theme_empty.c +++ b/src/lv_themes/lv_theme_empty.c @@ -13,10 +13,6 @@ #include "../lv_misc/lv_gc.h" -#if defined(LV_GC_INCLUDE) - #include LV_GC_INCLUDE -#endif /* LV_ENABLE_GC */ - /********************* * DEFINES *********************/ diff --git a/src/lv_themes/lv_theme_material.c b/src/lv_themes/lv_theme_material.c index 73d2e618d..6b71dc9f2 100644 --- a/src/lv_themes/lv_theme_material.c +++ b/src/lv_themes/lv_theme_material.c @@ -12,10 +12,6 @@ #include "../lv_misc/lv_gc.h" -#if defined(LV_GC_INCLUDE) - #include LV_GC_INCLUDE -#endif /* LV_ENABLE_GC */ - /********************* * DEFINES *********************/ diff --git a/src/lv_themes/lv_theme_mono.c b/src/lv_themes/lv_theme_mono.c index 0f2b1d233..b27975096 100644 --- a/src/lv_themes/lv_theme_mono.c +++ b/src/lv_themes/lv_theme_mono.c @@ -12,10 +12,6 @@ #include "../lv_misc/lv_gc.h" -#if defined(LV_GC_INCLUDE) - #include LV_GC_INCLUDE -#endif /* LV_ENABLE_GC */ - /********************* * DEFINES *********************/ diff --git a/src/lv_themes/lv_theme_template.c b/src/lv_themes/lv_theme_template.c index 5efa05018..a48af7210 100644 --- a/src/lv_themes/lv_theme_template.c +++ b/src/lv_themes/lv_theme_template.c @@ -12,10 +12,6 @@ #include "../lv_misc/lv_gc.h" -#if defined(LV_GC_INCLUDE) - #include LV_GC_INCLUDE -#endif /* LV_ENABLE_GC */ - /********************* * DEFINES *********************/ @@ -342,13 +338,8 @@ lv_theme_t * lv_theme_template_init(lv_color_t color_primary, lv_color_t color_s * styles' data if LVGL is used in a binding (e.g. Micropython) * In a general case styles could be simple `static lv_style_t my style` variables or allocated directly into `styles`*/ if(!inited) { -#if defined(LV_GC_INCLUDE) LV_GC_ROOT(_lv_theme_template_styles) = lv_mem_alloc(sizeof(theme_styles_t)); styles = (theme_styles_t *)LV_GC_ROOT(_lv_theme_template_styles); -#else - styles = lv_mem_alloc(sizeof(theme_styles_t)); -#endif - } theme.color_primary = color_primary; From 9ca4ffd64db6fb00bc71bada2db232e6337c9b69 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Tue, 12 Jan 2021 10:01:45 -0600 Subject: [PATCH 6/7] fix(format) correct comments in lv_gc.h, lv_ll.h and lv_log.h (#2016) --- src/lv_hal/lv_hal_tick.c | 4 ++-- src/lv_hal/lv_hal_tick.h | 2 +- src/lv_misc/lv_gc.h | 2 +- src/lv_misc/lv_ll.h | 2 +- src/lv_misc/lv_log.h | 10 +++++----- src/lv_misc/lv_printf.h | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/lv_hal/lv_hal_tick.c b/src/lv_hal/lv_hal_tick.c index 3a1a5128a..2ceb7adf6 100644 --- a/src/lv_hal/lv_hal_tick.c +++ b/src/lv_hal/lv_hal_tick.c @@ -1,5 +1,5 @@ /** - * @file systick.c + * @file lv_hal_tick.c * Provide access to the system tick with 1 millisecond resolution */ @@ -76,7 +76,7 @@ uint32_t lv_tick_get(void) /** * Get the elapsed milliseconds since a previous time stamp - * @param prev_tick a previous time stamp (return value of systick_get() ) + * @param prev_tick a previous time stamp (return value of lv_tick_get() ) * @return the elapsed milliseconds since 'prev_tick' */ uint32_t lv_tick_elaps(uint32_t prev_tick) diff --git a/src/lv_hal/lv_hal_tick.h b/src/lv_hal/lv_hal_tick.h index f99d5188c..a6068660c 100644 --- a/src/lv_hal/lv_hal_tick.h +++ b/src/lv_hal/lv_hal_tick.h @@ -51,7 +51,7 @@ uint32_t lv_tick_get(void); /** * Get the elapsed milliseconds since a previous time stamp - * @param prev_tick a previous time stamp (return value of systick_get() ) + * @param prev_tick a previous time stamp (return value of lv_tick_get() ) * @return the elapsed milliseconds since 'prev_tick' */ uint32_t lv_tick_elaps(uint32_t prev_tick); diff --git a/src/lv_misc/lv_gc.h b/src/lv_misc/lv_gc.h index 2236ab66d..915bf39a2 100644 --- a/src/lv_misc/lv_gc.h +++ b/src/lv_misc/lv_gc.h @@ -28,7 +28,7 @@ extern "C" { #define LV_ITERATE_ROOTS(f) \ f(lv_ll_t, _lv_task_ll) /*Linked list to store the lv_tasks*/ \ f(lv_ll_t, _lv_disp_ll) /*Linked list of screens*/ \ - f(lv_ll_t, _lv_indev_ll) /*Linked list of screens*/ \ + f(lv_ll_t, _lv_indev_ll) /*Linked list of input device*/ \ f(lv_ll_t, _lv_drv_ll) \ f(lv_ll_t, _lv_file_ll) \ f(lv_ll_t, _lv_anim_ll) \ diff --git a/src/lv_misc/lv_ll.h b/src/lv_misc/lv_ll.h index 906414d16..a4ce8c64c 100644 --- a/src/lv_misc/lv_ll.h +++ b/src/lv_misc/lv_ll.h @@ -1,5 +1,5 @@ /** - * @file lv_ll.c + * @file lv_ll.h * Handle linked lists. The nodes are dynamically allocated by the 'lv_mem' module. */ diff --git a/src/lv_misc/lv_log.h b/src/lv_misc/lv_log.h index a85427e78..99633a8a2 100644 --- a/src/lv_misc/lv_log.h +++ b/src/lv_misc/lv_log.h @@ -23,12 +23,12 @@ extern "C" { /*Possible log level. For compatibility declare it independently from `LV_USE_LOG`*/ #define LV_LOG_LEVEL_TRACE 0 /**< A lot of logs to give detailed information*/ -#define LV_LOG_LEVEL_INFO 1 /**< Log important events*/ -#define LV_LOG_LEVEL_WARN 2 /**< Log if something unwanted happened but didn't caused problem*/ +#define LV_LOG_LEVEL_INFO 1 /**< Log important events*/ +#define LV_LOG_LEVEL_WARN 2 /**< Log if something unwanted happened but didn't caused problem*/ #define LV_LOG_LEVEL_ERROR 3 /**< Only critical issue, when the system may fail*/ -#define LV_LOG_LEVEL_USER 4 /**< Custom logs from the user*/ -#define LV_LOG_LEVEL_NONE 5 /**< Do not log anything*/ -#define _LV_LOG_LEVEL_NUM 6 /**< Number of log levels */ +#define LV_LOG_LEVEL_USER 4 /**< Custom logs from the user*/ +#define LV_LOG_LEVEL_NONE 5 /**< Do not log anything*/ +#define _LV_LOG_LEVEL_NUM 6 /**< Number of log levels */ LV_EXPORT_CONST_INT(LV_LOG_LEVEL_TRACE); LV_EXPORT_CONST_INT(LV_LOG_LEVEL_INFO); diff --git a/src/lv_misc/lv_printf.h b/src/lv_misc/lv_printf.h index 1f9879f5c..a89617cd0 100644 --- a/src/lv_misc/lv_printf.h +++ b/src/lv_misc/lv_printf.h @@ -64,4 +64,4 @@ int lv_vsnprintf(char * buffer, size_t count, const char * format, va_list va); } #endif -#endif // _PRINTF_H_ +#endif // _LV_PRINTF_H_ From bc25998c5b2acc347eade7d3dac29675d81476b8 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Tue, 12 Jan 2021 12:26:26 -0600 Subject: [PATCH 7/7] Minor fix found in mem module (#2014) * fix(mem): Utilize ALIGN_MASK as much as possible to avoid check LV_ARCH_64 again and again and correct the comment about MEM_UNIT * fix(mem): Simplify _lv_memset implementation by SET8/SET32/REPEAT8 macro * fix(mem): Handle the out of memory gracefully in _lv_mem_buf_get don't modify the state in the failure * fix(mem): Remove the unnecessary memset, memcpy and assignment --- src/lv_misc/lv_mem.c | 121 ++++++++++++++----------------------------- 1 file changed, 38 insertions(+), 83 deletions(-) diff --git a/src/lv_misc/lv_mem.c b/src/lv_misc/lv_mem.c index 119ffadc5..0bcda313c 100644 --- a/src/lv_misc/lv_mem.c +++ b/src/lv_misc/lv_mem.c @@ -40,11 +40,11 @@ #if LV_ENABLE_GC == 0 /*gc custom allocations must not include header*/ -/*The size of this union must be 4 bytes (uint32_t)*/ +/*The size of this union must be 4/8 bytes (uint32_t/uint64_t)*/ typedef union { struct { MEM_UNIT used : 1; /* 1: if the entry is used*/ - MEM_UNIT d_size : 31; /* Size off the data (1 means 4 bytes)*/ + MEM_UNIT d_size : 31; /* Size of the data*/ } s; MEM_UNIT header; /* The header (used + d_size)*/ } lv_mem_header_t; @@ -100,6 +100,7 @@ static lv_mem_buf_t mem_buf_small[] = {{.p = mem_buf1_32, .size = MEM_BUF_SMALL_ #define COPY32 *d32 = *s32; d32++; s32++; #define COPY8 *d8 = *s8; d8++; s8++; #define SET32(x) *d32 = x; d32++; +#define SET8(x) *d8 = x; d8++; #define REPEAT8(expr) expr expr expr expr expr expr expr expr /********************** @@ -117,14 +118,13 @@ void _lv_mem_init(void) /*Allocate a large array to store the dynamically allocated data*/ static LV_MEM_ATTR MEM_UNIT work_mem_int[LV_MEM_SIZE / sizeof(MEM_UNIT)]; work_mem = (uint8_t *)work_mem_int; - mem_max_size = 0; #else work_mem = (uint8_t *)LV_MEM_ADR; #endif lv_mem_ent_t * full = (lv_mem_ent_t *)work_mem; full->header.s.used = 0; - /*The total mem size id reduced by the first header and the close patterns */ + /*The total mem size reduced by the first header and the close patterns */ full->header.s.d_size = LV_MEM_SIZE - sizeof(lv_mem_header_t); #endif } @@ -136,10 +136,9 @@ void _lv_mem_init(void) void _lv_mem_deinit(void) { #if LV_MEM_CUSTOM == 0 - _lv_memset_00(work_mem, (LV_MEM_SIZE / sizeof(MEM_UNIT)) * sizeof(MEM_UNIT)); lv_mem_ent_t * full = (lv_mem_ent_t *)work_mem; full->header.s.used = 0; - /*The total mem size id reduced by the first header and the close patterns */ + /*The total mem size reduced by the first header and the close patterns */ full->header.s.d_size = LV_MEM_SIZE - sizeof(lv_mem_header_t); #endif } @@ -155,13 +154,8 @@ void * lv_mem_alloc(size_t size) return &zero_mem; } -#ifdef LV_ARCH_64 - /*Round the size up to 8*/ - size = (size + 7) & (~0x7); -#else - /*Round the size up to 4*/ - size = (size + 3) & (~0x3); -#endif + /*Round the size up to ALIGN_MASK*/ + size = (size + ALIGN_MASK) & (~ALIGN_MASK); void * alloc = NULL; #if LV_MEM_CUSTOM == 0 @@ -260,7 +254,6 @@ void lv_mem_free(const void * data) lv_mem_defrag(); } - #endif /*LV_MEM_AUTO_DEFRAG*/ #else /*Use custom, user defined free function*/ #if LV_ENABLE_GC == 0 @@ -283,14 +276,8 @@ void lv_mem_free(const void * data) void * lv_mem_realloc(void * data_p, size_t new_size) { - -#ifdef LV_ARCH_64 - /*Round the size up to 8*/ - new_size = (new_size + 7) & (~0x7); -#else - /*Round the size up to 4*/ - new_size = (new_size + 3) & (~0x3); -#endif + /*Round the size up to ALIGN_MASK*/ + new_size = (new_size + ALIGN_MASK) & (~ALIGN_MASK); /*data_p could be previously freed pointer (in this case it is invalid)*/ if(data_p != NULL) { @@ -321,10 +308,10 @@ void * lv_mem_realloc(void * data_p, size_t new_size) if(data_p != NULL) { /*Copy the old data to the new. Use the smaller size*/ - if(old_size != 0) { + if(old_size != 0 && new_size != 0) { _lv_memcpy(new_p, data_p, LV_MATH_MIN(new_size, old_size)); - lv_mem_free(data_p); } + lv_mem_free(data_p); } return new_p; @@ -415,9 +402,8 @@ void lv_mem_monitor(lv_mem_monitor_t * mon_p) _lv_memset(mon_p, 0, sizeof(lv_mem_monitor_t)); #if LV_MEM_CUSTOM == 0 lv_mem_ent_t * e; - e = NULL; - e = ent_get_next(e); + e = ent_get_next(NULL); while(e != NULL) { if(e->header.s.used == 0) { @@ -435,13 +421,13 @@ void lv_mem_monitor(lv_mem_monitor_t * mon_p) } mon_p->total_size = LV_MEM_SIZE; mon_p->max_used = mem_max_size; - mon_p->used_pct = 100 - (100U * mon_p->free_size) / mon_p->total_size; + mon_p->used_pct = 100 - (100U * mon_p->free_size) / mon_p->total_size; if(mon_p->free_size > 0) { - mon_p->frag_pct = (uint32_t)mon_p->free_biggest_size * 100U / mon_p->free_size; - mon_p->frag_pct = 100 - mon_p->frag_pct; + mon_p->frag_pct = mon_p->free_biggest_size * 100U / mon_p->free_size; + mon_p->frag_pct = 100 - mon_p->frag_pct; } else { - mon_p->frag_pct = 0; /*no fragmentation if all the RAM is used*/ + mon_p->frag_pct = 0; /*no fragmentation if all the RAM is used*/ } #endif } @@ -518,14 +504,16 @@ void * _lv_mem_buf_get(uint32_t size) /*Reallocate a free buffer*/ for(i = 0; i < LV_MEM_BUF_MAX_NUM; i++) { if(LV_GC_ROOT(_lv_mem_buf[i]).used == 0) { + /*if this fails you probably need to increase your LV_MEM_SIZE/heap size*/ + void * buf = lv_mem_realloc(LV_GC_ROOT(_lv_mem_buf[i]).p, size); + if(buf == NULL) { + LV_DEBUG_ASSERT(false, "Out of memory, can't allocate a new buffer (increase your LV_MEM_SIZE/heap size)", 0x00); + return NULL; + } LV_GC_ROOT(_lv_mem_buf[i]).used = 1; LV_GC_ROOT(_lv_mem_buf[i]).size = size; - /*if this fails you probably need to increase your LV_MEM_SIZE/heap size*/ - LV_GC_ROOT(_lv_mem_buf[i]).p = lv_mem_realloc(LV_GC_ROOT(_lv_mem_buf[i]).p, size); - if(LV_GC_ROOT(_lv_mem_buf[i]).p == NULL) { - LV_DEBUG_ASSERT(false, "Out of memory, can't allocate a new buffer (increase your LV_MEM_SIZE/heap size", 0x00); - } - return LV_GC_ROOT(_lv_mem_buf[i]).p; + LV_GC_ROOT(_lv_mem_buf[i]).p = buf; + return LV_GC_ROOT(_lv_mem_buf[i]).p; } } @@ -659,8 +647,7 @@ LV_ATTRIBUTE_FAST_MEM void _lv_memset(void * dst, uint8_t v, size_t len) if(d_align) { d_align = ALIGN_MASK + 1 - d_align; while(d_align && len) { - *d8 = v; - d8++; + SET8(v); len--; d_align--; } @@ -671,14 +658,7 @@ LV_ATTRIBUTE_FAST_MEM void _lv_memset(void * dst, uint8_t v, size_t len) uint32_t * d32 = (uint32_t *)d8; while(len > 32) { - SET32(v32); - SET32(v32); - SET32(v32); - SET32(v32); - SET32(v32); - SET32(v32); - SET32(v32); - SET32(v32); + REPEAT8(SET32(v32)); len -= 32; } @@ -689,8 +669,7 @@ LV_ATTRIBUTE_FAST_MEM void _lv_memset(void * dst, uint8_t v, size_t len) d8 = (uint8_t *)d32; while(len) { - *d8 = v; - d8++; + SET8(v); len--; } } @@ -709,8 +688,7 @@ LV_ATTRIBUTE_FAST_MEM void _lv_memset_00(void * dst, size_t len) if(d_align) { d_align = ALIGN_MASK + 1 - d_align; while(d_align && len) { - *d8 = 0x00; - d8++; + SET8(0); len--; d_align--; } @@ -718,14 +696,7 @@ LV_ATTRIBUTE_FAST_MEM void _lv_memset_00(void * dst, size_t len) uint32_t * d32 = (uint32_t *)d8; while(len > 32) { - SET32(0); - SET32(0); - SET32(0); - SET32(0); - SET32(0); - SET32(0); - SET32(0); - SET32(0); + REPEAT8(SET32(0)); len -= 32; } @@ -736,8 +707,7 @@ LV_ATTRIBUTE_FAST_MEM void _lv_memset_00(void * dst, size_t len) d8 = (uint8_t *)d32; while(len) { - *d8 = 0; - d8++; + SET8(0); len--; } } @@ -756,8 +726,7 @@ LV_ATTRIBUTE_FAST_MEM void _lv_memset_ff(void * dst, size_t len) if(d_align) { d_align = ALIGN_MASK + 1 - d_align; while(d_align && len) { - *d8 = 0xFF; - d8++; + SET8(0xFF); len--; d_align--; } @@ -765,14 +734,7 @@ LV_ATTRIBUTE_FAST_MEM void _lv_memset_ff(void * dst, size_t len) uint32_t * d32 = (uint32_t *)d8; while(len > 32) { - SET32(0xFFFFFFFF); - SET32(0xFFFFFFFF); - SET32(0xFFFFFFFF); - SET32(0xFFFFFFFF); - SET32(0xFFFFFFFF); - SET32(0xFFFFFFFF); - SET32(0xFFFFFFFF); - SET32(0xFFFFFFFF); + REPEAT8(SET32(0xFFFFFFFF)); len -= 32; } @@ -783,8 +745,7 @@ LV_ATTRIBUTE_FAST_MEM void _lv_memset_ff(void * dst, size_t len) d8 = (uint8_t *)d32; while(len) { - *d8 = 0xFF; - d8++; + SET8(0xFF); len--; } } @@ -847,14 +808,8 @@ static void * ent_alloc(lv_mem_ent_t * e, size_t size) */ static void ent_trunc(lv_mem_ent_t * e, size_t size) { - -#ifdef LV_ARCH_64 - /*Round the size up to 8*/ - size = (size + 7) & (~0x7); -#else - /*Round the size up to 4*/ - size = (size + 3) & (~0x3); -#endif + /*Round the size up to ALIGN_MASK*/ + size = (size + ALIGN_MASK) & (~ALIGN_MASK); /*Don't let empty space only for a header without data*/ if(e->header.s.d_size == size + sizeof(lv_mem_header_t)) { @@ -867,10 +822,10 @@ static void ent_trunc(lv_mem_ent_t * e, size_t size) lv_mem_ent_t * after_new_e = (lv_mem_ent_t *)&e_data[size]; after_new_e->header.s.used = 0; after_new_e->header.s.d_size = (uint32_t)e->header.s.d_size - size - sizeof(lv_mem_header_t); - } - /* Set the new size for the original entry */ - e->header.s.d_size = (uint32_t)size; + /* Set the new size for the original entry */ + e->header.s.d_size = (uint32_t)size; + } } #endif