mirror of
https://github.com/micropython/micropython.git
synced 2025-12-16 01:40:14 +01:00
ports: Standardise arguments and output for make-pins.py script.
All ports now use `--board-csv`, `--prefix`, `--output-souce`, `--output-header` and no longer write to stdout. This matches the esp32 implementation. Ports that have an AF input use `--af-csv` (to match `--board-csv`). Any additional output files are now prefixed with `output-` (e.g. `--output-af-const`). Default arguments are removed (all makefiles should always specify all arguments, using default values is likely an error). Replaced the `af-defs-cmp-strings` and `hdr-obj-decls` args for stm32 with just `mboot-mode`. Previously they were set on the regular build, now the logic is reversed so mboot sets it. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
committed by
Damien George
parent
1ee5731122
commit
9cabee8252
@@ -44,11 +44,12 @@ class AF:
|
||||
self.unit = unit
|
||||
self.type = type
|
||||
|
||||
def print(self):
|
||||
def print(self, out_source):
|
||||
print(
|
||||
" AF({:16s}, {:4d}, {:8s}, {:4d}, {:8s}), // {}".format(
|
||||
self.name, self.idx, self.fn, self.unit, self.type, self.name
|
||||
)
|
||||
),
|
||||
file=out_source,
|
||||
)
|
||||
|
||||
|
||||
@@ -66,13 +67,13 @@ class Pin:
|
||||
def add_af(self, af):
|
||||
self.afs.append(af)
|
||||
|
||||
def print(self):
|
||||
print("// {}".format(self.name))
|
||||
def print(self, out_source):
|
||||
print("// {}".format(self.name), file=out_source)
|
||||
if len(self.afs):
|
||||
print("const pin_af_t pin_{}_af[] = {{".format(self.name))
|
||||
print("const pin_af_t pin_{}_af[] = {{".format(self.name), file=out_source)
|
||||
for af in self.afs:
|
||||
af.print()
|
||||
print("};")
|
||||
af.print(out_source)
|
||||
print("};", file=out_source)
|
||||
print(
|
||||
"pin_obj_t pin_{:4s} = PIN({:6s}, {:1d}, {:3d}, {:2d}, pin_{}_af, {});\n".format(
|
||||
self.name,
|
||||
@@ -82,17 +83,19 @@ class Pin:
|
||||
self.pin_num,
|
||||
self.name,
|
||||
len(self.afs),
|
||||
)
|
||||
),
|
||||
file=out_source,
|
||||
)
|
||||
else:
|
||||
print(
|
||||
"pin_obj_t pin_{:4s} = PIN({:6s}, {:1d}, {:3d}, {:2d}, NULL, 0);\n".format(
|
||||
self.name, self.name, self.port, self.gpio_bit, self.pin_num
|
||||
)
|
||||
),
|
||||
file=out_source,
|
||||
)
|
||||
|
||||
def print_header(self, hdr_file):
|
||||
hdr_file.write("extern pin_obj_t pin_{:s};\n".format(self.name))
|
||||
def print_header(self, out_header):
|
||||
print("extern pin_obj_t pin_{:s};".format(self.name), file=out_header)
|
||||
|
||||
|
||||
class Pins:
|
||||
@@ -153,93 +156,72 @@ class Pins:
|
||||
if pin:
|
||||
pin.board_pin = True
|
||||
|
||||
def print_named(self, label, pins):
|
||||
print("")
|
||||
def print_named(self, label, pins, out_source):
|
||||
print("", file=out_source)
|
||||
print(
|
||||
"STATIC const mp_rom_map_elem_t pin_{:s}_pins_locals_dict_table[] = {{".format(label)
|
||||
"STATIC const mp_rom_map_elem_t pin_{:s}_pins_locals_dict_table[] = {{".format(label),
|
||||
file=out_source,
|
||||
)
|
||||
for pin in pins:
|
||||
if pin.board_pin:
|
||||
print(
|
||||
" {{ MP_ROM_QSTR(MP_QSTR_{:6s}), MP_ROM_PTR(&pin_{:6s}) }},".format(
|
||||
pin.name, pin.name
|
||||
)
|
||||
),
|
||||
file=out_source,
|
||||
)
|
||||
print("};")
|
||||
print("};", file=out_source)
|
||||
print(
|
||||
"MP_DEFINE_CONST_DICT(pin_{:s}_pins_locals_dict, pin_{:s}_pins_locals_dict_table);".format(
|
||||
label, label
|
||||
)
|
||||
),
|
||||
file=out_source,
|
||||
)
|
||||
|
||||
def print(self):
|
||||
def print(self, out_source):
|
||||
for pin in self.board_pins:
|
||||
if pin.board_pin:
|
||||
pin.print()
|
||||
self.print_named("board", self.board_pins)
|
||||
print("")
|
||||
pin.print(out_source)
|
||||
self.print_named("board", self.board_pins, out_source)
|
||||
print("", file=out_source)
|
||||
|
||||
def print_header(self, hdr_filename):
|
||||
with open(hdr_filename, "wt") as hdr_file:
|
||||
for pin in self.board_pins:
|
||||
if pin.board_pin:
|
||||
pin.print_header(hdr_file)
|
||||
def print_header(self, out_header):
|
||||
for pin in self.board_pins:
|
||||
if pin.board_pin:
|
||||
pin.print_header(out_header)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
prog="make-pins.py",
|
||||
usage="%(prog)s [options] [command]",
|
||||
description="Generate board specific pin file",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-a",
|
||||
"--af",
|
||||
dest="af_filename",
|
||||
help="Specifies the alternate function file for the chip",
|
||||
default="cc3200_af.csv",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-b",
|
||||
"--board",
|
||||
dest="board_filename",
|
||||
help="Specifies the board file",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-p",
|
||||
"--prefix",
|
||||
dest="prefix_filename",
|
||||
help="Specifies beginning portion of generated pins file",
|
||||
default="cc3200_prefix.c",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-r",
|
||||
"--hdr",
|
||||
dest="hdr_filename",
|
||||
help="Specifies name of generated pin header file",
|
||||
default="build/pins.h",
|
||||
)
|
||||
args = parser.parse_args(sys.argv[1:])
|
||||
parser = argparse.ArgumentParser(description="Generate board specific pin file")
|
||||
parser.add_argument("--board-csv")
|
||||
parser.add_argument("--af-csv")
|
||||
parser.add_argument("--prefix")
|
||||
parser.add_argument("--output-source")
|
||||
parser.add_argument("--output-header")
|
||||
args = parser.parse_args()
|
||||
|
||||
pins = Pins()
|
||||
|
||||
print("// This file was automatically generated by make-pins.py")
|
||||
print("//")
|
||||
if args.af_filename:
|
||||
print("// --af {:s}".format(args.af_filename))
|
||||
pins.parse_af_file(args.af_filename, 0, 1, 3)
|
||||
with open(args.output_source, "w") as out_source:
|
||||
print("// This file was automatically generated by make-pins.py", file=out_source)
|
||||
print("//", file=out_source)
|
||||
if args.af_csv:
|
||||
print("// --af {:s}".format(args.af_csv), file=out_source)
|
||||
pins.parse_af_file(args.af_csv, 0, 1, 3)
|
||||
|
||||
if args.board_filename:
|
||||
print("// --board {:s}".format(args.board_filename))
|
||||
pins.parse_board_file(args.board_filename, 1)
|
||||
if args.board_csv:
|
||||
print("// --board {:s}".format(args.board_csv), file=out_source)
|
||||
pins.parse_board_file(args.board_csv, 1)
|
||||
|
||||
if args.prefix_filename:
|
||||
print("// --prefix {:s}".format(args.prefix_filename))
|
||||
print("")
|
||||
with open(args.prefix_filename, "r") as prefix_file:
|
||||
print(prefix_file.read())
|
||||
pins.print()
|
||||
pins.print_header(args.hdr_filename)
|
||||
if args.prefix:
|
||||
print("// --prefix {:s}".format(args.prefix), file=out_source)
|
||||
print("", file=out_source)
|
||||
with open(args.prefix, "r") as prefix_file:
|
||||
print(prefix_file.read(), file=out_source)
|
||||
pins.print(out_source)
|
||||
|
||||
with open(args.output_header, "w") as out_header:
|
||||
pins.print_header(out_header)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user