1#!/usr/bin/env python3 2 3''' 4Generates lv_conf_internal.h from lv_conf_template.h to provide default values 5''' 6 7import os 8import sys 9import re 10 11SCRIPT_DIR = os.path.dirname(__file__) 12LV_CONF_TEMPLATE = os.path.join(SCRIPT_DIR, "..", "lv_conf_template.h") 13LV_CONF_INTERNAL = os.path.join(SCRIPT_DIR, "..", "src", "lv_conf_internal.h") 14 15if sys.version_info < (3,6,0): 16 print("Python >=3.6 is required", file=sys.stderr) 17 exit(1) 18 19fin = open(LV_CONF_TEMPLATE) 20fout = open(LV_CONF_INTERNAL, "w") 21 22fout.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#endif 66 67#ifdef CONFIG_LV_COLOR_DEPTH 68 #define _LV_KCONFIG_PRESENT 69#endif 70 71/*---------------------------------- 72 * Start parsing lv_conf_template.h 73 -----------------------------------*/ 74''' 75) 76 77started = 0 78 79for line in fin.read().splitlines(): 80 if not started: 81 if '#define LV_CONF_H' in line: 82 started = 1 83 continue 84 else: 85 continue 86 87 if '/*--END OF LV_CONF_H--*/' in line: break 88 89 #Is there a #define in this line? 90 r = re.search(r'^([\s]*)#[\s]*define[\s]+([^\s]+).*$', line) # \s means any white space character 91 92 if r: 93 indent = r[1] 94 95 name = r[2] 96 name = re.sub('\(.*?\)', '', name, 1) #remove parentheses from macros. E.g. MY_FUNC(5) -> MY_FUNC 97 98 name_and_value = re.sub('[\s]*#[\s]*define', '', line, 1) 99 100 #If the value should be 1 (enabled) by default use a more complex structure for Kconfig checks because 101 #if a not defined CONFIG_... value should be interpreted as 0 and not the LVGL default 102 is_one = re.search(r'[\s]*#[\s]*define[\s]*[A-Z0-9_]+[\s]+1([\s]*$|[\s]+)', line) 103 if is_one: 104 #1. Use the value if already set from lv_conf.h or anything else (i.e. do nothing) 105 #2. In Kconfig environment use the CONFIG_... value if set, else use 0 106 #3. In not Kconfig environment use the LVGL's default value 107 108 fout.write( 109 f'{indent}#ifndef {name}\n' 110 f'{indent} #ifdef _LV_KCONFIG_PRESENT\n' 111 f'{indent} #ifdef CONFIG_{name.upper()}\n' 112 f'{indent} #define {name} CONFIG_{name.upper()}\n' 113 f'{indent} #else\n' 114 f'{indent} #define {name} 0\n' 115 f'{indent} #endif\n' 116 f'{indent} #else\n' 117 f'{indent} #define{name_and_value}\n' 118 f'{indent} #endif\n' 119 f'{indent}#endif\n' 120 ) 121 else: 122 #1. Use the value if already set from lv_conf.h or anything else (i.e. do nothing) 123 #2. Use the Kconfig value if set 124 #3. Use the LVGL's default value 125 126 fout.write( 127 f'{indent}#ifndef {name}\n' 128 f'{indent} #ifdef CONFIG_{name.upper()}\n' 129 f'{indent} #define {name} CONFIG_{name.upper()}\n' 130 f'{indent} #else\n' 131 f'{indent} #define{name_and_value}\n' 132 f'{indent} #endif\n' 133 f'{indent}#endif\n' 134 ) 135 136 elif re.search('^ *typedef .*;.*$', line): 137 continue #ignore typedefs to avoid redeclaration 138 else: 139 fout.write(f'{line}\n') 140 141fout.write( 142''' 143 144/*---------------------------------- 145 * End of parsing lv_conf_template.h 146 -----------------------------------*/ 147 148LV_EXPORT_CONST_INT(LV_DPI_DEF); 149 150#undef _LV_KCONFIG_PRESENT 151 152 153/*Set some defines if a dependency is disabled*/ 154#if LV_USE_LOG == 0 155 #define LV_LOG_LEVEL LV_LOG_LEVEL_NONE 156 #define LV_LOG_TRACE_MEM 0 157 #define LV_LOG_TRACE_TIMER 0 158 #define LV_LOG_TRACE_INDEV 0 159 #define LV_LOG_TRACE_DISP_REFR 0 160 #define LV_LOG_TRACE_EVENT 0 161 #define LV_LOG_TRACE_OBJ_CREATE 0 162 #define LV_LOG_TRACE_LAYOUT 0 163 #define LV_LOG_TRACE_ANIM 0 164#endif /*LV_USE_LOG*/ 165 166 167/*If running without lv_conf.h add typedefs with default value*/ 168#ifdef LV_CONF_SKIP 169 #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) /*Disable warnings for Visual Studio*/ 170 #define _CRT_SECURE_NO_WARNINGS 171 #endif 172#endif /*defined(LV_CONF_SKIP)*/ 173 174#endif /*LV_CONF_INTERNAL_H*/ 175''' 176) 177 178fin.close() 179fout.close() 180