feat(porting): add a macro lv_run_timer_handler_in_period to simplify porting (#3063)
* feat(porting): add a macro lv_run_timer_handler_in_period to simplify porting * feat: update helper function and doc * doc(porting): update function names * revise to the original os.md * fix: fix typo * fix: mitigate warnings
This commit is contained in:
@@ -13,6 +13,7 @@ extern "C" {
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "../lv_conf_internal.h"
|
||||
#include "../hal/lv_hal_tick.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
@@ -68,6 +69,24 @@ LV_ATTRIBUTE_TIMER_HANDLER uint32_t lv_timer_handler(void);
|
||||
|
||||
//! @endcond
|
||||
|
||||
/**
|
||||
* Call it in the super-loop of main() or threads. It will run lv_timer_handler()
|
||||
* with a given period in ms. You can use it with sleep or delay in OS environment.
|
||||
* This function is used to simplify the porting.
|
||||
* @param __ms the period for running lv_timer_handler()
|
||||
*/
|
||||
static inline LV_ATTRIBUTE_TIMER_HANDLER uint32_t lv_timer_handler_run_in_period(uint32_t ms)
|
||||
{
|
||||
static uint32_t last_tick = 0;
|
||||
uint32_t curr_tick = lv_tick_get();
|
||||
|
||||
if ((curr_tick - last_tick) >= (ms)) {
|
||||
last_tick = curr_tick;
|
||||
return lv_timer_handler();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an "empty" timer. It needs to initialized with at least
|
||||
* `lv_timer_set_cb` and `lv_timer_set_period`
|
||||
|
||||
Reference in New Issue
Block a user