Project restructuring (fixes macOS builds) (#198)
- Create `Include/` folder for all main projects - Fix some issues here and there (found while moving things) - All includes are now in `Tactility/` subfolder and must be included with that prefix. This fixes issues with clashing POSIX headers (e.g. `<semaphore.h>` versus Tactility's `Semaphore.h`)
This commit is contained in:
committed by
GitHub
parent
7856827ecf
commit
c87200a80d
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include "tt_app_manifest.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void* AppHandle;
|
||||
|
||||
/** @return the bundle that belongs to this application, or null if it wasn't started with parameters. */
|
||||
BundleHandle _Nullable tt_app_get_parameters(AppHandle handle);
|
||||
|
||||
/**
|
||||
* Set the result before closing an app.
|
||||
* The result and bundle are passed along to the app that launched this app, when this app is closed.
|
||||
* @param[in] handle the app context handle to set the result for
|
||||
* @param[in] result the result state to set
|
||||
* @param[in] bundle the result bundle to set
|
||||
*/
|
||||
void tt_app_set_result(AppHandle handle, Result result, BundleHandle _Nullable bundle);
|
||||
|
||||
/** @return true if a result was set for this app context */
|
||||
bool tt_app_has_result(AppHandle handle);
|
||||
|
||||
/**
|
||||
* Start an app by id.
|
||||
* @param[in] appId the app manifest id
|
||||
*/
|
||||
void tt_app_start(const char* appId);
|
||||
|
||||
/**
|
||||
* Start an app by id and bundle.
|
||||
* @param[in] appId the app manifest id
|
||||
* @param[in] parameters the parameters to pass onto the starting app
|
||||
*/
|
||||
void tt_app_start_with_bundle(const char* appId, BundleHandle parameters);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "tt_bundle.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* Show a dialog with the provided title, message and 0, 1 or more buttons.
|
||||
* @param[in] title the title to show in the toolbar
|
||||
* @param[in] message the message to display
|
||||
* @param[in] buttonLabels the buttons to show, or null when there are none to show
|
||||
* @param[in] buttonLabelCount the amount of buttons (0 or more)
|
||||
*/
|
||||
void tt_app_alertdialog_start(const char* title, const char* message, const char* buttonLabels[], uint32_t buttonLabelCount);
|
||||
|
||||
/**
|
||||
* @return the index of the button that was clicked (the index in the array when start() was called)
|
||||
*/
|
||||
int32_t tt_app_alertdialog_get_result_index(BundleHandle handle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include "tt_bundle.h"
|
||||
#include <lvgl.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Important: These values must map to tt::app::Result values exactly */
|
||||
typedef enum {
|
||||
AppResultOk = 0,
|
||||
AppResultCancelled = 1,
|
||||
AppResultError = 2
|
||||
} Result;
|
||||
|
||||
typedef void* AppHandle;
|
||||
|
||||
/** Important: These function types must map to t::app types exactly */
|
||||
typedef void* (*AppCreateData)();
|
||||
typedef void (*AppDestroyData)(void* data);
|
||||
typedef void (*AppOnCreate)(AppHandle app, void* _Nullable data);
|
||||
typedef void (*AppOnDestroy)(AppHandle app, void* _Nullable data);
|
||||
typedef void (*AppOnShow)(AppHandle app, void* _Nullable data, lv_obj_t* parent);
|
||||
typedef void (*AppOnHide)(AppHandle app, void* _Nullable data);
|
||||
typedef void (*AppOnResult)(AppHandle app, void* _Nullable data, Result result, BundleHandle resultData);
|
||||
|
||||
typedef struct {
|
||||
/** The application's human-readable name */
|
||||
const char* name;
|
||||
/** The application icon (you can use LV_SYMBOL_* too) */
|
||||
const char* _Nullable icon;
|
||||
/** The application can allocate data to re-use later (e.g. struct with state) */
|
||||
AppCreateData _Nullable createData;
|
||||
/** If createData is specified, this one must be specified too */
|
||||
AppDestroyData _Nullable destroyData;
|
||||
/** Called when the app is launched (started) */
|
||||
AppOnCreate _Nullable onCreate;
|
||||
/** Called when the app is exited (stopped) */
|
||||
AppOnDestroy _Nullable onDestroy;
|
||||
/** Called when the app is about to be shown to the user (app becomes visible) */
|
||||
AppOnShow _Nullable onShow;
|
||||
/** Called when the app is about to be invisible to the user (e.g. other app was launched by this app, and this app goes to the background) */
|
||||
AppOnHide _Nullable onHide;
|
||||
/** Called when the app receives a result after launching another app */
|
||||
AppOnResult _Nullable onResult;
|
||||
} ExternalAppManifest;
|
||||
|
||||
/** This is used to register the manifest of an external app. */
|
||||
void tt_app_register(const ExternalAppManifest* manifest);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include "tt_bundle.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Start an app that displays a list of items and allows the user to select one.
|
||||
* @param[in] title the title to show in the toolbar
|
||||
* @param[in] argc the amount of items that the list contains
|
||||
* @param[in] argv the labels of the items in the list
|
||||
*/
|
||||
void tt_app_selectiondialog_start(const char* title, int argc, const char* argv[]);
|
||||
|
||||
/** @return the index of the item that was clicked by the user, or -1 when the user didn't select anything */
|
||||
int32_t tt_app_selectiondialog_get_result_index(BundleHandle handle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,74 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/** The handle that represents a bundle instance */
|
||||
typedef void* BundleHandle;
|
||||
|
||||
/** @return a new bundle instance */
|
||||
BundleHandle tt_bundle_alloc();
|
||||
|
||||
/** Dealloc an existing bundle instance */
|
||||
void tt_bundle_free(BundleHandle handle);
|
||||
|
||||
/**
|
||||
* Try to get a boolean value from a Bundle
|
||||
* @param[in] handle the handle that represents the bundle
|
||||
* @param[in] key the identifier that represents the stored value (~variable name)
|
||||
* @param[out] out the output value (only set when return value is set to true)
|
||||
* @return true if "out" was set
|
||||
*/
|
||||
bool tt_bundle_opt_bool(BundleHandle handle, const char* key, bool* out);
|
||||
|
||||
/**
|
||||
* Try to get an int32_t value from a Bundle
|
||||
* @param[in] handle the handle that represents the bundle
|
||||
* @param[in] key the identifier that represents the stored value (~variable name)
|
||||
* @param[out] out the output value (only set when return value is set to true)
|
||||
* @return true if "out" was set
|
||||
*/
|
||||
bool tt_bundle_opt_int32(BundleHandle handle, const char* key, int32_t* out);
|
||||
|
||||
/**
|
||||
* Try to get a string from a Bundle
|
||||
* @warning outSize must be large enough to include null terminator. This means that your string has to be the expected text length + 1 extra character.
|
||||
* @param[in] handle the handle that represents the bundle
|
||||
* @param[in] key the identifier that represents the stored value (~variable name)
|
||||
* @param[out] out the buffer to store the string in
|
||||
* @param[in] outSize the size of the buffer
|
||||
* @return true if "out" was set
|
||||
*/
|
||||
bool tt_bundle_opt_string(BundleHandle handle, const char* key, char* out, uint32_t outSize);
|
||||
|
||||
/**
|
||||
* Store a boolean value in a Bundle
|
||||
* @param[in] handle the handle that represents the bundle
|
||||
* @param[in] key the identifier that represents the stored value (~variable name)
|
||||
* @param[in] value the value to store
|
||||
*/
|
||||
void tt_bundle_put_bool(BundleHandle handle, const char* key, bool value);
|
||||
|
||||
/**
|
||||
* Store an int32_t value in a Bundle
|
||||
* @param[in] handle the handle that represents the bundle
|
||||
* @param[in] key the identifier that represents the stored value (~variable name)
|
||||
* @param[in] value the value to store
|
||||
*/
|
||||
void tt_bundle_put_int32(BundleHandle handle, const char* key, int32_t value);
|
||||
|
||||
/**
|
||||
* Store a string value in a Bundle
|
||||
* @param[in] handle the handle that represents the bundle
|
||||
* @param[in] key the identifier that represents the stored value (~variable name)
|
||||
* @param[in] value the value to store
|
||||
*/
|
||||
void tt_bundle_put_string(BundleHandle handle, const char* key, const char* value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,111 @@
|
||||
#pragma once
|
||||
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <hal/i2c_types.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Start I2C communications for the specified port
|
||||
* @param[in] port the I2C port to init
|
||||
* @return true on success
|
||||
*/
|
||||
bool tt_hal_i2c_start(i2c_port_t port);
|
||||
|
||||
/**
|
||||
* Stop I2C communications for the specified port
|
||||
* @param[in] port the I2C port to deinit
|
||||
* @return true on success
|
||||
*/
|
||||
bool tt_hal_i2c_stop(i2c_port_t port);
|
||||
|
||||
/**
|
||||
* Check if the port was successfully started.
|
||||
* @param[in] port the port to check
|
||||
* @return true when the port was successfully started
|
||||
*/
|
||||
bool tt_hal_i2c_is_started(i2c_port_t port);
|
||||
|
||||
/**
|
||||
* Read from an I2C port in master mode.
|
||||
* @param[in] port the I2C port to read from
|
||||
* @param[in] address
|
||||
* @param[in] data
|
||||
* @param[in] dataSize
|
||||
* @param[in] timeout
|
||||
*/
|
||||
bool tt_hal_i2c_master_read(i2c_port_t port, uint8_t address, uint8_t* data, size_t dataSize, TickType_t timeout);
|
||||
|
||||
/**
|
||||
* Read a register from an I2C port in master mode.
|
||||
* @param[in] port the I2C port to read from
|
||||
* @param[in] address
|
||||
* @param[in] reg
|
||||
* @param[in] data
|
||||
* @param[in] dataSize
|
||||
* @param[in] timeout
|
||||
*/
|
||||
bool tt_hal_i2c_master_read_register(i2c_port_t port, uint8_t address, uint8_t reg, uint8_t* data, size_t dataSize, TickType_t timeout);
|
||||
|
||||
/**
|
||||
* Write to an I2C port in master mode.
|
||||
* @param[in] port the I2C port to write to
|
||||
* @param[in] address
|
||||
* @param[in] data
|
||||
* @param[in] dataSize
|
||||
* @param[in] timeout
|
||||
*/
|
||||
bool tt_hal_i2c_master_write(i2c_port_t port, uint8_t address, const uint8_t* data, uint16_t dataSize, TickType_t timeout);
|
||||
|
||||
/**
|
||||
* Write to a register of an I2C port in master mode.
|
||||
* @param[in] port the I2C port to write to
|
||||
* @param[in] address
|
||||
* @param[in] reg
|
||||
* @param[in] data
|
||||
* @param[in] dataSize
|
||||
* @param[in] timeout
|
||||
*/
|
||||
bool tt_hal_i2c_master_write_register(i2c_port_t port, uint8_t address, uint8_t reg, const uint8_t* data, uint16_t dataSize, TickType_t timeout);
|
||||
|
||||
/**
|
||||
* Write then read from an I2C port in master mode.
|
||||
* @param[in] port the I2C port to communicate with
|
||||
* @param[in] address
|
||||
* @param[in] writeData
|
||||
* @param[in] writeDataSize
|
||||
* @param[in] readData
|
||||
* @param[in] readDataSize
|
||||
* @param[in] timeout
|
||||
*/
|
||||
bool tt_hal_i2c_master_write_read(i2c_port_t port, uint8_t address, const uint8_t* writeData, size_t writeDataSize, uint8_t* readData, size_t readDataSize, TickType_t timeout);
|
||||
|
||||
/**
|
||||
* Check if an I2C port has a device at the specified address.
|
||||
* @param[in] port the I2C port to communicate with
|
||||
* @param[in] address
|
||||
* @param[in] timeout
|
||||
*/
|
||||
bool tt_hal_i2c_master_has_device_at_address(i2c_port_t port, uint8_t address, TickType_t timeout);
|
||||
|
||||
/**
|
||||
* Used to lock an I2C port.
|
||||
* This is useful for creating thread-safe I2C calls while calling ESP-IDF directly of third party I2C APIs.
|
||||
* @param[in] port the I2C port to lock
|
||||
* @param[in] timeout
|
||||
*/
|
||||
bool tt_hal_i2c_lock(i2c_port_t port, TickType_t timeout);
|
||||
|
||||
/**
|
||||
* Used to unlock an I2C port.
|
||||
* This is useful for creating thread-safe I2C calls while calling ESP-IDF directly of third party I2C APIs.
|
||||
* @param[in] port the I2C port to unlock
|
||||
*/
|
||||
bool tt_hal_i2c_unlock(i2c_port_t port);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Initialization method for TactilityC
|
||||
* @warning This is called from the main firmware. Don't call this from an external app!
|
||||
*/
|
||||
void tt_init_tactility_c();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <lvgl.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Create a spinner widget. */
|
||||
lv_obj_t* tt_lvgl_spinner_create(lv_obj_t* parent);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "tt_app.h"
|
||||
#include <lvgl.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Create a toolbar widget that shows the app name as title */
|
||||
lv_obj_t* tt_lvgl_toolbar_create(lv_obj_t* parent, AppHandle context);
|
||||
|
||||
/** Create a toolbar widget with the provided title*/
|
||||
lv_obj_t* tt_lvgl_toolbar_create_simple(lv_obj_t* parent, const char* title);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#include <freertos/FreeRTOS.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 total amount of messages that this queue can hold */
|
||||
uint32_t tt_message_queue_get_capacity(MessageQueueHandle handle);
|
||||
|
||||
/** @return the size of a single message in the queue */
|
||||
uint32_t tt_message_queue_get_message_size(MessageQueueHandle handle);
|
||||
|
||||
/** @return the current amount of items in the queue */
|
||||
uint32_t tt_message_queue_get_count(MessageQueueHandle handle);
|
||||
|
||||
/** @return the remaining capacity in the queue */
|
||||
uint32_t tt_message_queue_get_space(MessageQueueHandle handle);
|
||||
|
||||
/**
|
||||
* Remove all items from the queue (if any)
|
||||
* @return true on failure
|
||||
*/
|
||||
bool tt_message_queue_reset(MessageQueueHandle handle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include <freertos/FreeRTOS.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/** A handle that represents a mutex instance */
|
||||
typedef void* MutexHandle;
|
||||
|
||||
enum TtMutexType {
|
||||
MUTEX_TYPE_NORMAL,
|
||||
MUTEX_TYPE_RECURSIVE
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 instance
|
||||
*/
|
||||
MutexHandle tt_mutex_alloc(enum TtMutexType type);
|
||||
|
||||
/** Free up the memory of the specified mutex instance. */
|
||||
void tt_mutex_free(MutexHandle handle);
|
||||
|
||||
/**
|
||||
* Attempt to lock a mutex.
|
||||
* @param[in] handle the handle that represents the mutex instance
|
||||
* @param[in] timeout the maximum amount of ticks to wait when trying to lock
|
||||
* @return true when the lock was acquired
|
||||
*/
|
||||
bool tt_mutex_lock(MutexHandle handle, TickType_t timeout);
|
||||
|
||||
/**
|
||||
* Attempt to unlock a mutex.
|
||||
* @param[in] handle the handle that represents the mutex instance
|
||||
* @param[in] timeout the maximum amount of ticks to wait when trying to unlock
|
||||
* @return true when the lock was unlocked
|
||||
*/
|
||||
bool tt_mutex_unlock(MutexHandle handle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,50 @@
|
||||
#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
|
||||
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include "tt_app.h"
|
||||
#include "tt_bundle.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Start an application providing a manifest id and an optional bundle.
|
||||
* Execution is always deferred.
|
||||
* This function generally returns immediately unless the scheduler is blocked.
|
||||
* @param[in] id application manifest id
|
||||
* @param[in] bundle an allocated bundle (or NULL) of which the memory ownership is handed over to this function
|
||||
*/
|
||||
void tt_service_loader_start_app(const char* id, BundleHandle _Nullable bundle);
|
||||
|
||||
/**
|
||||
* Stop the currently active app.
|
||||
* Execution is always deferred.
|
||||
* This function generally returns immediately unless the scheduler is blocked.
|
||||
*/
|
||||
void tt_service_loader_stop_app();
|
||||
|
||||
/**
|
||||
* Get the context handle of the app that is currently shown on the screen.
|
||||
*/
|
||||
AppHandle tt_service_loader_get_current_app();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,150 @@
|
||||
#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 ThreadId;
|
||||
|
||||
/** 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 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 EventFlag or boolean+Mutex)
|
||||
*/
|
||||
bool tt_thread_join(ThreadHandle handle, TickType_t timeout);
|
||||
|
||||
/**
|
||||
* Get thread id
|
||||
* @param[in] handle the thread instance handle
|
||||
* @return the ThreadId of a thread
|
||||
* */
|
||||
ThreadId tt_thread_get_id(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
|
||||
@@ -0,0 +1,91 @@
|
||||
#pragma once
|
||||
|
||||
#include "tt_thread.h"
|
||||
#include <freertos/FreeRTOS.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/** The handle that represents a timer instance */
|
||||
typedef void* TimerHandle;
|
||||
|
||||
/** The behaviour of the timer */
|
||||
typedef enum {
|
||||
TimerTypeOnce = 0, ///< One-shot timer.
|
||||
TimerTypePeriodic = 1 ///< Repeating timer.
|
||||
} 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, 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
|
||||
* @parma[in] interval the interval of the timer
|
||||
* @return true when the timer was successfully started
|
||||
*/
|
||||
bool tt_timer_start(TimerHandle handle, TickType_t interval);
|
||||
|
||||
/**
|
||||
* Restart an already started timer
|
||||
* @param[in] handle the timer instance handle
|
||||
* @parma[in] interval the interval of the timer
|
||||
* @return true when the timer was successfully restarted
|
||||
*/
|
||||
bool tt_timer_restart(TimerHandle handle, TickType_t interval);
|
||||
|
||||
/**
|
||||
* 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 expire 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_expire_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
|
||||
Reference in New Issue
Block a user