From 4af09de19cbcf8acef549d094eab846b87ea46ba Mon Sep 17 00:00:00 2001 From: Peter Harper Date: Mon, 8 Jul 2024 15:57:13 +0100 Subject: [PATCH] rp2/boards/make-pins.py: Pass num-gpios/num-ext-gpios into make-pins. NUM_GPIOS amd NUM_EXT_GPIOS are currently hardcoded in make-pins.py, which makes it difficult to support SoCs with different pin count. This commit generalises make-pins.py by passing in the pin count in via the new arguments `--num-gpios` and `--num-ext-gpios`. These default to the current values supported by Pico, namely 30/10. This can be changed with PICO_NUM_GPIOS and PICO_NUM_EXT_GPIOS in `mpconfigboard.cmake`. Signed-off-by: Damien George --- ports/rp2/CMakeLists.txt | 10 +++++++++- ports/rp2/boards/make-pins.py | 35 +++++++++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/ports/rp2/CMakeLists.txt b/ports/rp2/CMakeLists.txt index 6f66181546271..0d5b10f337380 100644 --- a/ports/rp2/CMakeLists.txt +++ b/ports/rp2/CMakeLists.txt @@ -588,6 +588,14 @@ set(GEN_PINS_MKPINS "${MICROPY_PORT_DIR}/boards/make-pins.py") set(GEN_PINS_SRC "${CMAKE_BINARY_DIR}/pins_${MICROPY_BOARD}.c") set(GEN_PINS_HDR "${MICROPY_GENHDR_DIR}/pins.h") +if(NOT PICO_NUM_GPIOS) + set(PICO_NUM_GPIOS 30) +endif() + +if(NOT PICO_NUM_EXT_GPIOS) + set(PICO_NUM_EXT_GPIOS 10) +endif() + if(EXISTS "${MICROPY_BOARD_DIR}/pins.csv") set(GEN_PINS_BOARD_CSV "${MICROPY_BOARD_DIR}/pins.csv") set(GEN_PINS_CSV_ARG --board-csv "${GEN_PINS_BOARD_CSV}") @@ -600,7 +608,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-csv ${GEN_PINS_AF_CSV} --prefix ${GEN_PINS_PREFIX} --output-source ${GEN_PINS_SRC} --output-header ${GEN_PINS_HDR} + 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} --num-gpios ${PICO_NUM_GPIOS} --num-ext-gpios ${PICO_NUM_EXT_GPIOS} --output-header ${GEN_PINS_HDR} 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 f4ce74e5a42b3..1da2edb7cacd6 100755 --- a/ports/rp2/boards/make-pins.py +++ b/ports/rp2/boards/make-pins.py @@ -9,9 +9,9 @@ import boardgen # This is NUM_BANK0_GPIOS. Pin indices are 0 to 29 (inclusive). -NUM_GPIOS = 48 +NUM_GPIOS = None # Up to 32 additional extended pins (e.g. via the wifi chip or io expanders). -NUM_EXT_GPIOS = 32 +NUM_EXT_GPIOS = None class Rp2Pin(boardgen.Pin): @@ -108,12 +108,6 @@ def __init__(self): enable_af=True, ) - # Pre-define the pins (i.e. don't require them to be listed in pins.csv). - for i in range(NUM_GPIOS): - self.add_cpu_pin("GPIO{}".format(i)) - for i in range(NUM_EXT_GPIOS): - self.add_cpu_pin("EXT_GPIO{}".format(i)) - # Provided by pico-sdk. def cpu_table_size(self): return "NUM_BANK0_GPIOS" @@ -128,6 +122,31 @@ def print_source(self, out_source): super().print_source(out_source) self.print_cpu_locals_dict(out_source) + def extra_args(self, parser): + parser.add_argument("--num-gpios", type=int) + parser.add_argument("--num-ext-gpios", type=int) + + def load_inputs(self, out_source): + global NUM_GPIOS + global NUM_EXT_GPIOS + + # Needed by validate_cpu_pin_name + NUM_GPIOS = self.args.num_gpios + NUM_EXT_GPIOS = self.args.num_ext_gpios + + if NUM_GPIOS is None: + raise boardgen.PinGeneratorError("Please pass num-gpios") + + if NUM_EXT_GPIOS is None: + NUM_EXT_GPIOS = 0 + # Pre-define the pins (i.e. don't require them to be listed in pins.csv). + for i in range(NUM_GPIOS): + self.add_cpu_pin("GPIO{}".format(i)) + for i in range(NUM_EXT_GPIOS): + self.add_cpu_pin("EXT_GPIO{}".format(i)) + + super().load_inputs(out_source) + if __name__ == "__main__": Rp2PinGenerator().main()