diff --git a/docs/overview/timer.rst b/docs/overview/timer.rst index a8f029476..f8427ad28 100644 --- a/docs/overview/timer.rst +++ b/docs/overview/timer.rst @@ -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 ****************** diff --git a/src/misc/lv_timer.c b/src/misc/lv_timer.c index 32b27b00a..df23f6590 100644 --- a/src/misc/lv_timer.c +++ b/src/misc/lv_timer.c @@ -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; } diff --git a/src/misc/lv_timer.h b/src/misc/lv_timer.h index 85dd8b10f..d70d4216b 100644 --- a/src/misc/lv_timer.h +++ b/src/misc/lv_timer.h @@ -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`