我们先看 lv_gc.h,在 lv_gc.h 中定义了各种宏:
#define LV_DISPATCH(f, t, n) f(t, n)
#define LV_ITERATE_ROOTS(f) \
LV_DISPATCH(f, lv_ll_t, _lv_timer_ll) /*Linked list to store the lv_timers*/ \
LV_DISPATCH(f, lv_ll_t, _lv_disp_ll) /*Linked list of display device*/ \
LV_DISPATCH(f, lv_ll_t, _lv_indev_ll) /*Linked list of input device*/ \
LV_DISPATCH(f, lv_ll_t, _lv_fsdrv_ll) \
LV_DISPATCH(f, lv_ll_t, _lv_anim_ll) \
LV_DISPATCH(f, lv_ll_t, _lv_group_ll) \
LV_DISPATCH(f, lv_ll_t, _lv_img_decoder_ll) \
LV_DISPATCH(f, lv_ll_t, _lv_obj_style_trans_ll) \
LV_DISPATCH(f, lv_layout_dsc_t *, _lv_layout_list) \
LV_DISPATCH_COND(f, _lv_img_cache_entry_t*, _lv_img_cache_array, LV_IMG_CACHE_DEF, 1) \
LV_DISPATCH_COND(f, _lv_img_cache_entry_t, _lv_img_cache_single, LV_IMG_CACHE_DEF, 0) \
LV_DISPATCH(f, lv_timer_t*, _lv_timer_act) \
LV_DISPATCH(f, lv_mem_buf_arr_t , lv_mem_buf) \
LV_DISPATCH_COND(f, _lv_draw_mask_radius_circle_dsc_arr_t , _lv_circle_cache, LV_DRAW_COMPLEX, 1) \
LV_DISPATCH_COND(f, _lv_draw_mask_saved_arr_t , _lv_draw_mask_list, LV_DRAW_COMPLEX, 1) \
LV_DISPATCH(f, void * , _lv_theme_default_styles) \
LV_DISPATCH(f, void * , _lv_theme_basic_styles) \
LV_DISPATCH_COND(f, uint8_t *, _lv_font_decompr_buf, LV_USE_FONT_COMPRESSED, 1) \
LV_DISPATCH(f, uint8_t * , _lv_grad_cache_mem) \
LV_DISPATCH(f, uint8_t * , _lv_style_custom_prop_flag_lookup_table)
#define LV_DEFINE_ROOT(root_type, root_name) root_type root_name;
#define LV_ROOTS LV_ITERATE_ROOTS(LV_DEFINE_ROOT)
然后我们再看到 lv_gc.c 中的宏定义:
/**********************
* STATIC VARIABLES
**********************/
#if(!defined(LV_ENABLE_GC)) || LV_ENABLE_GC == 0
LV_ROOTS
#endif /*LV_ENABLE_GC*/
将 LV_ROOTS 宏展开就能得到变量的定义:
LV_ROOTS
LV_ITERATE_ROOTS(LV_DEFINE_ROOT)
LV_DISPATCH(LV_DEFINE_ROOT, lv_ll_t, _lv_timer_ll)
LV_DISPATCH(LV_DEFINE_ROOT, lv_ll_t, _lv_timer_ll)
LV_DEFINE_ROOT(lv_ll_t, _lv_timer_ll)
// 因为 LV_DEFINE_ROOT(root_type, root_name) root_type root_name; 因此可得:
lv_ll_t _lv_timer_ll;
其他的定义也是这样分析,这样就能得到 LV_ITERATE_ROOTS(f) 中列出的所有变量。
在 lv_gc.h 的宏定义 #define LV_GC_ROOT(x) x 我们不用理会,不要被其迷惑了。
1 个赞
棒棒棒!!!感谢老师讲解。。。。还得消化消化,LVGL代码有点深奥哟