Skip to content

Commit 4af09de

Browse files
peterharperukdpgeorge
authored andcommitted
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 <damien@micropython.org>
1 parent e6093c0 commit 4af09de

2 files changed

Lines changed: 36 additions & 9 deletions

File tree

ports/rp2/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,14 @@ set(GEN_PINS_MKPINS "${MICROPY_PORT_DIR}/boards/make-pins.py")
588588
set(GEN_PINS_SRC "${CMAKE_BINARY_DIR}/pins_${MICROPY_BOARD}.c")
589589
set(GEN_PINS_HDR "${MICROPY_GENHDR_DIR}/pins.h")
590590
591+
if(NOT PICO_NUM_GPIOS)
592+
set(PICO_NUM_GPIOS 30)
593+
endif()
594+
595+
if(NOT PICO_NUM_EXT_GPIOS)
596+
set(PICO_NUM_EXT_GPIOS 10)
597+
endif()
598+
591599
if(EXISTS "${MICROPY_BOARD_DIR}/pins.csv")
592600
set(GEN_PINS_BOARD_CSV "${MICROPY_BOARD_DIR}/pins.csv")
593601
set(GEN_PINS_CSV_ARG --board-csv "${GEN_PINS_BOARD_CSV}")
@@ -600,7 +608,7 @@ target_sources(${MICROPY_TARGET} PRIVATE
600608
# Generate pins
601609
add_custom_command(
602610
OUTPUT ${GEN_PINS_HDR} ${GEN_PINS_SRC}
603-
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}
611+
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}
604612
DEPENDS
605613
${GEN_PINS_AF_CSV}
606614
${GEN_PINS_BOARD_CSV}

ports/rp2/boards/make-pins.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
import boardgen
1010

1111
# This is NUM_BANK0_GPIOS. Pin indices are 0 to 29 (inclusive).
12-
NUM_GPIOS = 48
12+
NUM_GPIOS = None
1313
# Up to 32 additional extended pins (e.g. via the wifi chip or io expanders).
14-
NUM_EXT_GPIOS = 32
14+
NUM_EXT_GPIOS = None
1515

1616

1717
class Rp2Pin(boardgen.Pin):
@@ -108,12 +108,6 @@ def __init__(self):
108108
enable_af=True,
109109
)
110110

111-
# Pre-define the pins (i.e. don't require them to be listed in pins.csv).
112-
for i in range(NUM_GPIOS):
113-
self.add_cpu_pin("GPIO{}".format(i))
114-
for i in range(NUM_EXT_GPIOS):
115-
self.add_cpu_pin("EXT_GPIO{}".format(i))
116-
117111
# Provided by pico-sdk.
118112
def cpu_table_size(self):
119113
return "NUM_BANK0_GPIOS"
@@ -128,6 +122,31 @@ def print_source(self, out_source):
128122
super().print_source(out_source)
129123
self.print_cpu_locals_dict(out_source)
130124

125+
def extra_args(self, parser):
126+
parser.add_argument("--num-gpios", type=int)
127+
parser.add_argument("--num-ext-gpios", type=int)
128+
129+
def load_inputs(self, out_source):
130+
global NUM_GPIOS
131+
global NUM_EXT_GPIOS
132+
133+
# Needed by validate_cpu_pin_name
134+
NUM_GPIOS = self.args.num_gpios
135+
NUM_EXT_GPIOS = self.args.num_ext_gpios
136+
137+
if NUM_GPIOS is None:
138+
raise boardgen.PinGeneratorError("Please pass num-gpios")
139+
140+
if NUM_EXT_GPIOS is None:
141+
NUM_EXT_GPIOS = 0
142+
# Pre-define the pins (i.e. don't require them to be listed in pins.csv).
143+
for i in range(NUM_GPIOS):
144+
self.add_cpu_pin("GPIO{}".format(i))
145+
for i in range(NUM_EXT_GPIOS):
146+
self.add_cpu_pin("EXT_GPIO{}".format(i))
147+
148+
super().load_inputs(out_source)
149+
131150

132151
if __name__ == "__main__":
133152
Rp2PinGenerator().main()

0 commit comments

Comments
 (0)