I am very new to LVGL and I am having lots of trouble to get things working properly.
In the documentation you can find many examples, but they all lack a main function, which I believe you need to provide, and from it call the example.
This main function should initialise the display(s) and IO devices. It should also provide some sort of loop that calls lv_task_handler every so often.
Could someone post here a basic main function that can be used to call any of the examples in the documentation, please?
Thanks in advance!
Hey @demonskull, some time ago i ported the project i work on to LVGL 9.2 and also created a repo that have a basic code running, the code just changes the screen color between red, green and blue.
Hey @demonskull,
-
First: In the lines 223 to 228 is created a tick increase cb using the function given by lvgl as said in this section of the docs.
-
Second: thats right, it doesnt run any example but with this code inthe main loop it will run
//include the widgets examples
#include "widgets/lv_example_widgets.h"
extern "C" void app_main(void) {
init();
lv_obj_t *scr = lv_obj_create(nullptr);
lv_obj_set_size(scr, lv_pct(100), lv_pct(100));
lv_obj_center(scr);
lv_screen_load(scr);
lv_example_button_1();
static u32 del_time = 0;
for (;;) {
del_time = lv_timer_handler();
vTaskDelay(pdMS_TO_TICKS(del_time));
}
}
Now it probably should run.
EDIT: forgot to add the timer handler.
Hi Yuri,
Thank you once more (I managed to delete my previous comment!).
Your example seems to me a bit too complicated. I was looking for something more like a minimal working code. Yours seems to be part of a larger application. And again, doesn’t show how to use lv_task_handler.
lv_task_handler()
and lv_timer_handler()
are basically the same.
See: lvgl/src/lv_api_map_v8.h at cee1a01743520095debd0eeff10739931f02c34b · lvgl/lvgl · GitHub
The idea is that lv_task_handler()
returns a wait time and your code should wait that time before calling lv_task_handler()
again. If it’s earlier, also no problem (but if you are running an RTOS of some kind, you should delay somewhere).
Hey @demonskull , as said @theprogram01 lv_task_handler()
and lv_timer_handler()
are exactly the same thing in v9.2, see the image below.
and could you share a repo that you are trying to run? it will be better and more easy to give you any advice.
And yes, the code is a snippet of a bigger project, what will probably change to your usage will be the initialization code, since i dont know what type of MCU or screen controller you will be using.