feat(scripts): add default config generator (#6522)
Co-authored-by: Gabor Kiss-Vamosi <kisvegabor@gmail.com> Co-authored-by: Liam <30486941+liamHowatt@users.noreply.github.com>
This commit is contained in:
@@ -217,28 +217,28 @@
|
|||||||
#define LV_USE_DRAW_VG_LITE 0
|
#define LV_USE_DRAW_VG_LITE 0
|
||||||
|
|
||||||
#if LV_USE_DRAW_VG_LITE
|
#if LV_USE_DRAW_VG_LITE
|
||||||
/* Enable VG-Lite custom external 'gpu_init()' function */
|
/* Enable VG-Lite custom external 'gpu_init()' function */
|
||||||
#define LV_VG_LITE_USE_GPU_INIT 0
|
#define LV_VG_LITE_USE_GPU_INIT 0
|
||||||
|
|
||||||
/* Enable VG-Lite assert. */
|
/* Enable VG-Lite assert. */
|
||||||
#define LV_VG_LITE_USE_ASSERT 0
|
#define LV_VG_LITE_USE_ASSERT 0
|
||||||
|
|
||||||
/* VG-Lite flush commit trigger threshold. GPU will try to batch these many draw tasks. */
|
/* VG-Lite flush commit trigger threshold. GPU will try to batch these many draw tasks. */
|
||||||
#define LV_VG_LITE_FLUSH_MAX_COUNT 8
|
#define LV_VG_LITE_FLUSH_MAX_COUNT 8
|
||||||
|
|
||||||
/* Enable border to simulate shadow
|
/* Enable border to simulate shadow
|
||||||
* NOTE: which usually improves performance,
|
* NOTE: which usually improves performance,
|
||||||
* but does not guarantee the same rendering quality as the software. */
|
* but does not guarantee the same rendering quality as the software. */
|
||||||
#define LV_VG_LITE_USE_BOX_SHADOW 0
|
#define LV_VG_LITE_USE_BOX_SHADOW 0
|
||||||
|
|
||||||
/* VG-Lite gradient maximum cache number.
|
/* VG-Lite gradient maximum cache number.
|
||||||
* NOTE: The memory usage of a single gradient image is 4K bytes.
|
* NOTE: The memory usage of a single gradient image is 4K bytes.
|
||||||
*/
|
*/
|
||||||
#define LV_VG_LITE_GRAD_CACHE_CNT 32
|
#define LV_VG_LITE_GRAD_CACHE_CNT 32
|
||||||
|
|
||||||
/* VG-Lite stroke maximum cache number.
|
/* VG-Lite stroke maximum cache number.
|
||||||
*/
|
*/
|
||||||
#define LV_VG_LITE_STROKE_CACHE_CNT 32
|
#define LV_VG_LITE_STROKE_CACHE_CNT 32
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -763,8 +763,8 @@
|
|||||||
/*GIF decoder library*/
|
/*GIF decoder library*/
|
||||||
#define LV_USE_GIF 0
|
#define LV_USE_GIF 0
|
||||||
#if LV_USE_GIF
|
#if LV_USE_GIF
|
||||||
/*GIF decoder accelerate*/
|
/*GIF decoder accelerate*/
|
||||||
#define LV_GIF_CACHE_DECODE_DATA 0
|
#define LV_GIF_CACHE_DECODE_DATA 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
121
scripts/generate_lv_conf.py
Executable file
121
scripts/generate_lv_conf.py
Executable file
@@ -0,0 +1,121 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
DIR_SCRIPTS = os.path.dirname(__file__)
|
||||||
|
REPO_ROOT = os.path.join(DIR_SCRIPTS, "..")
|
||||||
|
DIR_CWD = os.getcwd()
|
||||||
|
|
||||||
|
|
||||||
|
def fatal(msg):
|
||||||
|
print()
|
||||||
|
print("ERROR! " + msg)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def get_args():
|
||||||
|
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter, description=""
|
||||||
|
"Update the configuration file of your existing project based on default parameters and latest LVGL template. Eg.:\n"
|
||||||
|
" python3 generate_lv_conf.py ./src \n"
|
||||||
|
" python3 generate_lv_conf.py --template modules/lvgl/lv_conf_template.h ./my_config_folder"
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument('--template', type=str, default=REPO_ROOT, nargs='?',
|
||||||
|
help='Path of "lv_conf_template.h" file or the folder containing it\n(optional, 1 folder above the python script by default)')
|
||||||
|
|
||||||
|
parser.add_argument('--config', type=str, default=None, nargs='?',
|
||||||
|
help='Path of "lv_conf.h" file (optional)')
|
||||||
|
|
||||||
|
parser.add_argument('--defaults', type=str, default=None, nargs='?',
|
||||||
|
help='Path of "lv_conf.defaults" file (optional)')
|
||||||
|
|
||||||
|
parser.add_argument('target', metavar='target', type=str, default=DIR_CWD, nargs='?',
|
||||||
|
help='Folder containing "lv_conf.h" and "lv_conf.defaults" files\n(optional, current work folder by default)')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if os.path.isdir(args.template):
|
||||||
|
args.template = os.path.join(args.template, "lv_conf_template.h")
|
||||||
|
|
||||||
|
if not args.config:
|
||||||
|
args.config = os.path.join(args.target, "lv_conf.h")
|
||||||
|
|
||||||
|
if not args.defaults:
|
||||||
|
args.defaults = os.path.join(args.target, "lv_conf.defaults")
|
||||||
|
|
||||||
|
if not os.path.exists(args.template):
|
||||||
|
fatal(f"Template file not found at {args.template}")
|
||||||
|
if not os.path.exists(args.config):
|
||||||
|
fatal(f"User config file not found at {args.config}")
|
||||||
|
if not os.path.exists(args.defaults):
|
||||||
|
fatal(f"User defaults not found at {args.defaults}")
|
||||||
|
|
||||||
|
return args
|
||||||
|
|
||||||
|
|
||||||
|
def parse_defaults(path: str):
|
||||||
|
defaults = {}
|
||||||
|
|
||||||
|
with open(path, 'r', encoding='utf-8') as file:
|
||||||
|
for line in file.readlines():
|
||||||
|
if len(line.strip()) == 0 or line.startswith('#'):
|
||||||
|
continue
|
||||||
|
groups = re.search(r'([A-Z0-9_]+)\s+(.+)', line).groups()
|
||||||
|
defaults[groups[0]] = groups[1]
|
||||||
|
|
||||||
|
return defaults
|
||||||
|
|
||||||
|
|
||||||
|
def generate_config(path_destination: str, path_source: str, defaults: dict):
|
||||||
|
with open(path_source, 'r', encoding='utf-8') as f_src:
|
||||||
|
src_lines = f_src.readlines()
|
||||||
|
|
||||||
|
keys_used = set()
|
||||||
|
dst_lines = []
|
||||||
|
|
||||||
|
for src_line in src_lines:
|
||||||
|
res = re.search(r'#define\s+([A-Z0-9_]+)\s+(.+)', src_line)
|
||||||
|
key = res.groups()[0] if res else None
|
||||||
|
|
||||||
|
if key in defaults.keys():
|
||||||
|
value = defaults[key]
|
||||||
|
pattern = r'(#define\s+[A-Z0-9_]+\s+)(.+)'
|
||||||
|
repl = r'\g<1>' + value
|
||||||
|
dst_line, _ = re.subn(pattern, repl, src_line)
|
||||||
|
|
||||||
|
if not dst_line:
|
||||||
|
fatal(f"Failed to apply key '{key}' to line '{src_line}'")
|
||||||
|
|
||||||
|
print(f"Applying: {key} = {value}")
|
||||||
|
keys_used.add(key)
|
||||||
|
elif 'Set it to "1" to enable content' in src_line:
|
||||||
|
dst_line = '#if 1 /*Content enable*/'
|
||||||
|
else:
|
||||||
|
dst_line = src_line
|
||||||
|
|
||||||
|
dst_lines.append(dst_line)
|
||||||
|
|
||||||
|
if len(keys_used) != len(defaults):
|
||||||
|
unused_keys = [k for k in defaults.keys() if k not in keys_used]
|
||||||
|
fatal('The following keys are deprecated:\n ' + '\n '.join(unused_keys))
|
||||||
|
|
||||||
|
with open(path_destination, 'w', encoding='utf-8') as f_dst:
|
||||||
|
for dst_line in dst_lines:
|
||||||
|
f_dst.write(dst_line)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
args = get_args()
|
||||||
|
|
||||||
|
print("Template:", args.template)
|
||||||
|
print("User config:", args.config)
|
||||||
|
print("User defaults:", args.defaults)
|
||||||
|
|
||||||
|
defaults = parse_defaults(args.defaults)
|
||||||
|
print(f"Loaded {len(defaults)} defaults")
|
||||||
|
|
||||||
|
generate_config(args.config, args.template, defaults)
|
||||||
|
print()
|
||||||
|
print('New config successfully generated!')
|
||||||
@@ -642,64 +642,64 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if LV_USE_DRAW_VG_LITE
|
#if LV_USE_DRAW_VG_LITE
|
||||||
/* Enable VG-Lite custom external 'gpu_init()' function */
|
/* Enable VG-Lite custom external 'gpu_init()' function */
|
||||||
#ifndef LV_VG_LITE_USE_GPU_INIT
|
#ifndef LV_VG_LITE_USE_GPU_INIT
|
||||||
#ifdef CONFIG_LV_VG_LITE_USE_GPU_INIT
|
#ifdef CONFIG_LV_VG_LITE_USE_GPU_INIT
|
||||||
#define LV_VG_LITE_USE_GPU_INIT CONFIG_LV_VG_LITE_USE_GPU_INIT
|
#define LV_VG_LITE_USE_GPU_INIT CONFIG_LV_VG_LITE_USE_GPU_INIT
|
||||||
#else
|
#else
|
||||||
#define LV_VG_LITE_USE_GPU_INIT 0
|
#define LV_VG_LITE_USE_GPU_INIT 0
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Enable VG-Lite assert. */
|
/* Enable VG-Lite assert. */
|
||||||
#ifndef LV_VG_LITE_USE_ASSERT
|
#ifndef LV_VG_LITE_USE_ASSERT
|
||||||
#ifdef CONFIG_LV_VG_LITE_USE_ASSERT
|
#ifdef CONFIG_LV_VG_LITE_USE_ASSERT
|
||||||
#define LV_VG_LITE_USE_ASSERT CONFIG_LV_VG_LITE_USE_ASSERT
|
#define LV_VG_LITE_USE_ASSERT CONFIG_LV_VG_LITE_USE_ASSERT
|
||||||
#else
|
#else
|
||||||
#define LV_VG_LITE_USE_ASSERT 0
|
#define LV_VG_LITE_USE_ASSERT 0
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
/* VG-Lite flush commit trigger threshold. GPU will try to batch these many draw tasks. */
|
/* VG-Lite flush commit trigger threshold. GPU will try to batch these many draw tasks. */
|
||||||
#ifndef LV_VG_LITE_FLUSH_MAX_COUNT
|
#ifndef LV_VG_LITE_FLUSH_MAX_COUNT
|
||||||
#ifdef CONFIG_LV_VG_LITE_FLUSH_MAX_COUNT
|
#ifdef CONFIG_LV_VG_LITE_FLUSH_MAX_COUNT
|
||||||
#define LV_VG_LITE_FLUSH_MAX_COUNT CONFIG_LV_VG_LITE_FLUSH_MAX_COUNT
|
#define LV_VG_LITE_FLUSH_MAX_COUNT CONFIG_LV_VG_LITE_FLUSH_MAX_COUNT
|
||||||
#else
|
#else
|
||||||
#define LV_VG_LITE_FLUSH_MAX_COUNT 8
|
#define LV_VG_LITE_FLUSH_MAX_COUNT 8
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Enable border to simulate shadow
|
/* Enable border to simulate shadow
|
||||||
* NOTE: which usually improves performance,
|
* NOTE: which usually improves performance,
|
||||||
* but does not guarantee the same rendering quality as the software. */
|
* but does not guarantee the same rendering quality as the software. */
|
||||||
#ifndef LV_VG_LITE_USE_BOX_SHADOW
|
#ifndef LV_VG_LITE_USE_BOX_SHADOW
|
||||||
#ifdef CONFIG_LV_VG_LITE_USE_BOX_SHADOW
|
#ifdef CONFIG_LV_VG_LITE_USE_BOX_SHADOW
|
||||||
#define LV_VG_LITE_USE_BOX_SHADOW CONFIG_LV_VG_LITE_USE_BOX_SHADOW
|
#define LV_VG_LITE_USE_BOX_SHADOW CONFIG_LV_VG_LITE_USE_BOX_SHADOW
|
||||||
#else
|
#else
|
||||||
#define LV_VG_LITE_USE_BOX_SHADOW 0
|
#define LV_VG_LITE_USE_BOX_SHADOW 0
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
/* VG-Lite gradient maximum cache number.
|
/* VG-Lite gradient maximum cache number.
|
||||||
* NOTE: The memory usage of a single gradient image is 4K bytes.
|
* NOTE: The memory usage of a single gradient image is 4K bytes.
|
||||||
*/
|
*/
|
||||||
#ifndef LV_VG_LITE_GRAD_CACHE_CNT
|
#ifndef LV_VG_LITE_GRAD_CACHE_CNT
|
||||||
#ifdef CONFIG_LV_VG_LITE_GRAD_CACHE_CNT
|
#ifdef CONFIG_LV_VG_LITE_GRAD_CACHE_CNT
|
||||||
#define LV_VG_LITE_GRAD_CACHE_CNT CONFIG_LV_VG_LITE_GRAD_CACHE_CNT
|
#define LV_VG_LITE_GRAD_CACHE_CNT CONFIG_LV_VG_LITE_GRAD_CACHE_CNT
|
||||||
#else
|
#else
|
||||||
#define LV_VG_LITE_GRAD_CACHE_CNT 32
|
#define LV_VG_LITE_GRAD_CACHE_CNT 32
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
/* VG-Lite stroke maximum cache number.
|
/* VG-Lite stroke maximum cache number.
|
||||||
*/
|
*/
|
||||||
#ifndef LV_VG_LITE_STROKE_CACHE_CNT
|
#ifndef LV_VG_LITE_STROKE_CACHE_CNT
|
||||||
#ifdef CONFIG_LV_VG_LITE_STROKE_CACHE_CNT
|
#ifdef CONFIG_LV_VG_LITE_STROKE_CACHE_CNT
|
||||||
#define LV_VG_LITE_STROKE_CACHE_CNT CONFIG_LV_VG_LITE_STROKE_CACHE_CNT
|
#define LV_VG_LITE_STROKE_CACHE_CNT CONFIG_LV_VG_LITE_STROKE_CACHE_CNT
|
||||||
#else
|
#else
|
||||||
#define LV_VG_LITE_STROKE_CACHE_CNT 32
|
#define LV_VG_LITE_STROKE_CACHE_CNT 32
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -2542,15 +2542,15 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#if LV_USE_GIF
|
#if LV_USE_GIF
|
||||||
/*GIF decoder accelerate*/
|
/*GIF decoder accelerate*/
|
||||||
#ifndef LV_GIF_CACHE_DECODE_DATA
|
#ifndef LV_GIF_CACHE_DECODE_DATA
|
||||||
#ifdef CONFIG_LV_GIF_CACHE_DECODE_DATA
|
#ifdef CONFIG_LV_GIF_CACHE_DECODE_DATA
|
||||||
#define LV_GIF_CACHE_DECODE_DATA CONFIG_LV_GIF_CACHE_DECODE_DATA
|
#define LV_GIF_CACHE_DECODE_DATA CONFIG_LV_GIF_CACHE_DECODE_DATA
|
||||||
#else
|
#else
|
||||||
#define LV_GIF_CACHE_DECODE_DATA 0
|
#define LV_GIF_CACHE_DECODE_DATA 0
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*Decode bin images to RAM*/
|
/*Decode bin images to RAM*/
|
||||||
|
|||||||
Reference in New Issue
Block a user