mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-02-23 00:45:05 +00:00
Compare commits
No commits in common. "83ec8105fdc400330b7ae631e1478c8221dc11cf" and "48145deb3a5aeac5c22e342de5466d1aa2c8962e" have entirely different histories.
83ec8105fd
...
48145deb3a
@ -8,7 +8,7 @@ class DeviceTreeConfig:
|
|||||||
bindings: list[str] = field(default_factory=list)
|
bindings: list[str] = field(default_factory=list)
|
||||||
dts: str = ""
|
dts: str = ""
|
||||||
|
|
||||||
def parse_config(file_path: str, project_root: str) -> DeviceTreeConfig:
|
def parse_config(file_path: str, project_root: str) -> list[DeviceTreeConfig]:
|
||||||
"""
|
"""
|
||||||
Parses devicetree.yaml and recursively finds dependencies.
|
Parses devicetree.yaml and recursively finds dependencies.
|
||||||
Returns a list of DeviceTreeConfig objects in post-order (dependencies first).
|
Returns a list of DeviceTreeConfig objects in post-order (dependencies first).
|
||||||
@ -42,9 +42,8 @@ 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)
|
|
||||||
|
|
||||||
_parse_recursive(file_path, True)
|
_parse_recursive(file_path, True)
|
||||||
return config
|
return config
|
||||||
|
|||||||
@ -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(device: Device, name: str) -> BindingProperty:
|
def find_binding_property(binding: Binding, name: str) -> BindingProperty:
|
||||||
for property in device.properties:
|
for property in binding.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 command and newline
|
# Join with comman 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")
|
||||||
@ -146,6 +146,23 @@ def write_device_init(file, device: Device, bindings: list[Binding], verbose: bo
|
|||||||
for child_device in device.devices:
|
for child_device in device.devices:
|
||||||
write_device_init(file, child_device, bindings, verbose)
|
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):
|
def generate_devicetree_c(filename: str, items: list[object], bindings: list[Binding], verbose: bool):
|
||||||
with open(filename, "w") as file:
|
with open(filename, "w") as file:
|
||||||
file.write(dedent('''\
|
file.write(dedent('''\
|
||||||
@ -171,7 +188,7 @@ def generate_devicetree_c(filename: str, items: list[object], bindings: list[Bin
|
|||||||
LOG_E(TAG, "Can't find driver: %s", compatible);
|
LOG_E(TAG, "Can't find driver: %s", compatible);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
device_construct(device);
|
device_construct(device);
|
||||||
device_set_driver(device, driver);
|
device_set_driver(device, driver);
|
||||||
device_add(device);
|
device_add(device);
|
||||||
const int err = device_start(device);
|
const int err = device_start(device);
|
||||||
|
|||||||
3
Devices/btt-panda-touch/devicetree.yaml
Normal file
3
Devices/btt-panda-touch/devicetree.yaml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
dependencies:
|
||||||
|
- TactilityKernel
|
||||||
|
dts: ../placeholder.dts
|
||||||
3
Devices/cyd-2432s024c/devicetree.yaml
Normal file
3
Devices/cyd-2432s024c/devicetree.yaml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
dependencies:
|
||||||
|
- TactilityKernel
|
||||||
|
dts: ../placeholder.dts
|
||||||
3
Devices/cyd-2432s028r/devicetree.yaml
Normal file
3
Devices/cyd-2432s028r/devicetree.yaml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
dependencies:
|
||||||
|
- TactilityKernel
|
||||||
|
dts: ../placeholder.dts
|
||||||
3
Devices/cyd-2432s028rv3/devicetree.yaml
Normal file
3
Devices/cyd-2432s028rv3/devicetree.yaml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
dependencies:
|
||||||
|
- TactilityKernel
|
||||||
|
dts: ../placeholder.dts
|
||||||
3
Devices/cyd-2432s032c/devicetree.yaml
Normal file
3
Devices/cyd-2432s032c/devicetree.yaml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
dependencies:
|
||||||
|
- TactilityKernel
|
||||||
|
dts: ../placeholder.dts
|
||||||
3
Devices/cyd-4848s040c/devicetree.yaml
Normal file
3
Devices/cyd-4848s040c/devicetree.yaml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
dependencies:
|
||||||
|
- TactilityKernel
|
||||||
|
dts: ../placeholder.dts
|
||||||
3
Devices/cyd-8048s043c/devicetree.yaml
Normal file
3
Devices/cyd-8048s043c/devicetree.yaml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
dependencies:
|
||||||
|
- TactilityKernel
|
||||||
|
dts: ../placeholder.dts
|
||||||
3
Devices/cyd-e32r28t/devicetree.yaml
Normal file
3
Devices/cyd-e32r28t/devicetree.yaml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
dependencies:
|
||||||
|
- TactilityKernel
|
||||||
|
dts: ../placeholder.dts
|
||||||
3
Devices/cyd-e32r32p/devicetree.yaml
Normal file
3
Devices/cyd-e32r32p/devicetree.yaml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
dependencies:
|
||||||
|
- TactilityKernel
|
||||||
|
dts: ../placeholder.dts
|
||||||
3
Devices/elecrow-crowpanel-advance-28/devicetree.yaml
Normal file
3
Devices/elecrow-crowpanel-advance-28/devicetree.yaml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
dependencies:
|
||||||
|
- TactilityKernel
|
||||||
|
dts: ../placeholder.dts
|
||||||
3
Devices/elecrow-crowpanel-advance-35/devicetree.yaml
Normal file
3
Devices/elecrow-crowpanel-advance-35/devicetree.yaml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
dependencies:
|
||||||
|
- TactilityKernel
|
||||||
|
dts: ../placeholder.dts
|
||||||
3
Devices/elecrow-crowpanel-advance-50/devicetree.yaml
Normal file
3
Devices/elecrow-crowpanel-advance-50/devicetree.yaml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
dependencies:
|
||||||
|
- TactilityKernel
|
||||||
|
dts: ../placeholder.dts
|
||||||
3
Devices/elecrow-crowpanel-basic-28/devicetree.yaml
Normal file
3
Devices/elecrow-crowpanel-basic-28/devicetree.yaml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
dependencies:
|
||||||
|
- TactilityKernel
|
||||||
|
dts: ../placeholder.dts
|
||||||
3
Devices/elecrow-crowpanel-basic-35/devicetree.yaml
Normal file
3
Devices/elecrow-crowpanel-basic-35/devicetree.yaml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
dependencies:
|
||||||
|
- TactilityKernel
|
||||||
|
dts: ../placeholder.dts
|
||||||
3
Devices/elecrow-crowpanel-basic-50/devicetree.yaml
Normal file
3
Devices/elecrow-crowpanel-basic-50/devicetree.yaml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
dependencies:
|
||||||
|
- TactilityKernel
|
||||||
|
dts: ../placeholder.dts
|
||||||
3
Devices/generic-esp32/devicetree.yaml
Normal file
3
Devices/generic-esp32/devicetree.yaml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
dependencies:
|
||||||
|
- TactilityKernel
|
||||||
|
dts: ../placeholder.dts
|
||||||
3
Devices/generic-esp32c6/devicetree.yaml
Normal file
3
Devices/generic-esp32c6/devicetree.yaml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
dependencies:
|
||||||
|
- TactilityKernel
|
||||||
|
dts: ../placeholder.dts
|
||||||
3
Devices/generic-esp32p4/devicetree.yaml
Normal file
3
Devices/generic-esp32p4/devicetree.yaml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
dependencies:
|
||||||
|
- TactilityKernel
|
||||||
|
dts: ../placeholder.dts
|
||||||
3
Devices/generic-esp32s3/devicetree.yaml
Normal file
3
Devices/generic-esp32s3/devicetree.yaml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
dependencies:
|
||||||
|
- TactilityKernel
|
||||||
|
dts: ../placeholder.dts
|
||||||
@ -19,7 +19,7 @@ struct InternalData {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#define GET_CONFIG(device) ((Esp32I2cConfig*)device->config)
|
#define GET_CONFIG(device) ((Esp32I2cConfig*)device->internal.driver_data)
|
||||||
#define GET_DATA(device) ((InternalData*)device->internal.driver_data)
|
#define GET_DATA(device) ((InternalData*)device->internal.driver_data)
|
||||||
|
|
||||||
#define lock(data) mutex_lock(&data->mutex);
|
#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);
|
auto* driver_data = GET_DATA(device);
|
||||||
lock(driver_data);
|
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);
|
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);
|
ESP_ERROR_CHECK_WITHOUT_ABORT(result);
|
||||||
return result == ESP_OK;
|
return result == ESP_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,21 +2,26 @@ cmake_minimum_required(VERSION 3.20)
|
|||||||
|
|
||||||
file(GLOB_RECURSE SOURCE_FILES "Source/*.c*")
|
file(GLOB_RECURSE SOURCE_FILES "Source/*.c*")
|
||||||
|
|
||||||
# For Generate target below
|
# Determine device identifier and project location
|
||||||
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 ()
|
else ()
|
||||||
set(TACTILITY_DEVICE_ID simulator)
|
set(TACTILITY_DEVICE_PROJECT "Devices/simulator")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
set(DEVICETREE_LOCATION "Devices/${TACTILITY_DEVICE_ID}")
|
||||||
|
|
||||||
|
if (NOT DEFINED ${COMPONENT_LIB})
|
||||||
set(COMPONENT_LIB FirmwareSim)
|
set(COMPONENT_LIB FirmwareSim)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
set(DEVICETREE_LOCATION "${CMAKE_SOURCE_DIR}/Devices/${TACTILITY_DEVICE_ID}")
|
|
||||||
|
|
||||||
if (DEFINED ENV{ESP_IDF_VERSION})
|
if (DEFINED ENV{ESP_IDF_VERSION})
|
||||||
|
|
||||||
idf_component_register(
|
idf_component_register(
|
||||||
SRCS ${SOURCE_FILES}
|
SRCS ${SOURCE_FILES}
|
||||||
|
REQUIRES ${DEVICE_COMPONENTS}
|
||||||
REQUIRES Tactility TactilityC TactilityKernel drivers-esp ${TACTILITY_DEVICE_PROJECT}
|
REQUIRES Tactility TactilityC TactilityKernel drivers-esp ${TACTILITY_DEVICE_PROJECT}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -32,16 +37,17 @@ 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"
|
||||||
@ -49,8 +55,6 @@ 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..."
|
||||||
)
|
)
|
||||||
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)
|
set_source_files_properties("${CMAKE_SOURCE_DIR}/Firmware/Generated/devicetree.c" PROPERTIES GENERATED TRUE)
|
||||||
# Update target for generated code
|
add_custom_target(Generated DEPENDS "${CMAKE_SOURCE_DIR}/Firmware/Generated/devicetree.c")
|
||||||
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")
|
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <errno.h>
|
#include <sys/errno.h>
|
||||||
|
|
||||||
#define CUSTOM_ERROR_CODE(x) (-2000 - x)
|
#define CUSTOM_ERROR_CODE(x) (-__ELASTERROR - x)
|
||||||
|
|
||||||
#define ERROR_UNDEFINED CUSTOM_ERROR_CODE(1)
|
#define ERROR_UNDEFINED CUSTOM_ERROR_CODE(1)
|
||||||
#define ERROR_INVALID_STATE CUSTOM_ERROR_CODE(2)
|
#define ERROR_INVALID_STATE CUSTOM_ERROR_CODE(2)
|
||||||
|
|||||||
@ -1,8 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "freertos/semphr.h"
|
|
||||||
|
|
||||||
|
|
||||||
#include <Tactility/FreeRTOS/semphr.h>
|
#include <Tactility/FreeRTOS/semphr.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@ -26,7 +23,7 @@ inline static void recursive_mutex_destruct(struct RecursiveMutex* mutex) {
|
|||||||
|
|
||||||
inline static void recursive_mutex_lock(struct RecursiveMutex* mutex) {
|
inline static void recursive_mutex_lock(struct RecursiveMutex* mutex) {
|
||||||
assert(mutex->handle != NULL);
|
assert(mutex->handle != NULL);
|
||||||
xSemaphoreTakeRecursive(mutex->handle, portMAX_DELAY);
|
xSemaphoreTake(mutex->handle, portMAX_DELAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static bool recursive_mutex_is_locked(struct RecursiveMutex* mutex) {
|
inline static bool recursive_mutex_is_locked(struct RecursiveMutex* mutex) {
|
||||||
@ -36,12 +33,12 @@ inline static bool recursive_mutex_is_locked(struct RecursiveMutex* mutex) {
|
|||||||
|
|
||||||
inline static bool recursive_mutex_try_lock(struct RecursiveMutex* mutex) {
|
inline static bool recursive_mutex_try_lock(struct RecursiveMutex* mutex) {
|
||||||
assert(mutex->handle != NULL);
|
assert(mutex->handle != NULL);
|
||||||
return xSemaphoreTakeRecursive(mutex->handle, 0) == pdTRUE;
|
return xSemaphoreTake(mutex->handle, 0) == pdTRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static void recursive_mutex_unlock(struct RecursiveMutex* mutex) {
|
inline static void recursive_mutex_unlock(struct RecursiveMutex* mutex) {
|
||||||
assert(mutex->handle != NULL);
|
assert(mutex->handle != NULL);
|
||||||
xSemaphoreGiveRecursive(mutex->handle);
|
xSemaphoreGive(mutex->handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
#ifndef ESP_PLATFORM
|
#ifndef ESP_PLATFORM
|
||||||
|
|
||||||
#include <Tactility/Log.h>
|
#include <tactility/log.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user