mirror of
https://github.com/openmv/openmv.git
synced 2025-09-26 23:09:13 +08:00
tools/alif: Update pin generator.
This commit is contained in:
parent
cf571aec92
commit
755bae1a35
@ -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,39 +39,57 @@ 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("/*")
|
||||||
|
print(" * This file is part of the OpenMV project.")
|
||||||
|
print(" *")
|
||||||
|
print(" * Copyright (c) 2024 Ibrahim Abdelkader <iabdalkader@openmv.io>")
|
||||||
|
print(" * Copyright (c) 2024 Kwabena W. Agyeman <kwagyeman@openmv.io>")
|
||||||
|
print(" *")
|
||||||
|
print(" * This work is licensed under the MIT license, see the file LICENSE for details.")
|
||||||
|
print(" */")
|
||||||
|
for pin_info in pins_data:
|
||||||
|
pin_name, *mux_modes = pin_info
|
||||||
|
port, pin = pin_name.split("P")[1].split("_")
|
||||||
|
pin_name = "PORT_"+port+"_PIN_"+pin
|
||||||
|
print("// ", pin_name)
|
||||||
|
for i, pin_af in enumerate(mux_modes):
|
||||||
|
if pin_af is not None:
|
||||||
|
# Remove the GPIO number from the generated mux GPIO function
|
||||||
|
if i == 0 and pin_af.startswith("GPIO"):
|
||||||
|
pin_af = "GPIO"
|
||||||
|
# Remove the last part of a mux function name if it has 3 parts
|
||||||
|
parts = pin_af.split("_")
|
||||||
|
if len(parts) == 3:
|
||||||
|
pin_af = "_".join(parts[:2])
|
||||||
|
|
||||||
print("// THIS FILE IS AUTO-GENERATED DO NOT EDIT.\n")
|
print(f"#define {f'{pin_name}_AF_{pin_af}'.ljust(30)} PINMUX_ALTERNATE_FUNCTION_{i}")
|
||||||
print("/*")
|
print("")
|
||||||
print(" * This file is part of the OpenMV project.")
|
|
||||||
print(" *")
|
|
||||||
print(" * Copyright (c) 2024 Ibrahim Abdelkader <iabdalkader@openmv.io>")
|
|
||||||
print(" * Copyright (c) 2024 Kwabena W. Agyeman <kwagyeman@openmv.io>")
|
|
||||||
print(" *")
|
|
||||||
print(" * This work is licensed under the MIT license, see the file LICENSE for details.")
|
|
||||||
print(" */")
|
|
||||||
|
|
||||||
for pin_info in pins_data:
|
|
||||||
pin_name, *mux_modes = pin_info
|
|
||||||
port, pin = pin_name.split("P")[1].split("_")
|
|
||||||
pin_name = "PORT_"+port+"_PIN_"+pin
|
|
||||||
print("// ", pin_name)
|
|
||||||
for i, function_name in enumerate(mux_modes):
|
|
||||||
if function_name is not None:
|
|
||||||
# Remove the GPIO number from the generated mux GPIO function
|
|
||||||
if i == 0 and function_name.startswith("GPIO"):
|
|
||||||
function_name = "GPIO"
|
|
||||||
# Remove the last part of a mux function name if it has 3 parts
|
|
||||||
parts = function_name.split("_")
|
|
||||||
if len(parts) == 3:
|
|
||||||
function_name = "_".join(parts[:2])
|
|
||||||
|
|
||||||
print(f"#define {f'{pin_name}_AF_{function_name}'.ljust(30)} PINMUX_ALTERNATE_FUNCTION_{i}")
|
|
||||||
print("")
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user