feat(timer): support lv_timer_handler_set_resume_cb (#4680)
Signed-off-by: XiaoweiYan <yanxiaowei@xiaomi.com> Co-authored-by: XiaoweiYan <yanxiaowei@xiaomi.com>
This commit is contained in:
@@ -69,6 +69,18 @@ You can make a timer repeat only a given number of times with
|
||||
automatically be deleted after it's called the defined number of times.
|
||||
Set the count to ``-1`` to repeat indefinitely.
|
||||
|
||||
Enable and Disable
|
||||
******************
|
||||
|
||||
You can enable or disable a timer with :cpp:expr:`lv_timer_enable(en)`.
|
||||
|
||||
Pause and Resume
|
||||
****************
|
||||
|
||||
:cpp:expr:`lv_timer_pause(timer)` pauses the specified timer.
|
||||
|
||||
:cpp:expr:`lv_timer_resume(timer)` resumes the specified timer.
|
||||
|
||||
Measure idle time
|
||||
*****************
|
||||
|
||||
@@ -78,6 +90,14 @@ the overall system, only :cpp:func:`lv_timer_handler`. It can be misleading if
|
||||
you use an operating system and call :cpp:func:`lv_timer_handler` in a timer, as
|
||||
it won't actually measure the time the OS spends in an idle thread.
|
||||
|
||||
Timer handler resume callback
|
||||
*****************************
|
||||
|
||||
When the `lv_timer_handler` is stopped, if you want to pay attention to the wake-up
|
||||
timing of the `lv_timer_handler`, you can set a resume callback using
|
||||
:cpp:expr:`lv_timer_handler_set_resume_cb(cb, user_data)`.
|
||||
The callback should have a ``void (*lv_timer_handler_resume_cb_t)(void*)`` prototype.
|
||||
|
||||
Asynchronous calls
|
||||
******************
|
||||
|
||||
|
||||
@@ -394,4 +394,13 @@ static void lv_timer_handler_resume(void)
|
||||
{
|
||||
/*If there is a timer which is ready to run then resume the timer loop*/
|
||||
state.timer_time_until_next = 0;
|
||||
if(state.resume_cb) {
|
||||
state.resume_cb(state.resume_data);
|
||||
}
|
||||
}
|
||||
|
||||
void lv_timer_handler_set_resume_cb(lv_timer_handler_resume_cb_t cb, void * data)
|
||||
{
|
||||
state.resume_cb = cb;
|
||||
state.resume_data = data;
|
||||
}
|
||||
|
||||
@@ -39,6 +39,11 @@ struct _lv_timer_t;
|
||||
*/
|
||||
typedef void (*lv_timer_cb_t)(struct _lv_timer_t *);
|
||||
|
||||
/**
|
||||
* Timer handler resume this type of function.
|
||||
*/
|
||||
typedef void (*lv_timer_handler_resume_cb_t)(void * data);
|
||||
|
||||
/**
|
||||
* Descriptor of a lv_timer
|
||||
*/
|
||||
@@ -65,6 +70,9 @@ typedef struct {
|
||||
uint32_t busy_time;
|
||||
uint32_t idle_period_start;
|
||||
uint32_t run_cnt;
|
||||
|
||||
lv_timer_handler_resume_cb_t resume_cb;
|
||||
void * resume_data;
|
||||
} lv_timer_state_t;
|
||||
|
||||
/**********************
|
||||
@@ -110,6 +118,13 @@ static inline LV_ATTRIBUTE_TIMER_HANDLER uint32_t lv_timer_handler_run_in_period
|
||||
*/
|
||||
LV_ATTRIBUTE_TIMER_HANDLER void lv_timer_periodic_handler(void);
|
||||
|
||||
/**
|
||||
* Set the resume callback to the timer handler
|
||||
* @param cb the function to call when timer handler is resumed
|
||||
* @param data pointer to a resume data
|
||||
*/
|
||||
void lv_timer_handler_set_resume_cb(lv_timer_handler_resume_cb_t cb, void * data);
|
||||
|
||||
/**
|
||||
* Create an "empty" timer. It needs to be initialized with at least
|
||||
* `lv_timer_set_cb` and `lv_timer_set_period`
|
||||
|
||||
Reference in New Issue
Block a user