Skip to content

Commit 43e885d

Browse files
committed
move all the info required to support a plugin board inside new_boards.json file
This way we have to modify this file only to add support for new boards. The `generate_boards_json()` function have been split: this way we can remove the old one when the time comes.
1 parent b017c1e commit 43e885d

File tree

2 files changed

+81
-81
lines changed

2 files changed

+81
-81
lines changed

Diff for: generator/generator.py

+50-76
Original file line numberDiff line numberDiff line change
@@ -25,55 +25,6 @@
2525

2626
DOWNLOAD_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
7829
def 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

327298
if __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

Diff for: generator/new_boards.json

+31-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
"arduino:renesas_uno:unor4wifi": {
33
"moduleName": "ESP32-S3",
44
"versions": ["0.1.0", "0.2.0", "0.2.1"],
5-
"name": "Arduino UNO R4 WiFi"
5+
"name": "Arduino UNO R4 WiFi",
6+
"uploader_plugin": "arduino:[email protected]",
7+
"additional_tools": [
8+
"arduino:[email protected]",
9+
10+
],
11+
"module": "ESP32-S3"
612
},
713
"arduino:samd:mkrwifi1010": {
814
"moduleName": "NINA",
@@ -25,7 +31,12 @@
2531
"1.4.8",
2632
"1.5.0"
2733
],
28-
"name": "Arduino MKR WiFi 1010"
34+
"name": "Arduino MKR WiFi 1010",
35+
"uploader_plugin": "arduino:[email protected]",
36+
"additional_tools": [
37+
38+
],
39+
"module": "NINA"
2940
},
3041
"arduino:samd:nano_33_iot": {
3142
"moduleName": "NINA",
@@ -48,7 +59,12 @@
4859
"1.4.8",
4960
"1.5.0"
5061
],
51-
"name": "Arduino NANO 33 IoT"
62+
"name": "Arduino NANO 33 IoT",
63+
"uploader_plugin": "arduino:[email protected]",
64+
"additional_tools": [
65+
66+
],
67+
"module": "NINA"
5268
},
5369
"arduino:megaavr:uno2018": {
5470
"moduleName": "NINA",
@@ -69,11 +85,21 @@
6985
"1.4.8",
7086
"1.5.0"
7187
],
72-
"name": "Arduino Uno WiFi Rev2"
88+
"name": "Arduino Uno WiFi Rev2",
89+
"uploader_plugin": "arduino:[email protected]",
90+
"additional_tools": [
91+
92+
],
93+
"module": "NINA"
7394
},
7495
"arduino:mbed_nano:nanorp2040connect": {
7596
"moduleName": "NINA",
7697
"versions": ["1.4.5", "1.4.6", "1.4.7", "1.4.8", "1.5.0"],
77-
"name": "Arduino Nano RP2040 Connect"
98+
"name": "Arduino Nano RP2040 Connect",
99+
"uploader_plugin": "arduino:[email protected]",
100+
"additional_tools": [
101+
102+
],
103+
"module": "NINA"
78104
}
79105
}

0 commit comments

Comments
 (0)