Skip to content

Commit 3203e95

Browse files
committed
tools/boardgen.py: Provide macro defns for number of cpu/board pins.
So a port can use them if needed to exclude the Pin.cpu/Pin.board objects. Signed-off-by: Damien George <[email protected]>
1 parent 1c2cdf9 commit 3203e95

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tools/boardgen.py

+22
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ def __init__(self, pin_type, enable_af=False):
172172
self._pins = []
173173
self._pin_type = pin_type
174174
self._enable_af = enable_af
175+
self._pin_cpu_num_entries = 0
176+
self._pin_board_num_entries = 0
175177

176178
# Allows a port to define a known cpu pin (without relying on it being in the
177179
# csv file).
@@ -298,6 +300,9 @@ def print_board_locals_dict(self, out_source):
298300
# Don't include hidden pins in Pins.board.
299301
continue
300302

303+
# Keep track of the total number of Pin.board entries.
304+
self._pin_board_num_entries += 1
305+
301306
# We don't use the enable macro for board pins, because they
302307
# shouldn't be referenced in pins.csv unless they're
303308
# available.
@@ -322,6 +327,9 @@ def print_cpu_locals_dict(self, out_source):
322327
file=out_source,
323328
)
324329
for pin in self.available_pins(exclude_hidden=True):
330+
# Keep track of the total number of Pin.cpu entries.
331+
self._pin_cpu_num_entries += 1
332+
325333
m = pin.enable_macro()
326334
if m:
327335
print(" #if {}".format(m), file=out_source)
@@ -351,6 +359,20 @@ def board_name_define_prefix(self):
351359

352360
# Print the pin_CPUNAME and pin_BOARDNAME macros.
353361
def print_defines(self, out_header, cpu=True, board=True):
362+
# Provide #defines for the number of cpu and board pins.
363+
print(
364+
"#define MICROPY_PY_MACHINE_PIN_CPU_NUM_ENTRIES ({})".format(
365+
self._pin_cpu_num_entries
366+
),
367+
file=out_header,
368+
)
369+
print(
370+
"#define MICROPY_PY_MACHINE_PIN_BOARD_NUM_ENTRIES ({})".format(
371+
self._pin_board_num_entries
372+
),
373+
file=out_header,
374+
)
375+
354376
# Provide #defines for each cpu pin.
355377
for pin in self.available_pins():
356378
print(file=out_header)

0 commit comments

Comments
 (0)