How to properly integrate LVGL as a Buildroot package? (Missing preview dependencies)

Background

I have used LVGL for about 2 days and I created a very simple UI via the preview editor integrated in VSCode. It properly compiles and displays there. The project format is identical to that of the XML hello world example found here except the ui folder is located within an overarching src folder which contains other application code.

Target application

  • 2.8" TFT LCD (ILI9341) driven with DRM
  • Beaglebone Black
  • Buildroot

I am now trying to integrate this application into a broader embedded linux project which is built & configured with buildroot. I have already confirmed that I can write properly to the display so now it’s just a matter of getting the graphics deployed.

My project is separated into two distinct repos:

  1. An ā€˜application’ where LVGL UI resides along with other application code
  2. A ā€˜platform’ where buildroot resides and integrates all necessary packages

Errors seen

I’m missing functions which are enabled in the preview environment. In the code itself I use a find_by_name function to obtain lv_obj_t for named XML items at runtime to make a grid. I also register a font at runtime as I couldn’t figure out how to do it properly in XML yet.

error: implicit declaration of function ā€˜lv_obj_set_name_static’; did you mean ā€˜lv_obj_set_state’? [-Wimplicit-function-declaration]
   49 |     lv_obj_set_name_static(lv_obj_0, "screen_secondary_#");
error: implicit declaration of function ā€˜lv_obj_get_name’; did you mean ā€˜lv_obj_get_state’? [-Wimplicit-function-declaration]
   16 |     const char *n = lv_obj_get_name(root); /* LVGL 9 */
error: implicit declaration of function ā€˜lv_xml_register_font’; did you mean ā€˜lv_style_register_prop’? [-Wimplicit-function-declaration]
  116 |     lv_xml_register_font(NULL, "plex_sans_12", plex_sans_12);
error: implicit declaration of function ā€˜lv_obj_set_name_static’; did you mean ā€˜lv_obj_set_state’? [-Wimplicit-function-declaration]
   69 |     lv_obj_set_name_static(lv_obj_0, "screen_main_#");
error: implicit declaration of function ā€˜lv_obj_set_name’; did you mean ā€˜lv_obj_set_state’? [-Wimplicit-function-declaration]
   80 |     lv_obj_set_name(time, "time");

Code to reproduce

This is the lvgl-graphics.mk I am using in a buildroot external tree to install LVGL on the target. The lv_conf.h is located within this external tree.

LVGL_GRAPHICS_VERSION = 4170bcb1ee04719a8e27dd6f7c64d30ba88ead18
LVGL_GRAPHICS_SITE = https://github.com/lvgl/lvgl.git
LVGL_GRAPHICS_SITE_METHOD = git

LVGL_GRAPHICS_INSTALL_STAGING = YES
LVGL_GRAPHICS_DEPENDENCIES = libdrm

LVGL_GRAPHICS_CONF_OPTS = \
	-DBUILD_SHARED_LIBS=OFF \
	-DCONFIG_LV_BUILD_EXAMPLES=OFF \
	-DCONFIG_LV_BUILD_DEMOS=OFF \
	-DLV_BUILD_CONF_DIR=$(@D) \
	-DCMAKE_C_FLAGS="$(TARGET_CFLAGS) -I$(STAGING_DIR)/usr/include/libdrm" \
	-DCMAKE_CXX_FLAGS="$(TARGET_CXXFLAGS) -I$(STAGING_DIR)/usr/include/libdrm"

define LVGL_GRAPHICS_PRE_CONFIGURE_HOOK
	cp $(LVGL_GRAPHICS_PKGDIR)/lv_conf.h $(@D)/lv_conf.h
endef
LVGL_GRAPHICS_PRE_CONFIGURE_HOOKS += LVGL_GRAPHICS_PRE_CONFIGURE_HOOK

define LVGL_GRAPHICS_INSTALL_STAGING_CMDS
	$(TARGET_MAKE_ENV) $(BR2_CMAKE) --install $(@D) --prefix $(STAGING_DIR)/usr
	$(INSTALL) -D -m 0644 $(LVGL_GRAPHICS_PKGDIR)/lv_conf.h \
		$(STAGING_DIR)/usr/include/lvgl/lv_conf.h
endef

define LVGL_GRAPHICS_INSTALL_TARGET_CMDS
	true
endef

$(eval $(cmake-package))

Questions

  1. How do I enable these missing functions in my target application?
  2. What is the best way to reference XML objects in code? Better way than obtaining by name at runtime?
  3. How do I register custom font so it’s recognized within XML?

How do I enable these missing functions in my target application?

guess: any chance you are writing code against LVGLv9 but compiling against LVGLv8?

For the missing lv_obj_set_name_statis / lv_obj_get_name requires setting the option LV_USE_OBJ_NAME in lv_conf.h.

For lv_xml_register_font as my understating the xml loader/engine is no longer part of the LVGL (free library present on GitHub). Check XML engine further plan - General discussion - LVGL Forum.

1 Like

I just updated the commit i’m pulling from to be associated with the v9.5.0 release tag: 85aa60d18b3d5e5588d7b247abf90198f07c8a63

Same issue though.

So I was originally setting LV_USE_OBJ_NAME, but it turns out I was just not properly compiling against the config I had installed in sysroot at /usr/include/lvgl/lv_conf.h. It was compiling, but choosing a default config which had that option set to 0.

I added these guards in the CMakeLists.txt such that it compiled against the correct config:
if(EXISTS "${CMAKE_SYSROOT}/usr/include/lvgl/lv_conf.h")

I removed lv_xml_register and when deployed on the system the text associated with that font is just omitted completely. Is there a way to get around this or is it a matter of dropping XML entirely anytime I use a custom font?

Deployed build:

Preview build (WIP):

1 Like

I have barerly used XML, only started looking into it this week…

Regarding fonts, what I have in the current ā€œdummyā€ project, is having the fonts as ā€œbinā€

	<fonts>
		<!-- Add <bin> , <tiny_ttf>, <freetype> tags here -->
		<bin name="font_small_1" as_file="false" src_path="fonts/Montserrat_Medium.ttf" size="12" bpp="4" />
		<bin name="font_medium_1" as_file="false" src_path="fonts/Montserrat_Medium.ttf" size="20" bpp="4" />
		<bin name="font_medium_26" as_file="false" src_path="fonts/Montserrat_Medium.ttf" size="26" bpp="4" />
		<bin name="font_large_1" as_file="false" src_path="fonts/Montserrat_Medium.ttf" size="40" bpp="4" />
	</fonts>

This will make the editor to crate a C file for the fonts, the same way they are generated on the online converter.

The editor is creating the relevant C Code to add the font so it can be used, with the XML parser been optional (I am not defining LV_USE_XML anywhere, so I only use the resultant C Code).

If using the font as ā€œfilesā€, I think it’s necessary to have the filesystem implemented and #if LV_USE_TINY_TTF && LV_TINY_TTF_FILE_SUPPORT and pass a valid ā€œpathā€ to ui_xxxxx_init( function.

But this will depend on how the fonts were defined in the XML…

1 Like

Thanks that worked. Simpler than what I was doing before with the lv_xml stuff.