@@ -27,6 +27,7 @@ def get_board_pins(pin_filename):
27
27
continue
28
28
29
29
board_member = search .group (1 )
30
+ extra_typing = None
30
31
31
32
board_type_search = re .search (r"MP_ROM_PTR\(&pin_(.*?)\)" , line )
32
33
if board_type_search :
@@ -38,8 +39,18 @@ def get_board_pins(pin_filename):
38
39
board_type_search = re .search (
39
40
r"MP_ROM_PTR\(&(.*?)\[0\].[display|epaper_display]" , line
40
41
)
42
+
43
+ if board_type_search is None :
44
+ board_type_search = re .search (r"MP_ROM_PTR\(&(.*?)_tuple" , line )
45
+ if board_type_search is not None :
46
+ extra_typing = "Tuple[Any]"
47
+ if board_type_search is None :
48
+ board_type_search = re .search (r"MP_ROM_PTR\(&(.*?)_dict" , line )
49
+ if board_type_search is not None :
50
+ extra_typing = "Dict[str, Any]"
51
+
41
52
if board_type_search is None :
42
- records .append (["unmapped" , None , line ])
53
+ records .append (["unmapped" , None , line , extra_typing ])
43
54
continue
44
55
45
56
board_type = board_type_search .group (1 )
@@ -56,7 +67,7 @@ def get_board_pins(pin_filename):
56
67
if extra_search :
57
68
extra = extra_search .group (1 )
58
69
59
- records .append ([board_type , board_member , extra ])
70
+ records .append ([board_type , board_member , extra , extra_typing ])
60
71
61
72
return records
62
73
@@ -69,8 +80,10 @@ def create_board_stubs(board_id, records, mappings, board_filename):
69
80
needs_busio = False
70
81
needs_displayio = False
71
82
needs_microcontroller = False
83
+ needs_dict = False
84
+ needs_tuple = False
72
85
73
- for board_type , board_member , extra in records :
86
+ for board_type , board_member , extra , extra_typing in records :
74
87
if board_type == "pin" :
75
88
needs_microcontroller = True
76
89
comment = f" # { extra } "
@@ -121,6 +134,13 @@ def create_board_stubs(board_id, records, mappings, board_filename):
121
134
member_data += f"{ board_member } : { class_name } \n "
122
135
members .append (member_data )
123
136
137
+ elif extra_typing is not None :
138
+ if "Dict" in extra_typing :
139
+ needs_dict = True
140
+ elif "Tuple" in extra_typing :
141
+ needs_tuple = True
142
+ members .append (f"{ board_member } : { extra_typing } \n " )
143
+
124
144
elif board_type == "unmapped" :
125
145
unmapped .append (extra )
126
146
@@ -152,6 +172,14 @@ def create_board_stubs(board_id, records, mappings, board_filename):
152
172
if needs_microcontroller :
153
173
boards_file .write ("import microcontroller\n " )
154
174
175
+ if needs_dict :
176
+ if needs_tuple :
177
+ boards_file .write ("from typing import Any, Dict, Tuple\n " )
178
+ else :
179
+ boards_file .write ("from typing import Any, Dict\n " )
180
+ elif needs_tuple :
181
+ boards_file .write ("from typing import Any, Tuple\n " )
182
+
155
183
boards_file .write ("\n \n " )
156
184
boards_file .write ("# Board Info:\n " )
157
185
boards_file .write ("board_id: str\n " )
@@ -200,7 +228,7 @@ def process(board_mappings, export_dir):
200
228
records = get_board_pins (pin_filename )
201
229
create_board_stubs (board_id , records , mappings , f"{ sub_dir } /__init__.pyi" )
202
230
203
- for board_type , board_member , extra in records :
231
+ for board_type , board_member , extra , extra_typing in records :
204
232
if board_type == "pin" :
205
233
total_pins += 1
206
234
elif board_type == "unmapped" :
0 commit comments