diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-06-01 15:41:47 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-06-01 15:41:47 +1000 |
| commit | dd27c3530432ea0b09f01e604bf577f31d8ef841 (patch) | |
| tree | bbf86cf81a78f0ff0b07f31f1c390db473f26fd3 /lib/lvgl/src/misc/lv_async.c | |
| parent | 6fd588e970470b15936187980829916d0dbe77bb (diff) | |
| download | tangara-fw-dd27c3530432ea0b09f01e604bf577f31d8ef841.tar.gz | |
convert lvgl from submodule to a plain old directory
Diffstat (limited to 'lib/lvgl/src/misc/lv_async.c')
| m--------- | lib/lvgl | 0 | ||||
| -rw-r--r-- | lib/lvgl/src/misc/lv_async.c | 105 |
2 files changed, 105 insertions, 0 deletions
diff --git a/lib/lvgl b/lib/lvgl deleted file mode 160000 -Subproject 0732400e7b564dd0e7dc4a924619d8e19c5b23a diff --git a/lib/lvgl/src/misc/lv_async.c b/lib/lvgl/src/misc/lv_async.c new file mode 100644 index 00000000..c4941e81 --- /dev/null +++ b/lib/lvgl/src/misc/lv_async.c @@ -0,0 +1,105 @@ +/** + * @file lv_async.c + * + */ + +/********************* + * INCLUDES + *********************/ + +#include "lv_async.h" +#include "lv_mem.h" +#include "lv_timer.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef struct _lv_async_info_t { + lv_async_cb_t cb; + void * user_data; +} lv_async_info_t; + +/********************** + * STATIC PROTOTYPES + **********************/ + +static void lv_async_timer_cb(lv_timer_t * timer); + +/********************** + * STATIC VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +lv_res_t lv_async_call(lv_async_cb_t async_xcb, void * user_data) +{ + /*Allocate an info structure*/ + lv_async_info_t * info = lv_mem_alloc(sizeof(lv_async_info_t)); + + if(info == NULL) + return LV_RES_INV; + + /*Create a new timer*/ + lv_timer_t * timer = lv_timer_create(lv_async_timer_cb, 0, info); + + if(timer == NULL) { + lv_mem_free(info); + return LV_RES_INV; + } + + info->cb = async_xcb; + info->user_data = user_data; + + lv_timer_set_repeat_count(timer, 1); + return LV_RES_OK; +} + +lv_res_t lv_async_call_cancel(lv_async_cb_t async_xcb, void * user_data) +{ + lv_timer_t * timer = lv_timer_get_next(NULL); + lv_res_t res = LV_RES_INV; + + while(timer != NULL) { + /*Find the next timer node*/ + lv_timer_t * timer_next = lv_timer_get_next(timer); + + /*Find async timer callback*/ + if(timer->timer_cb == lv_async_timer_cb) { + lv_async_info_t * info = (lv_async_info_t *)timer->user_data; + + /*Match user function callback and user data*/ + if(info->cb == async_xcb && info->user_data == user_data) { + lv_timer_del(timer); + lv_mem_free(info); + res = LV_RES_OK; + } + } + + timer = timer_next; + } + + return res; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +static void lv_async_timer_cb(lv_timer_t * timer) +{ + lv_async_info_t * info = (lv_async_info_t *)timer->user_data; + + info->cb(info->user_data); + lv_mem_free(info); +} |
