@ -10,6 +10,8 @@ import csv
table_header = """ // This file was automatically generated by make-pin-cap.py
/ /
/ / The Pin objects which are available on a board
"""
@ -45,20 +47,23 @@ class Pins:
def print_table ( self , table_filename , mcu_name ) :
with open ( table_filename , " wt " ) as table_file :
table_file . write ( table_header )
table_file . write ( " const machine_pin_obj_t pin_af_table[] = { \n " )
# Create the Pin objects
if mcu_name == " SAMD21 " :
for row in self . board_pins :
pin = " PIN_ " + row [ 0 ] . upper ( )
table_file . write ( " #ifdef " + pin + " \n " )
table_file . write ( " #ifdef " + pin + " \n " )
table_file . write ( " static const machine_pin_obj_t %s _obj = " % pin )
eic = row [ 1 ] if row [ 1 ] else " 0xff "
adc = row [ 2 ] if row [ 2 ] else " 0xff "
if pin in self . pin_names :
name = ' " %s " ' % self . pin_names [ pin ] [ 0 ]
name = " MP_QSTR_ %s " % self . pin_names [ pin ] [ 0 ]
type = self . pin_names [ pin ] [ 1 ]
else :
name = ' " - " '
name = " MP_QSTR_ "
type = " { &machine_pin_type} "
table_file . write ( " {%s , %s , %s , %s , %s " % ( type , pin , name , eic , adc ) )
table_file . write ( " { %s , %s , %s , %s , %s " % ( type , pin , name , eic , adc ) )
for cell in row [ 3 : ] :
if cell :
table_file . write (
@ -66,23 +71,24 @@ class Pins:
)
else :
table_file . write ( " , 0xff " )
table_file . write ( " }, \n " )
table_file . write ( " #endif\n " )
table_file . write ( " }; \n " )
table_file . write ( " #endif \n " )
else :
for row in self . board_pins :
pin = " PIN_ " + row [ 0 ] . upper ( )
table_file . write ( " #ifdef " + pin + " \n " )
table_file . write ( " #ifdef " + pin + " \n " )
table_file . write ( " const machine_pin_obj_t %s _obj = " % pin )
eic = row [ 1 ] if row [ 1 ] else " 0xff "
adc0 = row [ 2 ] if row [ 2 ] else " 0xff "
adc1 = row [ 3 ] if row [ 3 ] else " 0xff "
if pin in self . pin_names :
name = ' " %s " ' % self . pin_names [ pin ] [ 0 ]
name = " MP_QSTR_ %s " % self . pin_names [ pin ] [ 0 ]
type = self . pin_names [ pin ] [ 1 ]
else :
name = ' " - " '
name = " MP_QSTR_ "
type = " { &machine_pin_type} "
table_file . write (
" {%s , %s , %s , %s , %s , %s " % ( type , pin , name , eic , adc0 , adc1 )
" { %s , %s , %s , %s , %s , %s " % ( type , pin , name , eic , adc0 , adc1 )
)
for cell in row [ 4 : ] :
if cell :
@ -91,9 +97,60 @@ class Pins:
)
else :
table_file . write ( " , 0xff " )
table_file . write ( " }, \n " )
table_file . write ( " }; \n " )
table_file . write ( " #endif \n " )
# Create the Pin table
table_file . write ( " \n // The table of references to the pin objects. \n \n " )
table_file . write ( " static const machine_pin_obj_t *pin_af_table[] = { \n " )
for row in self . board_pins :
pin = " PIN_ " + row [ 0 ] . upper ( )
table_file . write ( " #ifdef " + pin + " \n " )
table_file . write ( " & %s _obj, \n " % pin )
table_file . write ( " #endif \n " )
table_file . write ( " }; \n " )
# Create the CPU pins dictionary table
table_file . write ( " \n #if MICROPY_PY_MACHINE_PIN_BOARD_CPU \n " )
table_file . write ( " \n // The cpu pins dictionary \n \n " )
table_file . write (
" STATIC const mp_rom_map_elem_t pin_cpu_pins_locals_dict_table[] = { \n "
)
for row in self . board_pins :
pin = " PIN_ " + row [ 0 ] . upper ( )
table_file . write ( " #ifdef " + pin + " \n " )
table_file . write (
" { MP_ROM_QSTR(MP_QSTR_ %s ), MP_ROM_PTR(& %s _obj) }, \n "
% ( row [ 0 ] . upper ( ) , pin )
)
table_file . write ( " #endif \n " )
table_file . write ( " }; \n " )
table_file . write (
" MP_DEFINE_CONST_DICT(machine_pin_cpu_pins_locals_dict, pin_cpu_pins_locals_dict_table); \n "
)
# Create the board pins dictionary table
table_file . write ( " \n // The board pins dictionary \n \n " )
table_file . write (
" STATIC const mp_rom_map_elem_t pin_board_pins_locals_dict_table[] = { \n "
)
for row in self . board_pins :
pin = " PIN_ " + row [ 0 ] . upper ( )
if pin in self . pin_names :
table_file . write ( " #ifdef " + pin + " \n " )
table_file . write (
" { MP_ROM_QSTR(MP_QSTR_ %s ), MP_ROM_PTR(& %s _obj) }, \n "
% ( self . pin_names [ pin ] [ 0 ] , pin )
)
table_file . write ( " #endif \n " )
table_file . write ( " }; \n " )
table_file . write (
" MP_DEFINE_CONST_DICT(machine_pin_board_pins_locals_dict, pin_board_pins_locals_dict_table); \n "
)
table_file . write ( " #endif \n " )
def main ( ) :