@@ -72,6 +72,9 @@ def ptr(self):
7272 return self .func
7373 return '{:s}{:d}' .format (self .func , self .fn_num )
7474
75+ def mux_name (self ):
76+ return 'AF{:d}_{:s}' .format (self .idx , self .ptr ())
77+
7578 def print (self ):
7679 """Prints the C representation of this AF."""
7780 if self .supported :
@@ -84,6 +87,9 @@ def print(self):
8487 print ('({:2d}, {:8s}, {:2d}, {:10s}, {:8s}), // {:s}' .format (self .idx ,
8588 self .func , fn_num , self .pin_type , self .ptr (), self .af_str ))
8689
90+ def qstr_list (self ):
91+ return [self .mux_name ()]
92+
8793
8894class Pin (object ):
8995 """Holds the information associated with a pin."""
@@ -170,6 +176,14 @@ def print_header(self, hdr_file):
170176 hdr_file .write ('extern const pin_af_obj_t pin_{:s}_af[];\n ' .
171177 format (self .cpu_pin_name ()))
172178
179+ def qstr_list (self ):
180+ result = []
181+ for alt_fn in self .alt_fn :
182+ if alt_fn .is_supported ():
183+ result += alt_fn .qstr_list ()
184+ return result
185+
186+
173187class NamedPin (object ):
174188
175189 def __init__ (self , name , pin ):
@@ -225,13 +239,13 @@ def parse_board_file(self, filename):
225239 self .board_pins .append (NamedPin (row [0 ], pin ))
226240
227241 def print_named (self , label , named_pins ):
228- print ('const pin_named_pin_t pin_{:s}_pins [] = {{' .format (label ))
242+ print ('STATIC const mp_map_elem_t pin_{:s}_pins_locals_dict_table [] = {{' .format (label ))
229243 for named_pin in named_pins :
230244 pin = named_pin .pin ()
231245 if pin .is_board_pin ():
232- print (' {{ "{:s}", &pin_{:s} }},' .format (named_pin .name (), pin .cpu_pin_name ()))
233- print (' { NULL, NULL }' )
246+ print (' {{ MP_OBJ_NEW_QSTR(MP_QSTR_{:s}), (mp_obj_t)&pin_{:s} }},' .format (named_pin .name (), pin .cpu_pin_name ()))
234247 print ('};' )
248+ print ('MP_DEFINE_CONST_DICT(pin_{:s}_pins_locals_dict, pin_{:s}_pins_locals_dict_table);' .format (label , label ));
235249
236250 def print (self ):
237251 for named_pin in self .cpu_pins :
@@ -269,6 +283,38 @@ def print_header(self, hdr_filename):
269283 hdr_file .write ('extern const pin_obj_t * const pin_adc2[];\n ' )
270284 hdr_file .write ('extern const pin_obj_t * const pin_adc3[];\n ' )
271285
286+ def print_qstr (self , qstr_filename ):
287+ with open (qstr_filename , 'wt' ) as qstr_file :
288+ qstr_set = set ([])
289+ for named_pin in self .cpu_pins :
290+ pin = named_pin .pin ()
291+ if pin .is_board_pin ():
292+ qstr_set |= set (pin .qstr_list ())
293+ qstr_set |= set ([named_pin .name ()])
294+ for named_pin in self .board_pins :
295+ qstr_set |= set ([named_pin .name ()])
296+ for qstr in sorted (qstr_set ):
297+ print ('Q({})' .format (qstr ), file = qstr_file )
298+
299+ def print_af_hdr (self , af_const_filename ):
300+ with open (af_const_filename , 'wt' ) as af_const_file :
301+ af_hdr_set = set ([])
302+ mux_name_width = 0
303+ for named_pin in self .cpu_pins :
304+ pin = named_pin .pin ()
305+ if pin .is_board_pin ():
306+ for af in pin .alt_fn :
307+ if af .is_supported ():
308+ mux_name = af .mux_name ()
309+ af_hdr_set |= set ([mux_name ])
310+ if len (mux_name ) > mux_name_width :
311+ mux_name_width = len (mux_name )
312+ for mux_name in sorted (af_hdr_set ):
313+ key = 'MP_OBJ_NEW_QSTR(MP_QSTR_{}),' .format (mux_name )
314+ val = 'MP_OBJ_NEW_SMALL_INT(GPIO_{})' .format (mux_name )
315+ print (' { %-*s %s },' % (mux_name_width + 26 , key , val ),
316+ file = af_const_file )
317+
272318
273319def main ():
274320 parser = argparse .ArgumentParser (
@@ -280,7 +326,13 @@ def main():
280326 "-a" , "--af" ,
281327 dest = "af_filename" ,
282328 help = "Specifies the alternate function file for the chip" ,
283- default = "stm32f4xx-af.csv"
329+ default = "stm32f4xx_af.csv"
330+ )
331+ parser .add_argument (
332+ "--af-const" ,
333+ dest = "af_const_filename" ,
334+ help = "Specifies header file for alternate function constants." ,
335+ default = "build/pins_af_const.h"
284336 )
285337 parser .add_argument (
286338 "-b" , "--board" ,
@@ -291,7 +343,13 @@ def main():
291343 "-p" , "--prefix" ,
292344 dest = "prefix_filename" ,
293345 help = "Specifies beginning portion of generated pins file" ,
294- default = "stm32f4xx-prefix.c"
346+ default = "stm32f4xx_prefix.c"
347+ )
348+ parser .add_argument (
349+ "-q" , "--qstr" ,
350+ dest = "qstr_filename" ,
351+ help = "Specifies name of generated qstr header file" ,
352+ default = "build/pins_qstr.h"
295353 )
296354 parser .add_argument (
297355 "-r" , "--hdr" ,
@@ -323,6 +381,8 @@ def main():
323381 pins .print_adc (2 )
324382 pins .print_adc (3 )
325383 pins .print_header (args .hdr_filename )
384+ pins .print_qstr (args .qstr_filename )
385+ pins .print_af_hdr (args .af_const_filename )
326386
327387
328388if __name__ == "__main__" :
0 commit comments