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>
This commit is contained in:
parent
e6093c0fbd
commit
4af09de19c
@ -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_SRC "${CMAKE_BINARY_DIR}/pins_${MICROPY_BOARD}.c")
|
||||||
set(GEN_PINS_HDR "${MICROPY_GENHDR_DIR}/pins.h")
|
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")
|
if(EXISTS "${MICROPY_BOARD_DIR}/pins.csv")
|
||||||
set(GEN_PINS_BOARD_CSV "${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}")
|
set(GEN_PINS_CSV_ARG --board-csv "${GEN_PINS_BOARD_CSV}")
|
||||||
@ -600,7 +608,7 @@ target_sources(${MICROPY_TARGET} PRIVATE
|
|||||||
# Generate pins
|
# Generate pins
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${GEN_PINS_HDR} ${GEN_PINS_SRC}
|
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
|
DEPENDS
|
||||||
${GEN_PINS_AF_CSV}
|
${GEN_PINS_AF_CSV}
|
||||||
${GEN_PINS_BOARD_CSV}
|
${GEN_PINS_BOARD_CSV}
|
||||||
|
|||||||
@ -9,9 +9,9 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../../tools"))
|
|||||||
import boardgen
|
import boardgen
|
||||||
|
|
||||||
# This is NUM_BANK0_GPIOS. Pin indices are 0 to 29 (inclusive).
|
# 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).
|
# 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):
|
class Rp2Pin(boardgen.Pin):
|
||||||
@ -108,12 +108,6 @@ class Rp2PinGenerator(boardgen.NumericPinGenerator):
|
|||||||
enable_af=True,
|
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.
|
# Provided by pico-sdk.
|
||||||
def cpu_table_size(self):
|
def cpu_table_size(self):
|
||||||
return "NUM_BANK0_GPIOS"
|
return "NUM_BANK0_GPIOS"
|
||||||
@ -128,6 +122,31 @@ class Rp2PinGenerator(boardgen.NumericPinGenerator):
|
|||||||
super().print_source(out_source)
|
super().print_source(out_source)
|
||||||
self.print_cpu_locals_dict(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__":
|
if __name__ == "__main__":
|
||||||
Rp2PinGenerator().main()
|
Rp2PinGenerator().main()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user