Compare commits

..

2 Commits

2 changed files with 22 additions and 17 deletions

View File

@@ -110,7 +110,9 @@ def inject_handlers_file(path: Path):
patched = content
for handler in INJECT_HANDLERS:
patched = patched.replace("void %s_Handler(void){"%(handler), "void %s_Handler(void){\nmy_%s();"%(handler, handler))
patched = patched \
.replace("void %sHandler(void)\n{\n /*"%(handler), "void %sHandler(void)\n{\n my_%s();\n /*"%(handler, handler)) \
.replace("/* USER CODE BEGIN PFP */\n\n", "/* USER CODE BEGIN PFP */\nvoid my_%s();\n"%(handler))
with open(path, "w") as of:
of.write(patched)
@@ -129,13 +131,14 @@ def call_my_main(path: Path):
with open(main_c, "r") as _if:
content = _if.read()
patched = content.replace("/* USER CODE BEGIN PFP */", "/* USER CODE BEGIN PFP */\nvoid my_main();").replace("/* USER CODE BEGIN WHILE */\n while (1)", "/* USER CODE BEGIN WHILE */\nmy_main();\n while (1)")
patched = content.replace("/* USER CODE BEGIN PFP */\n\n", "/* USER CODE BEGIN PFP */\nvoid my_main();\n").replace("/* USER CODE BEGIN WHILE */\n while (1)", "/* USER CODE BEGIN WHILE */\n my_main();\n while (1)")
with open(main_c, "w") as of:
of.write(patched)
def load_config(path: Path):
if not path.exists():
print("WARN: No config file", path)
return
if not path.is_file():
print("Config '%s' is not a file."%(path))
@@ -181,21 +184,21 @@ def overlay_config(config: dict):
print("exclude must be a list of strings")
exit(1)
CMAKE_EXCLUDE_SOURCES = config["exclude"]
if "assume-yes" in config and config["assume-yes"]:
if not isinstance(config["assume-yes"], bool):
print("assume-yes must be a bool")
if "assume_yes" in config and config["assume_yes"]:
if not isinstance(config["assume_yes"], bool):
print("assume_yes must be a bool")
exit(1)
ASSUME_YES |= config["assume-yes"]
if "inject-handlers" in config and config["inject-handlers"]:
if not isinstance(config["inject-handlers"], list):
print("inject-handlers must be a list of strings")
ASSUME_YES |= config["assume_yes"]
if "inject_handlers" in config and config["inject_handlers"]:
if not isinstance(config["inject_handlers"], list):
print("inject_handlers must be a list of strings")
exit(1)
INJECT_HANDLERS += config["inject-handlers"]
if "no-my-main" in config and config["no-my-main"]:
if not isinstance(config["no-my-main"], bool):
print("no-my-main must be a bool")
INJECT_HANDLERS += config["inject_handlers"]
if "no_my_main" in config and config["no_my_main"]:
if not isinstance(config["no_my_main"], bool):
print("no_my_main must be a bool")
exit(1)
NO_MY_MAIN |= config["no-my-main"]
NO_MY_MAIN |= config["no_my_main"]
def print_config():
print("MX_DISCARD_PATHS", MX_DISCARD_PATHS)
@@ -223,17 +226,19 @@ def main2(ns: Namespace):
recurse_cmakelists(ns.path)
root_cmakelists(ns.path)
if not INJECT_HANDLERS:
if INJECT_HANDLERS:
inject_handlers(ns.path)
if not NO_MY_MAIN:
call_my_main(ns.path)
print("Convert complete")
def main():
parser = ArgumentParser(prog="MX Convert")
parser.add_argument("-c", "--config", action="store", type=Path, default="mx_convert.toml", help="The config file to read. If not specified, defaults to 'mx_convert.toml'.")
parser.add_argument("-d", "--discard", action="append", help="Add a file to the discard list (delete if found).")
parser.add_argument("-i", "--inject-handlers", action="store", help="Add a call to your own handler functions in MX generated code.")
parser.add_argument("-i", "--inject-handlers", action="append", help="Add a call to your own handler functions in MX generated code. Ex: for PendSV_Handler use '-i PendSV_'")
parser.add_argument("-H", "--header", action="append", help="Add a pattern to the headers list, single wildcards allowed. Includes *.h by default.")
parser.add_argument("-n", "--no-my-main", action="store_true", help="Disable added call to my_main inside the generated main function.")
parser.add_argument("-s", "--source", action="append", help="Add a pattern to the sources list, single wildcards allowed. Includes *.c and *.s by default.")

View File

@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "mx_convert"
version = "0.5.5"
version = "0.5.6"
description = "A Cube MX projct conversion helper"
authors = [{ name = "Didas72" }]
dependencies = []