2525
2626DOWNLOAD_URL = "https://downloads.arduino.cc/arduino-fwuploader"
2727
28-
29- # create a different dictionary for new boards
30- def create_boards_dictionary (new ):
31- boards = {
32- "arduino:samd:mkr1000" : {"fqbn" : "arduino:samd:mkr1000" , "firmware" : []},
33- "arduino:samd:mkrvidor4000" : {
34- "fqbn" : "arduino:samd:mkrvidor4000" ,
35- "firmware" : [],
36- }
37- }
38- # the boards that support the plugin system (the ones present in the new_boards.json file)
39- if new :
40- boards = {
41- "arduino:renesas_uno:unor4wifi" : {
42- "fqbn" : "arduino:renesas_uno:unor4wifi" ,
43- "firmware" : [],
44- # "uploader_plugin" and "additional_tools" need to be hard coded because
45- # there is no way to retrieve them dinamically
46- "uploader_plugin" :
"arduino:[email protected] " ,
47- "additional_tools" : [
"arduino:[email protected] " ,
"arduino:[email protected] " ],
48- },
49- "arduino:samd:mkrwifi1010" : {
50- "fqbn" : "arduino:samd:mkrwifi1010" ,
51- "firmware" : [],
52- "uploader_plugin" :
"arduino:[email protected] " ,
53- "additional_tools" : [
"arduino:[email protected] " ],
54- },
55- "arduino:samd:nano_33_iot" : {
56- "fqbn" : "arduino:samd:nano_33_iot" ,
57- "firmware" : [],
58- "uploader_plugin" :
"arduino:[email protected] " ,
59- "additional_tools" : [
"arduino:[email protected] " ],
60- },
61- "arduino:megaavr:uno2018" : {
62- "fqbn" : "arduino:megaavr:uno2018" ,
63- "firmware" : [],
64- "uploader_plugin" :
"arduino:[email protected] " ,
65- "additional_tools" : [
"arduino:[email protected] " ],
66- },
67- "arduino:mbed_nano:nanorp2040connect" : {
68- "fqbn" : "arduino:mbed_nano:nanorp2040connect" ,
69- "firmware" : [],
70- "uploader_plugin" :
"arduino:[email protected] " ,
71- "additional_tools" : [
"arduino:[email protected] " ],
72- },
73- }
74- return boards
75-
76-
7728# handle firmware name
7829def get_firmware_file (module , simple_fqbn , version ):
7930 firmware_full_path = Path (__file__ ).parent .parent / "firmwares" / module / version
@@ -270,46 +221,42 @@ def create_upload_data(fqbn, installed_cores): # noqa: C901
270221 return upload_data
271222
272223
273- def generate_boards_json (input_data , arduino_cli_path , new_boards ):
274- # List of old boards that need precompiled sketch data and uploader information obtained through platform.txt.
275- old_boards = [
276- "arduino:samd:mkr1000" ,
277- "arduino:samd:mkrvidor4000" ,
278- ]
279-
280- boards = create_boards_dictionary ( new_boards )
224+ def generate_boards_json (input_data , arduino_cli_path ):
225+ boards = {
226+ "arduino:samd:mkr1000" : { "fqbn" : "arduino:samd:mkr1000" , "firmware" : []},
227+ "arduino:samd:mkrvidor4000" : {
228+ "fqbn" : "arduino:samd:mkrvidor4000" ,
229+ "firmware" : [],
230+ }
231+ }
281232
282233 # Gets the installed cores
283234 res = arduino_cli (cli_path = arduino_cli_path , args = ["core" , "list" , "--format" , "json" ])
284235 installed_cores = {c ["id" ]: c for c in json .loads (res )}
285236
286237 # Verify all necessary cores are installed
287238 # TODO: Should we check that the latest version is installed too?
288- for fqbn in old_boards :
239+ for fqbn , data in input_data . items () :
289240 core_id = ":" .join (fqbn .split (":" )[:2 ])
290241 if core_id not in installed_cores :
291242 print (f"Board { fqbn } is not installed, install its core { core_id } " )
292243 sys .exit (1 )
293244
294- for fqbn , data in input_data .items ():
295245 simple_fqbn = fqbn .replace (":" , "." )
296246
297- if fqbn in old_boards :
298- boards [fqbn ]["loader_sketch" ] = create_precomp_sketch_data (simple_fqbn , "loader" )
299- boards [fqbn ]["version_sketch" ] = create_precomp_sketch_data (simple_fqbn , "getversion" )
300- boards [fqbn ].update (create_upload_data (fqbn , installed_cores ))
301- # Gets the old_board name
302- res = arduino_cli (
303- cli_path = arduino_cli_path ,
304- args = ["board" , "search" , fqbn , "--format" , "json" ],
305- )
306- for board in json .loads (res ):
307- if board ["fqbn" ] == fqbn :
308- boards [fqbn ]["name" ] = board ["name" ]
309- break
310-
311- else :
312- boards [fqbn ]["name" ] = data ["name" ]
247+ # List of old boards that need precompiled sketch data and uploader information obtained through platform.txt.
248+ boards [fqbn ]["loader_sketch" ] = create_precomp_sketch_data (simple_fqbn , "loader" )
249+ boards [fqbn ]["version_sketch" ] = create_precomp_sketch_data (simple_fqbn , "getversion" )
250+ boards [fqbn ].update (create_upload_data (fqbn , installed_cores ))
251+ # Gets the old_board name
252+ res = arduino_cli (
253+ cli_path = arduino_cli_path ,
254+ args = ["board" , "search" , fqbn , "--format" , "json" ],
255+ )
256+ for board in json .loads (res ):
257+ if board ["fqbn" ] == fqbn :
258+ boards [fqbn ]["name" ] = board ["name" ]
259+ break
313260
314261 for firmware_version in data ["versions" ]:
315262 module = data ["moduleName" ]
@@ -323,6 +270,30 @@ def generate_boards_json(input_data, arduino_cli_path, new_boards):
323270
324271 return boards_json
325272
273+ def generate_new_boards_json (input_data ):
274+ # init the boards dict
275+ boards = {}
276+ for fqbn , data in input_data .items ():
277+ simple_fqbn = fqbn .replace (":" , "." )
278+
279+ # populate the boards dict
280+ boards [fqbn ] = {}
281+ boards [fqbn ]["fqbn" ] = fqbn
282+ module = data ["moduleName" ]
283+ boards [fqbn ]["firmware" ] = []
284+ for firmware_version in data ["versions" ]:
285+ firmware_file = get_firmware_file (module , simple_fqbn , firmware_version )
286+ boards [fqbn ]["firmware" ].append (create_firmware_data (firmware_file , module , firmware_version ))
287+ boards [fqbn ]["uploader_plugin" ] = data ["uploader_plugin" ]
288+ boards [fqbn ]["additional_tools" ] = data ["additional_tools" ]
289+ boards [fqbn ]["module" ] = module
290+ boards [fqbn ]["name" ] = data ["name" ]
291+
292+ boards_json = []
293+ for _ , b in boards .items ():
294+ boards_json .append (b )
295+
296+ return boards_json
326297
327298if __name__ == "__main__" :
328299 parser = argparse .ArgumentParser (prog = "generator.py" )
@@ -353,7 +324,10 @@ def generate_boards_json(input_data, arduino_cli_path, new_boards):
353324 with open (input_file , "r" ) as f :
354325 boards = json .load (f )
355326
356- boards_json = generate_boards_json (boards , args .arduino_cli , args .new )
327+ if args .new :
328+ boards_json = generate_new_boards_json (boards )
329+ else :
330+ boards_json = generate_boards_json (boards , args .arduino_cli )
357331
358332 Path ("boards" ).mkdir (exist_ok = True )
359333
0 commit comments