Skip to content

Commit

Permalink
move all the info required to support a plugin board inside `new_boar…
Browse files Browse the repository at this point in the history
…ds.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.
  • Loading branch information
umbynos committed Aug 1, 2023
1 parent b017c1e commit 43e885d
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 81 deletions.
126 changes: 50 additions & 76 deletions generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,55 +25,6 @@

DOWNLOAD_URL = "https://downloads.arduino.cc/arduino-fwuploader"


# create a different dictionary for new boards
def create_boards_dictionary(new):
boards = {
"arduino:samd:mkr1000": {"fqbn": "arduino:samd:mkr1000", "firmware": []},
"arduino:samd:mkrvidor4000": {
"fqbn": "arduino:samd:mkrvidor4000",
"firmware": [],
}
}
# the boards that support the plugin system (the ones present in the new_boards.json file)
if new:
boards = {
"arduino:renesas_uno:unor4wifi": {
"fqbn": "arduino:renesas_uno:unor4wifi",
"firmware": [],
# "uploader_plugin" and "additional_tools" need to be hard coded because
# there is no way to retrieve them dinamically
"uploader_plugin": "arduino:uno-r4-wifi-fwuploader-plugin@1.0.0",
"additional_tools": ["arduino:espflash@2.0.0", "arduino:bossac@1.9.1-arduino5"],
},
"arduino:samd:mkrwifi1010": {
"fqbn": "arduino:samd:mkrwifi1010",
"firmware": [],
"uploader_plugin": "arduino:nina-fwuploader-plugin@1.0.0",
"additional_tools": ["arduino:bossac@1.7.0-arduino3"],
},
"arduino:samd:nano_33_iot": {
"fqbn": "arduino:samd:nano_33_iot",
"firmware": [],
"uploader_plugin": "arduino:nina-fwuploader-plugin@1.0.0",
"additional_tools": ["arduino:bossac@1.7.0-arduino3"],
},
"arduino:megaavr:uno2018": {
"fqbn": "arduino:megaavr:uno2018",
"firmware": [],
"uploader_plugin": "arduino:nina-fwuploader-plugin@1.0.0",
"additional_tools": ["arduino:avrdude@6.3.0-arduino17"],
},
"arduino:mbed_nano:nanorp2040connect": {
"fqbn": "arduino:mbed_nano:nanorp2040connect",
"firmware": [],
"uploader_plugin": "arduino:nina-fwuploader-plugin@1.0.0",
"additional_tools": ["arduino:bossac@1.9.1-arduino2"],
},
}
return boards


# handle firmware name
def get_firmware_file(module, simple_fqbn, version):

Check failure on line 29 in generator/generator.py

View workflow job for this annotation

GitHub Actions / lint

expected 2 blank lines, found 1
firmware_full_path = Path(__file__).parent.parent / "firmwares" / module / version
Expand Down Expand Up @@ -270,46 +221,42 @@ def create_upload_data(fqbn, installed_cores): # noqa: C901
return upload_data


def generate_boards_json(input_data, arduino_cli_path, new_boards):
# List of old boards that need precompiled sketch data and uploader information obtained through platform.txt.
old_boards = [
"arduino:samd:mkr1000",
"arduino:samd:mkrvidor4000",
]

boards = create_boards_dictionary(new_boards)
def generate_boards_json(input_data, arduino_cli_path):
boards = {
"arduino:samd:mkr1000": {"fqbn": "arduino:samd:mkr1000", "firmware": []},
"arduino:samd:mkrvidor4000": {
"fqbn": "arduino:samd:mkrvidor4000",
"firmware": [],
}
}

# Gets the installed cores
res = arduino_cli(cli_path=arduino_cli_path, args=["core", "list", "--format", "json"])
installed_cores = {c["id"]: c for c in json.loads(res)}

# Verify all necessary cores are installed
# TODO: Should we check that the latest version is installed too?
for fqbn in old_boards:
for fqbn, data in input_data.items():
core_id = ":".join(fqbn.split(":")[:2])
if core_id not in installed_cores:
print(f"Board {fqbn} is not installed, install its core {core_id}")
sys.exit(1)

for fqbn, data in input_data.items():
simple_fqbn = fqbn.replace(":", ".")

if fqbn in old_boards:
boards[fqbn]["loader_sketch"] = create_precomp_sketch_data(simple_fqbn, "loader")
boards[fqbn]["version_sketch"] = create_precomp_sketch_data(simple_fqbn, "getversion")
boards[fqbn].update(create_upload_data(fqbn, installed_cores))
# Gets the old_board name
res = arduino_cli(
cli_path=arduino_cli_path,
args=["board", "search", fqbn, "--format", "json"],
)
for board in json.loads(res):
if board["fqbn"] == fqbn:
boards[fqbn]["name"] = board["name"]
break

else:
boards[fqbn]["name"] = data["name"]
# List of old boards that need precompiled sketch data and uploader information obtained through platform.txt.
boards[fqbn]["loader_sketch"] = create_precomp_sketch_data(simple_fqbn, "loader")
boards[fqbn]["version_sketch"] = create_precomp_sketch_data(simple_fqbn, "getversion")
boards[fqbn].update(create_upload_data(fqbn, installed_cores))
# Gets the old_board name
res = arduino_cli(
cli_path=arduino_cli_path,
args=["board", "search", fqbn, "--format", "json"],
)
for board in json.loads(res):
if board["fqbn"] == fqbn:
boards[fqbn]["name"] = board["name"]
break

for firmware_version in data["versions"]:
module = data["moduleName"]
Expand All @@ -323,6 +270,30 @@ def generate_boards_json(input_data, arduino_cli_path, new_boards):

return boards_json

def generate_new_boards_json(input_data):

Check failure on line 273 in generator/generator.py

View workflow job for this annotation

GitHub Actions / lint

expected 2 blank lines, found 1
# init the boards dict
boards = {}
for fqbn, data in input_data.items():
simple_fqbn = fqbn.replace(":", ".")

# populate the boards dict
boards[fqbn] = {}
boards[fqbn]["fqbn"] = fqbn
module = data["moduleName"]
boards[fqbn]["firmware"] = []
for firmware_version in data["versions"]:
firmware_file = get_firmware_file(module, simple_fqbn, firmware_version)
boards[fqbn]["firmware"].append(create_firmware_data(firmware_file, module, firmware_version))
boards[fqbn]["uploader_plugin"] = data["uploader_plugin"]
boards[fqbn]["additional_tools"] = data["additional_tools"]
boards[fqbn]["module"] = module
boards[fqbn]["name"] = data["name"]

boards_json = []
for _, b in boards.items():
boards_json.append(b)

return boards_json

if __name__ == "__main__":

Check failure on line 298 in generator/generator.py

View workflow job for this annotation

GitHub Actions / lint

expected 2 blank lines after class or function definition, found 1
parser = argparse.ArgumentParser(prog="generator.py")
Expand Down Expand Up @@ -353,7 +324,10 @@ def generate_boards_json(input_data, arduino_cli_path, new_boards):
with open(input_file, "r") as f:
boards = json.load(f)

boards_json = generate_boards_json(boards, args.arduino_cli, args.new)
if args.new:
boards_json = generate_new_boards_json(boards)
else:
boards_json = generate_boards_json(boards, args.arduino_cli)

Path("boards").mkdir(exist_ok=True)

Expand Down
36 changes: 31 additions & 5 deletions generator/new_boards.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
"arduino:renesas_uno:unor4wifi": {
"moduleName": "ESP32-S3",
"versions": ["0.1.0", "0.2.0", "0.2.1"],
"name": "Arduino UNO R4 WiFi"
"name": "Arduino UNO R4 WiFi",
"uploader_plugin": "arduino:uno-r4-wifi-fwuploader-plugin@1.0.0",
"additional_tools": [
"arduino:espflash@2.0.0",
"arduino:bossac@1.9.1-arduino5"
],
"module": "ESP32-S3"
},
"arduino:samd:mkrwifi1010": {
"moduleName": "NINA",
Expand All @@ -25,7 +31,12 @@
"1.4.8",
"1.5.0"
],
"name": "Arduino MKR WiFi 1010"
"name": "Arduino MKR WiFi 1010",
"uploader_plugin": "arduino:nina-fwuploader-plugin@1.0.0",
"additional_tools": [
"arduino:bossac@1.7.0-arduino3"
],
"module": "NINA"
},
"arduino:samd:nano_33_iot": {
"moduleName": "NINA",
Expand All @@ -48,7 +59,12 @@
"1.4.8",
"1.5.0"
],
"name": "Arduino NANO 33 IoT"
"name": "Arduino NANO 33 IoT",
"uploader_plugin": "arduino:nina-fwuploader-plugin@1.0.0",
"additional_tools": [
"arduino:bossac@1.7.0-arduino3"
],
"module": "NINA"
},
"arduino:megaavr:uno2018": {
"moduleName": "NINA",
Expand All @@ -69,11 +85,21 @@
"1.4.8",
"1.5.0"
],
"name": "Arduino Uno WiFi Rev2"
"name": "Arduino Uno WiFi Rev2",
"uploader_plugin": "arduino:nina-fwuploader-plugin@1.0.0",
"additional_tools": [
"arduino:avrdude@6.3.0-arduino17"
],
"module": "NINA"
},
"arduino:mbed_nano:nanorp2040connect": {
"moduleName": "NINA",
"versions": ["1.4.5", "1.4.6", "1.4.7", "1.4.8", "1.5.0"],
"name": "Arduino Nano RP2040 Connect"
"name": "Arduino Nano RP2040 Connect",
"uploader_plugin": "arduino:nina-fwuploader-plugin@1.0.0",
"additional_tools": [
"arduino:bossac@1.9.1-arduino2"
],
"module": "NINA"
}
}

0 comments on commit 43e885d

Please sign in to comment.