Skip to content

tools/boardgen.py: Add a common library for ports to implement make-pins.py. #12211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2eda513
py/mkrules.mk: Add rule for compiling auto-generated source files.
jimmo Aug 3, 2023
c3c7c60
rp2/boards/make-pins.py: Don't generate qstrs.
jimmo Aug 3, 2023
fc54d25
stm32/boards/make-pins.py: Don't generate qstrs.
jimmo Aug 3, 2023
3f99dbd
nrf/boards/make-pins.py: Don't generate qstrs.
jimmo Aug 3, 2023
df28aa1
renesas-ra/boards/make-pins.py: Don't generate qstrs.
jimmo Aug 3, 2023
cb37b7b
cc3200/boards/make-pins.py: Don't generate qstrs.
jimmo Aug 4, 2023
59f3c7f
examples/pins.py: Remove this pins printing example.
jimmo Aug 3, 2023
1ee5731
ports: Remove SRC_QSTR_AUTO_DEPS from all ports' Makefiles.
jimmo Aug 3, 2023
9cabee8
ports: Standardise arguments and output for make-pins.py script.
jimmo Aug 3, 2023
b0aec6a
esp32/machine_pin: Make irq object a sub-field of pin object.
jimmo Aug 7, 2023
4bd6ec9
tools/boardgen.py: Add initial implementation of a common make-pins.py.
jimmo Aug 7, 2023
98dff07
stm32/boards: Fix errors in pins.csv and af.csv.
jimmo Aug 10, 2023
286b1b3
stm32/boards: Format stm32 alternate function csv files.
jimmo Nov 2, 2023
b4236c7
stm32: Rename pin_obj_t to machine_pin_obj_t.
jimmo Aug 8, 2023
724ebb9
stm32/boards/make-pins.py: Update to use tools/boardgen.py.
jimmo Aug 8, 2023
ff6c2ad
stm32/boards/make-pins.py: Add initial support for H7 dual-pad pins.
jimmo Nov 2, 2023
4d568a5
samd/boards/make-pins.py: Update to use tools/boardgen.py.
jimmo Aug 14, 2023
c0b64a3
mimxrt/boards/make-pins.py: Update to use tools/boardgen.py.
jimmo Aug 16, 2023
1f804e0
renesas-ra/boards/make-pins.py: Update to use tools/boardgen.py.
jimmo Aug 24, 2023
6ef9b29
{cc3200,nrf}/boards/make-pins.py: Add a note about tools/boardgen.py.
jimmo Aug 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 0 additions & 60 deletions examples/pins.py

This file was deleted.

2 changes: 1 addition & 1 deletion ports/cc3200/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ FLASH_SIZE_LAUNCHXL = 1M

ifeq ($(BTARGET), application)
# qstr definitions (must come before including py.mk)
QSTR_DEFS = qstrdefsport.h $(BUILD)/pins_qstr.h
QSTR_DEFS = qstrdefsport.h

# MicroPython feature configurations
MICROPY_ROM_TEXT_COMPRESSION ?= 1
Expand Down
14 changes: 4 additions & 10 deletions ports/cc3200/application.mk
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,7 @@ OBJ += $(BUILD)/shared/runtime/gchelper_thumb2.o
OBJ += $(BUILD)/pins.o

# List of sources for qstr extraction
SRC_QSTR += $(APP_MODS_SRC_C) $(APP_MISC_SRC_C) $(APP_STM_SRC_C) $(APP_SHARED_SRC_C) $(APP_HAL_SRC_C)
# Append any auto-generated sources that are needed by sources listed in
# SRC_QSTR
SRC_QSTR_AUTO_DEPS +=
SRC_QSTR += $(APP_MODS_SRC_C) $(APP_MISC_SRC_C) $(APP_STM_SRC_C) $(APP_SHARED_SRC_C) $(APP_HAL_SRC_C) $(GEN_PINS_SRC)

# Add the linker script
LINKER_SCRIPT = application.lds
Expand Down Expand Up @@ -228,7 +225,6 @@ AF_FILE = boards/cc3200_af.csv
PREFIX_FILE = boards/cc3200_prefix.c
GEN_PINS_SRC = $(BUILD)/pins.c
GEN_PINS_HDR = $(HEADER_BUILD)/pins.h
GEN_PINS_QSTR = $(BUILD)/pins_qstr.h

# Making OBJ use an order-only dependency on the generated pins.h file
# has the side effect of making the pins.h file before we actually compile
Expand All @@ -238,9 +234,7 @@ GEN_PINS_QSTR = $(BUILD)/pins_qstr.h
$(OBJ): | $(GEN_PINS_HDR)

# Call make-pins.py to generate both pins_gen.c and pins.h
$(GEN_PINS_SRC) $(GEN_PINS_HDR) $(GEN_PINS_QSTR): $(BOARD_PINS) $(MAKE_PINS) $(AF_FILE) $(PREFIX_FILE) | $(HEADER_BUILD)
$(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) --qstr $(GEN_PINS_QSTR) > $(GEN_PINS_SRC)

$(BUILD)/pins.o: $(BUILD)/pins.c
$(call compile_c)
$(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)
163 changes: 62 additions & 101 deletions ports/cc3200/boards/make-pins.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env python
"""Generates the pins file for the CC3200."""

# Do not use this as a reference for new ports. See tools/boardgen.py and e.g.
# ports/stm32/boards/make-pins.py.

from __future__ import print_function

import argparse
Expand Down Expand Up @@ -44,11 +47,12 @@ def __init__(self, name, idx, fn, unit, type):
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,
)


Expand All @@ -66,13 +70,13 @@ def __init__(self, name, port, gpio_bit, pin_num):
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,
Expand All @@ -82,17 +86,19 @@ def print(self):
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:
Expand Down Expand Up @@ -153,117 +159,72 @@ def parse_board_file(self, filename, cpu_pin_col):
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(out_source)
self.print_named("board", self.board_pins, out_source)
print("", file=out_source)

def print_header(self, out_header):
for pin in self.board_pins:
if pin.board_pin:
pin.print()
self.print_named("board", self.board_pins)
print("")

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_qstr(self, qstr_filename):
with open(qstr_filename, "wt") as qstr_file:
pin_qstr_set = set([])
af_qstr_set = set([])
for pin in self.board_pins:
if pin.board_pin:
pin_qstr_set |= set([pin.name])
for af in pin.afs:
af_qstr_set |= set([af.name])
print("// Board pins", file=qstr_file)
for qstr in sorted(pin_qstr_set):
print("Q({})".format(qstr), file=qstr_file)
print("\n// Pin AFs", file=qstr_file)
for qstr in sorted(af_qstr_set):
print("Q({})".format(qstr), file=qstr_file)
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(
"-q",
"--qstr",
dest="qstr_filename",
help="Specifies name of generated qstr header file",
default="build/pins_qstr.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")
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_qstr(args.qstr_filename)
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__":
Expand Down
Loading