lv_timer.h

Defines

LV_NO_TIMER_READY

Typedefs

typedef void (*lv_timer_cb_t)(lv_timer_t*)

Timers execute this type of functions.

typedef void (*lv_timer_handler_resume_cb_t)(void *data)

Timer handler resume this type of function.

Functions

void _lv_timer_core_init(void)

Init the lv_timer module

void _lv_timer_core_deinit(void)

Deinit the lv_timer module

static inline uint32_t lv_timer_handler_run_in_period(uint32_t period)

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.

Parameters:

period -- the period for running lv_timer_handler()

Returns:

the time after which it must be called again

void lv_timer_periodic_handler(void)

Call it in the super-loop of main() or threads. It will automatically call lv_timer_handler() at the right time. This function is used to simplify the porting.

void lv_timer_handler_set_resume_cb(lv_timer_handler_resume_cb_t cb, void *data)

Set the resume callback to the timer handler

Parameters:
  • cb -- the function to call when timer handler is resumed

  • data -- pointer to a resume data

lv_timer_t *lv_timer_create_basic(void)

Create an "empty" timer. It needs to be initialized with at least lv_timer_set_cb and lv_timer_set_period

Returns:

pointer to the created timer

lv_timer_t *lv_timer_create(lv_timer_cb_t timer_xcb, uint32_t period, void *user_data)

Create a new lv_timer

Parameters:
  • timer_xcb -- a callback to call periodically. (the 'x' in the argument name indicates that it's not a fully generic function because it not follows the func_name(object, callback, ...) convention)

  • period -- call period in ms unit

  • user_data -- custom parameter

Returns:

pointer to the new timer

void lv_timer_delete(lv_timer_t *timer)

Delete a lv_timer

Parameters:

timer -- pointer to an lv_timer

void lv_timer_pause(lv_timer_t *timer)

Pause a timer.

Parameters:

timer -- pointer to an lv_timer

void lv_timer_resume(lv_timer_t *timer)

Resume a timer.

Parameters:

timer -- pointer to an lv_timer

void lv_timer_set_cb(lv_timer_t *timer, lv_timer_cb_t timer_cb)

Set the callback to the timer (the function to call periodically)

Parameters:
  • timer -- pointer to a timer

  • timer_cb -- the function to call periodically

void lv_timer_set_period(lv_timer_t *timer, uint32_t period)

Set new period for a lv_timer

Parameters:
  • timer -- pointer to a lv_timer

  • period -- the new period

void lv_timer_ready(lv_timer_t *timer)

Make a lv_timer ready. It will not wait its period.

Parameters:

timer -- pointer to a lv_timer.

void lv_timer_set_repeat_count(lv_timer_t *timer, int32_t repeat_count)

Set the number of times a timer will repeat.

Parameters:
  • timer -- pointer to a lv_timer.

  • repeat_count -- -1 : infinity; 0 : stop ; n>0: residual times

void lv_timer_set_auto_delete(lv_timer_t *timer, bool auto_delete)

Set whether a lv_timer will be deleted automatically when it is called repeat_count times.

Parameters:
  • timer -- pointer to a lv_timer.

  • auto_delete -- true: auto delete; false: timer will be paused when it is called repeat_count times.

void lv_timer_set_user_data(lv_timer_t *timer, void *user_data)

Set custom parameter to the lv_timer.

Parameters:
  • timer -- pointer to a lv_timer.

  • user_data -- custom parameter

void lv_timer_reset(lv_timer_t *timer)

Reset a lv_timer. It will be called the previously set period milliseconds later.

Parameters:

timer -- pointer to a lv_timer.

void lv_timer_enable(bool en)

Enable or disable the whole lv_timer handling

Parameters:

en -- true: lv_timer handling is running, false: lv_timer handling is suspended

uint32_t lv_timer_get_idle(void)

Get idle percentage

Returns:

the lv_timer idle in percentage

uint32_t lv_timer_get_time_until_next(void)

Get the time remaining until the next timer will run

Returns:

the time remaining in ms

lv_timer_t *lv_timer_get_next(lv_timer_t *timer)

Iterate through the timers

Parameters:

timer -- NULL to start iteration or the previous return value to get the next timer

Returns:

the next timer or NULL if there is no more timer

static inline void *lv_timer_get_user_data(lv_timer_t *timer)

Get the user_data passed when the timer was created

Parameters:

timer -- pointer to the lv_timer

Returns:

pointer to the user_data

static inline bool lv_timer_get_paused(lv_timer_t *timer)

Get the pause state of a timer

Parameters:

timer -- pointer to a lv_timer

Returns:

true: timer is paused; false: timer is running

struct _lv_timer_t
#include <lv_timer.h>

Descriptor of a lv_timer

Public Members

uint32_t period

How often the timer should run

uint32_t last_run

Last time the timer ran

lv_timer_cb_t timer_cb

Timer function

void *user_data

Custom user data

int32_t repeat_count

1: One time; -1 : infinity; n>0: residual times

uint32_t paused
uint32_t auto_delete
struct lv_timer_state_t

Public Members

lv_ll_t timer_ll
bool lv_timer_run
uint8_t idle_last
bool timer_deleted
bool timer_created
uint32_t timer_time_until_next
bool already_running
uint32_t periodic_last_tick
uint32_t busy_time
uint32_t idle_period_start
uint32_t run_cnt
lv_timer_handler_resume_cb_t resume_cb
void *resume_data