summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/rp2/CMakeLists.txt10
-rwxr-xr-xports/rp2/boards/make-pins.py35
2 files changed, 36 insertions, 9 deletions
diff --git a/ports/rp2/CMakeLists.txt b/ports/rp2/CMakeLists.txt
index 6f6618154..0d5b10f33 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 f4ce74e5a..1da2edb7c 100755
--- a/ports/rp2/boards/make-pins.py
+++ b/ports/rp2/boards/make-pins.py
@@ -9,9 +9,9 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../../tools"))
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 @@ class Rp2PinGenerator(boardgen.NumericPinGenerator):
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 @@ class Rp2PinGenerator(boardgen.NumericPinGenerator):
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()