examples/pins.py: Remove this pins printing example.

It's not supported on all ports, adds complexity to the build to generate
pins_af.py, and can mostly be replicated just by printing the pin objects.

Remove support for generating pins_af.py from all ports (nrf, stm32,
renesas-ra, mimxrt, rp2).

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
Jim Mussared 2023-08-03 15:02:41 +10:00 committed by Damien George
parent cb37b7bba7
commit 59f3c7facb
11 changed files with 5 additions and 133 deletions

View File

@ -1,60 +0,0 @@
# Print a nice list of pins, their current settings, and available afs.
# Requires pins_af.py from ports/stm32/build-PYBV10/ directory.
import pyb
import pins_af
def af():
max_name_width = 0
max_af_width = 0
for pin_entry in pins_af.PINS_AF:
max_name_width = max(max_name_width, len(pin_entry[0]))
for af_entry in pin_entry[1:]:
max_af_width = max(max_af_width, len(af_entry[1]))
for pin_entry in pins_af.PINS_AF:
pin_name = pin_entry[0]
print("%-*s " % (max_name_width, pin_name), end="")
for af_entry in pin_entry[1:]:
print("%2d: %-*s " % (af_entry[0], max_af_width, af_entry[1]), end="")
print("")
def pins():
mode_str = {
pyb.Pin.IN: "IN",
pyb.Pin.OUT_PP: "OUT_PP",
pyb.Pin.OUT_OD: "OUT_OD",
pyb.Pin.AF_PP: "AF_PP",
pyb.Pin.AF_OD: "AF_OD",
pyb.Pin.ANALOG: "ANALOG",
}
pull_str = {pyb.Pin.PULL_NONE: "", pyb.Pin.PULL_UP: "PULL_UP", pyb.Pin.PULL_DOWN: "PULL_DOWN"}
width = [0, 0, 0, 0]
rows = []
for pin_entry in pins_af.PINS_AF:
row = []
pin_name = pin_entry[0]
pin = pyb.Pin(pin_name)
pin_mode = pin.mode()
row.append(pin_name)
row.append(mode_str[pin_mode])
row.append(pull_str[pin.pull()])
if pin_mode == pyb.Pin.AF_PP or pin_mode == pyb.Pin.AF_OD:
pin_af = pin.af()
for af_entry in pin_entry[1:]:
if pin_af == af_entry[0]:
af_str = "%d: %s" % (pin_af, af_entry[1])
break
else:
af_str = "%d" % pin_af
else:
af_str = ""
row.append(af_str)
for col in range(len(width)):
width[col] = max(width[col], len(row[col]))
rows.append(row)
for row in rows:
for col in range(len(width)):
print("%-*s " % (width[col], row[col]), end="")
print("")

View File

@ -62,7 +62,6 @@ BOARD_PINS = $(BOARD_DIR)/pins.csv
PREFIX_FILE = boards/mimxrt_prefix.c
GEN_FLEXRAM_CONFIG_SRC = $(BUILD)/flexram_config.s
GEN_PINS_AF_CONST = $(HEADER_BUILD)/pins_af_const.h
GEN_PINS_AF_PY = $(BUILD)/pins_af.py
GEN_PINS_HDR = $(HEADER_BUILD)/pins.h
GEN_PINS_SRC = $(BUILD)/pins_gen.c

View File

@ -119,7 +119,6 @@ PREFIX_FILE = boards/$(MCU_VARIANT)_prefix.c
GEN_PINS_SRC = $(BUILD)/pins_gen.c
GEN_PINS_HDR = $(HEADER_BUILD)/pins.h
GEN_PINS_AF_CONST = $(HEADER_BUILD)/pins_af_const.h
GEN_PINS_AF_PY = $(BUILD)/pins_af.py
CFLAGS_CORTEX_M = -mthumb -mabi=aapcs -fsingle-precision-constant -Wdouble-promotion
@ -544,7 +543,7 @@ $(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) --af-py $(GEN_PINS_AF_PY) > $(GEN_PINS_SRC)
$(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)
$(PY_BUILD)/nlr%.o: CFLAGS += -Os -fno-lto

View File

@ -320,17 +320,6 @@ class Pins(object):
val = "MP_ROM_INT(GPIO_{})".format(mux_name)
print(" { %-*s %s }," % (mux_name_width + 26, key, val), file=af_const_file)
def print_af_py(self, af_py_filename):
with open(af_py_filename, "wt") as af_py_file:
print("PINS_AF = (", file=af_py_file)
for named_pin in self.board_pins:
print(" ('%s', " % named_pin.name(), end="", file=af_py_file)
for af in named_pin.pin().alt_fn:
if af.is_supported():
print("(%d, '%s'), " % (af.idx, af.af_str), end="", file=af_py_file)
print("),", file=af_py_file)
print(")", file=af_py_file)
def main():
parser = argparse.ArgumentParser(
@ -351,12 +340,6 @@ def main():
help="Specifies header file for alternate function constants.",
default="build/pins_af_const.h",
)
parser.add_argument(
"--af-py",
dest="af_py_filename",
help="Specifies the filename for the python alternate function mappings.",
default="build/pins_af.py",
)
parser.add_argument(
"-b",
"--board",
@ -401,7 +384,6 @@ def main():
pins.print()
pins.print_header(args.hdr_filename)
pins.print_af_hdr(args.af_const_filename)
pins.print_af_py(args.af_py_filename)
if __name__ == "__main__":

View File

@ -558,7 +558,6 @@ GEN_PINS_SRC = $(BUILD)/pins_$(BOARD).c
GEN_PINS_HDR = $(HEADER_BUILD)/pins.h
# Currently unused.
GEN_PINS_AD_CONST = $(HEADER_BUILD)/pins_ad_const.h
GEN_PINS_AF_PY = $(BUILD)/pins_af.py
FILE2H = $(TOP)/tools/file2h.py
@ -581,7 +580,7 @@ $(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) --af-py $(GEN_PINS_AF_PY) > $(GEN_PINS_SRC)
$(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)
CMSIS_MCU_HDR = $(CMSIS_DIR)/$(CMSIS_MCU_LOWER).h

View File

@ -240,12 +240,6 @@ def main():
help="Specifies header file for AD function constants.",
default="build/pins_ad_const.h",
)
parser.add_argument(
"--af-py",
dest="af_py_filename",
help="Specifies the filename for the python alternate function mappings.",
default="build/pins_af.py",
)
parser.add_argument(
"--af-defs",
dest="af_defs_filename",

View File

@ -480,7 +480,6 @@ set(GEN_PINS_MKPINS "${MICROPY_BOARDS_DIR}/make-pins.py")
set(GEN_PINS_SRC "${CMAKE_BINARY_DIR}/pins_${MICROPY_BOARD}.c")
set(GEN_PINS_HDR "${MICROPY_GENHDR_DIR}/pins.h")
set(GEN_PINS_AF_CONST "${MICROPY_GENHDR_DIR}/pins_af_const.h")
set(GEN_PINS_AF_PY "${CMAKE_BINARY_DIR}/pins_af.py")
if(EXISTS "${MICROPY_BOARDS_DIR}/${MICROPY_BOARD}/pins.csv")
set(GEN_PINS_BOARD_CSV "${MICROPY_BOARDS_DIR}/${MICROPY_BOARD}/pins.csv")
@ -495,7 +494,7 @@ target_sources(${MICROPY_TARGET} PRIVATE
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} --af-py ${GEN_PINS_AF_PY} > ${GEN_PINS_SRC}
--hdr ${GEN_PINS_HDR} > ${GEN_PINS_SRC}
DEPENDS
${GEN_PINS_AF_CSV}
${GEN_PINS_BOARD_CSV}

View File

@ -284,17 +284,6 @@ class Pins(object):
)
)
def print_af_py(self, af_py_filename):
with open(af_py_filename, "wt") as af_py_file:
print("PINS_AF = (", file=af_py_file)
for named_pin in self.board_pins:
print(" ('%s', " % named_pin.name(), end="", file=af_py_file)
for af in named_pin.pin().alt_fn:
if af.is_supported():
print("(%d, '%s'), " % (af.idx, af.af_str), end="", file=af_py_file)
print("),", file=af_py_file)
print(")", file=af_py_file)
def main():
parser = argparse.ArgumentParser(
@ -309,12 +298,6 @@ def main():
help="Specifies the alternate function file for the chip",
default="rp2_af.csv",
)
parser.add_argument(
"--af-py",
dest="af_py_filename",
help="Specifies the filename for the python alternate function mappings.",
default="build/pins_af.py",
)
parser.add_argument(
"-b",
"--board",
@ -356,7 +339,6 @@ def main():
print(prefix_file.read())
pins.print()
pins.print_header(args.hdr_filename, True)
pins.print_af_py(args.af_py_filename)
if __name__ == "__main__":

View File

@ -72,7 +72,6 @@ GEN_PINS_SRC = $(BUILD)/pins_$(BOARD).c
GEN_PINS_HDR = $(HEADER_BUILD)/pins.h
GEN_PINS_AF_CONST = $(HEADER_BUILD)/pins_af_const.h
GEN_PINS_AF_DEFS = $(HEADER_BUILD)/pins_af_defs.h
GEN_PINS_AF_PY = $(BUILD)/pins_af.py
INSERT_USB_IDS = $(TOP)/tools/insert-usb-ids.py
FILE2H = $(TOP)/tools/file2h.py
@ -678,7 +677,7 @@ $(BUILD)/%_$(BOARD).c $(HEADER_BUILD)/%.h $(HEADER_BUILD)/%_af_const.h $(HEADER_
$(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 --af-py $(GEN_PINS_AF_PY) > $(GEN_PINS_SRC)
--af-defs-cmp-strings > $(GEN_PINS_SRC)
modmachine.c: $(GEN_PLLFREQTABLE_HDR)
$(GEN_PLLFREQTABLE_HDR): $(PLLVALUES) | $(HEADER_BUILD)

View File

@ -503,19 +503,6 @@ class Pins(object):
print("\n".join(sorted(pins)), file=af_defs_file)
print(" (0xffffffffffffffffULL))\n", file=af_defs_file)
def print_af_py(self, af_py_filename):
with open(af_py_filename, "wt") as af_py_file:
print("PINS_AF = (", file=af_py_file)
for named_pin in self.board_pins:
if named_pin.is_hidden():
continue
print(" ('%s', " % named_pin.name(), end="", file=af_py_file)
for af in named_pin.pin().alt_fn:
if af.is_supported():
print("(%d, '%s'), " % (af.idx, af.af_str), end="", file=af_py_file)
print("),", file=af_py_file)
print(")", file=af_py_file)
def main():
parser = argparse.ArgumentParser(
@ -536,12 +523,6 @@ def main():
help="Specifies header file for alternate function constants.",
default="build/pins_af_const.h",
)
parser.add_argument(
"--af-py",
dest="af_py_filename",
help="Specifies the filename for the python alternate function mappings.",
default="build/pins_af.py",
)
parser.add_argument(
"--af-defs",
dest="af_defs_filename",
@ -604,7 +585,6 @@ def main():
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_py(args.af_py_filename)
pins.print_af_defs(args.af_defs_filename, args.af_defs_cmp_strings)

View File

@ -229,7 +229,6 @@ GEN_PINS_SRC = $(BUILD)/pins_$(BOARD).c
GEN_PINS_HDR = $(HEADER_BUILD)/pins.h
GEN_PINS_AF_CONST = $(HEADER_BUILD)/pins_af_const.h
GEN_PINS_AF_DEFS = $(HEADER_BUILD)/pins_af_defs.h
GEN_PINS_AF_PY = $(BUILD)/pins_af.py
$(OBJ): $(GEN_QSTRDEFS_GENERATED) $(GEN_ROOT_POINTERS) $(GEN_PINS_AF_DEFS)
@ -247,7 +246,7 @@ $(GEN_PINS_AF_DEFS): $(BOARD_PINS) $(MAKE_PINS) ../$(AF_FILE) $(PREFIX_FILE) | $
$(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) \
--af-py $(GEN_PINS_AF_PY) > $(GEN_PINS_SRC)
> $(GEN_PINS_SRC)
#########################################