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:
parent
1ee5731122
commit
9cabee8252
@ -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)
|
||||
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__":
|
||||
|
@ -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
|
||||
|
@ -93,34 +93,36 @@ class Pin(object):
|
||||
def add_af(self, af):
|
||||
self.alt_fn.append(af)
|
||||
|
||||
def print_pin_af(self):
|
||||
def print_pin_af(self, out_source):
|
||||
if self.alt_fn:
|
||||
print(
|
||||
"static const machine_pin_af_obj_t pin_{0}_af[{1}] = {{".format(
|
||||
self.name, len(self.alt_fn)
|
||||
)
|
||||
),
|
||||
file=out_source,
|
||||
)
|
||||
for af in self.alt_fn:
|
||||
af.print()
|
||||
print("};")
|
||||
af.print(out_source)
|
||||
print("};", file=out_source)
|
||||
else:
|
||||
raise ValueError("Pin '{}' has no alternative functions".format(self.name))
|
||||
|
||||
def print_pin_adc(self):
|
||||
def print_pin_adc(self, out_source):
|
||||
if self.adc_fns:
|
||||
print(
|
||||
"static const machine_pin_adc_obj_t pin_{0}_adc[{1}] = {{".format(
|
||||
self.name, len(self.adc_fns)
|
||||
)
|
||||
),
|
||||
file=out_source,
|
||||
)
|
||||
for adc_fn in self.adc_fns:
|
||||
adc_fn.print()
|
||||
print("};")
|
||||
adc_fn.print(out_source)
|
||||
print("};", file=out_source)
|
||||
|
||||
def print(self):
|
||||
def print(self, out_source):
|
||||
if self.alt_fn:
|
||||
self.print_pin_af()
|
||||
self.print_pin_adc()
|
||||
self.print_pin_af(out_source)
|
||||
self.print_pin_adc(out_source)
|
||||
|
||||
options = {
|
||||
"GPIO_LPSR_00": "PIN_LPSR",
|
||||
@ -165,12 +167,13 @@ class Pin(object):
|
||||
int(self.pin),
|
||||
len(self.adc_fns),
|
||||
"pin_{}_adc".format(self.name) if self.adc_fns else "NULL",
|
||||
)
|
||||
),
|
||||
file=out_source,
|
||||
)
|
||||
else:
|
||||
raise ValueError("Pin '{}' has no alternative functions".format(self.name))
|
||||
|
||||
def print_header(self, hdr_file):
|
||||
def print_header(self, out_header):
|
||||
pass
|
||||
|
||||
|
||||
@ -182,9 +185,9 @@ class AdcFunction(object):
|
||||
self.instance = instance
|
||||
self.channel = channel
|
||||
|
||||
def print(self):
|
||||
def print(self, out_source):
|
||||
"""Prints the C representation of this AF."""
|
||||
print(f" PIN_ADC({self.peripheral}{self.instance}, {self.channel}),")
|
||||
print(f" PIN_ADC({self.peripheral}{self.instance}, {self.channel}),", file=out_source)
|
||||
|
||||
|
||||
class AlternateFunction(object):
|
||||
@ -197,12 +200,13 @@ class AlternateFunction(object):
|
||||
self.input_daisy = input_daisy
|
||||
self.instance = self.af_str.split("_")[0]
|
||||
|
||||
def print(self):
|
||||
def print(self, out_source):
|
||||
"""Prints the C representation of this AF."""
|
||||
print(
|
||||
" PIN_AF({0}, PIN_AF_MODE_ALT{1}, {2}, {3}, {4}, {5}),".format(
|
||||
self.af_str, self.idx, self.input_daisy, self.instance, self.input_reg, "0x10B0U"
|
||||
)
|
||||
),
|
||||
file=out_source,
|
||||
)
|
||||
|
||||
|
||||
@ -292,54 +296,62 @@ class Pins(object):
|
||||
self.cpu_pins.append(pin)
|
||||
|
||||
@staticmethod
|
||||
def print_named(label, pins):
|
||||
print("")
|
||||
def print_named(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:
|
||||
print(
|
||||
" {{ MP_ROM_QSTR(MP_QSTR_{}), MP_ROM_PTR(&pin_{}) }},".format(pin.name, pin.pad)
|
||||
(
|
||||
print(
|
||||
" {{ MP_ROM_QSTR(MP_QSTR_{}), MP_ROM_PTR(&pin_{}) }},".format(
|
||||
pin.name, pin.pad
|
||||
),
|
||||
file=out_source,
|
||||
),
|
||||
)
|
||||
print("};")
|
||||
print("};", file=out_source)
|
||||
print(
|
||||
"MP_DEFINE_CONST_DICT(machine_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):
|
||||
# Print Pin Object declarations
|
||||
for pin in self.cpu_pins:
|
||||
pin.print()
|
||||
pin.print(out_source)
|
||||
|
||||
print("")
|
||||
print("const machine_pin_obj_t* machine_pin_board_pins [] = {")
|
||||
print("", file=out_source)
|
||||
print("const machine_pin_obj_t* machine_pin_board_pins [] = {", file=out_source)
|
||||
for pin in self.board_pins:
|
||||
print(" &pin_{},".format(pin.pad))
|
||||
print("};")
|
||||
print("const uint32_t num_board_pins = {:d};".format(len(self.board_pins)))
|
||||
print(" &pin_{},".format(pin.pad), file=out_source)
|
||||
print("};", file=out_source)
|
||||
print(
|
||||
"const uint32_t num_board_pins = {:d};".format(len(self.board_pins)), file=out_source
|
||||
)
|
||||
# Print Pin mapping dictionaries
|
||||
self.print_named("cpu", self.cpu_pins)
|
||||
self.print_named("board", self.board_pins)
|
||||
print("")
|
||||
self.print_named("cpu", self.cpu_pins, 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, "w") as hdr_file:
|
||||
for pin in self.cpu_pins:
|
||||
hdr_file.write("extern const machine_pin_obj_t pin_{};\n".format(pin.name))
|
||||
hdr_file.write("extern const machine_pin_obj_t* machine_pin_board_pins[];\n")
|
||||
hdr_file.write("extern const uint32_t num_board_pins;\n")
|
||||
hdr_file.write("extern const mp_obj_dict_t machine_pin_cpu_pins_locals_dict;\n")
|
||||
hdr_file.write("extern const mp_obj_dict_t machine_pin_board_pins_locals_dict;\n")
|
||||
|
||||
hdr_file.write("\n// Defines\n")
|
||||
module_instance_factory(self.cpu_pins, hdr_file, "USDHC")
|
||||
module_instance_factory(self.cpu_pins, hdr_file, "FLEXPWM")
|
||||
module_instance_factory(self.cpu_pins, hdr_file, "TMR")
|
||||
def print_header(self, out_header):
|
||||
for pin in self.cpu_pins:
|
||||
print("extern const machine_pin_obj_t pin_{};".format(pin.name), file=out_header)
|
||||
print("extern const machine_pin_obj_t* machine_pin_board_pins[];", file=out_header)
|
||||
print("extern const uint32_t num_board_pins;", file=out_header)
|
||||
print("extern const mp_obj_dict_t machine_pin_cpu_pins_locals_dict;", file=out_header)
|
||||
print("extern const mp_obj_dict_t machine_pin_board_pins_locals_dict;", file=out_header)
|
||||
print("", file=out_header)
|
||||
print("// Defines", file=out_header)
|
||||
module_instance_factory(self.cpu_pins, out_header, "USDHC")
|
||||
module_instance_factory(self.cpu_pins, out_header, "FLEXPWM")
|
||||
module_instance_factory(self.cpu_pins, out_header, "TMR")
|
||||
|
||||
|
||||
def module_instance_factory(pins, output_file, name):
|
||||
def module_instance_factory(pins, out_header, name):
|
||||
module_pin = filter(lambda p: any([af for af in p.alt_fn if name in af.af_str]), pins)
|
||||
|
||||
module_instances = dict()
|
||||
@ -357,80 +369,47 @@ def module_instance_factory(pins, output_file, name):
|
||||
)
|
||||
|
||||
for k, v in module_instances.items():
|
||||
output_file.write(f"// {k}\n")
|
||||
output_file.write(f"#define {k}_AVAIL (1)\n")
|
||||
print(f"// {k}", file=out_header)
|
||||
print(f"#define {k}_AVAIL (1)", file=out_header)
|
||||
if name == "FLEXPWM":
|
||||
output_file.write(f"#define {k} {k[-4:]}\n")
|
||||
print(f"#define {k} {k[-4:]}", file=out_header)
|
||||
for i in v:
|
||||
output_file.write(i + "\n")
|
||||
print(i, file=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="mimxrt1021_af.csv",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-i",
|
||||
"--iomux",
|
||||
dest="iomux_filename",
|
||||
help="Specifies the fsl_iomuxc.h file for the chip",
|
||||
default="fsl_iomuxc.h",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-b",
|
||||
"--board",
|
||||
dest="board_filename",
|
||||
help="Specifies the board file",
|
||||
default="MIMXRT1020_EVK/pins.csv",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-p",
|
||||
"--prefix",
|
||||
dest="prefix_filename",
|
||||
help="Specifies beginning portion of generated pins file",
|
||||
default="mimxrt_prefix.c",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-r",
|
||||
"--hdr",
|
||||
dest="hdr_filename",
|
||||
help="Specifies name of generated pin header file",
|
||||
default="build/pins.h",
|
||||
)
|
||||
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("--iomux-header")
|
||||
parser.add_argument("--output-source")
|
||||
parser.add_argument("--output-header")
|
||||
args = parser.parse_args()
|
||||
|
||||
pins = Pins()
|
||||
|
||||
# test code
|
||||
args = parser.parse_args()
|
||||
#
|
||||
with open(args.output_source, "w") as out_source:
|
||||
if args.af_csv:
|
||||
print("// --af {:s}".format(args.af_csv), file=out_source)
|
||||
pins.parse_af_file(args.af_csv, args.iomux_header)
|
||||
|
||||
if args.af_filename:
|
||||
print("// --af {:s}".format(args.af_filename))
|
||||
pins.parse_af_file(args.af_filename, args.iomux_filename)
|
||||
if args.board_csv:
|
||||
print("// --board {:s}".format(args.board_csv), file=out_source)
|
||||
pins.parse_board_file(args.board_csv)
|
||||
|
||||
if args.board_filename:
|
||||
print("// --board {:s}".format(args.board_filename))
|
||||
pins.parse_board_file(args.board_filename)
|
||||
if args.output_header:
|
||||
print("// --hdr {:s}".format(args.output_header), file=out_source)
|
||||
|
||||
if args.hdr_filename:
|
||||
print("// --hdr {:s}".format(args.hdr_filename))
|
||||
if args.prefix:
|
||||
print("// --prefix {:s}".format(args.prefix), file=out_source)
|
||||
with open(args.prefix, "r") as prefix_file:
|
||||
print(prefix_file.read(), file=out_source)
|
||||
|
||||
if args.prefix_filename:
|
||||
print("// --prefix {:s}".format(args.prefix_filename))
|
||||
with open(args.prefix_filename, "r") as prefix_file:
|
||||
print(prefix_file.read())
|
||||
pins.print(out_source)
|
||||
|
||||
pins.print()
|
||||
pins.print_header(args.hdr_filename)
|
||||
with open(args.output_header, "w") as out_header:
|
||||
pins.print_header(out_header)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -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
|
||||
|
||||
|
@ -67,19 +67,20 @@ class AlternateFunction(object):
|
||||
def mux_name(self):
|
||||
return "AF{:d}_{:s}".format(self.idx, self.ptr())
|
||||
|
||||
def print(self):
|
||||
def print(self, out_source):
|
||||
"""Prints the C representation of this AF."""
|
||||
if self.supported:
|
||||
print(" AF", end="")
|
||||
print(" AF", end="", file=out_source)
|
||||
else:
|
||||
print(" //", end="")
|
||||
print(" //", end="", file=out_source)
|
||||
fn_num = self.fn_num
|
||||
if fn_num is None:
|
||||
fn_num = 0
|
||||
print(
|
||||
"({:2d}, {:8s}, {:2d}, {:10s}, {:8s}), // {:s}".format(
|
||||
self.idx, self.func, fn_num, self.pin_type, self.ptr(), self.af_str
|
||||
)
|
||||
),
|
||||
file=out_source,
|
||||
)
|
||||
|
||||
|
||||
@ -144,23 +145,24 @@ class Pin(object):
|
||||
str = "0"
|
||||
return str
|
||||
|
||||
def print_const_table_entry(self):
|
||||
def print_const_table_entry(self, out_source):
|
||||
print(
|
||||
" PIN({:d}, {:s}, {:s}, {:d}),".format(
|
||||
self.pin, self.alt_fn_name(null_if_0=True), self.adc_num_str(), self.adc_channel
|
||||
)
|
||||
),
|
||||
file=out_source,
|
||||
)
|
||||
|
||||
def print(self):
|
||||
def print(self, out_source):
|
||||
if self.alt_fn_count == 0:
|
||||
print("// ", end="")
|
||||
print("const pin_af_obj_t {:s}[] = {{".format(self.alt_fn_name()))
|
||||
print("// ", end="", file=out_source)
|
||||
print("const pin_af_obj_t {:s}[] = {{".format(self.alt_fn_name()), file=out_source)
|
||||
for alt_fn in self.alt_fn:
|
||||
alt_fn.print()
|
||||
alt_fn.print(out_source)
|
||||
if self.alt_fn_count == 0:
|
||||
print("// ", end="")
|
||||
print("};")
|
||||
print("")
|
||||
print("// ", end="", file=out_source)
|
||||
print("};", file=out_source)
|
||||
print("", file=out_source)
|
||||
print(
|
||||
"const pin_obj_t pin_{:s} = PIN({:d}, {:s}, {:s}, {:d});".format(
|
||||
self.cpu_pin_name(),
|
||||
@ -168,15 +170,17 @@ class Pin(object):
|
||||
self.alt_fn_name(null_if_0=True),
|
||||
self.adc_num_str(),
|
||||
self.adc_channel,
|
||||
)
|
||||
),
|
||||
file=out_source,
|
||||
)
|
||||
print("")
|
||||
print("", file=out_source)
|
||||
|
||||
def print_header(self, hdr_file):
|
||||
hdr_file.write("extern const pin_obj_t pin_{:s};\n".format(self.cpu_pin_name()))
|
||||
def print_header(self, out_header):
|
||||
print("extern const pin_obj_t pin_{:s};".format(self.cpu_pin_name()), file=out_header)
|
||||
if self.alt_fn_count > 0:
|
||||
hdr_file.write(
|
||||
"extern const pin_af_obj_t pin_{:s}_af[];\n".format(self.cpu_pin_name())
|
||||
print(
|
||||
"extern const pin_af_obj_t pin_{:s}_af[];\n".format(self.cpu_pin_name()),
|
||||
file=out_header,
|
||||
)
|
||||
|
||||
|
||||
@ -232,9 +236,10 @@ class Pins(object):
|
||||
pin.set_is_board_pin()
|
||||
self.board_pins.append(NamedPin(row[0], 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()
|
||||
@ -242,148 +247,109 @@ class Pins(object):
|
||||
print(
|
||||
" {{ MP_ROM_QSTR(MP_QSTR_{:s}), MP_ROM_PTR(&machine_board_pin_obj[{:d}]) }},".format(
|
||||
named_pin.name(), pin.board_index
|
||||
)
|
||||
),
|
||||
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_const_table(self):
|
||||
def print_const_table(self, out_source):
|
||||
num_board_pins = 0
|
||||
for named_pin in self.cpu_pins:
|
||||
pin = named_pin.pin()
|
||||
if pin.is_board_pin():
|
||||
pin.set_board_index(num_board_pins)
|
||||
num_board_pins += 1
|
||||
print("")
|
||||
print("const uint8_t machine_pin_num_of_board_pins = {:d};".format(num_board_pins))
|
||||
print("")
|
||||
print("const pin_obj_t machine_board_pin_obj[{:d}] = {{".format(num_board_pins))
|
||||
print("", file=out_source)
|
||||
print(
|
||||
"const uint8_t machine_pin_num_of_board_pins = {:d};".format(num_board_pins),
|
||||
file=out_source,
|
||||
)
|
||||
print("", file=out_source)
|
||||
print(
|
||||
"const pin_obj_t machine_board_pin_obj[{:d}] = {{".format(num_board_pins),
|
||||
file=out_source,
|
||||
)
|
||||
for named_pin in self.cpu_pins:
|
||||
pin = named_pin.pin()
|
||||
if pin.is_board_pin():
|
||||
pin.print_const_table_entry()
|
||||
print("};")
|
||||
pin.print_const_table_entry(out_source)
|
||||
print("};", file=out_source)
|
||||
|
||||
def print(self):
|
||||
self.print_named("cpu", self.cpu_pins)
|
||||
print("")
|
||||
self.print_named("board", self.board_pins)
|
||||
def print(self, 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_adc(self, adc_num):
|
||||
print("")
|
||||
print("const pin_obj_t * const pin_adc{:d}[] = {{".format(adc_num))
|
||||
for channel in range(16):
|
||||
adc_found = False
|
||||
for named_pin in self.cpu_pins:
|
||||
pin = named_pin.pin()
|
||||
if (
|
||||
pin.is_board_pin()
|
||||
and (pin.adc_num & (1 << (adc_num - 1)))
|
||||
and (pin.adc_channel == channel)
|
||||
):
|
||||
print(" &pin_{:s}, // {:d}".format(pin.cpu_pin_name(), channel))
|
||||
adc_found = True
|
||||
break
|
||||
if not adc_found:
|
||||
print(" NULL, // {:d}".format(channel))
|
||||
print("};")
|
||||
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)
|
||||
print("extern const pin_obj_t * const pin_adc1[];", file=out_header)
|
||||
print("extern const pin_obj_t * const pin_adc2[];", file=out_header)
|
||||
print("extern const pin_obj_t * const pin_adc3[];", file=out_header)
|
||||
|
||||
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)
|
||||
hdr_file.write("extern const pin_obj_t * const pin_adc1[];\n")
|
||||
hdr_file.write("extern const pin_obj_t * const pin_adc2[];\n")
|
||||
hdr_file.write("extern const pin_obj_t * const pin_adc3[];\n")
|
||||
|
||||
def print_af_hdr(self, af_const_filename):
|
||||
with open(af_const_filename, "wt") as af_const_file:
|
||||
af_hdr_set = set([])
|
||||
mux_name_width = 0
|
||||
for named_pin in self.cpu_pins:
|
||||
pin = named_pin.pin()
|
||||
if pin.is_board_pin():
|
||||
for af in pin.alt_fn:
|
||||
if af.is_supported():
|
||||
mux_name = af.mux_name()
|
||||
af_hdr_set |= set([mux_name])
|
||||
if len(mux_name) > mux_name_width:
|
||||
mux_name_width = len(mux_name)
|
||||
for mux_name in sorted(af_hdr_set):
|
||||
key = "MP_ROM_QSTR(MP_QSTR_{}),".format(mux_name)
|
||||
val = "MP_ROM_INT(GPIO_{})".format(mux_name)
|
||||
print(" { %-*s %s }," % (mux_name_width + 26, key, val), file=af_const_file)
|
||||
def print_af_hdr(self, out_af_const):
|
||||
af_hdr_set = set([])
|
||||
mux_name_width = 0
|
||||
for named_pin in self.cpu_pins:
|
||||
pin = named_pin.pin()
|
||||
if pin.is_board_pin():
|
||||
for af in pin.alt_fn:
|
||||
if af.is_supported():
|
||||
mux_name = af.mux_name()
|
||||
af_hdr_set |= set([mux_name])
|
||||
if len(mux_name) > mux_name_width:
|
||||
mux_name_width = len(mux_name)
|
||||
for mux_name in sorted(af_hdr_set):
|
||||
key = "MP_ROM_QSTR(MP_QSTR_{}),".format(mux_name)
|
||||
val = "MP_ROM_INT(GPIO_{})".format(mux_name)
|
||||
print(" { %-*s %s }," % (mux_name_width + 26, key, val), file=out_af_const)
|
||||
|
||||
|
||||
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="nrf.csv",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--af-const",
|
||||
dest="af_const_filename",
|
||||
help="Specifies header file for alternate function constants.",
|
||||
default="build/pins_af_const.h",
|
||||
)
|
||||
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="nrf52_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")
|
||||
parser.add_argument("--output-af-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, 1, 2, 2)
|
||||
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, 1, 2, 2)
|
||||
|
||||
if args.board_filename:
|
||||
print("// --board {:s}".format(args.board_filename))
|
||||
pins.parse_board_file(args.board_filename)
|
||||
if args.board_csv:
|
||||
print("// --board {:s}".format(args.board_csv), file=out_source)
|
||||
pins.parse_board_file(args.board_csv)
|
||||
|
||||
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())
|
||||
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_const_table()
|
||||
pins.print()
|
||||
pins.print_header(args.hdr_filename)
|
||||
pins.print_af_hdr(args.af_const_filename)
|
||||
pins.print_const_table(out_source)
|
||||
pins.print(out_source)
|
||||
|
||||
with open(args.output_header, "w") as out_header:
|
||||
pins.print_header(out_header)
|
||||
|
||||
with open(args.output_af_const, "w") as out_af_const:
|
||||
pins.print_af_hdr(out_af_const)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -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()
|
||||
self.print_named("cpu", self.cpu_pins)
|
||||
print("")
|
||||
self.print_named("board", self.board_pins)
|
||||
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, 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)
|
||||
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_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)
|
||||
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_filename:
|
||||
print("// --board {:s}".format(args.board_filename))
|
||||
pins.parse_board_file(args.board_filename)
|
||||
if args.board_csv:
|
||||
print("// --board {:s}".format(args.board_csv), file=out_source)
|
||||
pins.parse_board_file(args.board_csv)
|
||||
|
||||
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())
|
||||
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()
|
||||
pins.print_header(args.hdr_filename)
|
||||
pins.print_ad_hdr(args.ad_const_filename)
|
||||
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}
|
||||
|
@ -68,16 +68,19 @@ class AlternateFunction(object):
|
||||
def is_supported(self):
|
||||
return self.supported
|
||||
|
||||
def print(self):
|
||||
def print(self, out_source):
|
||||
"""Prints the C representation of this AF."""
|
||||
if self.supported:
|
||||
print(" AF", end="")
|
||||
print(" AF", end="", file=out_source)
|
||||
else:
|
||||
print(" //", end="")
|
||||
print(" //", end="", file=out_source)
|
||||
fn_num = self.fn_num
|
||||
if fn_num is None:
|
||||
fn_num = 0
|
||||
print("({:d}, {:4s}, {:d}), // {:s}".format(self.idx, self.func, fn_num, self.af_str))
|
||||
print(
|
||||
"({:d}, {:4s}, {:d}), // {:s}".format(self.idx, self.func, fn_num, self.af_str),
|
||||
file=out_source,
|
||||
)
|
||||
|
||||
|
||||
class Pin(object):
|
||||
@ -116,19 +119,19 @@ class Pin(object):
|
||||
return "NULL"
|
||||
return "pin_{:s}_af".format(self.cpu_pin_name())
|
||||
|
||||
def print(self):
|
||||
def print(self, out_source):
|
||||
if self.is_ext:
|
||||
print("#if (MICROPY_HW_PIN_EXT_COUNT > {:d})".format(self.pin))
|
||||
print("#if (MICROPY_HW_PIN_EXT_COUNT > {:d})".format(self.pin), file=out_source)
|
||||
|
||||
if self.alt_fn_count == 0:
|
||||
print("// ", end="")
|
||||
print("const machine_pin_af_obj_t {:s}[] = {{".format(self.alt_fn_name()))
|
||||
print("// ", end="", file=out_source)
|
||||
print("const machine_pin_af_obj_t {:s}[] = {{".format(self.alt_fn_name()), file=out_source)
|
||||
for alt_fn in self.alt_fn:
|
||||
alt_fn.print()
|
||||
alt_fn.print(out_source)
|
||||
if self.alt_fn_count == 0:
|
||||
print("// ", end="")
|
||||
print("};")
|
||||
print("")
|
||||
print("// ", end="", file=out_source)
|
||||
print("};", file=out_source)
|
||||
print("", file=out_source)
|
||||
print(
|
||||
"{:s}machine_pin_obj_t pin_{:s} = PIN({:d}, {:s}, {:d}, {:d}, {:s});".format(
|
||||
"" if self.is_ext else "const ",
|
||||
@ -138,19 +141,21 @@ class Pin(object):
|
||||
self.is_ext,
|
||||
self.alt_fn_count,
|
||||
self.alt_fn_name(null_if_0=True),
|
||||
)
|
||||
),
|
||||
file=out_source,
|
||||
)
|
||||
if self.is_ext:
|
||||
print("#endif")
|
||||
print("")
|
||||
print("#endif", file=out_source)
|
||||
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{:s}machine_pin_obj_t pin_{:s};\n".format(" " if self.is_ext else " const ", n)
|
||||
print(
|
||||
"extern{:s}machine_pin_obj_t pin_{:s};".format(" " if self.is_ext else " const ", n),
|
||||
file=out_header,
|
||||
)
|
||||
if self.alt_fn_count > 0:
|
||||
hdr_file.write("extern const machine_pin_af_obj_t pin_{:s}_af[];\n".format(n))
|
||||
print("extern const machine_pin_af_obj_t pin_{:s}_af[];".format(n), file=out_header)
|
||||
|
||||
|
||||
class NamedPin(object):
|
||||
@ -219,126 +224,107 @@ class Pins(object):
|
||||
if row[0]: # Only add board pins that have a name
|
||||
self.board_pins.append(NamedPin(row[0], pin))
|
||||
|
||||
def print_table(self, label, named_pins):
|
||||
print("")
|
||||
print("const machine_pin_obj_t *machine_pin_{:s}_pins[] = {{".format(label))
|
||||
def print_table(self, label, named_pins, out_source):
|
||||
print("", file=out_source)
|
||||
print(
|
||||
"const machine_pin_obj_t *machine_pin_{:s}_pins[] = {{".format(label), file=out_source
|
||||
)
|
||||
for pin in named_pins:
|
||||
if not pin.pin().is_ext:
|
||||
print(" &pin_{},".format(pin.name()))
|
||||
print("};")
|
||||
print("")
|
||||
print(" &pin_{},".format(pin.name()), file=out_source)
|
||||
print("};", file=out_source)
|
||||
print("", file=out_source)
|
||||
|
||||
def print_named(self, label, named_pins):
|
||||
print("")
|
||||
def print_named(self, label, named_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 named_pin in named_pins:
|
||||
pin = named_pin.pin()
|
||||
if pin.is_ext:
|
||||
print(" #if (MICROPY_HW_PIN_EXT_COUNT > {:d})".format(pin.pin))
|
||||
print(" #if (MICROPY_HW_PIN_EXT_COUNT > {:d})".format(pin.pin), file=out_source)
|
||||
print(
|
||||
" {{ MP_ROM_QSTR(MP_QSTR_{:s}), MP_ROM_PTR(&pin_{:s}) }},".format(
|
||||
named_pin.name(), pin.cpu_pin_name()
|
||||
)
|
||||
),
|
||||
file=out_source,
|
||||
)
|
||||
if pin.is_ext:
|
||||
print(" #endif")
|
||||
print(" #endif", 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,
|
||||
)
|
||||
print("")
|
||||
print("", file=out_source)
|
||||
|
||||
def print(self):
|
||||
def print(self, out_source):
|
||||
for pin in self.cpu_pins:
|
||||
pin.pin().print()
|
||||
pin.pin().print(out_source)
|
||||
|
||||
for pin in self.ext_pins:
|
||||
if pin.pin().is_ext:
|
||||
pin.pin().print()
|
||||
pin.pin().print(out_source)
|
||||
|
||||
self.print_table("cpu", self.cpu_pins)
|
||||
self.print_named("cpu", self.cpu_pins + self.ext_pins)
|
||||
self.print_named("board", self.board_pins)
|
||||
self.print_table("cpu", self.cpu_pins, out_source)
|
||||
self.print_named("cpu", self.cpu_pins + self.ext_pins, out_source)
|
||||
self.print_named("board", self.board_pins, out_source)
|
||||
|
||||
def print_header(self, hdr_filename, obj_decls):
|
||||
with open(hdr_filename, "wt") as hdr_file:
|
||||
if obj_decls:
|
||||
for named_pin in self.cpu_pins:
|
||||
pin = named_pin.pin()
|
||||
pin.print_header(hdr_file)
|
||||
for named_pin in self.board_pins:
|
||||
pin = named_pin.pin()
|
||||
if pin.is_ext:
|
||||
pin.print_header(hdr_file)
|
||||
# provide #define's mapping board to cpu name
|
||||
for named_pin in self.board_pins:
|
||||
if named_pin.pin().is_board_pin():
|
||||
hdr_file.write(
|
||||
"#define pin_{:s} pin_{:s}\n".format(
|
||||
named_pin.name(), named_pin.pin().cpu_pin_name()
|
||||
)
|
||||
)
|
||||
def print_header(self, out_header):
|
||||
for named_pin in self.cpu_pins:
|
||||
pin = named_pin.pin()
|
||||
pin.print_header(out_header)
|
||||
for named_pin in self.board_pins:
|
||||
pin = named_pin.pin()
|
||||
if pin.is_ext:
|
||||
pin.print_header(out_header)
|
||||
# provide #define's mapping board to cpu name
|
||||
for named_pin in self.board_pins:
|
||||
if named_pin.pin().is_board_pin():
|
||||
print(
|
||||
"#define pin_{:s} pin_{:s}".format(
|
||||
named_pin.name(), named_pin.pin().cpu_pin_name()
|
||||
),
|
||||
file=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="rp2_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="rp2_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)
|
||||
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)
|
||||
|
||||
if args.board_filename:
|
||||
print("// --board {:s}".format(args.board_filename))
|
||||
pins.parse_board_file(args.board_filename)
|
||||
if args.board_csv:
|
||||
print("// --board {:s}".format(args.board_csv), file=out_source)
|
||||
pins.parse_board_file(args.board_csv)
|
||||
|
||||
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, True)
|
||||
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__":
|
||||
|
@ -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)
|
||||
|
@ -116,7 +116,7 @@ def conditional_var(name_num):
|
||||
return var
|
||||
|
||||
|
||||
def print_conditional_if(cond_var, file=None):
|
||||
def print_conditional_if(cond_var, file):
|
||||
if cond_var:
|
||||
cond_str = []
|
||||
for var in cond_var:
|
||||
@ -127,7 +127,7 @@ def print_conditional_if(cond_var, file=None):
|
||||
print("#if " + " || ".join(cond_str), file=file)
|
||||
|
||||
|
||||
def print_conditional_endif(cond_var, file=None):
|
||||
def print_conditional_endif(cond_var, file):
|
||||
if cond_var:
|
||||
print("#endif", file=file)
|
||||
|
||||
@ -169,24 +169,25 @@ class AlternateFunction(object):
|
||||
def mux_name(self):
|
||||
return "AF{:d}_{:s}".format(self.idx, self.ptr())
|
||||
|
||||
def print(self):
|
||||
def print(self, out_source):
|
||||
"""Prints the C representation of this AF."""
|
||||
cond_var = None
|
||||
if self.supported:
|
||||
cond_var = conditional_var("{}{}".format(self.func, self.fn_num))
|
||||
print_conditional_if(cond_var)
|
||||
print(" AF", end="")
|
||||
print_conditional_if(cond_var, file=out_source)
|
||||
print(" AF", end="", file=out_source)
|
||||
else:
|
||||
print(" //", end="")
|
||||
print(" //", end="", file=out_source)
|
||||
fn_num = self.fn_num
|
||||
if fn_num is None:
|
||||
fn_num = 0
|
||||
print(
|
||||
"({:2d}, {:8s}, {:2d}, {:10s}, {:8s}), // {:s}".format(
|
||||
self.idx, self.func, fn_num, self.pin_type, self.ptr(), self.af_str
|
||||
)
|
||||
),
|
||||
file=out_source,
|
||||
)
|
||||
print_conditional_endif(cond_var)
|
||||
print_conditional_endif(cond_var, file=out_source)
|
||||
|
||||
|
||||
class Pin(object):
|
||||
@ -269,16 +270,16 @@ class Pin(object):
|
||||
str = "0"
|
||||
return str
|
||||
|
||||
def print(self):
|
||||
def print(self, out_source):
|
||||
if self.alt_fn_count == 0:
|
||||
print("// ", end="")
|
||||
print("const pin_af_obj_t {:s}[] = {{".format(self.alt_fn_name()))
|
||||
print("// ", end="", file=out_source)
|
||||
print("const pin_af_obj_t {:s}[] = {{".format(self.alt_fn_name()), file=out_source)
|
||||
for alt_fn in self.alt_fn:
|
||||
alt_fn.print()
|
||||
alt_fn.print(out_source)
|
||||
if self.alt_fn_count == 0:
|
||||
print("// ", end="")
|
||||
print("};")
|
||||
print("")
|
||||
print("// ", end="", file=out_source)
|
||||
print("};", file=out_source)
|
||||
print("", file=out_source)
|
||||
print(
|
||||
"const pin_obj_t pin_{:s}_obj = PIN({:s}, {:d}, {:s}, {:s}, {:d});".format(
|
||||
self.cpu_pin_name(),
|
||||
@ -287,16 +288,17 @@ class Pin(object):
|
||||
self.alt_fn_name(null_if_0=True),
|
||||
self.adc_num_str(),
|
||||
self.adc_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_obj_t pin_{:s}_obj;\n".format(n))
|
||||
hdr_file.write("#define pin_{:s} (&pin_{:s}_obj)\n".format(n, n))
|
||||
print("extern const pin_obj_t pin_{:s}_obj;".format(n), file=out_header)
|
||||
print("#define pin_{:s} (&pin_{:s}_obj)".format(n, n), file=out_header)
|
||||
if self.alt_fn_count > 0:
|
||||
hdr_file.write("extern const pin_af_obj_t pin_{:s}_af[];\n".format(n))
|
||||
print("extern const pin_af_obj_t pin_{:s}_af[];".format(n), file=out_header)
|
||||
|
||||
|
||||
class NamedPin(object):
|
||||
@ -377,9 +379,10 @@ class Pins(object):
|
||||
if row[0]: # Only add board pins that have a name
|
||||
self.board_pins.append(NamedPin(row[0], 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()
|
||||
@ -387,25 +390,27 @@ 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()
|
||||
self.print_named("cpu", self.cpu_pins)
|
||||
print("")
|
||||
self.print_named("board", self.board_pins)
|
||||
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_adc(self, adc_num):
|
||||
def print_adc(self, adc_num, out_source):
|
||||
adc_pins = {}
|
||||
for named_pin in self.cpu_pins:
|
||||
pin = named_pin.pin()
|
||||
@ -421,171 +426,134 @@ class Pins(object):
|
||||
# If ADCx pins are hidden, print an empty table to prevent linker errors.
|
||||
table_size = 0
|
||||
self.adc_table_size[adc_num] = table_size
|
||||
print("")
|
||||
print("const pin_obj_t * const pin_adc{:d}[{:d}] = {{".format(adc_num, table_size))
|
||||
print("", file=out_source)
|
||||
print(
|
||||
"const pin_obj_t * const pin_adc{:d}[{:d}] = {{".format(adc_num, table_size),
|
||||
file=out_source,
|
||||
)
|
||||
for channel in range(table_size):
|
||||
if channel in adc_pins:
|
||||
obj = "&pin_{:s}_obj".format(adc_pins[channel].cpu_pin_name())
|
||||
else:
|
||||
obj = "NULL"
|
||||
print(" [{:d}] = {},".format(channel, obj))
|
||||
print("};")
|
||||
print(" [{:d}] = {},".format(channel, obj), file=out_source)
|
||||
print("};", file=out_source)
|
||||
|
||||
def print_header(self, hdr_filename, obj_decls):
|
||||
with open(hdr_filename, "wt") as hdr_file:
|
||||
if obj_decls:
|
||||
for named_pin in self.cpu_pins:
|
||||
pin = named_pin.pin()
|
||||
if pin.is_board_pin():
|
||||
pin.print_header(hdr_file)
|
||||
for adc_num, table_size in self.adc_table_size.items():
|
||||
hdr_file.write(
|
||||
"extern const pin_obj_t * const pin_adc{:d}[{:d}];\n".format(
|
||||
adc_num, table_size
|
||||
)
|
||||
)
|
||||
# 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()
|
||||
)
|
||||
)
|
||||
|
||||
def print_af_hdr(self, af_const_filename):
|
||||
with open(af_const_filename, "wt") as af_const_file:
|
||||
af_hdr_set = set([])
|
||||
mux_name_width = 0
|
||||
def print_header(self, out_header, obj_decls):
|
||||
if obj_decls:
|
||||
for named_pin in self.cpu_pins:
|
||||
pin = named_pin.pin()
|
||||
if pin.is_board_pin():
|
||||
for af in pin.alt_fn:
|
||||
if af.is_supported():
|
||||
mux_name = af.mux_name()
|
||||
af_hdr_set |= set([mux_name])
|
||||
if len(mux_name) > mux_name_width:
|
||||
mux_name_width = len(mux_name)
|
||||
for mux_name in sorted(af_hdr_set):
|
||||
af_words = mux_name.split("_") # ex mux_name: AF9_I2C2
|
||||
cond_var = conditional_var(af_words[1])
|
||||
print_conditional_if(cond_var, file=af_const_file)
|
||||
key = "MP_ROM_QSTR(MP_QSTR_{}),".format(mux_name)
|
||||
val = "MP_ROM_INT(GPIO_{})".format(mux_name)
|
||||
print(" { %-*s %s }," % (mux_name_width + 26, key, val), file=af_const_file)
|
||||
print_conditional_endif(cond_var, file=af_const_file)
|
||||
pin.print_header(out_header)
|
||||
for adc_num, table_size in self.adc_table_size.items():
|
||||
print(
|
||||
"extern const pin_obj_t * const pin_adc{:d}[{:d}];".format(
|
||||
adc_num, table_size
|
||||
),
|
||||
file=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_af_defs(self, af_defs_filename, cmp_strings):
|
||||
with open(af_defs_filename, "wt") as af_defs_file:
|
||||
STATIC_AF_TOKENS = {}
|
||||
for named_pin in self.cpu_pins:
|
||||
for af in named_pin.pin().alt_fn:
|
||||
func = "%s%d" % (af.func, af.fn_num) if af.fn_num else af.func
|
||||
pin_type = (af.pin_type or "NULL").split("(")[0]
|
||||
tok = "#define STATIC_AF_%s_%s(pin_obj) ( \\" % (func, pin_type)
|
||||
if tok not in STATIC_AF_TOKENS:
|
||||
STATIC_AF_TOKENS[tok] = []
|
||||
if cmp_strings:
|
||||
pin_name = named_pin.pin().cpu_pin_name()
|
||||
cmp_str = (
|
||||
' ((strcmp( #pin_obj , "(&pin_%s_obj)") '
|
||||
' & strcmp( #pin_obj , "((&pin_%s_obj))")) == 0) ? (%d) : \\'
|
||||
% (pin_name, pin_name, af.idx)
|
||||
)
|
||||
else:
|
||||
cmp_str = " ((pin_obj) == (pin_%s)) ? (%d) : \\" % (
|
||||
named_pin.pin().cpu_pin_name(),
|
||||
af.idx,
|
||||
)
|
||||
STATIC_AF_TOKENS[tok].append(cmp_str)
|
||||
def print_af_hdr(self, out_af_const):
|
||||
af_hdr_set = set([])
|
||||
mux_name_width = 0
|
||||
for named_pin in self.cpu_pins:
|
||||
pin = named_pin.pin()
|
||||
if pin.is_board_pin():
|
||||
for af in pin.alt_fn:
|
||||
if af.is_supported():
|
||||
mux_name = af.mux_name()
|
||||
af_hdr_set |= set([mux_name])
|
||||
if len(mux_name) > mux_name_width:
|
||||
mux_name_width = len(mux_name)
|
||||
for mux_name in sorted(af_hdr_set):
|
||||
af_words = mux_name.split("_") # ex mux_name: AF9_I2C2
|
||||
cond_var = conditional_var(af_words[1])
|
||||
print_conditional_if(cond_var, file=out_af_const)
|
||||
key = "MP_ROM_QSTR(MP_QSTR_{}),".format(mux_name)
|
||||
val = "MP_ROM_INT(GPIO_{})".format(mux_name)
|
||||
print(" { %-*s %s }," % (mux_name_width + 26, key, val), file=out_af_const)
|
||||
print_conditional_endif(cond_var, file=out_af_const)
|
||||
|
||||
for tok, pins in STATIC_AF_TOKENS.items():
|
||||
print(tok, file=af_defs_file)
|
||||
print("\n".join(sorted(pins)), file=af_defs_file)
|
||||
print(" (0xffffffffffffffffULL))\n", file=af_defs_file)
|
||||
def print_af_defs(self, out_af_defs, cmp_strings):
|
||||
STATIC_AF_TOKENS = {}
|
||||
for named_pin in self.cpu_pins:
|
||||
for af in named_pin.pin().alt_fn:
|
||||
func = "%s%d" % (af.func, af.fn_num) if af.fn_num else af.func
|
||||
pin_type = (af.pin_type or "NULL").split("(")[0]
|
||||
tok = "#define STATIC_AF_%s_%s(pin_obj) ( \\" % (func, pin_type)
|
||||
if tok not in STATIC_AF_TOKENS:
|
||||
STATIC_AF_TOKENS[tok] = []
|
||||
if cmp_strings:
|
||||
pin_name = named_pin.pin().cpu_pin_name()
|
||||
cmp_str = (
|
||||
' ((strcmp( #pin_obj , "(&pin_%s_obj)") '
|
||||
' & strcmp( #pin_obj , "((&pin_%s_obj))")) == 0) ? (%d) : \\'
|
||||
% (pin_name, pin_name, af.idx)
|
||||
)
|
||||
else:
|
||||
cmp_str = " ((pin_obj) == (pin_%s)) ? (%d) : \\" % (
|
||||
named_pin.pin().cpu_pin_name(),
|
||||
af.idx,
|
||||
)
|
||||
STATIC_AF_TOKENS[tok].append(cmp_str)
|
||||
|
||||
for tok, pins in STATIC_AF_TOKENS.items():
|
||||
print(tok, file=out_af_defs)
|
||||
print("\n".join(sorted(pins)), file=out_af_defs)
|
||||
print(" (0xffffffffffffffffULL))\n", file=out_af_defs)
|
||||
|
||||
|
||||
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="stm32f4xx_af.csv",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--af-const",
|
||||
dest="af_const_filename",
|
||||
help="Specifies header file for alternate function constants.",
|
||||
default="build/pins_af_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(
|
||||
"--af-defs-cmp-strings",
|
||||
dest="af_defs_cmp_strings",
|
||||
help="Whether to compare pin name strings for the alternate function defines instead of object values",
|
||||
action="store_true",
|
||||
)
|
||||
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="stm32f4xx_prefix.c",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-r",
|
||||
"--hdr",
|
||||
dest="hdr_filename",
|
||||
help="Specifies name of generated pin header file",
|
||||
default="build/pins.h",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--hdr-obj-decls",
|
||||
dest="hdr_obj_decls",
|
||||
help="Whether to include declarations for pin objects in pin header file",
|
||||
action="store_true",
|
||||
)
|
||||
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-af-const")
|
||||
parser.add_argument("--output-af-defs")
|
||||
parser.add_argument("--mboot-mode", action="store_true")
|
||||
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, 1, 2)
|
||||
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, 1, 2)
|
||||
|
||||
if args.board_filename:
|
||||
print("// --board {:s}".format(args.board_filename))
|
||||
pins.parse_board_file(args.board_filename)
|
||||
if args.board_csv:
|
||||
print("// --board {:s}".format(args.board_csv), file=out_source)
|
||||
pins.parse_board_file(args.board_csv)
|
||||
|
||||
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()
|
||||
for i in range(1, 4):
|
||||
pins.print_adc(i)
|
||||
pins.print_header(args.hdr_filename, args.hdr_obj_decls)
|
||||
pins.print_af_hdr(args.af_const_filename)
|
||||
pins.print_af_defs(args.af_defs_filename, args.af_defs_cmp_strings)
|
||||
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)
|
||||
for i in range(1, 4):
|
||||
pins.print_adc(i, out_source)
|
||||
|
||||
with open(args.output_header, "w") as out_header:
|
||||
pins.print_header(out_header, not args.mboot_mode)
|
||||
|
||||
with open(args.output_af_const, "w") as out_af_const:
|
||||
pins.print_af_hdr(out_af_const)
|
||||
|
||||
with open(args.output_af_defs, "w") as out_af_defs:
|
||||
pins.print_af_defs(out_af_defs, not args.mboot_mode)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -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
|
||||
|
||||
#########################################
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user