@@ -172,6 +172,8 @@ def __init__(self, pin_type, enable_af=False):
172
172
self ._pins = []
173
173
self ._pin_type = pin_type
174
174
self ._enable_af = enable_af
175
+ self ._pin_cpu_num_entries = 0
176
+ self ._pin_board_num_entries = 0
175
177
176
178
# Allows a port to define a known cpu pin (without relying on it being in the
177
179
# csv file).
@@ -298,6 +300,9 @@ def print_board_locals_dict(self, out_source):
298
300
# Don't include hidden pins in Pins.board.
299
301
continue
300
302
303
+ # Keep track of the total number of Pin.board entries.
304
+ self ._pin_board_num_entries += 1
305
+
301
306
# We don't use the enable macro for board pins, because they
302
307
# shouldn't be referenced in pins.csv unless they're
303
308
# available.
@@ -322,6 +327,9 @@ def print_cpu_locals_dict(self, out_source):
322
327
file = out_source ,
323
328
)
324
329
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
+
325
333
m = pin .enable_macro ()
326
334
if m :
327
335
print (" #if {}" .format (m ), file = out_source )
@@ -351,6 +359,20 @@ def board_name_define_prefix(self):
351
359
352
360
# Print the pin_CPUNAME and pin_BOARDNAME macros.
353
361
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
+
354
376
# Provide #defines for each cpu pin.
355
377
for pin in self .available_pins ():
356
378
print (file = out_header )
0 commit comments