Commit 9cabee82 authored by Jim Mussared's avatar Jim Mussared Committed by Damien George

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: default avatarJim Mussared <jim.mussared@gmail.com>
parent 1ee57311
......@@ -236,4 +236,5 @@ $(OBJ): | $(GEN_PINS_HDR)
# Call make-pins.py to generate both pins_gen.c and pins.h
$(GEN_PINS_SRC) $(GEN_PINS_HDR): $(BOARD_PINS) $(MAKE_PINS) $(AF_FILE) $(PREFIX_FILE) | $(HEADER_BUILD)
$(ECHO) "Create $@"
$(Q)$(PYTHON) $(MAKE_PINS) --board $(BOARD_PINS) --af $(AF_FILE) --prefix $(PREFIX_FILE) --hdr $(GEN_PINS_HDR) > $(GEN_PINS_SRC)
$(Q)$(PYTHON) $(MAKE_PINS) --board-csv $(BOARD_PINS) --af-csv $(AF_FILE) --prefix $(PREFIX_FILE) \
--output-source $(GEN_PINS_SRC) --output-header $(GEN_PINS_HDR)
......@@ -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)
if args.board_filename:
print("// --board {:s}".format(args.board_filename))
pins.parse_board_file(args.board_filename, 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)
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_csv:
print("// --board {:s}".format(args.board_csv), file=out_source)
pins.parse_board_file(args.board_csv, 1)
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__":
......
......@@ -154,20 +154,18 @@ def main():
parser.add_argument("--prefix")
parser.add_argument("--output-source")
parser.add_argument("--output-header")
args = parser.parse_args(sys.argv[1:])
args = parser.parse_args()
pins = Pins()
pins.create_pins()
if args.board_csv:
pins.parse_board_file(args.board_csv)
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.board_csv:
print("// --board-csv {:s}".format(args.board_csv), file=out_source)
pins.parse_board_file(args.board_csv)
if args.prefix:
print("// --prefix {:s}".format(args.prefix), file=out_source)
......
......@@ -505,8 +505,8 @@ $(GEN_FLEXRAM_CONFIG_SRC):
# both pins_gen.c and pins.h
$(BUILD)/%_gen.c $(HEADER_BUILD)/%.h: $(BOARD_PINS) $(MAKE_PINS) $(AF_FILE) $(PREFIX_FILE) | $(HEADER_BUILD)
$(ECHO) "Create $@"
$(Q)$(PYTHON) $(MAKE_PINS) --board $(BOARD_PINS) --af $(AF_FILE)\
--iomux $(abspath $(TOP)/$(MCU_DIR)/drivers/fsl_iomuxc.h) \
--prefix $(PREFIX_FILE) --hdr $(GEN_PINS_HDR) > $(GEN_PINS_SRC)
$(Q)$(PYTHON) $(MAKE_PINS) --board-csv $(BOARD_PINS) --af-csv $(AF_FILE) \
--prefix $(PREFIX_FILE) --iomux $(abspath $(TOP)/$(MCU_DIR)/drivers/fsl_iomuxc.h) \
--output-source $(GEN_PINS_SRC) --output-header $(GEN_PINS_HDR)
include $(TOP)/py/mkrules.mk
This diff is collapsed.
......@@ -539,7 +539,8 @@ $(OBJ): | $(HEADER_BUILD)/pins.h
# both pins_gen.c and pins.h
$(BUILD)/%_gen.c $(HEADER_BUILD)/%.h $(HEADER_BUILD)/%_af_const.h: boards/$(BOARD)/%.csv $(MAKE_PINS) $(AF_FILE) $(PREFIX_FILE) | $(HEADER_BUILD)
$(ECHO) "Create $@"
$(Q)$(PYTHON) $(MAKE_PINS) --board $(BOARD_PINS) --af $(AF_FILE) --prefix $(PREFIX_FILE) --hdr $(GEN_PINS_HDR) --af-const $(GEN_PINS_AF_CONST) > $(GEN_PINS_SRC)
$(Q)$(PYTHON) $(MAKE_PINS) --board-csv $(BOARD_PINS) --af-csv $(AF_FILE) --prefix $(PREFIX_FILE) \
--output-source $(GEN_PINS_SRC) --output-header $(GEN_PINS_HDR) --output-af-const $(GEN_PINS_AF_CONST)
$(PY_BUILD)/nlr%.o: CFLAGS += -Os -fno-lto
......
This diff is collapsed.
......@@ -580,7 +580,8 @@ $(HEADER_BUILD)/qstrdefs.generated.h: $(BOARD_DIR)/mpconfigboard.h
.PRECIOUS: $(GEN_PINS_SRC)
$(BUILD)/%_$(BOARD).c $(HEADER_BUILD)/%.h $(HEADER_BUILD)/%_ad_const.h: $(BOARD_DIR)/%.csv $(MAKE_PINS) $(AF_FILE) $(PREFIX_FILE) | $(HEADER_BUILD)
$(ECHO) "GEN $@"
$(Q)$(PYTHON) $(MAKE_PINS) --board $(BOARD_PINS) --af $(AF_FILE) --prefix $(PREFIX_FILE) --hdr $(GEN_PINS_HDR) --ad-const $(GEN_PINS_AD_CONST) > $(GEN_PINS_SRC)
$(Q)$(PYTHON) $(MAKE_PINS) --board-csv $(BOARD_PINS) --af-csv $(AF_FILE) --prefix $(PREFIX_FILE) \
--output-source $(GEN_PINS_SRC) --output-header $(GEN_PINS_HDR) --output-ad-const $(GEN_PINS_AD_CONST)
CMSIS_MCU_HDR = $(CMSIS_DIR)/$(CMSIS_MCU_LOWER).h
......
......@@ -28,18 +28,19 @@ class PinAD(object):
def channel(self):
return self._channel
def print(self):
def print(self, out_source):
print(
"const pin_ad_obj_t pin_{:s}_ad_obj = PIN_AD({:s}, {:d}, {:d}, {:d});".format(
self._cpu_pin_name, self._name, self._pin_idx, self._bit, self._channel
)
),
file=out_source,
)
print("")
print("", file=out_source)
def print_header(self, hdr_file):
def print_header(self, out_header):
n = self.cpu_pin_name()
hdr_file.write("extern const pin_ad_obj_t pin_{:s}_ad_obj;\n".format(n))
hdr_file.write("#define pin_{:s}_ad (&pin_{:s}_ad_obj)\n".format(n, n))
print("extern const pin_ad_obj_t pin_{:s}_ad_obj;".format(n), file=out_header)
print("#define pin_{:s}_ad (&pin_{:s}_ad_obj)".format(n, n), file=out_header)
class Pin(object):
......@@ -78,22 +79,23 @@ class Pin(object):
ad_channel = int(ad_str[2:4])
self._pin_ad.append(PinAD(ad_str, self._name, self._pin_idx, ad_bit, ad_channel))
def print(self):
def print(self, out_source):
pin_ad_name = "NULL"
for pin_ad in self._pin_ad:
pin_ad.print()
pin_ad.print(out_source)
pin_ad_name = "pin_{:s}_ad".format(pin_ad.cpu_pin_name())
print(
"const machine_pin_obj_t pin_{:s}_obj = PIN({:s}, {:d}, {:s});".format(
self._name, self._name, self._pin_idx, pin_ad_name
)
),
file=out_source,
)
print("")
print("", file=out_source)
def print_header(self, hdr_file):
def print_header(self, out_header):
n = self.cpu_pin_name()
hdr_file.write("extern const machine_pin_obj_t pin_{:s}_obj;\n".format(n))
hdr_file.write("#define pin_{:s} (&pin_{:s}_obj)\n".format(n, n))
print("extern const machine_pin_obj_t pin_{:s}_obj;".format(n), file=out_header)
print("#define pin_{:s} (&pin_{:s}_obj)".format(n, n), file=out_header)
class NamedPin(object):
......@@ -152,9 +154,10 @@ class Pins(object):
pin.set_is_board_pin()
self.board_pins.append(NamedPin(board_pin_name, pin))
def print_named(self, label, named_pins):
def print_named(self, label, named_pins, 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 named_pin in named_pins:
pin = named_pin.pin()
......@@ -162,120 +165,93 @@ class Pins(object):
print(
" {{ MP_ROM_QSTR(MP_QSTR_{:s}), MP_ROM_PTR(&pin_{:s}_obj) }},".format(
named_pin.name(), pin.cpu_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 named_pin in self.cpu_pins:
pin = named_pin.pin()
if pin.is_board_pin():
pin.print(out_source)
self.print_named("cpu", self.cpu_pins, out_source)
print("", file=out_source)
self.print_named("board", self.board_pins, out_source)
def print_header(self, out_header):
for named_pin in self.cpu_pins:
pin = named_pin.pin()
if pin.is_board_pin():
pin.print_header(out_header)
pin_ads = pin.pin_ad()
for pin_ad in pin_ads:
pin_ad.print_header(out_header)
# provide #define's mapping board to cpu name
for named_pin in self.board_pins:
print(
"#define pyb_pin_{:s} pin_{:s}".format(
named_pin.name(), named_pin.pin().cpu_pin_name()
),
file=out_header,
)
def print_ad_hdr(self, out_ad_const):
for named_pin in self.cpu_pins:
pin = named_pin.pin()
if pin.is_board_pin():
pin.print()
self.print_named("cpu", self.cpu_pins)
print("")
self.print_named("board", self.board_pins)
def print_header(self, hdr_filename):
with open(hdr_filename, "wt") as hdr_file:
for named_pin in self.cpu_pins:
pin = named_pin.pin()
if pin.is_board_pin():
pin.print_header(hdr_file)
pin_ads = pin.pin_ad()
for pin_ad in pin_ads:
pin_ad.print_header(hdr_file)
# provide #define's mapping board to cpu name
for named_pin in self.board_pins:
hdr_file.write(
"#define pyb_pin_{:s} pin_{:s}\n".format(
named_pin.name(), named_pin.pin().cpu_pin_name()
print(
" {{ MP_ROM_QSTR(MP_QSTR_{:s}), MP_ROM_INT(GPIO_{:s}) }}, \n".format(
pin_ad.name(), pin_ad.name()
),
file=out_ad_const,
)
)
def print_ad_hdr(self, ad_const_filename):
with open(ad_const_filename, "wt") as ad_const_file:
for named_pin in self.cpu_pins:
pin = named_pin.pin()
if pin.is_board_pin():
pin_ads = pin.pin_ad()
for pin_ad in pin_ads:
ad_const_file.write(
" {{ MP_ROM_QSTR(MP_QSTR_{:s}), MP_ROM_INT(GPIO_{:s}) }}, \n".format(
pin_ad.name(), pin_ad.name()
)
)
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="ra4m1_af.csv",
)
parser.add_argument(
"-b", "--board", dest="board_filename", help="Specifies the board file", default="pins.csv"
)
parser.add_argument(
"-p",
"--prefix",
dest="prefix_filename",
help="Specifies beginning portion of generated pins file",
default="ra4m1_prefix.c",
)
parser.add_argument(
"--ad-const",
dest="ad_const_filename",
help="Specifies header file for AD function constants.",
default="build/pins_ad_const.h",
)
parser.add_argument(
"--af-defs",
dest="af_defs_filename",
help="Specifies the filename for the alternate function defines.",
default="build/pins_af_defs.h",
)
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")
parser.add_argument("--output-ad-const")
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)
if args.board_filename:
print("// --board {:s}".format(args.board_filename))
pins.parse_board_file(args.board_filename)
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)
pins.print_ad_hdr(args.ad_const_filename)
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)
if args.board_csv:
print("// --board {:s}".format(args.board_csv), file=out_source)
pins.parse_board_file(args.board_csv)
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)
with open(args.output_ad_const, "w") as out_ad_const:
pins.print_ad_hdr(out_ad_const)
if __name__ == "__main__":
......
......@@ -483,7 +483,7 @@ set(GEN_PINS_AF_CONST "${MICROPY_GENHDR_DIR}/pins_af_const.h")
if(EXISTS "${MICROPY_BOARDS_DIR}/${MICROPY_BOARD}/pins.csv")
set(GEN_PINS_BOARD_CSV "${MICROPY_BOARDS_DIR}/${MICROPY_BOARD}/pins.csv")
set(GEN_PINS_CSV_ARG --board "${GEN_PINS_BOARD_CSV}")
set(GEN_PINS_CSV_ARG --board-csv "${GEN_PINS_BOARD_CSV}")
endif()
target_sources(${MICROPY_TARGET} PRIVATE
......@@ -493,8 +493,7 @@ target_sources(${MICROPY_TARGET} PRIVATE
# Generate pins
add_custom_command(
OUTPUT ${GEN_PINS_HDR} ${GEN_PINS_SRC}
COMMAND ${Python3_EXECUTABLE} ${GEN_PINS_MKPINS} ${GEN_PINS_CSV_ARG} --af ${GEN_PINS_AF_CSV} --prefix ${GEN_PINS_PREFIX}
--hdr ${GEN_PINS_HDR} > ${GEN_PINS_SRC}
COMMAND ${Python3_EXECUTABLE} ${GEN_PINS_MKPINS} ${GEN_PINS_CSV_ARG} --af-csv ${GEN_PINS_AF_CSV} --prefix ${GEN_PINS_PREFIX} --output-source ${GEN_PINS_SRC} --output-header ${GEN_PINS_HDR}
DEPENDS
${GEN_PINS_AF_CSV}
${GEN_PINS_BOARD_CSV}
......
This diff is collapsed.
......@@ -673,10 +673,9 @@ main.c: $(GEN_CDCINF_HEADER)
# both pins_$(BOARD).c and pins.h
$(BUILD)/%_$(BOARD).c $(HEADER_BUILD)/%.h $(HEADER_BUILD)/%_af_const.h $(HEADER_BUILD)/%_af_defs.h: $(BOARD_DIR)/%.csv $(MAKE_PINS) $(AF_FILE) $(PREFIX_FILE) | $(HEADER_BUILD)
$(ECHO) "GEN $@"
$(Q)$(PYTHON) $(MAKE_PINS) --board $(BOARD_PINS) --af $(AF_FILE) \
--prefix $(PREFIX_FILE) --hdr $(GEN_PINS_HDR) --hdr-obj-decls \
--af-const $(GEN_PINS_AF_CONST) --af-defs $(GEN_PINS_AF_DEFS) \
--af-defs-cmp-strings > $(GEN_PINS_SRC)
$(Q)$(PYTHON) $(MAKE_PINS) --board-csv $(BOARD_PINS) --af-csv $(AF_FILE) --prefix $(PREFIX_FILE) \
--output-source $(GEN_PINS_SRC) --output-header $(GEN_PINS_HDR) \
--output-af-const $(GEN_PINS_AF_CONST) --output-af-defs $(GEN_PINS_AF_DEFS)
modmachine.c: $(GEN_PLLFREQTABLE_HDR)
$(GEN_PLLFREQTABLE_HDR): $(PLLVALUES) | $(HEADER_BUILD)
......
This diff is collapsed.
......@@ -243,10 +243,10 @@ $(GEN_ROOT_POINTERS): | $(HEADER_BUILD)
$(GEN_PINS_AF_DEFS): $(BOARD_PINS) $(MAKE_PINS) ../$(AF_FILE) $(PREFIX_FILE) | $(HEADER_BUILD)
$(ECHO) "GEN $@"
$(Q)$(PYTHON) $(MAKE_PINS) --board $(BOARD_PINS) --af ../$(AF_FILE) \
--prefix $(PREFIX_FILE) --hdr $(GEN_PINS_HDR) \
--af-const $(GEN_PINS_AF_CONST) --af-defs $(GEN_PINS_AF_DEFS) \
> $(GEN_PINS_SRC)
$(Q)$(PYTHON) $(MAKE_PINS) --board-csv $(BOARD_PINS) --af-csv ../$(AF_FILE) --prefix $(PREFIX_FILE) \
--output-source $(GEN_PINS_SRC) --output-header $(GEN_PINS_HDR) \
--output-af-const $(GEN_PINS_AF_CONST) --output-af-defs $(GEN_PINS_AF_DEFS) \
--mboot-mode
#########################################
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment