TactilitySDK updates (#442)

- Removed custom `TickType`
- Removed TactilityC functionality that is now covered by TactilityFreeRtos
This commit is contained in:
Ken Van Hoeylandt 2026-01-03 22:00:31 +01:00 committed by GitHub
parent 524b197105
commit 812c2901db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 17 additions and 649 deletions

View File

@ -1,8 +1,8 @@
#pragma once
#include <tt_kernel.h>
#include <tt_hal_device.h>
#include <stdbool.h>
#include <freertos/FreeRTOS.h>
#ifdef __cplusplus
extern "C" {
@ -48,7 +48,7 @@ void tt_hal_display_driver_free(DisplayDriverHandle handle);
* @param[in] timeout the maximum amount of ticks to wait for getting a lock
* @return true if the lock was acquired
*/
bool tt_hal_display_driver_lock(DisplayDriverHandle handle, TickType timeout);
bool tt_hal_display_driver_lock(DisplayDriverHandle handle, TickType_t timeout);
/**
* Unlock the display device. Must be called exactly once after locking.

View File

@ -3,7 +3,7 @@
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include <tt_kernel.h>
#include <freertos/FreeRTOS.h>
#ifdef __cplusplus
extern "C" {
@ -91,7 +91,7 @@ bool tt_hal_uart_stop(UartHandle handle);
* to wait indefinitely.
* @return The number of bytes read (0 on timeout with no data). Never exceeds bufferSize.
*/
size_t tt_hal_uart_read_bytes(UartHandle handle, char* buffer, size_t bufferSize, TickType timeout);
size_t tt_hal_uart_read_bytes(UartHandle handle, char* buffer, size_t bufferSize, TickType_t timeout);
/**
* @brief Read a single byte.
@ -102,7 +102,7 @@ size_t tt_hal_uart_read_bytes(UartHandle handle, char* buffer, size_t bufferSize
* to wait indefinitely.
* @return true if a byte was read and stored in output; false on timeout or failure.
*/
bool tt_hal_uart_read_byte(UartHandle handle, char* output, TickType timeout);
bool tt_hal_uart_read_byte(UartHandle handle, char* output, TickType_t timeout);
/**
* @brief Write up to bufferSize bytes from buffer.
@ -117,7 +117,7 @@ bool tt_hal_uart_read_byte(UartHandle handle, char* output, TickType timeout);
* to wait indefinitely.
* @return The number of bytes written (may be less than bufferSize on timeout).
*/
size_t tt_hal_uart_write_bytes(UartHandle handle, const char* buffer, size_t bufferSize, TickType timeout);
size_t tt_hal_uart_write_bytes(UartHandle handle, const char* buffer, size_t bufferSize, TickType_t timeout);
/**
* @brief Get the number of bytes currently available to read without blocking.

View File

@ -1,14 +0,0 @@
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef unsigned long TickType;
#define TT_MAX_TICKS ((TickType)(~(TickType)0))
#ifdef __cplusplus
}
#endif

View File

@ -1,7 +1,7 @@
#pragma once
#include "tt_kernel.h"
#include <stdbool.h>
#include <freertos/FreeRTOS.h>
#ifdef __cplusplus
extern "C" {
@ -15,13 +15,6 @@ typedef enum {
MutexTypeRecursive
} TtMutexType;
/**
* Allocate a new mutex instance
* @param[in] type specify if the mutex is either a normal one, or whether it can recursively (re)lock
* @return the allocated lock handle
*/
LockHandle tt_lock_alloc_mutex(TtMutexType type);
/**
* Allocate a lock for a file or folder.
* Locking is required before reading files for filesystems that are on a shared bus (e.g. SPI SD card sharing the bus with the display)
@ -36,7 +29,7 @@ LockHandle tt_lock_alloc_for_path(const char* path);
* @param[in] timeout the maximum amount of ticks to wait when trying to lock
* @return true when the lock was acquired
*/
bool tt_lock_acquire(LockHandle handle, TickType timeout);
bool tt_lock_acquire(LockHandle handle, TickType_t timeout);
/**
* Attempt to unlock the lock.

View File

@ -1,6 +1,7 @@
#pragma once
#include <stdbool.h>
#include <freertos/FreeRTOS.h>
#ifdef __cplusplus
extern "C" {
@ -18,7 +19,7 @@ void tt_lvgl_start();
void tt_lvgl_stop();
/** Lock the LVGL context. Call this before doing LVGL-related operations from a non-LVLG thread */
bool tt_lvgl_lock(TickType timeout);
bool tt_lvgl_lock(TickType_t timeout);
/** Unlock the LVGL context */
void tt_lvgl_unlock();

View File

@ -1,54 +0,0 @@
#pragma once
#include <freertos/FreeRTOS.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stdbool.h>
/** A handle that represents a message queue instance */
typedef void* MessageQueueHandle;
/**
* Allocate a new message queue in memory.
* @param[in] capacity how many messages this queue can contain before it starts blocking input
* @param[in] messageSize the size of a message
*/
MessageQueueHandle tt_message_queue_alloc(uint32_t capacity, uint32_t messageSize);
/** Free up the memory of a queue (dealloc) */
void tt_message_queue_free(MessageQueueHandle handle);
/**
* Put (post) a message in the queue
* @param[in] handle the queue handle
* @param[in] message the message of the correct size - its data will be copied
* @param[timeout] timeout the amount of ticks to wait until the message is queued
* @return true if the item was successfully queued
*/
bool tt_message_queue_put(MessageQueueHandle handle, const void* message, TickType_t timeout);
/**
* Get the oldest message from the queue.
* @param[in] handle the queue handle
* @param[out] message a pointer to a message of the correct size
* @param[in] timeout the amount of ticks to wait until a message was copied
* @return true if a message was successfully copied
*/
bool tt_message_queue_get(MessageQueueHandle handle, void* message, TickType_t timeout);
/** @return the current amount of items in the queue */
uint32_t tt_message_queue_get_count(MessageQueueHandle handle);
/**
* Remove all items from the queue (if any)
*/
void tt_message_queue_reset(MessageQueueHandle handle);
#ifdef __cplusplus
}
#endif

View File

@ -1,50 +0,0 @@
#pragma once
#include <freertos/FreeRTOS.h>
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stdbool.h>
/** A handle that represents a semaphore instance */
typedef void* SemaphoreHandle;
/**
* Allocate a new semaphore instance.
* @param[in] maxCount the maximum counter value
* @param[in] initialCount the initial counter value
* @return the handle that represents the new instance
*/
SemaphoreHandle tt_semaphore_alloc(uint32_t maxCount, TickType_t initialCount);
/** Free up the memory of a specified semaphore instance */
void tt_semaphore_free(SemaphoreHandle handle);
/**
* Attempt to acquire a semaphore (increase counter)
* @param[in] handle the instance handle
* @param[in] timeout the maximum amount of ticks to wait while trying to acquire
* @return true on successfully acquiring the semaphore (counter is increased)
*/
bool tt_semaphore_acquire(SemaphoreHandle handle, TickType_t timeout);
/**
* Release an acquired semaphore (decrease counter)
* @param[in] handle the instance handle
* @return true on successfully releasing the semaphore (counter is decreased)
*/
bool tt_semaphore_release(SemaphoreHandle handle);
/**
* Get the counter value of this semaphore instance
* @param[in] handle the instance handle
* @return the current counter value (acquisition count)
*/
uint32_t tt_semaphore_get_count(SemaphoreHandle handle);
#ifdef __cplusplus
}
#endif

View File

@ -1,156 +0,0 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#ifdef ESP_PLATFORM
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#else
#include "FreeRTOS.h"
#include "task.h"
#endif
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
/** The handle that represents the thread insance */
typedef void* ThreadHandle;
/** The state of a thread instance */
typedef enum {
ThreadStateStopped,
ThreadStateStarting,
ThreadStateRunning,
} ThreadState;
/** The identifier that represents the thread */
typedef TaskHandle_t TaskHandle;
/** ThreadCallback Your callback to run in new thread
* @warning never use osThreadExit in Thread
*/
typedef int32_t (*ThreadCallback)(void* context);
/** Thread state change callback called upon thread state change
* @param state new thread state
* @param context callback context
*/
typedef void (*ThreadStateCallback)(ThreadState state, void* context);
typedef enum {
ThreadPriorityNone = 0U, /**< Uninitialized, choose system default */
ThreadPriorityIdle = 1U,
ThreadPriorityLowest = 2U,
ThreadPriorityLow = 3U,
ThreadPriorityNormal = 4U,
ThreadPriorityHigh = 5U,
ThreadPriorityHigher = 6U,
ThreadPriorityHighest = 7U
} ThreadPriority;
/** @return a thread handle that represents a newly allocated thread instance */
ThreadHandle tt_thread_alloc();
/**
* Allocate a thread and provide some common parameters so it's all ready to be started.
* @param[in] name the name of the thread
* @param[in] stackSize the size of the stack in bytes
* @param[in] callback the callback to call from the thread
* @param[in] callbackContext the data to pass to the callback
*/
ThreadHandle tt_thread_alloc_ext(
const char* name,
uint32_t stackSize,
ThreadCallback callback,
void* _Nullable callbackContext
);
/**
* Free up the memory of the thread that is represented by this handle
* @param[in] handle the thread instance handle
*/
void tt_thread_free(ThreadHandle handle);
/**
* Set the name of a thread
* @param[in] handle the thread instance handle
* @param[in] name the name to set
*/
void tt_thread_set_name(ThreadHandle handle, const char* name);
/**
* Set the stack size of the thread (in bytes)
* @param[in] handle the thread instance handle
* @param[in] the size of the thread in bytes
*/
void tt_thread_set_stack_size(ThreadHandle handle, size_t size);
/** Set CPu core affinity for this thread
* @param[in] handle the thread instance handle
* @param[in] affinity -1 means not pinned, otherwise it's the core id (e.g. 0 or 1 on ESP32)
*/
void tt_thread_set_affinity(ThreadHandle handle, int affinity);
/**
* Set the callback for a thread. This method is executed when the thread is started.
* @param[in] handle the thread instance handle
* @param[in] callback the callback to set
* @param[in] callbackContext the data to pass to the callback
*/
void tt_thread_set_callback(ThreadHandle handle, ThreadCallback callback, void* _Nullable callbackContext);
/**
* Set the priority of a thread
* @param[in] handle the thread instance handle
* @param[in] priority the priority to set
*/
void tt_thread_set_priority(ThreadHandle handle, ThreadPriority priority);
/**
* Set the state callback for a thread
* @param[in] handle the thread instance handle
* @param[in] callback the callback to set
* @param[in] callbackContext the data to pass to the callback
*/
void tt_thread_set_state_callback(ThreadHandle handle, ThreadStateCallback callback, void* _Nullable callbackContext);
/**
* @param[in] handle the thread instance handle
* @return the current state of a thread
*/
ThreadState tt_thread_get_state(ThreadHandle handle);
/**
* Start a thread
* @param[in] handle the thread instance handle
*/
void tt_thread_start(ThreadHandle handle);
/**
* Wait (block) for the thread to finish.
* @param[in] handle the thread instance handle
* @warning make sure you manually interrupt any logic in your thread (e.g. by an EventGroup or boolean+Mutex)
*/
bool tt_thread_join(ThreadHandle handle, TickType_t timeout);
/**
* Get thread task handle
* @param[in] handle the thread instance handle
* @return the task handle of a thread
* */
TaskHandle tt_thread_get_task_handle(ThreadHandle handle);
/**
* Get the return code of a thread
* @warning crashes when state is not "stopped"
* @param[in] handle the thread instance handle
* @return the return code of a thread or
*/
int32_t tt_thread_get_return_code(ThreadHandle handle);
#ifdef __cplusplus
}
#endif

View File

@ -1,97 +0,0 @@
#pragma once
#include "tt_kernel.h"
#include "tt_thread.h"
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
/** The handle that represents a timer instance */
typedef void* TimerHandle;
/** The behaviour of the timer */
typedef enum {
TimerTypeOnce = 0, // Timer triggers once after time has passed
TimerTypePeriodic = 1 // Timer triggers repeatedly after time has passed
} TimerType;
typedef void (*TimerCallback)(void* context);
typedef void (*TimerPendingCallback)(void* context, uint32_t arg);
/**
* Create a new timer instance
* @param[in] callback the callback to call when the timer expires
* @param[in] callbackContext the data to pass to the callback
*/
TimerHandle tt_timer_alloc(TimerType type, TickType ticks, TimerCallback callback, void* callbackContext);
/** Free up the memory of a timer instance */
void tt_timer_free(TimerHandle handle);
/**
* Start the timer
* @param[in] handle the timer instance handle
* @return true when the timer was successfully started
*/
bool tt_timer_start(TimerHandle handle);
/**
* Restart an already started timer
* @param[in] handle the timer instance handle
* @param[in] interval the timer new interval
* @return true when the timer was successfully restarted
*/
bool tt_timer_reset_with_interval(TimerHandle handle, TickType interval);
/**
* Restart an already started timer
* @param[in] handle the timer instance handle
* @return true when the timer was successfully restarted
*/
bool tt_timer_reset(TimerHandle handle);
/**
* Stop a started timer
* @param[in] handle the timer instance handle
* @return true when the timer was successfully stopped
*/
bool tt_timer_stop(TimerHandle handle);
/**
* Check if a timer is started
* @param[in] handle the timer instance handle
* @return true when the timer is started (pending)
*/
bool tt_timer_is_running(TimerHandle handle);
/**
* Get the expiry time of a timer
* @param[in] handle the timer instance handle
* @return the absolute timestamp at which the timer will expire
*/
uint32_t tt_timer_get_expiry_time(TimerHandle handle);
/**
* Set the pending callback for a timer
* @param[in] handle the timer instance handle
* @param[in] callback the callback to set
* @param[in] callbackContext the context to pass to the callback
* @param[in] timeout the timeout for setting the callback
* @return when the callback was successfully set
*/
bool tt_timer_set_pending_callback(TimerHandle handle, TimerPendingCallback callback, void* callbackContext, uint32_t callbackArg, TickType_t timeout);
/**
* Set the thread priority for the callback of the timer
* @param[in] handle the timer instance handle
* @param[in] priority the thread priority to set
*/
void tt_timer_set_thread_priority(TimerHandle handle, ThreadPriority priority);
#ifdef __cplusplus
}
#endif

View File

@ -55,7 +55,7 @@ void tt_hal_display_driver_free(DisplayDriverHandle handle) {
delete wrapper;
}
bool tt_hal_display_driver_lock(DisplayDriverHandle handle, TickType timeout) {
bool tt_hal_display_driver_lock(DisplayDriverHandle handle, TickType_t timeout) {
auto wrapper = static_cast<DriverWrapper*>(handle);
return wrapper->driver->getLock()->lock(timeout);
}

View File

@ -53,15 +53,15 @@ bool tt_hal_uart_stop(UartHandle handle) {
return HANDLE_AS_UART(handle)->stop();
}
size_t tt_hal_uart_read_bytes(UartHandle handle, char* buffer, size_t bufferSize, TickType timeout) {
size_t tt_hal_uart_read_bytes(UartHandle handle, char* buffer, size_t bufferSize, TickType_t timeout) {
return HANDLE_AS_UART(handle)->readBytes(reinterpret_cast<std::byte*>(buffer), bufferSize, timeout);
}
bool tt_hal_uart_read_byte(UartHandle handle, char* output, TickType timeout) {
bool tt_hal_uart_read_byte(UartHandle handle, char* output, TickType_t timeout) {
return HANDLE_AS_UART(handle)->readByte(reinterpret_cast<std::byte*>(output), timeout);
}
size_t tt_hal_uart_write_bytes(UartHandle handle, const char* buffer, size_t bufferSize, TickType timeout) {
size_t tt_hal_uart_write_bytes(UartHandle handle, const char* buffer, size_t bufferSize, TickType_t timeout) {
return HANDLE_AS_UART(handle)->writeBytes(reinterpret_cast<const std::byte*>(buffer), bufferSize, timeout);
}

View File

@ -17,12 +17,8 @@
#include "tt_lvgl_keyboard.h"
#include "tt_lvgl_spinner.h"
#include "tt_lvgl_toolbar.h"
#include "tt_message_queue.h"
#include "tt_preferences.h"
#include "tt_semaphore.h"
#include "tt_thread.h"
#include "tt_time.h"
#include "tt_timer.h"
#include "tt_wifi.h"
#include "symbols/esp_event.h"
@ -49,7 +45,6 @@
#include <esp_random.h>
#include <esp_sntp.h>
#include <esp_netif.h>
#include <esp_wifi.h>
#include <dirent.h>
#include <sys/stat.h>
#include <time.h>
@ -199,7 +194,6 @@ const esp_elfsym main_symbols[] {
ESP_ELFSYM_EXPORT(tt_app_get_user_data_child_path),
ESP_ELFSYM_EXPORT(tt_app_get_assets_path),
ESP_ELFSYM_EXPORT(tt_app_get_assets_child_path),
ESP_ELFSYM_EXPORT(tt_lock_alloc_mutex),
ESP_ELFSYM_EXPORT(tt_lock_alloc_for_path),
ESP_ELFSYM_EXPORT(tt_lock_acquire),
ESP_ELFSYM_EXPORT(tt_lock_release),
@ -281,12 +275,6 @@ const esp_elfsym main_symbols[] {
ESP_ELFSYM_EXPORT(tt_lvgl_toolbar_add_switch_action),
ESP_ELFSYM_EXPORT(tt_lvgl_toolbar_add_spinner_action),
ESP_ELFSYM_EXPORT(tt_lvgl_toolbar_clear_actions),
ESP_ELFSYM_EXPORT(tt_message_queue_alloc),
ESP_ELFSYM_EXPORT(tt_message_queue_free),
ESP_ELFSYM_EXPORT(tt_message_queue_put),
ESP_ELFSYM_EXPORT(tt_message_queue_get),
ESP_ELFSYM_EXPORT(tt_message_queue_get_count),
ESP_ELFSYM_EXPORT(tt_message_queue_reset),
ESP_ELFSYM_EXPORT(tt_preferences_alloc),
ESP_ELFSYM_EXPORT(tt_preferences_free),
ESP_ELFSYM_EXPORT(tt_preferences_opt_bool),
@ -295,35 +283,6 @@ const esp_elfsym main_symbols[] {
ESP_ELFSYM_EXPORT(tt_preferences_put_bool),
ESP_ELFSYM_EXPORT(tt_preferences_put_int32),
ESP_ELFSYM_EXPORT(tt_preferences_put_string),
ESP_ELFSYM_EXPORT(tt_semaphore_alloc),
ESP_ELFSYM_EXPORT(tt_semaphore_free),
ESP_ELFSYM_EXPORT(tt_semaphore_acquire),
ESP_ELFSYM_EXPORT(tt_semaphore_release),
ESP_ELFSYM_EXPORT(tt_semaphore_get_count),
ESP_ELFSYM_EXPORT(tt_thread_alloc),
ESP_ELFSYM_EXPORT(tt_thread_alloc_ext),
ESP_ELFSYM_EXPORT(tt_thread_free),
ESP_ELFSYM_EXPORT(tt_thread_set_name),
ESP_ELFSYM_EXPORT(tt_thread_set_stack_size),
ESP_ELFSYM_EXPORT(tt_thread_set_affinity),
ESP_ELFSYM_EXPORT(tt_thread_set_callback),
ESP_ELFSYM_EXPORT(tt_thread_set_priority),
ESP_ELFSYM_EXPORT(tt_thread_set_state_callback),
ESP_ELFSYM_EXPORT(tt_thread_get_state),
ESP_ELFSYM_EXPORT(tt_thread_start),
ESP_ELFSYM_EXPORT(tt_thread_join),
ESP_ELFSYM_EXPORT(tt_thread_get_task_handle),
ESP_ELFSYM_EXPORT(tt_thread_get_return_code),
ESP_ELFSYM_EXPORT(tt_timer_alloc),
ESP_ELFSYM_EXPORT(tt_timer_free),
ESP_ELFSYM_EXPORT(tt_timer_start),
ESP_ELFSYM_EXPORT(tt_timer_reset),
ESP_ELFSYM_EXPORT(tt_timer_reset_with_interval),
ESP_ELFSYM_EXPORT(tt_timer_stop),
ESP_ELFSYM_EXPORT(tt_timer_is_running),
ESP_ELFSYM_EXPORT(tt_timer_get_expiry_time),
ESP_ELFSYM_EXPORT(tt_timer_set_pending_callback),
ESP_ELFSYM_EXPORT(tt_timer_set_thread_priority),
ESP_ELFSYM_EXPORT(tt_timezone_set),
ESP_ELFSYM_EXPORT(tt_timezone_get_name),
ESP_ELFSYM_EXPORT(tt_timezone_get_code),

View File

@ -8,27 +8,12 @@
extern "C" {
LockHandle tt_lock_alloc_mutex(TtMutexType type) {
auto* lock_holder = new LockHolder();
switch (type) {
case MutexTypeNormal:
lock_holder->lock = std::make_shared<tt::Mutex>();
break;
case MutexTypeRecursive:
lock_holder->lock = std::make_shared<tt::RecursiveMutex>();
break;
default:
tt_crash("Type not supported");
}
return lock_holder;
}
LockHandle tt_lock_alloc_for_path(const char* path) {
const auto lock = tt::file::getLock(path);
return new LockHolder(lock);
}
bool tt_lock_acquire(LockHandle handle, TickType timeout) {
bool tt_lock_acquire(LockHandle handle, TickType_t timeout) {
return HANDLE_AS_LOCK(handle)->lock(timeout);
}

View File

@ -1,4 +1,3 @@
#include <tt_kernel.h>
#include <Tactility/lvgl/Lvgl.h>
#include <Tactility/lvgl/LvglSync.h>
@ -16,8 +15,8 @@ void tt_lvgl_stop() {
tt::lvgl::stop();
}
void tt_lvgl_lock(TickType timeout) {
tt::lvgl::getSyncLock()->lock(timeout);
bool tt_lvgl_lock(TickType_t timeout) {
return tt::lvgl::getSyncLock()->lock(timeout);
}
void tt_lvgl_unlock() {

View File

@ -1,32 +0,0 @@
#include "tt_message_queue.h"
#include <Tactility/MessageQueue.h>
#define HANDLE_TO_MESSAGE_QUEUE(handle) ((tt::MessageQueue*)(handle))
extern "C" {
MessageQueueHandle tt_message_queue_alloc(uint32_t capacity, uint32_t messageSize) {
return new tt::MessageQueue(capacity, messageSize);
}
void tt_message_queue_free(MessageQueueHandle handle) {
delete HANDLE_TO_MESSAGE_QUEUE(handle);
}
bool tt_message_queue_put(MessageQueueHandle handle, const void* message, TickType_t timeout) {
return HANDLE_TO_MESSAGE_QUEUE(handle)->put(message, timeout);
}
bool tt_message_queue_get(MessageQueueHandle handle, void* message, TickType_t timeout) {
return HANDLE_TO_MESSAGE_QUEUE(handle)->get(message, timeout);
}
uint32_t tt_message_queue_get_count(MessageQueueHandle handle) {
return HANDLE_TO_MESSAGE_QUEUE(handle)->getCount();
}
void tt_message_queue_reset(MessageQueueHandle handle) {
return HANDLE_TO_MESSAGE_QUEUE(handle)->reset();
}
}

View File

@ -1,28 +0,0 @@
#include "tt_semaphore.h"
#include <Tactility/Semaphore.h>
extern "C" {
#define HANDLE_AS_SEMAPHORE(handle) ((tt::Semaphore*)(handle))
SemaphoreHandle tt_semaphore_alloc(uint32_t maxCount, TickType_t initialCount) {
return new tt::Semaphore(maxCount, initialCount);
}
void tt_semaphore_free(SemaphoreHandle handle) {
delete HANDLE_AS_SEMAPHORE(handle);
}
bool tt_semaphore_acquire(SemaphoreHandle handle, TickType_t timeoutTicks) {
return HANDLE_AS_SEMAPHORE(handle)->acquire(timeoutTicks);
}
bool tt_semaphore_release(SemaphoreHandle handle) {
return HANDLE_AS_SEMAPHORE(handle)->release();
}
uint32_t tt_semaphore_get_count(SemaphoreHandle handle) {
return HANDLE_AS_SEMAPHORE(handle)->getAvailable();
}
}

View File

@ -1,77 +0,0 @@
#include "tt_thread.h"
#include <Tactility/Thread.h>
extern "C" {
#define HANDLE_AS_THREAD(handle) ((tt::Thread*)(handle))
ThreadHandle tt_thread_alloc() {
return new tt::Thread();
}
ThreadHandle tt_thread_alloc_ext(
const char* name,
uint32_t stackSize,
ThreadCallback callback,
void* _Nullable callbackContext
) {
return new tt::Thread(
name,
stackSize,
[callback, callbackContext] {
return callback(callbackContext);
}
);
}
void tt_thread_free(ThreadHandle handle) {
delete HANDLE_AS_THREAD(handle);
}
void tt_thread_set_name(ThreadHandle handle, const char* name) {
HANDLE_AS_THREAD(handle)->setName(name);
}
void tt_thread_set_stack_size(ThreadHandle handle, size_t size) {
HANDLE_AS_THREAD(handle)->setStackSize(size);
}
void tt_thread_set_affinity(ThreadHandle handle, int affinity) {
HANDLE_AS_THREAD(handle)->setAffinity(affinity);
}
void tt_thread_set_callback(ThreadHandle handle, ThreadCallback callback, void* _Nullable callbackContext) {
HANDLE_AS_THREAD(handle)->setMainFunction([callback, callbackContext]() {
return callback(callbackContext);
});
}
void tt_thread_set_priority(ThreadHandle handle, ThreadPriority priority) {
HANDLE_AS_THREAD(handle)->setPriority((tt::Thread::Priority)priority);
}
void tt_thread_set_state_callback(ThreadHandle handle, ThreadStateCallback callback, void* _Nullable callbackContext) {
HANDLE_AS_THREAD(handle)->setStateCallback((tt::Thread::StateCallback)callback, callbackContext);
}
ThreadState tt_thread_get_state(ThreadHandle handle) {
return (ThreadState)HANDLE_AS_THREAD(handle)->getState();
}
void tt_thread_start(ThreadHandle handle) {
HANDLE_AS_THREAD(handle)->start();
}
bool tt_thread_join(ThreadHandle handle, TickType_t timeout) {
return HANDLE_AS_THREAD(handle)->join(timeout);
}
TaskHandle tt_thread_get_task_handle(ThreadHandle handle) {
return HANDLE_AS_THREAD(handle)->getTaskHandle();
}
int32_t tt_thread_get_return_code(ThreadHandle handle) {
return HANDLE_AS_THREAD(handle)->getReturnCode();
}
}

View File

@ -1,61 +0,0 @@
#include "tt_timer.h"
#include <Tactility/Timer.h>
struct TimerWrapper {
std::unique_ptr<tt::Timer> timer;
};
#define HANDLE_TO_WRAPPER(handle) static_cast<TimerWrapper*>(handle)
extern "C" {
TimerHandle tt_timer_alloc(TimerType type, TickType ticks, TimerCallback callback, void* callbackContext) {
auto wrapper = new TimerWrapper;
wrapper->timer = std::make_unique<tt::Timer>(static_cast<tt::Timer::Type>(type), ticks, [callback, callbackContext](){ callback(callbackContext); });
return wrapper;
}
void tt_timer_free(TimerHandle handle) {
auto* wrapper = static_cast<TimerWrapper*>(handle);
wrapper->timer = nullptr;
delete wrapper;
}
bool tt_timer_start(TimerHandle handle) {
return HANDLE_TO_WRAPPER(handle)->timer->start();
}
bool tt_timer_reset(TimerHandle handle) {
return HANDLE_TO_WRAPPER(handle)->timer->reset();
}
bool tt_timer_reset_with_interval(TimerHandle handle, TickType interval) {
return HANDLE_TO_WRAPPER(handle)->timer->reset(interval);
}
bool tt_timer_stop(TimerHandle handle) {
return HANDLE_TO_WRAPPER(handle)->timer->stop();
}
bool tt_timer_is_running(TimerHandle handle) {
return HANDLE_TO_WRAPPER(handle)->timer->isRunning();
}
uint32_t tt_timer_get_expiry_time(TimerHandle handle) {
return HANDLE_TO_WRAPPER(handle)->timer->getExpiryTime();
}
bool tt_timer_set_pending_callback(TimerHandle handle, TimerPendingCallback callback, void* callbackContext, uint32_t callbackArg, TickType_t timeoutTicks) {
return HANDLE_TO_WRAPPER(handle)->timer->setPendingCallback(
callback,
callbackContext,
callbackArg,
timeoutTicks
);
}
void tt_timer_set_thread_priority(TimerHandle handle, ThreadPriority priority) {
HANDLE_TO_WRAPPER(handle)->timer->setCallbackPriority(static_cast<tt::Thread::Priority>(priority));
}
}