mirror of
https://github.com/TinyTapeout/tt-support-tools.git
synced 2026-11-03 04:36:09 +01:00
feat(tt_tool): improve "pinout" section validation
- Verify that the user filled the pinout (at least one pin description) - Disallow unrecognized keys
This commit is contained in:
+19
-8
@@ -11,23 +11,34 @@ class ProjectYamlError(Exception):
|
|||||||
|
|
||||||
class PinoutSection:
|
class PinoutSection:
|
||||||
def __init__(self, yaml_data: Dict[str, Any]):
|
def __init__(self, yaml_data: Dict[str, Any]):
|
||||||
|
self.__nonEmptyPins = 0
|
||||||
|
yaml_data = yaml_data.copy()
|
||||||
self.ui = self._pins(yaml_data, "ui", 8)
|
self.ui = self._pins(yaml_data, "ui", 8)
|
||||||
self.uo = self._pins(yaml_data, "uo", 8)
|
self.uo = self._pins(yaml_data, "uo", 8)
|
||||||
self.uio = self._pins(yaml_data, "uio", 8)
|
self.uio = self._pins(yaml_data, "uio", 8)
|
||||||
self.ua: List[str] = []
|
self.ua: List[str] = self._pins(yaml_data, "ua", 8, True)
|
||||||
for i in range(8):
|
if self.__nonEmptyPins == 0:
|
||||||
pin = yaml_data.get(f"ua[{i}]")
|
raise ProjectYamlError("Please fill in the 'pinout' section")
|
||||||
if pin is None:
|
if len(yaml_data) > 0:
|
||||||
break
|
raise ProjectYamlError(
|
||||||
self.ua.append(pin)
|
f"Invalid keys {list(yaml_data.keys())} in 'pinout' section. Please remove them."
|
||||||
|
)
|
||||||
|
|
||||||
def _pins(self, yaml_data: Dict[str, Any], name: str, count: int) -> List[str]:
|
def _pins(
|
||||||
|
self, yaml_data: Dict[str, Any], name: str, count: int, optional: bool = False
|
||||||
|
) -> List[str]:
|
||||||
result: List[str] = []
|
result: List[str] = []
|
||||||
for i in range(count):
|
for i in range(count):
|
||||||
pin = yaml_data.get(f"{name}[{i}]")
|
key = f"{name}[{i}]"
|
||||||
|
pin = yaml_data.get(key)
|
||||||
if pin is None:
|
if pin is None:
|
||||||
|
if optional:
|
||||||
|
break
|
||||||
raise ProjectYamlError(f"Missing '{name}[{i}]' in 'pinout' section")
|
raise ProjectYamlError(f"Missing '{name}[{i}]' in 'pinout' section")
|
||||||
|
if pin != "":
|
||||||
|
self.__nonEmptyPins += 1
|
||||||
result.append(pin)
|
result.append(pin)
|
||||||
|
del yaml_data[key]
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user