2023-04-27 06:42:02 -06:00
.. _tick:
==============
Tick interface
==============
2024-03-10 07:50:08 +01:00
LVGL needs a system tick to know the elapsed time for animations and other
2023-04-27 06:42:02 -06:00
tasks.
2024-03-10 07:50:08 +01:00
There are two ways to provide the tick to LVGL:
2023-08-19 01:42:37 +02:00
2024-03-10 07:50:08 +01:00
1. Call `` lv_tick_set_cb(my_get_milliseconds_function); `` : `my_get_milliseconds_function` needs to tell how many milliseconds have elapsed since start up. Most of the platforms have built-in functions that can be used as they are. For example
2023-08-19 01:42:37 +02:00
2024-03-10 07:50:08 +01:00
- SDL: `` lv_tick_set_cb(SDL_GetTicks); ``
2024-04-05 10:23:43 +02:00
- Arduino: `` lv_tick_set_cb(my_tick_get_cb); `` , where `` my_tick_get_cb `` is: `` static uint32_t my_tick_get_cb(void) { return millis(); } ``
2024-03-10 07:50:08 +01:00
- FreeRTOS: `` lv_tick_set_cb(xTaskGetTickCount); ``
- STM32: `` lv_tick_set_cb(HAL_GetTick); ``
- ESP32: `` lv_tick_set_cb(my_tick_get_cb); `` , where `` my_tick_get_cb `` is a wrapper for `` esp_timer_get_time() / 1000; ``
2023-08-19 01:42:37 +02:00
2024-03-10 07:50:08 +01:00
2. Call `` lv_tick_inc(x) `` periodically, where `` x `` is the elapsed milliseconds since the last call. `` lv_tick_inc `` should be called from a high priority interrupt.
2023-04-27 06:42:02 -06:00
2024-03-10 07:50:08 +01:00
The ticks (milliseconds) should be independent from any other activities of the MCU.
2023-04-27 06:42:02 -06:00
2024-03-10 07:50:08 +01:00
For example this works, but LVGL's timing will be incorrect as the execution time of `` lv_timer_handler `` is not considered:
2023-04-27 06:42:02 -06:00
.. code :: c
2024-03-10 07:50:08 +01:00
// Bad idea
lv_timer_handler();
lv_tick_inc(5);
my_delay_ms(5);
2023-04-27 06:42:02 -06:00
API
---