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_conf_internal_gen.py (5527B)
1 #!/usr/bin/env python3 2 3 ''' 4 Generates lv_conf_internal.h from lv_conf_template.h to provide default values 5 ''' 6 7 import os 8 import sys 9 import re 10 11 SCRIPT_DIR = os.path.dirname(__file__) 12 LV_CONF_TEMPLATE = os.path.join(SCRIPT_DIR, "..", "lv_conf_template.h") 13 LV_CONF_INTERNAL = os.path.join(SCRIPT_DIR, "..", "src", "lv_conf_internal.h") 14 15 if sys.version_info < (3,6,0): 16 print("Python >=3.6 is required", file=sys.stderr) 17 exit(1) 18 19 fin = open(LV_CONF_TEMPLATE) 20 fout = open(LV_CONF_INTERNAL, "w") 21 22 fout.write( 23 '''/** 24 * GENERATED FILE, DO NOT EDIT IT! 25 * @file lv_conf_internal.h 26 * Make sure all the defines of lv_conf.h have a default value 27 **/ 28 29 #ifndef LV_CONF_INTERNAL_H 30 #define LV_CONF_INTERNAL_H 31 /* clang-format off */ 32 33 #include <stdint.h> 34 35 /* Handle special Kconfig options */ 36 #ifndef LV_KCONFIG_IGNORE 37 #include "lv_conf_kconfig.h" 38 #ifdef CONFIG_LV_CONF_SKIP 39 #define LV_CONF_SKIP 40 #endif 41 #endif 42 43 /*If "lv_conf.h" is available from here try to use it later.*/ 44 #ifdef __has_include 45 #if __has_include("lv_conf.h") 46 #ifndef LV_CONF_INCLUDE_SIMPLE 47 #define LV_CONF_INCLUDE_SIMPLE 48 #endif 49 #endif 50 #endif 51 52 /*If lv_conf.h is not skipped include it*/ 53 #ifndef LV_CONF_SKIP 54 #ifdef LV_CONF_PATH /*If there is a path defined for lv_conf.h use it*/ 55 #define __LV_TO_STR_AUX(x) #x 56 #define __LV_TO_STR(x) __LV_TO_STR_AUX(x) 57 #include __LV_TO_STR(LV_CONF_PATH) 58 #undef __LV_TO_STR_AUX 59 #undef __LV_TO_STR 60 #elif defined(LV_CONF_INCLUDE_SIMPLE) /*Or simply include lv_conf.h is enabled*/ 61 #include "lv_conf.h" 62 #else 63 #include "../../lv_conf.h" /*Else assume lv_conf.h is next to the lvgl folder*/ 64 #endif 65 #if !defined(LV_CONF_H) && !defined(LV_CONF_SUPPRESS_DEFINE_CHECK) 66 /* #include will sometimes silently fail when __has_include is used */ 67 /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80753 */ 68 #pragma message("Possible failure to include lv_conf.h, please read the comment in this file if you get errors") 69 #endif 70 #endif 71 72 #ifdef CONFIG_LV_COLOR_DEPTH 73 #define _LV_KCONFIG_PRESENT 74 #endif 75 76 /*---------------------------------- 77 * Start parsing lv_conf_template.h 78 -----------------------------------*/ 79 ''' 80 ) 81 82 started = 0 83 84 for line in fin.read().splitlines(): 85 if not started: 86 if '#define LV_CONF_H' in line: 87 started = 1 88 continue 89 else: 90 continue 91 92 if '/*--END OF LV_CONF_H--*/' in line: break 93 94 #Is there a #define in this line? 95 r = re.search(r'^([\s]*)#[\s]*define[\s]+([^\s]+).*$', line) # \s means any white space character 96 97 if r: 98 indent = r[1] 99 100 name = r[2] 101 name = re.sub('\(.*?\)', '', name, 1) #remove parentheses from macros. E.g. MY_FUNC(5) -> MY_FUNC 102 103 name_and_value = re.sub('[\s]*#[\s]*define', '', line, 1) 104 105 #If the value should be 1 (enabled) by default use a more complex structure for Kconfig checks because 106 #if a not defined CONFIG_... value should be interpreted as 0 and not the LVGL default 107 is_one = re.search(r'[\s]*#[\s]*define[\s]*[A-Z0-9_]+[\s]+1([\s]*$|[\s]+)', line) 108 if is_one: 109 #1. Use the value if already set from lv_conf.h or anything else (i.e. do nothing) 110 #2. In Kconfig environment use the CONFIG_... value if set, else use 0 111 #3. In not Kconfig environment use the LVGL's default value 112 113 fout.write( 114 f'{indent}#ifndef {name}\n' 115 f'{indent} #ifdef _LV_KCONFIG_PRESENT\n' 116 f'{indent} #ifdef CONFIG_{name.upper()}\n' 117 f'{indent} #define {name} CONFIG_{name.upper()}\n' 118 f'{indent} #else\n' 119 f'{indent} #define {name} 0\n' 120 f'{indent} #endif\n' 121 f'{indent} #else\n' 122 f'{indent} #define{name_and_value}\n' 123 f'{indent} #endif\n' 124 f'{indent}#endif\n' 125 ) 126 else: 127 #1. Use the value if already set from lv_conf.h or anything else (i.e. do nothing) 128 #2. Use the Kconfig value if set 129 #3. Use the LVGL's default value 130 131 fout.write( 132 f'{indent}#ifndef {name}\n' 133 f'{indent} #ifdef CONFIG_{name.upper()}\n' 134 f'{indent} #define {name} CONFIG_{name.upper()}\n' 135 f'{indent} #else\n' 136 f'{indent} #define{name_and_value}\n' 137 f'{indent} #endif\n' 138 f'{indent}#endif\n' 139 ) 140 141 elif re.search('^ *typedef .*;.*$', line): 142 continue #ignore typedefs to avoid redeclaration 143 else: 144 fout.write(f'{line}\n') 145 146 fout.write( 147 ''' 148 149 /*---------------------------------- 150 * End of parsing lv_conf_template.h 151 -----------------------------------*/ 152 153 LV_EXPORT_CONST_INT(LV_DPI_DEF); 154 155 #undef _LV_KCONFIG_PRESENT 156 157 158 /*Set some defines if a dependency is disabled*/ 159 #if LV_USE_LOG == 0 160 #define LV_LOG_LEVEL LV_LOG_LEVEL_NONE 161 #define LV_LOG_TRACE_MEM 0 162 #define LV_LOG_TRACE_TIMER 0 163 #define LV_LOG_TRACE_INDEV 0 164 #define LV_LOG_TRACE_DISP_REFR 0 165 #define LV_LOG_TRACE_EVENT 0 166 #define LV_LOG_TRACE_OBJ_CREATE 0 167 #define LV_LOG_TRACE_LAYOUT 0 168 #define LV_LOG_TRACE_ANIM 0 169 #endif /*LV_USE_LOG*/ 170 171 172 /*If running without lv_conf.h add typedefs with default value*/ 173 #ifdef LV_CONF_SKIP 174 #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) /*Disable warnings for Visual Studio*/ 175 #define _CRT_SECURE_NO_WARNINGS 176 #endif 177 #endif /*defined(LV_CONF_SKIP)*/ 178 179 #endif /*LV_CONF_INTERNAL_H*/ 180 ''' 181 ) 182 183 fin.close() 184 fout.close()