mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-02-20 07:25:06 +00:00
Compare commits
3 Commits
48145deb3a
...
83ec8105fd
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83ec8105fd | ||
|
|
33fbf44a68 | ||
|
|
0d9cfe8e8b |
@ -8,7 +8,7 @@ class DeviceTreeConfig:
|
||||
bindings: list[str] = field(default_factory=list)
|
||||
dts: str = ""
|
||||
|
||||
def parse_config(file_path: str, project_root: str) -> list[DeviceTreeConfig]:
|
||||
def parse_config(file_path: str, project_root: str) -> DeviceTreeConfig:
|
||||
"""
|
||||
Parses devicetree.yaml and recursively finds dependencies.
|
||||
Returns a list of DeviceTreeConfig objects in post-order (dependencies first).
|
||||
@ -42,8 +42,9 @@ def parse_config(file_path: str, project_root: str) -> list[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
|
||||
|
||||
@ -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")
|
||||
@ -146,23 +146,6 @@ def write_device_init(file, device: Device, bindings: list[Binding], verbose: bo
|
||||
for child_device in device.devices:
|
||||
write_device_init(file, child_device, bindings, verbose)
|
||||
|
||||
def write_device_list_entry(file, device: Device):
|
||||
compatible_property = find_binding_property(device, "compatible")
|
||||
if compatible_property is None:
|
||||
raise Exception(f"Cannot find 'compatible' property for {device.identifier}")
|
||||
identifier = get_device_identifier_safe(device)
|
||||
file.write(f"\t&{identifier},\n")
|
||||
for child in device.devices:
|
||||
write_device_list_entry(file, child)
|
||||
|
||||
def write_device_list(file, devices: list[Device]):
|
||||
file.write("struct device* devices_builtin[] = {\n")
|
||||
for device in devices:
|
||||
write_device_list_entry(file, device)
|
||||
# Terminator
|
||||
file.write(f"\tNULL\n")
|
||||
file.write("};\n\n")
|
||||
|
||||
def generate_devicetree_c(filename: str, items: list[object], bindings: list[Binding], verbose: bool):
|
||||
with open(filename, "w") as file:
|
||||
file.write(dedent('''\
|
||||
@ -188,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);
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
dependencies:
|
||||
- TactilityKernel
|
||||
dts: ../placeholder.dts
|
||||
@ -1,3 +0,0 @@
|
||||
dependencies:
|
||||
- TactilityKernel
|
||||
dts: ../placeholder.dts
|
||||
@ -1,3 +0,0 @@
|
||||
dependencies:
|
||||
- TactilityKernel
|
||||
dts: ../placeholder.dts
|
||||
@ -1,3 +0,0 @@
|
||||
dependencies:
|
||||
- TactilityKernel
|
||||
dts: ../placeholder.dts
|
||||
@ -1,3 +0,0 @@
|
||||
dependencies:
|
||||
- TactilityKernel
|
||||
dts: ../placeholder.dts
|
||||
@ -1,3 +0,0 @@
|
||||
dependencies:
|
||||
- TactilityKernel
|
||||
dts: ../placeholder.dts
|
||||
@ -1,3 +0,0 @@
|
||||
dependencies:
|
||||
- TactilityKernel
|
||||
dts: ../placeholder.dts
|
||||
@ -1,3 +0,0 @@
|
||||
dependencies:
|
||||
- TactilityKernel
|
||||
dts: ../placeholder.dts
|
||||
@ -1,3 +0,0 @@
|
||||
dependencies:
|
||||
- TactilityKernel
|
||||
dts: ../placeholder.dts
|
||||
@ -1,3 +0,0 @@
|
||||
dependencies:
|
||||
- TactilityKernel
|
||||
dts: ../placeholder.dts
|
||||
@ -1,3 +0,0 @@
|
||||
dependencies:
|
||||
- TactilityKernel
|
||||
dts: ../placeholder.dts
|
||||
@ -1,3 +0,0 @@
|
||||
dependencies:
|
||||
- TactilityKernel
|
||||
dts: ../placeholder.dts
|
||||
@ -1,3 +0,0 @@
|
||||
dependencies:
|
||||
- TactilityKernel
|
||||
dts: ../placeholder.dts
|
||||
@ -1,3 +0,0 @@
|
||||
dependencies:
|
||||
- TactilityKernel
|
||||
dts: ../placeholder.dts
|
||||
@ -1,3 +0,0 @@
|
||||
dependencies:
|
||||
- TactilityKernel
|
||||
dts: ../placeholder.dts
|
||||
@ -1,3 +0,0 @@
|
||||
dependencies:
|
||||
- TactilityKernel
|
||||
dts: ../placeholder.dts
|
||||
@ -1,3 +0,0 @@
|
||||
dependencies:
|
||||
- TactilityKernel
|
||||
dts: ../placeholder.dts
|
||||
@ -1,3 +0,0 @@
|
||||
dependencies:
|
||||
- TactilityKernel
|
||||
dts: ../placeholder.dts
|
||||
@ -1,3 +0,0 @@
|
||||
dependencies:
|
||||
- TactilityKernel
|
||||
dts: ../placeholder.dts
|
||||
@ -19,7 +19,7 @@ struct InternalData {
|
||||
}
|
||||
};
|
||||
|
||||
#define GET_CONFIG(device) ((Esp32I2cConfig*)device->internal.driver_data)
|
||||
#define GET_CONFIG(device) ((Esp32I2cConfig*)device->config)
|
||||
#define GET_DATA(device) ((InternalData*)device->internal.driver_data)
|
||||
|
||||
#define lock(data) mutex_lock(&data->mutex);
|
||||
@ -52,7 +52,7 @@ static bool write_read(Device* device, uint8_t address, const uint8_t* write_dat
|
||||
auto* driver_data = GET_DATA(device);
|
||||
lock(driver_data);
|
||||
const esp_err_t result = i2c_master_write_read_device(GET_CONFIG(device)->port, address, write_data, write_data_size, read_data, read_data_size, timeout);
|
||||
unlock(driver_data)
|
||||
unlock(driver_data);
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(result);
|
||||
return result == ESP_OK;
|
||||
}
|
||||
|
||||
@ -2,26 +2,21 @@ cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
file(GLOB_RECURSE SOURCE_FILES "Source/*.c*")
|
||||
|
||||
# Determine device identifier and project location
|
||||
# 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_PROJECT "Devices/simulator")
|
||||
endif ()
|
||||
|
||||
set(DEVICETREE_LOCATION "Devices/${TACTILITY_DEVICE_ID}")
|
||||
|
||||
if (NOT DEFINED ${COMPONENT_LIB})
|
||||
set(TACTILITY_DEVICE_ID simulator)
|
||||
set(COMPONENT_LIB FirmwareSim)
|
||||
endif ()
|
||||
|
||||
if (DEFINED ENV{ESP_IDF_VERSION})
|
||||
set(DEVICETREE_LOCATION "${CMAKE_SOURCE_DIR}/Devices/${TACTILITY_DEVICE_ID}")
|
||||
|
||||
if (DEFINED ENV{ESP_IDF_VERSION})
|
||||
idf_component_register(
|
||||
SRCS ${SOURCE_FILES}
|
||||
REQUIRES ${DEVICE_COMPONENTS}
|
||||
REQUIRES Tactility TactilityC TactilityKernel drivers-esp ${TACTILITY_DEVICE_PROJECT}
|
||||
)
|
||||
|
||||
@ -37,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"
|
||||
@ -55,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")
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <sys/errno.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define CUSTOM_ERROR_CODE(x) (-__ELASTERROR - x)
|
||||
#define CUSTOM_ERROR_CODE(x) (-2000 - x)
|
||||
|
||||
#define ERROR_UNDEFINED CUSTOM_ERROR_CODE(1)
|
||||
#define ERROR_INVALID_STATE CUSTOM_ERROR_CODE(2)
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
|
||||
#include <Tactility/FreeRTOS/semphr.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -23,7 +26,7 @@ inline static void recursive_mutex_destruct(struct RecursiveMutex* mutex) {
|
||||
|
||||
inline static void recursive_mutex_lock(struct RecursiveMutex* mutex) {
|
||||
assert(mutex->handle != NULL);
|
||||
xSemaphoreTake(mutex->handle, portMAX_DELAY);
|
||||
xSemaphoreTakeRecursive(mutex->handle, portMAX_DELAY);
|
||||
}
|
||||
|
||||
inline static bool recursive_mutex_is_locked(struct RecursiveMutex* mutex) {
|
||||
@ -33,12 +36,12 @@ inline static bool recursive_mutex_is_locked(struct RecursiveMutex* mutex) {
|
||||
|
||||
inline static bool recursive_mutex_try_lock(struct RecursiveMutex* mutex) {
|
||||
assert(mutex->handle != NULL);
|
||||
return xSemaphoreTake(mutex->handle, 0) == pdTRUE;
|
||||
return xSemaphoreTakeRecursive(mutex->handle, 0) == pdTRUE;
|
||||
}
|
||||
|
||||
inline static void recursive_mutex_unlock(struct RecursiveMutex* mutex) {
|
||||
assert(mutex->handle != NULL);
|
||||
xSemaphoreGive(mutex->handle);
|
||||
xSemaphoreGiveRecursive(mutex->handle);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#ifndef ESP_PLATFORM
|
||||
|
||||
#include <tactility/log.h>
|
||||
#include <Tactility/Log.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user