tools/alif: Update pin generator.

This commit is contained in:
iabdalkader 2025-01-09 19:03:57 +01:00
parent cf571aec92
commit 755bae1a35

View File

@ -10,6 +10,7 @@ import sys
import re import re
import argparse import argparse
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
import csv
def parse_svd_file(svd_file): def parse_svd_file(svd_file):
tree = ET.parse(svd_file) tree = ET.parse(svd_file)
@ -38,12 +39,31 @@ def parse_svd_file(svd_file):
def main(): def main():
parser = argparse.ArgumentParser(description = "Usage: python gen_iomux_pins.py <fsl_iomuxc.h>.") parser = argparse.ArgumentParser(description = "Usage: python gen_iomux_pins.py <fsl_iomuxc.h>.")
parser.add_argument("--svd", action = "store", help = "Input SVD file.", required=True) parser.add_argument("--svd", action = "store", help = "Input SVD file.", required=True)
parser.add_argument("--csv", action = "store_true", help = "Generate CSV")
args = parser.parse_args() args = parser.parse_args()
svd_file = sys.argv[1] svd_file = sys.argv[1]
pins_data = parse_svd_file(args.svd) pins_data = parse_svd_file(args.svd)
functions = []
if args.csv:
print(",".join(["Pin", "AF0", "AF1", "AF2", "AF3", "AF4", "AF5", "AF6", "AF7"]))
for pin_info in pins_data:
pin_name, *mux_modes = pin_info
port, pin = pin_name.split("P")[1].split("_")
row = [f"P{port}_{pin}", ""]
for i, pin_af in enumerate(mux_modes):
if i == 0:
continue
if pin_af is None:
row.append("")
continue
pin_af = re.match(r'[A-Z]+[0-9]*[A-Z]+|[A-Z]+', pin_af).group()
row.append(pin_af)
functions.append(f"AF_FN_{pin_af}")
print(",".join(row))
#for i in sorted(set(functions)):
# print(i+",")
else:
print("// THIS FILE IS AUTO-GENERATED DO NOT EDIT.\n") print("// THIS FILE IS AUTO-GENERATED DO NOT EDIT.\n")
print("/*") print("/*")
print(" * This file is part of the OpenMV project.") print(" * This file is part of the OpenMV project.")
@ -53,23 +73,22 @@ def main():
print(" *") print(" *")
print(" * This work is licensed under the MIT license, see the file LICENSE for details.") print(" * This work is licensed under the MIT license, see the file LICENSE for details.")
print(" */") print(" */")
for pin_info in pins_data: for pin_info in pins_data:
pin_name, *mux_modes = pin_info pin_name, *mux_modes = pin_info
port, pin = pin_name.split("P")[1].split("_") port, pin = pin_name.split("P")[1].split("_")
pin_name = "PORT_"+port+"_PIN_"+pin pin_name = "PORT_"+port+"_PIN_"+pin
print("// ", pin_name) print("// ", pin_name)
for i, function_name in enumerate(mux_modes): for i, pin_af in enumerate(mux_modes):
if function_name is not None: if pin_af is not None:
# Remove the GPIO number from the generated mux GPIO function # Remove the GPIO number from the generated mux GPIO function
if i == 0 and function_name.startswith("GPIO"): if i == 0 and pin_af.startswith("GPIO"):
function_name = "GPIO" pin_af = "GPIO"
# Remove the last part of a mux function name if it has 3 parts # Remove the last part of a mux function name if it has 3 parts
parts = function_name.split("_") parts = pin_af.split("_")
if len(parts) == 3: if len(parts) == 3:
function_name = "_".join(parts[:2]) pin_af = "_".join(parts[:2])
print(f"#define {f'{pin_name}_AF_{function_name}'.ljust(30)} PINMUX_ALTERNATE_FUNCTION_{i}") print(f"#define {f'{pin_name}_AF_{pin_af}'.ljust(30)} PINMUX_ALTERNATE_FUNCTION_{i}")
print("") print("")
if __name__ == "__main__": if __name__ == "__main__":