acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

lv_async.c (1500B)

      1 /**
      2  * @file lv_async.c
      3  *
      4  */
      5 
      6 /*********************
      7  *      INCLUDES
      8  *********************/
      9 
     10 #include "lv_async.h"
     11 #include "lv_mem.h"
     12 #include "lv_timer.h"
     13 
     14 /*********************
     15  *      DEFINES
     16  *********************/
     17 
     18 /**********************
     19  *      TYPEDEFS
     20  **********************/
     21 
     22 typedef struct _lv_async_info_t {
     23     lv_async_cb_t cb;
     24     void * user_data;
     25 } lv_async_info_t;
     26 
     27 /**********************
     28  *  STATIC PROTOTYPES
     29  **********************/
     30 
     31 static void lv_async_timer_cb(lv_timer_t * timer);
     32 
     33 /**********************
     34  *  STATIC VARIABLES
     35  **********************/
     36 
     37 /**********************
     38  *      MACROS
     39  **********************/
     40 
     41 /**********************
     42  *   GLOBAL FUNCTIONS
     43  **********************/
     44 
     45 lv_res_t lv_async_call(lv_async_cb_t async_xcb, void * user_data)
     46 {
     47     /*Allocate an info structure*/
     48     lv_async_info_t * info = lv_mem_alloc(sizeof(lv_async_info_t));
     49 
     50     if(info == NULL)
     51         return LV_RES_INV;
     52 
     53     /*Create a new timer*/
     54     lv_timer_t * timer = lv_timer_create(lv_async_timer_cb, 0, info);
     55 
     56     if(timer == NULL) {
     57         lv_mem_free(info);
     58         return LV_RES_INV;
     59     }
     60 
     61     info->cb = async_xcb;
     62     info->user_data = user_data;
     63 
     64     lv_timer_set_repeat_count(timer, 1);
     65     return LV_RES_OK;
     66 }
     67 
     68 /**********************
     69  *   STATIC FUNCTIONS
     70  **********************/
     71 
     72 static void lv_async_timer_cb(lv_timer_t * timer)
     73 {
     74     lv_async_info_t * info = (lv_async_info_t *)timer->user_data;
     75 
     76     info->cb(info->user_data);
     77     lv_mem_free(info);
     78 }