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,6 +42,7 @@ def parse_config(file_path: str, project_root: str) -> DeviceTreeConfig:
config.dts = os.path.join(current_path, dts_path) config.dts = os.path.join(current_path, dts_path)
bindings = data.get("bindings", "") bindings = data.get("bindings", "")
if bindings:
bindings_resolved = os.path.join(current_path, bindings) bindings_resolved = os.path.join(current_path, bindings)
config.bindings.append(bindings_resolved) config.bindings.append(bindings_resolved)

View File

@ -31,8 +31,8 @@ def find_device_property(device: Device, name: str) -> DeviceProperty:
return property return property
return None return None
def find_binding_property(binding: Binding, name: str) -> BindingProperty: def find_binding_property(device: Device, name: str) -> BindingProperty:
for property in binding.properties: for property in device.properties:
if property.name == name: if property.name == name:
return property return property
return None return None
@ -97,7 +97,7 @@ def write_config(file, device: Device, bindings: list[Binding], type_name: str):
# Indent all params # Indent all params
for index, config_param in enumerate(config_params): for index, config_param in enumerate(config_params):
config_params[index] = f"\t{config_param}" config_params[index] = f"\t{config_param}"
# Join with comman and newline # Join with command and newline
if len(config_params) > 0: if len(config_params) > 0:
config_params_joined = ",\n".join(config_params) config_params_joined = ",\n".join(config_params)
file.write(f"{config_params_joined}\n") file.write(f"{config_params_joined}\n")

View File

@ -2,15 +2,19 @@ cmake_minimum_required(VERSION 3.20)
file(GLOB_RECURSE SOURCE_FILES "Source/*.c*") file(GLOB_RECURSE SOURCE_FILES "Source/*.c*")
if (NOT DEFINED ENV{ESP_IDF_VERSION}) # For Generate target below
set(COMPONENT_LIB FirmwareSim)
endif ()
if (DEFINED ENV{ESP_IDF_VERSION}) if (DEFINED ENV{ESP_IDF_VERSION})
include("../Buildscripts/device.cmake") include("../Buildscripts/device.cmake")
init_tactility_globals("../sdkconfig") init_tactility_globals("../sdkconfig")
get_property(TACTILITY_DEVICE_PROJECT GLOBAL PROPERTY TACTILITY_DEVICE_PROJECT) 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( idf_component_register(
SRCS ${SOURCE_FILES} SRCS ${SOURCE_FILES}
REQUIRES Tactility TactilityC TactilityKernel drivers-esp ${TACTILITY_DEVICE_PROJECT} REQUIRES Tactility TactilityC TactilityKernel drivers-esp ${TACTILITY_DEVICE_PROJECT}
@ -28,17 +32,16 @@ else ()
PRIVATE SDL2::SDL2-static SDL2-static PRIVATE SDL2::SDL2-static SDL2-static
) )
target_include_directories(FirmwareSim PRIVATE "${CMAKE_SOURCE_DIR}/Firmware/Generated")
add_definitions(-D_Nullable=) add_definitions(-D_Nullable=)
add_definitions(-D_Nonnull=) add_definitions(-D_Nonnull=)
endif () endif ()
file(MAKE_DIRECTORY "${CMAKE_SOURCE_DIR}/Firmware/Generated")
# Generate devicetree code and attach to Firmware component # Generate devicetree code and attach to Firmware component
add_custom_command( add_custom_command(
OUTPUT "${CMAKE_SOURCE_DIR}/Firmware/Generated/devicetree.c" OUTPUT "${CMAKE_SOURCE_DIR}/Firmware/Generated/devicetree.c"
"${CMAKE_SOURCE_DIR}/Firmware/Generated/devicetree.h" "${CMAKE_SOURCE_DIR}/Firmware/Generated/devicetree.h"
COMMAND mkdir -p "${CMAKE_SOURCE_DIR}/Firmware/Generated"
COMMAND pip install lark pyyaml COMMAND pip install lark pyyaml
COMMAND python "${CMAKE_SOURCE_DIR}/Buildscripts/devicetree-compiler/compile.py" COMMAND python "${CMAKE_SOURCE_DIR}/Buildscripts/devicetree-compiler/compile.py"
"${DEVICETREE_LOCATION}" "Firmware/Generated" "${DEVICETREE_LOCATION}" "Firmware/Generated"
@ -46,6 +49,8 @@ add_custom_command(
DEPENDS "${DEVICETREE_LOCATION}/devicetree.yaml" # Optional: trigger rebuild if source changes DEPENDS "${DEVICETREE_LOCATION}/devicetree.yaml" # Optional: trigger rebuild if source changes
COMMENT "Generating devicetree source files..." 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") 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_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 #pragma once
#include <sys/errno.h> #include <errno.h>
#define CUSTOM_ERROR_CODE(x) (-2000 - x) #define CUSTOM_ERROR_CODE(x) (-2000 - x)