[English]

Timer Handler

显示原文

To handle the tasks of LVGL you need to call lv_timer_handler() periodically in one of the following:

  • while(1) of main() function

  • timer interrupt periodically (lower priority than lv_tick_inc())

  • an OS task periodically

Example:


要处理 LVGL 的任务,您需要以下列方式之一中定期调用 lv_timer_handler()

  • main() 函数的 while(1)

  • 定时器定期中断(比 lv_tick_inc() 优先级低)

  • 定期执行操作系统任务

示例:

while(1) {
  uint32_t time_till_next = lv_timer_handler();
  my_delay_ms(time_till_next);
}
显示原文

If you want to use lv_timer_handler() in a super-loop, a helper function lv_timer_handler_run_in_period() is provided to simplify the porting:


如果要在超级循环中使用 lv_timer_handler() ,则提供了一个辅助函数 lv_timer_handler_run_in_period() 来简化移植过程:

while(1) {
   ...
   lv_timer_handler_run_in_period(5); /* run lv_timer_handler() every 5ms */
   ...
}
显示原文

Or use the sleep time automatically calculated by LVGL:


或者使用LVGL自动计算的睡眠时间:

while(1) {
  ...
  lv_timer_periodic_handler();
  ...
}
显示原文

In an OS environment, you can use it together with the delay or sleep provided by OS to release CPU whenever possible:


在操作系统环境中,您可以将其与操作系统提供的 延迟睡眠 一起使用,以尽可能释放 CPU:

while (1) {
   uint32_t time_till_next = lv_timer_handler();
   os_delay_ms(time_till_next); /* delay to avoid unnecessary polling */
}
显示原文

To learn more about timers visit the Timer Handler section.


若要了解有关计时器的详细信息,请访问 Timer Handler 部分。

API

lv_timer.h