7
7
import sys
8
8
import csv
9
9
10
+ # Must have matching entries in AF_FN_* enum in ..\pin_defs_stm32.h
10
11
SUPPORTED_FN = {
11
12
'TIM' : ['CH1' , 'CH2' , 'CH3' , 'CH4' ,
12
13
'CH1N' , 'CH2N' , 'CH3N' , 'CH1_ETR' , 'ETR' , 'BKIN' ],
@@ -291,7 +292,7 @@ def print_named(self, label, named_pins):
291
292
if pin .is_board_pin ():
292
293
print (' {{ MP_ROM_QSTR(MP_QSTR_{:s}), MP_ROM_PTR(&pin_{:s}_obj) }},' .format (named_pin .name (), pin .cpu_pin_name ()))
293
294
print ('};' )
294
- print ('MP_DEFINE_CONST_DICT(pin_{:s}_pins_locals_dict, pin_{:s}_pins_locals_dict_table);' .format (label , label ));
295
+ print ('MP_DEFINE_CONST_DICT(pin_{:s}_pins_locals_dict, pin_{:s}_pins_locals_dict_table);' .format (label , label ))
295
296
296
297
def print (self ):
297
298
for named_pin in self .cpu_pins :
@@ -303,7 +304,7 @@ def print(self):
303
304
self .print_named ('board' , self .board_pins )
304
305
305
306
def print_adc (self , adc_num ):
306
- print ('' );
307
+ print ('' )
307
308
print ('const pin_obj_t * const pin_adc{:d}[] = {{' .format (adc_num ))
308
309
for channel in range (17 ):
309
310
if channel == 16 :
@@ -378,9 +379,31 @@ def print_af_hdr(self, af_const_filename):
378
379
file = af_const_file )
379
380
print_conditional_endif (cond_var , file = af_const_file )
380
381
382
+ def print_af_defs (self , af_defs_filename ):
383
+ with open (af_defs_filename , 'wt' ) as af_defs_file :
384
+
385
+ STATIC_AF_TOKENS = {}
386
+ for named_pin in self .board_pins :
387
+ for af in named_pin .pin ().alt_fn :
388
+ func = "%s%d" % (af .func , af .fn_num ) if af .fn_num else af .func
389
+ pin_type = (af .pin_type or "NULL" ).split ('(' )[0 ]
390
+ tok = "#define STATIC_AF_%s_%s(pin_obj) ( \\ " % (func , pin_type )
391
+ if tok not in STATIC_AF_TOKENS :
392
+ STATIC_AF_TOKENS [tok ] = []
393
+ STATIC_AF_TOKENS [tok ].append (
394
+ ' ((strcmp( #pin_obj , "(&pin_%s_obj)") & strcmp( #pin_obj , "((&pin_%s_obj))")) == 0) ? (%d) : \\ ' % (
395
+ named_pin .pin ().cpu_pin_name (), named_pin .pin ().cpu_pin_name (), af .idx
396
+ )
397
+ )
398
+
399
+ for tok , pins in STATIC_AF_TOKENS .items ():
400
+ print (tok , file = af_defs_file )
401
+ print ("\n " .join (sorted (pins )), file = af_defs_file )
402
+ print (" (0xffffffffffffffffULL))\n " , file = af_defs_file )
403
+
381
404
def print_af_py (self , af_py_filename ):
382
405
with open (af_py_filename , 'wt' ) as af_py_file :
383
- print ('PINS_AF = (' , file = af_py_file );
406
+ print ('PINS_AF = (' , file = af_py_file )
384
407
for named_pin in self .board_pins :
385
408
print (" ('%s', " % named_pin .name (), end = '' , file = af_py_file )
386
409
for af in named_pin .pin ().alt_fn :
@@ -414,6 +437,12 @@ def main():
414
437
help = "Specifies the filename for the python alternate function mappings." ,
415
438
default = "build/pins_af.py"
416
439
)
440
+ parser .add_argument (
441
+ "--af-defs" ,
442
+ dest = "af_defs_filename" ,
443
+ help = "Specifies the filename for the alternate function defines." ,
444
+ default = "build/pins_af_defs.h"
445
+ )
417
446
parser .add_argument (
418
447
"-b" , "--board" ,
419
448
dest = "board_filename" ,
@@ -464,6 +493,7 @@ def main():
464
493
pins .print_qstr (args .qstr_filename )
465
494
pins .print_af_hdr (args .af_const_filename )
466
495
pins .print_af_py (args .af_py_filename )
496
+ pins .print_af_defs (args .af_defs_filename )
467
497
468
498
469
499
if __name__ == "__main__" :
0 commit comments