- git latest lv_micropython source code, running in ESP32
- Based on Fonts — LVGL documentation, I used lv_font_conv to crate a new font file “lv_font_my_26.c” (Montserrat 26), copied it to \lib\lv_bindings\lvgl\src\font folder, then build by following command successfully.
make LV_CFLAGS="-DLV_COLOR_DEPTH=16 -DLV_COLOR_16_SWAP=1 -DLV_FONT_CUSTOM_DECLARE=LV_FONT_DECLARE(lv_font_my_26)" BOARD=GENERIC_SPIRAM
- flashed the firmware into ESP32
- import lvgl as lv; a) help(lv), the font lv_font_my_26 is not showed up. b) either label.set_style_text_font(lv.lv_font_my_26, 0) or label.set_style_text_font(lv.font_my_26, 0) failed with “‘module’ object has no attribute ‘lv_font_my_26’”
anything worong? Thanks
Hi @amoywolf !
First, if you have enough RAM (or if your ESP32 board has spi-ram) then it’s easier to load fonts on runtime.
The advantage is that you don’t need to rebuild the firmware every time you want to add a new font or change an existing one.
If you want to build the font as part of your firmware, I think you are in the right direction.
The one part you are missing is how to tell the Micropython Binding Script about the new font.
The Micropython Binding Script parses
lvgl.h so all you need to do is to add
LV_FONT_DECLARE(lv_font_my_26) there or on some other file that is included by it (
lv_conf.h for example).
Another option is to edit
lv_conf.h and specify your font in
LV_FONT_CUSTOM_DECLARE instead of the empty declaration there.
Passing a makefile parameter like you did seems to be broken but is easy to fix. I think that simply wrapping the
#define LV_FONT_CUSTOM_DECLARE in
#ifndef LV_FONT_CUSTOM_DECLARE should be enough, but you’ll need to test it. You are welcome to open a Pull Request if you want.
Hi @amirgon, thanks for your quick response.
I succeed to use lv.font_load to load font dynamically, but it takes >10 seconds for each font, even there are only tens of Chinese characters in the font file. That’s why I try to make a firmware font.
I change to
#define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(lv_font_my_26) in lvgl.h, but it fails with
undefined reference to lv_font_my_26’` while building with make command.
I also try
#define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(lv_font_my_26) in lvgl.h +
make LV_CFLAGS="-DLV_COLOR_DEPTH=16 -DLV_COLOR_16_SWAP=1 -DLV_FONT_CUSTOM_DECLARE=LV_FONT_DECLARE(lv_font_my_26)" BOARD=GENERIC_SPIRAM, it has same failure.
I attach the font .c file FYI.
lv_font_my_26.c (131.0 KB)
This means that either the font C file is not being built, or the name you specified in
LV_FONT_DECLARE doesn’t match the font name as defined in the font C file.
Try to clean and rebuild lv_micropython.
Try to check which of these happens.
I just downloaded your font, copied it under
#define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(lv_font_my_26) under
lv_conf.h and built the unix port.
It works just fine. The font
lv.font_my_26 is available in Micropython. I didn’t try it on esp32 but I believe it should work in the same way.
It works just fine. The font
lv.font_my_26is available in Micropython. I didn’t try it on esp32 but I believe it should work in the same way.
It works for me on port unix. Looks it is a esp32 related issue, I use ESP-IDF V4.0.2.
fs_driver.fs_register(fs_drv, 'S', 500), lv.font_load time is down from 16 seconds to <1 second. It’s perfect, so at the moment I will use this solution.
BTW, I attach the error log file (
#define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(lv_font_my_26) in lvgl.h) in case you are interested.
Thanks for your quick help, @amirgon
make_error_log.txt (8.6 KB)