Files
tactility/Buildscripts/DevicetreeCompiler/source/binding_parser.py
T
Ken Van Hoeylandt 599fa46766 Driver improvements (#535)
- New drivers:
  - SD SPI
  - spi_peripheral
  - touch_placeholder
  - display_placeholder
- Devicetree compiler:
  - Implement phandle-arrays
  - Implement device addresses
- Add placeholder drivers to all devices with a SPI display
- SPI driver: add `cs-pins` and set them to high on driver start
- FileSystem: add `file_system_set_owner()` and `file_system_get_owner()`
- File locking is now checking if the related `FileSystem` is part of a shared SPI bus
- Add `device_get_child_count()`
- SDMMC driver: Remove default of `slot` value
- Fix for Crowpanel Basic 3.5" display (add delay to booting)
- Fix for LilyGO T-HMI SD card mounting (delayed mounting by disabling it initially in the dts)
2026-06-27 17:32:05 +02:00

60 lines
2.1 KiB
Python

import yaml
import os
from .models import Binding, BindingProperty
def parse_binding(file_path: str, binding_dirs: list[str]) -> Binding:
with open(file_path, 'r') as f:
data = yaml.safe_load(f)
description = data.get('description', '')
bus = data.get('bus', None)
properties_dict = {}
# Handle inclusions
includes = data.get('include', [])
all_includes = list(includes) # Copy for iteration
for include_file in includes:
include_path = None
for binding_dir in binding_dirs:
potential_path = os.path.join(binding_dir, include_file)
if os.path.exists(potential_path):
include_path = potential_path
break
if not include_path:
print(f"Warning: Could not find include file {include_file}")
continue
parent_binding = parse_binding(include_path, binding_dirs)
if not description and parent_binding.description:
description = parent_binding.description
if not bus and parent_binding.bus:
bus = parent_binding.bus
for prop in parent_binding.properties:
properties_dict[prop.name] = prop
for include in parent_binding.includes:
all_includes.append(include)
# Parse local properties
compatible = data.get('compatible', None)
properties_raw = data.get('properties', {})
for name, details in properties_raw.items():
prop = BindingProperty(
name=name,
type=details.get('type', 'unknown'),
required=details.get('required', False),
description=details.get('description', '').strip(),
default=details.get('default', None),
element_type=details.get('element-type', None),
)
properties_dict[name] = prop
filename = os.path.basename(file_path)
return Binding(
filename=filename,
compatible=compatible,
description=description.strip(),
properties=list(properties_dict.values()),
includes=all_includes,
bus=bus
)