lvgl: kill LVGL_MEM_POOL_HEAP_KERNEL and LVGL_MEM_POOL_KERNEL

Current lvgl code allows to use the kernel heap for dynamic memory
allocation. The k_heap API doesn't however provide k_realloc() which
will be needed in order to update lvgl to v8. Nico suggested there's
no good reason for lvgl to use k_heap and it should stick to either
the libc's allocator or depend on its own private sys_heap.

The alternative would be to extend the k_heap API to provide k_realloc()
but this may be tricky for several reasons and for now there would
be a single user anyway.

This removes the choice of using k_heap for lvgl and renames the user
pool to SYS_HEAP in Kconfig and makes it the default option.

The prj.conf for the lvgl sample is modifed to specify the number of
memory pool blocks instead of the total size as the default block
size is 2048 and it results in the same size of memory.

Suggested-by: Nicolas Pitre <npitre@baylibre.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@huawei.com>
This commit is contained in:
Bartosz Golaszewski 2021-12-17 18:07:34 +01:00 committed by Carles Cufí
commit 595131c2d0
6 changed files with 9 additions and 36 deletions

View file

@ -13,7 +13,6 @@ zephyr_library_sources(lvgl_display_16bit.c)
zephyr_library_sources(lvgl_display_24bit.c)
zephyr_library_sources(lvgl_display_32bit.c)
zephyr_library_sources_ifdef(CONFIG_LVGL_USE_FILESYSTEM lvgl_fs.c)
zephyr_library_sources_ifdef(CONFIG_LVGL_MEM_POOL_USER lvgl_mem_user.c)
zephyr_library_sources_ifdef(CONFIG_LVGL_MEM_POOL_KERNEL lvgl_mem_kernel.c)
zephyr_library_sources_ifdef(CONFIG_LVGL_MEM_POOL_SYS_HEAP lvgl_mem.c)
zephyr_library_link_libraries(lvgl)

View file

@ -14,36 +14,24 @@ config LVGL_BITS_PER_PIXEL
choice
prompt "Memory pool"
default LVGL_MEM_POOL_HEAP_KERNEL
default LVGL_MEM_POOL_SYS_HEAP
help
Memory pool to use for lvgl allocated objects
config LVGL_MEM_POOL_HEAP_KERNEL
bool "Kernel Heap"
depends on HEAP_MEM_POOL_SIZE != 0
help
Use k_malloc and k_free to allocate objects on the kernel heap
config LVGL_MEM_POOL_HEAP_LIB_C
bool "C library Heap"
depends on !MINIMAL_LIBC || (MINIMAL_LIBC_MALLOC_ARENA_SIZE != 0)
help
Use C library malloc and free to allocate objects on the C library heap
config LVGL_MEM_POOL_KERNEL
bool "Kernel space lvgl pool"
help
Use a dedicated memory pool in kernel space to allocate lvgl objects
on
config LVGL_MEM_POOL_USER
config LVGL_MEM_POOL_SYS_HEAP
bool "User space lvgl pool"
help
Use a dedicated memory pool in user space to allocate lvgl objects on
Use a dedicated memory pool from a private sys heap.
endchoice
if LVGL_MEM_POOL_KERNEL || LVGL_MEM_POOL_USER
if LVGL_MEM_POOL_SYS_HEAP
config LVGL_MEM_POOL_MIN_SIZE
int "Minimum memory pool block size"

View file

@ -65,13 +65,7 @@ typedef short lv_coord_t;
#define LV_MEMCPY_MEMSET_STD 1
#ifdef CONFIG_LVGL_MEM_POOL_HEAP_KERNEL
#define LV_MEM_CUSTOM_INCLUDE "kernel.h"
#define LV_MEM_CUSTOM_ALLOC k_malloc
#define LV_MEM_CUSTOM_FREE k_free
#elif defined(CONFIG_LVGL_MEM_POOL_HEAP_LIB_C)
#if defined(CONFIG_LVGL_MEM_POOL_HEAP_LIB_C)
#define LV_MEM_CUSTOM_INCLUDE "stdlib.h"
#define LV_MEM_CUSTOM_ALLOC malloc

View file

@ -1,4 +1,4 @@
CONFIG_HEAP_MEM_POOL_SIZE=16384
CONFIG_LVGL_MEM_POOL_NUMBER_BLOCKS=8
CONFIG_MAIN_STACK_SIZE=2048
CONFIG_DISPLAY=y

View file

@ -10,20 +10,12 @@ tests:
- CONFIG_NEWLIB_LIBC=y
- CONFIG_LVGL_BUFFER_ALLOC_DYNAMIC=y
- CONFIG_LVGL_MEM_POOL_HEAP_LIB_C=y
libraries.gui.lvgl.dynamic.pool.user:
libraries.gui.lvgl.dynamic.pool.sys_heap:
tags: display gui
platform_allow: native_posix
extra_configs:
- CONFIG_LVGL_BUFFER_ALLOC_DYNAMIC=y
- CONFIG_LVGL_MEM_POOL_USER=y
- CONFIG_LVGL_MEM_POOL_NUMBER_BLOCKS=3
- CONFIG_LVGL_MEM_POOL_MAX_SIZE=32768
libraries.gui.lvgl.dynamic.pool.kernel:
tags: display gui
platform_allow: native_posix
extra_configs:
- CONFIG_LVGL_BUFFER_ALLOC_DYNAMIC=y
- CONFIG_LVGL_MEM_POOL_KERNEL=y
- CONFIG_LVGL_MEM_POOL_SYS_HEAP=y
- CONFIG_LVGL_MEM_POOL_NUMBER_BLOCKS=3
- CONFIG_LVGL_MEM_POOL_MAX_SIZE=32768
libraries.gui.lvgl.16bit: