Compare commits

...

9 Commits

Author SHA1 Message Date
Ken Van Hoeylandt
1a7d603a64 Fixes and tests 2026-01-22 23:05:30 +01:00
Ken Van Hoeylandt
3e0dd608da Simulator fixes 2026-01-22 22:16:34 +01:00
Ken Van Hoeylandt
d9311a98e3 Fixes 2026-01-22 21:54:24 +01:00
Ken Van Hoeylandt
d1dcae0c50 Fixes 2026-01-22 21:50:54 +01:00
Ken Van Hoeylandt
5ceadc4ebf Fixes 2026-01-22 21:37:31 +01:00
Ken Van Hoeylandt
5565b77c7c Fixes 2026-01-22 21:31:35 +01:00
Ken Van Hoeylandt
179ec6ca6a Fix 2026-01-22 20:51:57 +01:00
Ken Van Hoeylandt
9b428d76db Revert "Trigger review - revert this later"
This reverts commit 0d9cfe8e8b37a23d5f1c33758c8c625ebf738e76.
2026-01-22 18:10:04 +01:00
Ken Van Hoeylandt
5c74e84489 Improvement 2026-01-22 18:09:35 +01:00
83 changed files with 413 additions and 65 deletions

View File

@ -52,7 +52,7 @@ def find_binding(compatible: str, bindings: list[Binding]) -> Binding:
return binding
return None
def property_to_string(property: Property) -> str:
def property_to_string(property: DeviceProperty) -> str:
type = property.type
if type == "value":
return property.value
@ -215,6 +215,8 @@ def generate_devicetree_h(filename: str):
'''))
def generate(output_path: str, items: list[object], bindings: list[Binding], verbose: bool):
if not os.path.exists(output_path):
os.makedirs(output_path)
devicetree_c_filename = os.path.join(output_path, "devicetree.c")
generate_devicetree_c(devicetree_c_filename, items, bindings, verbose)
devicetree_h_filename = os.path.join(output_path, "devicetree.h")

View File

@ -11,7 +11,7 @@ class Device:
devices: list
@dataclass
class Property:
class DeviceProperty:
name: str
type: str
value: object

View File

@ -26,7 +26,7 @@ class DtsTransformer(Transformer):
for index, entry in enumerate(tokens):
if index == 0:
identifier = entry.value
elif type(entry) is Property:
elif type(entry) is DeviceProperty:
properties.append(entry)
elif type(entry) is Device:
devices.append(entry)
@ -35,7 +35,7 @@ class DtsTransformer(Transformer):
assert len(objects) == 2
if not type(objects[1]) is PropertyValue:
raise Exception(f"Object was not converted to PropertyValue: {objects[1]}")
return Property(objects[0], objects[1].type, objects[1].value)
return DeviceProperty(objects[0], objects[1].type, objects[1].value)
def property_value(self, tokens: List):
token = tokens[0]
if type(token) is Token:

View File

@ -76,6 +76,7 @@ if (NOT DEFINED ENV{ESP_IDF_VERSION})
add_subdirectory(TactilityCore)
add_subdirectory(TactilityFreeRtos)
add_subdirectory(TactilityKernel)
add_subdirectory(Drivers/PlatformPosix)
add_subdirectory(Devices/simulator)
add_subdirectory(Libraries/cJSON)
add_subdirectory(Libraries/lv_screenshot)

View File

@ -0,0 +1,3 @@
dependencies:
- TactilityKernel
dts: ../placeholder.dts

View File

@ -0,0 +1,3 @@
dependencies:
- TactilityKernel
dts: ../placeholder.dts

View File

@ -0,0 +1,3 @@
dependencies:
- TactilityKernel
dts: ../placeholder.dts

View File

@ -0,0 +1,3 @@
dependencies:
- TactilityKernel
dts: ../placeholder.dts

View File

@ -0,0 +1,3 @@
dependencies:
- TactilityKernel
dts: ../placeholder.dts

View File

@ -0,0 +1,3 @@
dependencies:
- TactilityKernel
dts: ../placeholder.dts

View File

@ -0,0 +1,3 @@
dependencies:
- TactilityKernel
dts: ../placeholder.dts

View File

@ -0,0 +1,3 @@
dependencies:
- TactilityKernel
dts: ../placeholder.dts

View File

@ -0,0 +1,3 @@
dependencies:
- TactilityKernel
dts: ../placeholder.dts

View File

@ -0,0 +1,3 @@
dependencies:
- TactilityKernel
dts: ../placeholder.dts

View File

@ -0,0 +1,3 @@
dependencies:
- TactilityKernel
dts: ../placeholder.dts

View File

@ -0,0 +1,3 @@
dependencies:
- TactilityKernel
dts: ../placeholder.dts

View File

@ -0,0 +1,3 @@
dependencies:
- TactilityKernel
dts: ../placeholder.dts

View File

@ -0,0 +1,3 @@
dependencies:
- TactilityKernel
dts: ../placeholder.dts

View File

@ -0,0 +1,3 @@
dependencies:
- TactilityKernel
dts: ../placeholder.dts

View File

@ -0,0 +1,3 @@
dependencies:
- TactilityKernel
dts: ../placeholder.dts

View File

@ -0,0 +1,3 @@
dependencies:
- TactilityKernel
dts: ../placeholder.dts

View File

@ -0,0 +1,3 @@
dependencies:
- TactilityKernel
dts: ../placeholder.dts

View File

@ -0,0 +1,3 @@
dependencies:
- TactilityKernel
dts: ../placeholder.dts

View File

@ -3,5 +3,5 @@ file(GLOB_RECURSE SOURCE_FILES Source/*.c*)
idf_component_register(
SRCS ${SOURCE_FILES}
INCLUDE_DIRS "Source"
REQUIRES Tactility esp_lcd ST7796 BQ25896 BQ27220 TCA8418 DRV2605 PwmBacklight driver esp_adc drivers-esp
REQUIRES Tactility esp_lcd ST7796 BQ25896 BQ27220 TCA8418 DRV2605 PwmBacklight driver esp_adc PlatformEsp32
)

View File

@ -1,4 +1,4 @@
dependencies:
- Drivers/drivers-esp
- Drivers/PlatformEsp32
bindings: ./
dts: lilygo,tlora_pager.dts

View File

@ -1,3 +1,4 @@
dependencies:
- TactilityKernel
- Drivers/PlatformPosix
dts: ../placeholder.dts

View File

@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.20)
file(GLOB_RECURSE SOURCES "Source/*.c**")
if (DEFINED ENV{ESP_IDF_VERSION})
idf_component_register(
SRCS ${SOURCES}
INCLUDE_DIRS "Include/"
REQUIRES TactilityKernel driver
)
else ()
add_library(PlatformEsp32 OBJECT)
target_sources(PlatformEsp32 PRIVATE ${SOURCES})
target_include_directories(PlatformEsp32 PUBLIC Include/)
target_link_libraries(PlatformEsp32 PUBLIC TactilityKernel)
endif ()

View File

@ -46,7 +46,7 @@ static bool set_options(Device* device, gpio_pin_t pin, gpio_flags_t options) {
.pull_down_en = (options & GPIO_PULL_DOWN) ? GPIO_PULLDOWN_ENABLE : GPIO_PULLDOWN_DISABLE,
.intr_type = GPIO_INTERRUPT_FROM_OPTIONS(options),
#if SOC_GPIO_SUPPORT_PIN_HYS_FILTER
.hys_ctrl_mode = GPIO_HYS_CTRL_EFUSE
.hys_ctrl_mode = GPIO_HYS_SOFT_DISABLE
#endif
};

View File

@ -8,7 +8,7 @@
#define TAG LOG_TAG(esp32_i2c)
struct InternalData {
Mutex mutex {};
Mutex mutex { 0 };
InternalData() {
mutex_construct(&mutex);

View File

@ -1,3 +1,3 @@
dependencies:
- TactilityKernel
bindings: bindings
bindings: Bindings

View File

@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.20)
file(GLOB_RECURSE SOURCES "Source/*.c**")
if (DEFINED ENV{ESP_IDF_VERSION})
idf_component_register(
SRCS ${SOURCES}
# INCLUDE_DIRS "Include/"
REQUIRES TactilityKernel driver
)
else ()
add_library(PlatformPosix OBJECT)
target_sources(PlatformPosix PRIVATE ${SOURCES})
# target_include_directories(PlatformPosix PUBLIC Include/)
target_link_libraries(PlatformPosix PUBLIC TactilityKernel)
endif ()

View File

@ -0,0 +1,9 @@
#include <Tactility/Driver.h>
extern "C" {
extern void register_platform_drivers() {
/* Placeholder */
}
}

View File

@ -0,0 +1,2 @@
dependencies:
- TactilityKernel

View File

@ -1,20 +0,0 @@
cmake_minimum_required(VERSION 3.20)
file(GLOB_RECURSE SOURCES "source/*.c**")
if (DEFINED ENV{ESP_IDF_VERSION})
idf_component_register(
SRCS ${SOURCES}
INCLUDE_DIRS "include/"
REQUIRES TactilityKernel driver
)
else ()
add_library(drivers-esp OBJECT)
target_sources(drivers-esp PRIVATE ${SOURCES})
target_include_directories(drivers-esp PUBLIC include/)
target_link_libraries(drivers-esp PUBLIC core)
endif ()

View File

@ -15,21 +15,23 @@ 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}
SRCS ${SOURCE_FILES} "${CMAKE_SOURCE_DIR}/Firmware/Generated/devicetree.c"
REQUIRES Tactility TactilityC TactilityKernel PlatformEsp32 ${TACTILITY_DEVICE_PROJECT}
)
else ()
add_executable(FirmwareSim ${SOURCE_FILES} "${CMAKE_SOURCE_DIR}/Firmware/Generated/devicetree.c")
target_link_libraries(FirmwareSim
PRIVATE Tactility
PRIVATE TactilityCore
PRIVATE TactilityFreeRtos
PRIVATE TactilityKernel
PRIVATE Simulator
PRIVATE SDL2::SDL2-static SDL2-static
target_link_libraries(FirmwareSim PRIVATE
Tactility
TactilityCore
TactilityFreeRtos
TactilityKernel
Simulator
PlatformPosix
SDL2::SDL2-static SDL2-static
)
add_definitions(-D_Nullable=)
@ -51,6 +53,7 @@ add_custom_command(
)
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.h" 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

@ -29,7 +29,7 @@ static const LoggerAdapter genericLoggerAdapter = [](LogLevel level, const char*
constexpr auto COLOR_GREY = "\033[37m";
std::stringstream buffer;
buffer << COLOR_GREY << getLogTimestamp() << ' ' << toTagColour(level) << toPrefix(level) << COLOR_GREY << " [" << COLOR_RESET << tag << COLOR_GREY << "] " << toMessageColour(level) << message << COLOR_RESET << std::endl;
printf(buffer.str().c_str());
printf("%s", buffer.str().c_str());
};
}

View File

@ -1,18 +1,18 @@
cmake_minimum_required(VERSION 3.20)
file(GLOB_RECURSE SOURCES "source/*.c**")
file(GLOB_RECURSE SOURCES "Source/*.c**")
if (DEFINED ENV{ESP_IDF_VERSION})
idf_component_register(
SRCS ${SOURCES}
INCLUDE_DIRS "include/"
INCLUDE_DIRS "Include/"
)
else ()
add_library(core OBJECT ${SOURCES})
target_include_directories(core PUBLIC include/)
target_link_libraries(core PUBLIC freertos_kernel)
add_library(TactilityKernel OBJECT ${SOURCES})
target_include_directories(TactilityKernel PUBLIC Include/)
target_link_libraries(TactilityKernel PUBLIC freertos_kernel)
endif ()

View File

@ -154,8 +154,21 @@ static inline void device_unlock(struct Device* device) {
static inline const struct DeviceType* device_get_type(struct Device* device) {
return device->internal.driver->device_type;
}
/**
* Iterate through all the known devices
* @param callback_context the parameter to pass to the callback. NULL is valid.
* @param on_device the function to call for each filtered device. return true to continue iterating or false to stop.
*/
void for_each_device(void* callback_context, bool(*on_device)(struct Device* device, void* context));
/**
/**
* Iterate through all the child devices of the specified device
* @param callback_context the parameter to pass to the callback. NULL is valid.
* @param on_device the function to call for each filtered device. return true to continue iterating or false to stop.
*/
void for_each_device_child(struct Device* device, void* callback_context, bool(*on_device)(struct Device* device, void* context));
/**
* Iterate through all the known devices of a specific type
* @param type the type to filter
* @param callback_context the parameter to pass to the callback. NULL is valid.

View File

@ -5,3 +5,6 @@
#else
#include <FreeRTOS.h>
#endif
// Custom port compatibility definitins, mainly for PC compatibility
#include "port.h"

View File

@ -1,10 +1,10 @@
#pragma once
#include "FreeRTOS.h"
#ifdef ESP_PLATFORM
#include <freertos/FreeRTOS.h>
#include <freertos/event_groups.h>
#else
#include <FreeRTOS.h>
#include <event_groups.h>
#endif

View File

@ -4,4 +4,5 @@
#ifndef ESP_PLATFORM
#define xPortInIsrContext(x) (false)
#define vPortAssertIfInISR()
#endif

View File

@ -1,10 +1,10 @@
#pragma once
#include "FreeRTOS.h"
#ifdef ESP_PLATFORM
#include <freertos/FreeRTOS.h>
#include <freertos/queue.h>
#else
#include <FreeRTOS.h>
#include <queue.h>
#endif

View File

@ -1,9 +1,9 @@
#pragma once
#include "FreeRTOS.h"
#ifdef ESP_PLATFORM
#include <freertos/FreeRTOS.h>
#include <freertos/semphr.h>
#else
#include <FreeRTOS.h>
#include <semphr.h>
#endif

View File

@ -1,10 +1,10 @@
#pragma once
#include "FreeRTOS.h"
#ifdef ESP_PLATFORM
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#else
#include <FreeRTOS.h>
#include <task.h>
#endif

View File

@ -1,9 +1,9 @@
#pragma once
#include "FreeRTOS.h"
#ifdef ESP_PLATFORM
#include <freertos/FreeRTOS.h>
#include <freertos/timers.h>
#else
#include <FreeRTOS.h>
#include <timers.h>
#endif

View File

@ -2,6 +2,7 @@
#include <Tactility/FreeRTOS/semphr.h>
#include <assert.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {

View File

@ -1,8 +1,6 @@
#pragma once
#include "freertos/semphr.h"
#include <stdbool.h>
#include <Tactility/FreeRTOS/semphr.h>
#ifdef __cplusplus
@ -20,6 +18,7 @@ inline static void recursive_mutex_construct(struct RecursiveMutex* mutex) {
inline static void recursive_mutex_destruct(struct RecursiveMutex* mutex) {
assert(mutex != NULL);
assert(mutex->handle != NULL);
vPortAssertIfInISR();
vSemaphoreDelete(mutex->handle);
mutex->handle = NULL;
}

View File

@ -3,7 +3,7 @@
#include <Tactility/Driver.h>
#include <Tactility/Log.h>
#include <algorithm>
#include <ranges>
#include <cassert>
#include <cstring>
#include <sys/errno.h>
@ -17,7 +17,7 @@ struct DeviceData {
struct DeviceLedger {
std::vector<Device*> devices;
Mutex mutex {};
Mutex mutex { 0 };
DeviceLedger() {
mutex_construct(&mutex);
@ -54,7 +54,8 @@ int device_destruct(Device* device) {
/** Add a child to the list of children */
static void device_add_child(struct Device* device, struct Device* child) {
device_lock(device);
get_device_data(device)->children.push_back(device);
assert(device->internal.state.added);
get_device_data(device)->children.push_back(child);
device_unlock(device);
}
@ -175,6 +176,25 @@ void device_set_parent(Device* device, Device* parent) {
device->parent = parent;
}
void for_each_device(void* callback_context, bool(*on_device)(Device* device, void* context)) {
ledger_lock();
for (auto* device : ledger.devices) {
if (!on_device(device, callback_context)) {
break;
}
}
ledger_unlock()
}
void for_each_device_child(Device* device, void* callback_context, bool(*on_device)(struct Device* device, void* context)) {
auto* data = get_device_data(device);
for (auto* child_device : data->children) {
if (!on_device(child_device, callback_context)) {
break;
}
}
}
void for_each_device_of_type(const DeviceType* type, void* callback_context, bool(*on_device)(Device* device, void* context)) {
ledger_lock();
for (auto* device : ledger.devices) {

View File

@ -1,4 +1,5 @@
#include <sys/errno.h>
#include <cstring>
#include <ranges>
#include <vector>
#include <Tactility/concurrent/Mutex.h>
@ -10,7 +11,7 @@
#define TAG LOG_TAG(driver)
struct DriverInternalData {
Mutex mutex {};
Mutex mutex { 0 };
int use_count = 0;
DriverInternalData() {
@ -24,7 +25,7 @@ struct DriverInternalData {
struct DriverLedger {
std::vector<Driver*> drivers = {};
Mutex mutex {};
Mutex mutex { 0 };
DriverLedger() {
mutex_construct(&mutex);

View File

@ -1 +1 @@
bindings: bindings
bindings: Bindings

View File

@ -5,9 +5,11 @@ set(DOCTESTINC ${PROJECT_SOURCE_DIR}/Include)
enable_testing()
add_subdirectory(TactilityCore)
add_subdirectory(TactilityFreeRtos)
add_subdirectory(TactilityKernel)
add_subdirectory(Tactility)
add_custom_target(build-tests)
add_dependencies(build-tests TactilityCoreTests)
add_dependencies(build-tests TactilityFreeRtosTests)
add_dependencies(build-tests TactilityTests)
add_dependencies(build-tests TactilityKernelTests)

View File

@ -0,0 +1,14 @@
project(TactilityCoreTests)
enable_language(C CXX ASM)
set(CMAKE_CXX_COMPILER g++)
file(GLOB_RECURSE TEST_SOURCES ${PROJECT_SOURCE_DIR}/*.cpp)
add_executable(TactilityKernelTests EXCLUDE_FROM_ALL ${TEST_SOURCES})
target_include_directories(TactilityKernelTests PRIVATE ${DOCTESTINC})
add_test(NAME TactilityKernelTests COMMAND TactilityKernelTests)
target_link_libraries(TactilityKernelTests PUBLIC TactilityKernel)

View File

@ -0,0 +1,92 @@
#include "doctest.h"
#include <string.h>
#include <vector>
#include <Tactility/Device.h>
TEST_CASE("device_construct and device_destruct should set and unset the correct fields") {
Device device = { 0 };
device_construct(&device);
CHECK_NE(device.internal.data, nullptr);
CHECK_NE(device.internal.mutex.handle, nullptr);
device_destruct(&device);
CHECK_EQ(device.internal.data, nullptr);
CHECK_EQ(device.internal.mutex.handle, nullptr);
Device comparison_device = { 0 };
comparison_device.internal.data = device.internal.data;
comparison_device.internal.mutex.handle = device.internal.mutex.handle;
// Check that no other data was set
CHECK_EQ(memcmp(&device, &comparison_device, sizeof(struct Device)), 0);
}
TEST_CASE("device_add should make the device discoverable") {
Device device = { 0 };
device_construct(&device);
device_add(&device);
// Gather all devices
std::vector<Device*> devices;
for_each_device(&devices, [](auto* device, auto* context) {
auto* devices_ptr = (std::vector<Device*>*)context;
devices_ptr->push_back(device);
return true;
});
CHECK_EQ(devices.size(), 1);
CHECK_EQ(devices[0], &device);
device_remove(&device);
device_destruct(&device);
}
TEST_CASE("device_add should add the device to its parent") {
Device parent = { 0 };
Device child = {
.name = nullptr,
.config = nullptr,
.parent = &parent
};
device_construct(&parent);
device_add(&parent);
device_construct(&child);
device_add(&child);
// Gather all child devices
std::vector<Device*> children;
for_each_device_child(&parent, &children, [](auto* child_device, auto* context) {
auto* children_ptr = (std::vector<Device*>*)context;
children_ptr->push_back(child_device);
return true;
});
CHECK_EQ(children.size(), 1);
CHECK_EQ(children[0], &child);
device_remove(&child);
device_destruct(&child);
device_remove(&parent);
device_destruct(&parent);
}
TEST_CASE("device_add should set the state to 'added'") {
Device device = { 0 };
device_construct(&device);
CHECK_EQ(device.internal.state.added, false);
device_add(&device);
CHECK_EQ(device.internal.state.added, true);
device_remove(&device);
device_destruct(&device);
}

View File

@ -0,0 +1,6 @@
#include "doctest.h"
#include <Tactility/Driver.h>
TEST_CASE("placeholder driver test") {
// TODO: Implement
}

View File

@ -0,0 +1,59 @@
#define DOCTEST_CONFIG_IMPLEMENT
#include "doctest.h"
#include <cassert>
#include <Tactility/FreeRTOS/task.h>
typedef struct {
int argc;
char** argv;
int result;
} TestTaskData;
void test_task(void* parameter) {
auto* data = (TestTaskData*)parameter;
doctest::Context context;
context.applyCommandLine(data->argc, data->argv);
// overrides
context.setOption("no-breaks", true); // don't break in the debugger when assertions fail
data->result = context.run();
if (context.shouldExit()) { // important - query flags (and --exit) rely on the user doing this
vTaskEndScheduler();
}
vTaskDelete(nullptr);
}
int main(int argc, char** argv) {
TestTaskData data = {
.argc = argc,
.argv = argv,
.result = 0
};
BaseType_t task_result = xTaskCreate(
test_task,
"test_task",
8192,
&data,
1,
nullptr
);
assert(task_result == pdPASS);
vTaskStartScheduler();
return data.result;
}
extern "C" {
// Required for FreeRTOS
void vAssertCalled(unsigned long line, const char* const file) {
__assert_fail("assert failed", file, line, "");
}
}

View File

@ -0,0 +1,42 @@
#pragma once
#include "doctest.h"
#include <unistd.h>
#include <Tactility/file/File.h>
/**
* A class for creating test files that can automatically clean themselves up.
*/
class TestFile {
const char* path;
bool autoClean;
public:
TestFile(const char* path, bool autoClean = true) : path(path), autoClean(autoClean) {
if (autoClean && exists()) {
remove();
}
}
~TestFile() {
if (autoClean && exists()) {
remove();
}
}
const char* getPath() const { return path; }
void writeData(const char* data) const {
CHECK_EQ(tt::file::writeString(path, data), true);
}
bool exists() const {
return access(path, F_OK) == 0;
}
void remove() const {
::remove(path);
}
};