From 9b8e00c7fa895888580bb8eb05b85d780b6a9b6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Tue, 14 Nov 2023 22:34:07 +0100 Subject: [PATCH] [boards] Support and validate MCU name aliases --- .github/workflows/push-master.yml | 2 +- boards/t102-v1.1.json | 3 +- boards/t112-v1.1.json | 3 +- docs/scripts/write_boards.py | 67 ++++++++++++++++++++++++------- 4 files changed, 57 insertions(+), 18 deletions(-) diff --git a/.github/workflows/push-master.yml b/.github/workflows/push-master.yml index a887ba4a1..f7fc1f768 100644 --- a/.github/workflows/push-master.yml +++ b/.github/workflows/push-master.yml @@ -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: | diff --git a/boards/t102-v1.1.json b/boards/t102-v1.1.json index b18d55c61..7bb0daf51 100644 --- a/boards/t102-v1.1.json +++ b/boards/t102-v1.1.json @@ -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" diff --git a/boards/t112-v1.1.json b/boards/t112-v1.1.json index 548be1dd3..2d43fe4dd 100644 --- a/boards/t112-v1.1.json +++ b/boards/t112-v1.1.json @@ -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" diff --git a/docs/scripts/write_boards.py b/docs/scripts/write_boards.py index 27f25297c..e40833308 100644 --- a/docs/scripts/write_boards.py +++ b/docs/scripts/write_boards.py @@ -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 @@ -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 @@ -315,7 +343,8 @@ 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 @@ -323,8 +352,8 @@ def write_boards_list(boards: list[Board]): 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 @@ -332,14 +361,19 @@ def write_boards_list(boards: list[Board]): # 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 @@ -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 @@ -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 @@ -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