Skip to content

Commit

Permalink
rp2/boards/make-pins.py: Pass num-gpios/num-ext-gpios into make-pins.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
peterharperuk authored and dpgeorge committed Oct 15, 2024
1 parent e6093c0 commit 4af09de
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
10 changes: 9 additions & 1 deletion ports/rp2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -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}
Expand Down
35 changes: 27 additions & 8 deletions ports/rp2/boards/make-pins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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"
Expand All @@ -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()

0 comments on commit 4af09de

Please sign in to comment.