Skip to content

Commit

Permalink
[boards] Support and validate MCU name aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba2k2 committed Nov 14, 2023
1 parent b97825d commit 9b8e00c
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/push-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
python-version: '3.10'

- name: Install docs dependencies
run: pip install -U ltchiptool boardgen
run: pip install -U ltchiptool "boardgen>=0.11.0"

- name: Generate docs and static JSON files
run: |
Expand Down
3 changes: 2 additions & 1 deletion boards/t102-v1.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"url": "https://docs.libretiny.eu/boards/t102-v1.1/",
"vendor": "Unknown",
"doc": {
"fccid": "2AU7O-T102V11"
"fccid": "2AU7O-T102V11",
"mcu": "w302"
},
"pcb": {
"symbol": "T102_V1.1"
Expand Down
3 changes: 2 additions & 1 deletion boards/t112-v1.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"url": "https://docs.libretiny.eu/boards/t112-v1.1/",
"vendor": "Unknown",
"doc": {
"fccid": "2AU7O-T102V11"
"fccid": "2AU7O-T102V11",
"mcu": "w302"
},
"pcb": {
"symbol": "T112_V1.1"
Expand Down
67 changes: 52 additions & 15 deletions docs/scripts/write_boards.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Copyright (c) Kuba Szczodrzyński 2022-05-31.

import os
import sys

while os.getcwd() in sys.path:
sys.path.remove(os.getcwd())

import re
from os.path import dirname, isfile, join

Expand Down Expand Up @@ -48,19 +54,41 @@ def get_families_json() -> dict[str, int]:
}


def get_mcus_boards(boards: list[Board]) -> dict[str, str]:
def get_mcus_boards(boards: list[Board], aliases: dict[str, str]) -> dict[str, str]:
out = {}
for board in boards:
mcu_name: str = board["build.mcu"].upper()
family_name: str = board.family.short_name

def check_mcu(mcu_name, family_name):
if mcu_name in out and out[mcu_name] != family_name:
print(
Fore.RED
+ f"ERROR: MCU '{mcu_name}' of board '{board.name}' belongs to multiple families: '{out[mcu_name]}' and '{family_name}'"
+ Style.RESET_ALL
+ Style.RESET_ALL,
file=sys.stderr,
)
continue
out[mcu_name] = family_name

for board in boards:
mcu_name: str = board["build.mcu"].upper()
mcu_alias: str = board["doc.mcu"]
family_name: str = board.family.short_name
check_mcu(mcu_name, family_name)
if mcu_alias:
mcu_alias = mcu_alias.upper()
check_mcu(mcu_alias, family_name)
if mcu_alias not in aliases:
print(
Fore.RED
+ f"ERROR: MCU alias '{mcu_alias}' of board '{board.name}' is not defined in enum"
+ Style.RESET_ALL,
file=sys.stderr,
)
elif aliases[mcu_alias] != mcu_name:
print(
Fore.RED
+ f"ERROR: MCU alias '{mcu_alias}' of board '{board.name}' doesn't match real name '{mcu_name}'"
+ Style.RESET_ALL,
file=sys.stderr,
)
return out


Expand Down Expand Up @@ -315,31 +343,37 @@ def write_boards_list(boards: list[Board]):
print(
Fore.RED
+ f"ERROR: Invalid build.variant of '{board['source']}': '{board.name}'"
+ Style.RESET_ALL
+ Style.RESET_ALL,
file=sys.stderr,
)
errors = True

families_json = get_families_json()
families_enum = get_families_enum(code)
families_json_keys = set(families_json.keys())
families_enum_keys = set(families_enum.keys())
mcus_boards = get_mcus_boards(boards)
mcus_enum, mcu_aliases = get_mcus_enum(code)
mcus_boards = get_mcus_boards(boards, mcu_aliases)
mcus_boards_keys = set(mcus_boards.keys())
mcus_enum_keys = set(mcus_enum.keys())
mcus_missing_in_boards = mcus_enum_keys - mcus_boards_keys
mcus_missing_in_enum = mcus_boards_keys - mcus_enum_keys

# check if all families are defined in lt_types.h and families.json
if families_json_keys != families_enum_keys:
print(Fore.RED + f"ERROR: Inconsistent lt_types.h vs families.json:")
print(
"- Missing in JSON: " + ", ".join(families_enum_keys - families_json_keys)
Fore.RED + f"ERROR: Inconsistent lt_types.h vs families.json:",
file=sys.stderr,
)
print(
"- Missing in enum: " + ", ".join(families_json_keys - families_enum_keys)
"- Missing in JSON: " + ", ".join(families_enum_keys - families_json_keys),
file=sys.stderr,
)
print(Style.RESET_ALL, end="")
print(
"- Missing in enum: " + ", ".join(families_json_keys - families_enum_keys),
file=sys.stderr,
)
print(Style.RESET_ALL, end="", file=sys.stderr)
errors = True

# verify that family IDs match
Expand All @@ -352,7 +386,8 @@ def write_boards_list(boards: list[Board]):
print(
Fore.RED
+ f"ERROR: Family ID mismatch for '{family}': 0x{families_json[family]:08X} vs 0x{families_enum[family]:08X}"
+ Style.RESET_ALL
+ Style.RESET_ALL,
file=sys.stderr,
)
errors = True

Expand All @@ -371,7 +406,8 @@ def write_boards_list(boards: list[Board]):
Fore.RED
+ f"ERROR: Undefined MCUs in lt_types.h: "
+ ", ".join(mcus_missing_in_enum)
+ Style.RESET_ALL
+ Style.RESET_ALL,
file=sys.stderr,
)
errors = True

Expand All @@ -385,7 +421,8 @@ def write_boards_list(boards: list[Board]):
print(
Fore.RED
+ f"ERROR: MCU family mismatch for '{mcu}': '{mcus_boards[mcu]}' vs '{mcus_enum[mcu]}'"
+ Style.RESET_ALL
+ Style.RESET_ALL,
file=sys.stderr,
)
errors = True

Expand Down

0 comments on commit 9b8e00c

Please sign in to comment.