diff --git a/src/misc/lv_timer.c b/src/misc/lv_timer.c index 3c0d61786..32011d6e0 100644 --- a/src/misc/lv_timer.c +++ b/src/misc/lv_timer.c @@ -60,7 +60,7 @@ void _lv_timer_core_init(void) } /** - * Call it periodically to handle lv_timers. + * Call it periodically to handle lv_timers. * @return the time after which it must be called again */ LV_ATTRIBUTE_TIMER_HANDLER uint32_t lv_timer_handler(void) @@ -69,12 +69,14 @@ LV_ATTRIBUTE_TIMER_HANDLER uint32_t lv_timer_handler(void) /*Avoid concurrent running of the timer handler*/ static bool already_running = false; - if(already_running) return 1; + if(already_running) { + TIMER_TRACE("already running, concurrent calls are not allow, returning"); + return 1; + } already_running = true; if(lv_timer_run == false) { already_running = false; /*Release mutex*/ - TIMER_TRACE("already running, concurrent calls are not allow, returning"); return 1; } @@ -85,7 +87,7 @@ LV_ATTRIBUTE_TIMER_HANDLER uint32_t lv_timer_handler(void) if(handler_start == 0) { static uint32_t run_cnt = 0; - run_cnt ++; + run_cnt++; if(run_cnt > 100) { run_cnt = 0; LV_LOG_WARN("It seems lv_tick_inc() is not called."); @@ -141,6 +143,7 @@ LV_ATTRIBUTE_TIMER_HANDLER uint32_t lv_timer_handler(void) TIMER_TRACE("finished (%d ms until the next timer call)", time_till_next); return time_till_next; } + /** * Create an "empty" timer. It needs to initialized with at least * `lv_timer_set_cb` and `lv_timer_set_period` @@ -168,7 +171,7 @@ lv_timer_t * lv_timer_create(lv_timer_cb_t timer_xcb, uint32_t period, void * us LV_ASSERT_MALLOC(new_timer); if(new_timer == NULL) return NULL; - new_timer->period = period; + new_timer->period = period; new_timer->timer_cb = timer_xcb; new_timer->repeat_count = -1; new_timer->paused = 0; @@ -297,12 +300,6 @@ static bool lv_timer_exec(lv_timer_t * timer) { if(timer->paused) return false; - if(timer->repeat_count == 0) { - TIMER_TRACE("deleting timer with %p callback because the repeat count is over", timer->timer_cb); - lv_timer_del(timer); - return false; - } - bool exec = false; if(lv_timer_time_remaining(timer) == 0) { /* Decrement the repeat count before executing the timer_cb. @@ -315,17 +312,16 @@ static bool lv_timer_exec(lv_timer_t * timer) if(timer->timer_cb && original_repeat_count != 0) timer->timer_cb(timer); TIMER_TRACE("timer callback %p finished", timer->timer_cb); LV_ASSERT_MEM_INTEGRITY(); - - /*Delete if it was a one shot lv_timer*/ - if(timer_deleted == false) { /*The timer might be deleted by itself as well*/ - if(timer->repeat_count == 0) { - TIMER_TRACE("deleting timer with %p callback because the repeat count is over", timer->timer_cb); - lv_timer_del(timer); - } - } exec = true; } + if(timer_deleted == false) { /*The timer might be deleted by itself as well*/ + if(timer->repeat_count == 0) { /*The repeat count is over, delete the timer*/ + TIMER_TRACE("deleting timer with %p callback because the repeat count is over", timer->timer_cb); + lv_timer_del(timer); + } + } + return exec; } diff --git a/src/misc/lv_timer.h b/src/misc/lv_timer.h index 093009cc3..71c63655f 100644 --- a/src/misc/lv_timer.h +++ b/src/misc/lv_timer.h @@ -63,7 +63,7 @@ void _lv_timer_core_init(void); //! @cond Doxygen_Suppress /** - * Call it periodically to handle lv_timers. + * Call it periodically to handle lv_timers. * @return time till it needs to be run next (in ms) */ LV_ATTRIBUTE_TIMER_HANDLER uint32_t lv_timer_handler(void); @@ -97,7 +97,6 @@ void lv_timer_del(lv_timer_t * timer); /** * Pause/resume a timer. * @param timer pointer to an lv_timer - * @param pause true: pause the timer; false: resume */ void lv_timer_pause(lv_timer_t * timer);