mirror of
https://github.com/micropython/micropython.git
synced 2025-12-16 01:40:14 +01:00
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:
committed by
Damien George
parent
e6093c0fbd
commit
4af09de19c
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user