1#!/usr/bin/env python3 2 3''' 4Generates a checker file for lv_conf.h from lv_conf_templ.h define all the not defined values 5''' 6 7 8import sys 9import re 10 11if sys.version_info < (3,6,0): 12 print("Python >=3.6 is required", file=sys.stderr) 13 exit(1) 14 15fin = open("../lv_conf_template.h", "r") 16fout = open("../src/lv_conf_internal.h", "w") 17 18 19fout.write( 20'''/** 21 * GENERATED FILE, DO NOT EDIT IT! 22 * @file lv_conf_internal.h 23 * Make sure all the defines of lv_conf.h have a default value 24**/ 25 26#ifndef LV_CONF_INTERNAL_H 27#define LV_CONF_INTERNAL_H 28/* clang-format off */ 29 30#include <stdint.h> 31 32/*If lv_conf.h is not skipped include it*/ 33#if !defined(LV_CONF_SKIP) && !defined(CONFIG_LV_CONF_SKIP) 34# if defined(LV_CONF_PATH) /*If there is a path defined for lv_conf.h use it*/ 35# define __LV_TO_STR_AUX(x) #x 36# define __LV_TO_STR(x) __LV_TO_STR_AUX(x) 37# include __LV_TO_STR(LV_CONF_PATH) 38# undef __LV_TO_STR_AUX 39# undef __LV_TO_STR 40# elif defined(LV_CONF_INCLUDE_SIMPLE) /*Or simply include lv_conf.h is enabled*/ 41# include "lv_conf.h" 42# else 43# include "../../lv_conf.h" /*Else assume lv_conf.h is next to the lvgl folder */ 44# endif 45#endif 46 47''' 48) 49 50started = 0 51 52for i in fin.read().splitlines(): 53 if not started: 54 if '#define LV_CONF_H' in i: 55 started = 1 56 continue 57 else: 58 continue 59 60 if '/*--END OF LV_CONF_H--*/' in i: break 61 62 r = re.search(r'^ *# *define ([^\s]+).*$', i) 63 64#ifndef LV_USE_BTN /*Only if not defined in lv_conf.h*/ 65# ifdef CONFIG_LV_USE_BTN /*Use KConfig value if set*/ 66# define LV_USE_BTN CONFIG_LV_USE_BTN 67# else 68# define LV_USE_BTN 1 /*Use default value*/ 69# endif 70#endif 71 72 if r: 73 line = re.sub('\(.*?\)', '', r[1], 1) #remove parentheses from macros 74 75 dr = re.sub('.*# *define', '', i, 1) 76 d = "# define " + dr 77 78 fout.write( 79 f'#ifndef {line}\n' 80 f'# ifdef CONFIG_{line}\n' 81 f'# define {line} CONFIG_{line}\n' 82 f'# else\n' 83 f'{d}\n' 84 f'# endif\n' 85 f'#endif\n' 86 ) 87 elif re.search('^ *typedef .*;.*$', i): 88 continue #ignore typedefs to avoide redeclaration 89 else: 90 fout.write(f'{i}\n') 91 92 93fout.write( 94''' 95 96/*If running without lv_conf.h add typdesf with default value*/ 97#if defined(LV_CONF_SKIP) || defined(CONFIG_LV_CONF_SKIP) 98 99 /* Type of coordinates. Should be `int16_t` (or `int32_t` for extreme cases) */ 100 typedef int16_t lv_coord_t; 101 102# if LV_USE_ANIMATION 103 /*Declare the type of the user data of animations (can be e.g. `void *`, `int`, `struct`)*/ 104 typedef void * lv_anim_user_data_t; 105# endif 106 107# if LV_USE_GROUP 108 typedef void * lv_group_user_data_t; 109# endif 110 111# if LV_USE_FILESYSTEM 112 typedef void * lv_fs_drv_user_data_t; 113# endif 114 115 typedef void * lv_img_decoder_user_data_t; 116 117 typedef void * lv_disp_drv_user_data_t; /*Type of user data in the display driver*/ 118 typedef void * lv_indev_drv_user_data_t; /*Type of user data in the input device driver*/ 119 120 typedef void * lv_font_user_data_t; 121 122# if LV_USE_USER_DATA 123 typedef void * lv_obj_user_data_t; 124# endif 125 126#endif 127 128#endif /*LV_CONF_INTERNAL_H*/ 129''' 130) 131 132fin.close() 133fout.close() 134