mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-02-20 15:35:05 +00:00
Compare commits
No commits in common. "1a7d603a647033b889c73aed6d00cf74426f4489" and "83ec8105fdc400330b7ae631e1478c8221dc11cf" have entirely different histories.
1a7d603a64
...
83ec8105fd
@ -52,7 +52,7 @@ def find_binding(compatible: str, bindings: list[Binding]) -> Binding:
|
||||
return binding
|
||||
return None
|
||||
|
||||
def property_to_string(property: DeviceProperty) -> str:
|
||||
def property_to_string(property: Property) -> str:
|
||||
type = property.type
|
||||
if type == "value":
|
||||
return property.value
|
||||
@ -215,8 +215,6 @@ 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")
|
||||
|
||||
@ -11,7 +11,7 @@ class Device:
|
||||
devices: list
|
||||
|
||||
@dataclass
|
||||
class DeviceProperty:
|
||||
class Property:
|
||||
name: str
|
||||
type: str
|
||||
value: object
|
||||
|
||||
@ -26,7 +26,7 @@ class DtsTransformer(Transformer):
|
||||
for index, entry in enumerate(tokens):
|
||||
if index == 0:
|
||||
identifier = entry.value
|
||||
elif type(entry) is DeviceProperty:
|
||||
elif type(entry) is Property:
|
||||
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 DeviceProperty(objects[0], objects[1].type, objects[1].value)
|
||||
return Property(objects[0], objects[1].type, objects[1].value)
|
||||
def property_value(self, tokens: List):
|
||||
token = tokens[0]
|
||||
if type(token) is Token:
|
||||
|
||||
@ -76,7 +76,6 @@ 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)
|
||||
|
||||
@ -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
|
||||
@ -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 PlatformEsp32
|
||||
REQUIRES Tactility esp_lcd ST7796 BQ25896 BQ27220 TCA8418 DRV2605 PwmBacklight driver esp_adc drivers-esp
|
||||
)
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
dependencies:
|
||||
- Drivers/PlatformEsp32
|
||||
- Drivers/drivers-esp
|
||||
bindings: ./
|
||||
dts: lilygo,tlora_pager.dts
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
dependencies:
|
||||
- TactilityKernel
|
||||
- Drivers/PlatformPosix
|
||||
dts: ../placeholder.dts
|
||||
|
||||
@ -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(PlatformEsp32 OBJECT)
|
||||
target_sources(PlatformEsp32 PRIVATE ${SOURCES})
|
||||
target_include_directories(PlatformEsp32 PUBLIC Include/)
|
||||
target_link_libraries(PlatformEsp32 PUBLIC TactilityKernel)
|
||||
|
||||
endif ()
|
||||
@ -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(PlatformPosix OBJECT)
|
||||
target_sources(PlatformPosix PRIVATE ${SOURCES})
|
||||
# target_include_directories(PlatformPosix PUBLIC Include/)
|
||||
target_link_libraries(PlatformPosix PUBLIC TactilityKernel)
|
||||
|
||||
endif ()
|
||||
@ -1,9 +0,0 @@
|
||||
#include <Tactility/Driver.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
extern void register_platform_drivers() {
|
||||
/* Placeholder */
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,2 +0,0 @@
|
||||
dependencies:
|
||||
- TactilityKernel
|
||||
20
Drivers/drivers-esp/CMakeLists.txt
Normal file
20
Drivers/drivers-esp/CMakeLists.txt
Normal 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(drivers-esp OBJECT)
|
||||
target_sources(drivers-esp PRIVATE ${SOURCES})
|
||||
target_include_directories(drivers-esp PUBLIC include/)
|
||||
target_link_libraries(drivers-esp PUBLIC core)
|
||||
|
||||
endif ()
|
||||
@ -1,3 +1,3 @@
|
||||
dependencies:
|
||||
- TactilityKernel
|
||||
bindings: Bindings
|
||||
bindings: bindings
|
||||
@ -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_SOFT_DISABLE
|
||||
.hys_ctrl_mode = GPIO_HYS_CTRL_EFUSE
|
||||
#endif
|
||||
};
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
#define TAG LOG_TAG(esp32_i2c)
|
||||
|
||||
struct InternalData {
|
||||
Mutex mutex { 0 };
|
||||
Mutex mutex {};
|
||||
|
||||
InternalData() {
|
||||
mutex_construct(&mutex);
|
||||
@ -15,23 +15,21 @@ endif ()
|
||||
set(DEVICETREE_LOCATION "${CMAKE_SOURCE_DIR}/Devices/${TACTILITY_DEVICE_ID}")
|
||||
|
||||
if (DEFINED ENV{ESP_IDF_VERSION})
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${SOURCE_FILES} "${CMAKE_SOURCE_DIR}/Firmware/Generated/devicetree.c"
|
||||
REQUIRES Tactility TactilityC TactilityKernel PlatformEsp32 ${TACTILITY_DEVICE_PROJECT}
|
||||
SRCS ${SOURCE_FILES}
|
||||
REQUIRES Tactility TactilityC TactilityKernel drivers-esp ${TACTILITY_DEVICE_PROJECT}
|
||||
)
|
||||
|
||||
else ()
|
||||
|
||||
add_executable(FirmwareSim ${SOURCE_FILES} "${CMAKE_SOURCE_DIR}/Firmware/Generated/devicetree.c")
|
||||
target_link_libraries(FirmwareSim PRIVATE
|
||||
Tactility
|
||||
TactilityCore
|
||||
TactilityFreeRtos
|
||||
TactilityKernel
|
||||
Simulator
|
||||
PlatformPosix
|
||||
SDL2::SDL2-static SDL2-static
|
||||
target_link_libraries(FirmwareSim
|
||||
PRIVATE Tactility
|
||||
PRIVATE TactilityCore
|
||||
PRIVATE TactilityFreeRtos
|
||||
PRIVATE TactilityKernel
|
||||
PRIVATE Simulator
|
||||
PRIVATE SDL2::SDL2-static SDL2-static
|
||||
)
|
||||
|
||||
add_definitions(-D_Nullable=)
|
||||
@ -53,7 +51,6 @@ 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")
|
||||
|
||||
@ -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("%s", buffer.str().c_str());
|
||||
printf(buffer.str().c_str());
|
||||
};
|
||||
|
||||
}
|
||||
@ -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(TactilityKernel OBJECT ${SOURCES})
|
||||
target_include_directories(TactilityKernel PUBLIC Include/)
|
||||
target_link_libraries(TactilityKernel PUBLIC freertos_kernel)
|
||||
add_library(core OBJECT ${SOURCES})
|
||||
target_include_directories(core PUBLIC include/)
|
||||
target_link_libraries(core PUBLIC freertos_kernel)
|
||||
|
||||
endif ()
|
||||
|
||||
@ -1 +1 @@
|
||||
bindings: Bindings
|
||||
bindings: bindings
|
||||
|
||||
@ -154,21 +154,8 @@ 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.
|
||||
@ -5,6 +5,3 @@
|
||||
#else
|
||||
#include <FreeRTOS.h>
|
||||
#endif
|
||||
|
||||
// Custom port compatibility definitins, mainly for PC compatibility
|
||||
#include "port.h"
|
||||
@ -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
|
||||
|
||||
@ -4,5 +4,4 @@
|
||||
|
||||
#ifndef ESP_PLATFORM
|
||||
#define xPortInIsrContext(x) (false)
|
||||
#define vPortAssertIfInISR()
|
||||
#endif
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
@ -2,7 +2,6 @@
|
||||
|
||||
#include <Tactility/FreeRTOS/semphr.h>
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
|
||||
#include <Tactility/FreeRTOS/semphr.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -18,7 +20,6 @@ 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;
|
||||
}
|
||||
@ -3,7 +3,7 @@
|
||||
#include <Tactility/Driver.h>
|
||||
#include <Tactility/Log.h>
|
||||
|
||||
#include <ranges>
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <sys/errno.h>
|
||||
@ -17,7 +17,7 @@ struct DeviceData {
|
||||
|
||||
struct DeviceLedger {
|
||||
std::vector<Device*> devices;
|
||||
Mutex mutex { 0 };
|
||||
Mutex mutex {};
|
||||
|
||||
DeviceLedger() {
|
||||
mutex_construct(&mutex);
|
||||
@ -54,8 +54,7 @@ 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);
|
||||
assert(device->internal.state.added);
|
||||
get_device_data(device)->children.push_back(child);
|
||||
get_device_data(device)->children.push_back(device);
|
||||
device_unlock(device);
|
||||
}
|
||||
|
||||
@ -176,25 +175,6 @@ 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) {
|
||||
@ -1,5 +1,4 @@
|
||||
#include <cstring>
|
||||
#include <ranges>
|
||||
#include <sys/errno.h>
|
||||
#include <vector>
|
||||
|
||||
#include <Tactility/concurrent/Mutex.h>
|
||||
@ -11,7 +10,7 @@
|
||||
#define TAG LOG_TAG(driver)
|
||||
|
||||
struct DriverInternalData {
|
||||
Mutex mutex { 0 };
|
||||
Mutex mutex {};
|
||||
int use_count = 0;
|
||||
|
||||
DriverInternalData() {
|
||||
@ -25,7 +24,7 @@ struct DriverInternalData {
|
||||
|
||||
struct DriverLedger {
|
||||
std::vector<Driver*> drivers = {};
|
||||
Mutex mutex { 0 };
|
||||
Mutex mutex {};
|
||||
|
||||
DriverLedger() {
|
||||
mutex_construct(&mutex);
|
||||
@ -5,11 +5,9 @@ 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)
|
||||
|
||||
@ -1,14 +0,0 @@
|
||||
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)
|
||||
@ -1,92 +0,0 @@
|
||||
#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);
|
||||
}
|
||||
@ -1,6 +0,0 @@
|
||||
#include "doctest.h"
|
||||
#include <Tactility/Driver.h>
|
||||
|
||||
TEST_CASE("placeholder driver test") {
|
||||
// TODO: Implement
|
||||
}
|
||||
@ -1,59 +0,0 @@
|
||||
#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, "");
|
||||
}
|
||||
}
|
||||
@ -1,42 +0,0 @@
|
||||
#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);
|
||||
}
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user