From 59f3c7facbb6100108750efa857f1550f23f2482 Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Thu, 3 Aug 2023 15:02:41 +1000 Subject: [PATCH] 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 --- examples/pins.py | 60 ---------------------------- ports/mimxrt/Makefile | 1 - ports/nrf/Makefile | 3 +- ports/nrf/boards/make-pins.py | 18 --------- ports/renesas-ra/Makefile | 3 +- ports/renesas-ra/boards/make-pins.py | 6 --- ports/rp2/CMakeLists.txt | 3 +- ports/rp2/boards/make-pins.py | 18 --------- ports/stm32/Makefile | 3 +- ports/stm32/boards/make-pins.py | 20 ---------- ports/stm32/mboot/Makefile | 3 +- 11 files changed, 5 insertions(+), 133 deletions(-) delete mode 100644 examples/pins.py diff --git a/examples/pins.py b/examples/pins.py deleted file mode 100644 index 3a8472e8a6..0000000000 --- a/examples/pins.py +++ /dev/null @@ -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("") diff --git a/ports/mimxrt/Makefile b/ports/mimxrt/Makefile index c22c5442a9..51cf5178ba 100644 --- a/ports/mimxrt/Makefile +++ b/ports/mimxrt/Makefile @@ -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 diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index 7d7589cc20..cb81ad847f 100644 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -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 diff --git a/ports/nrf/boards/make-pins.py b/ports/nrf/boards/make-pins.py index b535e2418b..6bfb662514 100644 --- a/ports/nrf/boards/make-pins.py +++ b/ports/nrf/boards/make-pins.py @@ -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__": diff --git a/ports/renesas-ra/Makefile b/ports/renesas-ra/Makefile index e77843b1e3..8c09dc91bd 100644 --- a/ports/renesas-ra/Makefile +++ b/ports/renesas-ra/Makefile @@ -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 diff --git a/ports/renesas-ra/boards/make-pins.py b/ports/renesas-ra/boards/make-pins.py index 4127c9ff11..43267a1fa3 100644 --- a/ports/renesas-ra/boards/make-pins.py +++ b/ports/renesas-ra/boards/make-pins.py @@ -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", diff --git a/ports/rp2/CMakeLists.txt b/ports/rp2/CMakeLists.txt index 4a0d2fbad7..f643b66793 100644 --- a/ports/rp2/CMakeLists.txt +++ b/ports/rp2/CMakeLists.txt @@ -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} diff --git a/ports/rp2/boards/make-pins.py b/ports/rp2/boards/make-pins.py index 4029d7b1cf..9c66248885 100755 --- a/ports/rp2/boards/make-pins.py +++ b/ports/rp2/boards/make-pins.py @@ -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__": diff --git a/ports/stm32/Makefile b/ports/stm32/Makefile index 3bb18ee3cb..5b853592c9 100644 --- a/ports/stm32/Makefile +++ b/ports/stm32/Makefile @@ -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) diff --git a/ports/stm32/boards/make-pins.py b/ports/stm32/boards/make-pins.py index f0fcb82437..99b507a3a8 100755 --- a/ports/stm32/boards/make-pins.py +++ b/ports/stm32/boards/make-pins.py @@ -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) diff --git a/ports/stm32/mboot/Makefile b/ports/stm32/mboot/Makefile index a37b046ca5..fab8ce2159 100755 --- a/ports/stm32/mboot/Makefile +++ b/ports/stm32/mboot/Makefile @@ -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) #########################################