1 /** 2 * @file lv_async.c 3 * 4 */ 5 6 /********************* 7 * INCLUDES 8 *********************/ 9 10 #include "lv_async.h" 11 12 /********************* 13 * DEFINES 14 *********************/ 15 16 /********************** 17 * TYPEDEFS 18 **********************/ 19 20 /********************** 21 * STATIC PROTOTYPES 22 **********************/ 23 24 static void lv_async_task_cb(lv_task_t * task); 25 26 /********************** 27 * STATIC VARIABLES 28 **********************/ 29 30 /********************** 31 * MACROS 32 **********************/ 33 34 /********************** 35 * GLOBAL FUNCTIONS 36 **********************/ 37 lv_async_call(lv_async_cb_t async_xcb,void * user_data)38lv_res_t lv_async_call(lv_async_cb_t async_xcb, void * user_data) 39 { 40 /*Allocate an info structure */ 41 lv_async_info_t * info = lv_mem_alloc(sizeof(lv_async_info_t)); 42 43 if(info == NULL) 44 return LV_RES_INV; 45 46 /* Create a new task */ 47 /* Use highest priority so that it will run before a refresh */ 48 lv_task_t * task = lv_task_create(lv_async_task_cb, 0, LV_TASK_PRIO_HIGHEST, info); 49 50 if(task == NULL) { 51 lv_mem_free(info); 52 return LV_RES_INV; 53 } 54 55 info->cb = async_xcb; 56 info->user_data = user_data; 57 58 /* Set the task's user data */ 59 task->user_data = info; 60 lv_task_set_repeat_count(task, 1); 61 return LV_RES_OK; 62 } 63 64 /********************** 65 * STATIC FUNCTIONS 66 **********************/ 67 lv_async_task_cb(lv_task_t * task)68static void lv_async_task_cb(lv_task_t * task) 69 { 70 lv_async_info_t * info = (lv_async_info_t *)task->user_data; 71 72 info->cb(info->user_data); 73 74 lv_mem_free(info); 75 } 76