This commit is contained in:
Ken Van Hoeylandt 2026-01-22 09:06:20 +01:00
parent 33fbf44a68
commit 83ec8105fd
4 changed files with 21 additions and 15 deletions

View File

@ -42,8 +42,9 @@ def parse_config(file_path: str, project_root: str) -> DeviceTreeConfig:
config.dts = os.path.join(current_path, dts_path)
bindings = data.get("bindings", "")
bindings_resolved = os.path.join(current_path, bindings)
config.bindings.append(bindings_resolved)
if bindings:
bindings_resolved = os.path.join(current_path, bindings)
config.bindings.append(bindings_resolved)
_parse_recursive(file_path, True)
return config

View File

@ -31,8 +31,8 @@ def find_device_property(device: Device, name: str) -> DeviceProperty:
return property
return None
def find_binding_property(binding: Binding, name: str) -> BindingProperty:
for property in binding.properties:
def find_binding_property(device: Device, name: str) -> BindingProperty:
for property in device.properties:
if property.name == name:
return property
return None
@ -97,7 +97,7 @@ def write_config(file, device: Device, bindings: list[Binding], type_name: str):
# Indent all params
for index, config_param in enumerate(config_params):
config_params[index] = f"\t{config_param}"
# Join with comman and newline
# Join with command and newline
if len(config_params) > 0:
config_params_joined = ",\n".join(config_params)
file.write(f"{config_params_joined}\n")
@ -171,7 +171,7 @@ def generate_devicetree_c(filename: str, items: list[object], bindings: list[Bin
LOG_E(TAG, "Can't find driver: %s", compatible);
return -1;
}
device_construct(device);
device_construct(device);
device_set_driver(device, driver);
device_add(device);
const int err = device_start(device);

View File

@ -2,15 +2,19 @@ cmake_minimum_required(VERSION 3.20)
file(GLOB_RECURSE SOURCE_FILES "Source/*.c*")
if (NOT DEFINED ENV{ESP_IDF_VERSION})
set(COMPONENT_LIB FirmwareSim)
endif ()
# For Generate target below
if (DEFINED ENV{ESP_IDF_VERSION})
include("../Buildscripts/device.cmake")
init_tactility_globals("../sdkconfig")
get_property(TACTILITY_DEVICE_PROJECT GLOBAL PROPERTY TACTILITY_DEVICE_PROJECT)
else ()
set(TACTILITY_DEVICE_ID simulator)
set(COMPONENT_LIB FirmwareSim)
endif ()
set(DEVICETREE_LOCATION "${CMAKE_SOURCE_DIR}/Devices/${TACTILITY_DEVICE_ID}")
if (DEFINED ENV{ESP_IDF_VERSION})
idf_component_register(
SRCS ${SOURCE_FILES}
REQUIRES Tactility TactilityC TactilityKernel drivers-esp ${TACTILITY_DEVICE_PROJECT}
@ -28,17 +32,16 @@ else ()
PRIVATE SDL2::SDL2-static SDL2-static
)
target_include_directories(FirmwareSim PRIVATE "${CMAKE_SOURCE_DIR}/Firmware/Generated")
add_definitions(-D_Nullable=)
add_definitions(-D_Nonnull=)
endif ()
file(MAKE_DIRECTORY "${CMAKE_SOURCE_DIR}/Firmware/Generated")
# Generate devicetree code and attach to Firmware component
add_custom_command(
OUTPUT "${CMAKE_SOURCE_DIR}/Firmware/Generated/devicetree.c"
"${CMAKE_SOURCE_DIR}/Firmware/Generated/devicetree.h"
COMMAND mkdir -p "${CMAKE_SOURCE_DIR}/Firmware/Generated"
COMMAND pip install lark pyyaml
COMMAND python "${CMAKE_SOURCE_DIR}/Buildscripts/devicetree-compiler/compile.py"
"${DEVICETREE_LOCATION}" "Firmware/Generated"
@ -46,6 +49,8 @@ add_custom_command(
DEPENDS "${DEVICETREE_LOCATION}/devicetree.yaml" # Optional: trigger rebuild if source changes
COMMENT "Generating devicetree source files..."
)
set_source_files_properties("${CMAKE_SOURCE_DIR}/Firmware/Generated/devicetree.c" PROPERTIES GENERATED TRUE)
add_custom_target(Generated DEPENDS "${CMAKE_SOURCE_DIR}/Firmware/Generated/devicetree.c")
set_source_files_properties("${CMAKE_SOURCE_DIR}/Firmware/Generated/devicetree.c" PROPERTIES GENERATED TRUE)
# Update target for generated code
target_sources(${COMPONENT_LIB} PRIVATE "${CMAKE_SOURCE_DIR}/Firmware/Generated/devicetree.c")
target_include_directories(${COMPONENT_LIB} PRIVATE "${CMAKE_SOURCE_DIR}/Firmware/Generated")

View File

@ -1,6 +1,6 @@
#pragma once
#include <sys/errno.h>
#include <errno.h>
#define CUSTOM_ERROR_CODE(x) (-2000 - x)