Implement UI scaling and more (#501)

**New Features**
 * Runtime font accessors and new symbol fonts for text, launcher, statusbar, and shared icons.
 * Added font height base setting to device.properties
 * Text fonts now have 3 sizes: small, default, large

**Improvements**
 * Renamed `UiScale` to `UiDensity`
 * Statusbar, toolbar and many UI components now compute heights and spacing from fonts/density.
 * SSD1306 initialization sequence refined for more stable startup.
 * Multiple image assets replaced by symbol-font rendering.
 * Many layout improvements related to density, font scaling and icon scaling
 * Updated folder name capitalization for newer style
This commit is contained in:
Ken Van Hoeylandt
2026-02-15 01:41:47 +01:00
committed by GitHub
parent 72c9b2b113
commit 9a11e6f47b
264 changed files with 5923 additions and 494 deletions
@@ -0,0 +1,78 @@
// SPDX-License-Identifier: Apache-2.0
/**
* Dispatcher is a thread-safe code execution queue.
*/
#pragma once
#include <tactility/freertos/freertos.h>
#include <tactility/error.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef void (*DispatcherCallback)(void* context);
typedef void* DispatcherHandle_t;
DispatcherHandle_t dispatcher_alloc(void);
void dispatcher_free(DispatcherHandle_t dispatcher);
/**
* Queue a function to be consumed elsewhere.
*
* @param[in] callbackContext the data to pass to the function upon execution
* @param[in] callback the function to execute elsewhere
* @param[in] timeout lock acquisition timeout
* @retval ERROR_TIMEOUT
* @retval ERROR_RESOURCE when failing to set event
* @retval ERROR_INVALID_STATE when the dispatcher is in the process of shutting down
* @retval ERROR_NONE
*/
error_t dispatcher_dispatch_timed(DispatcherHandle_t dispatcher, void* callbackContext, DispatcherCallback callback, TickType_t timeout);
/**
* Queue a function to be consumed elsewhere.
*
* @param[in] callbackContext the data to pass to the function upon execution
* @param[in] callback the function to execute elsewhere
* @retval ERROR_RESOURCE when failing to set event
* @retval ERROR_TIMEOUT unlikely to occur unless there's an issue with the internal mutex
* @retval ERROR_INVALID_STATE when the dispatcher is in the process of shutting down
* @retval ERROR_NONE
*/
static inline error_t dispatcher_dispatch(DispatcherHandle_t dispatcher, void* callbackContext, DispatcherCallback callback) {
return dispatcher_dispatch_timed(dispatcher, callbackContext, callback, portMAX_DELAY);
}
/**
* Consume 1 or more dispatched functions (if any) until the queue is empty.
*
* @warning The timeout is only the wait time before consuming the message! It is not a limit to the total execution time when calling this method.
*
* @param[in] timeout the ticks to wait for a message
* @retval ERROR_TIMEOUT
* @retval ERROR_RESOURCE failed to wait for event
* @retval ERROR_INVALID_STATE when the dispatcher is in the process of shutting down
* @retval ERROR_NONE
*/
error_t dispatcher_consume_timed(DispatcherHandle_t dispatcher, TickType_t timeout);
/**
* Consume 1 or more dispatched functions (if any) until the queue is empty.
*
* @warning The timeout is only the wait time before consuming the message! It is not a limit to the total execution time when calling this method.
*
* @retval ERROR_TIMEOUT unlikely to occur unless there's an issue with the internal mutex
* @retval ERROR_RESOURCE failed to wait for event
* @retval ERROR_INVALID_STATE when the dispatcher is in the process of shutting down
* @retval ERROR_NONE
*/
static inline error_t dispatcher_consume(DispatcherHandle_t dispatcher) {
return dispatcher_consume_timed(dispatcher, portMAX_DELAY);
}
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,78 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stdint.h>
#include <tactility/freertos/event_groups.h>
#include <tactility/check.h>
#include <tactility/error.h>
static inline void event_group_construct(EventGroupHandle_t* eventGroup) {
check(xPortInIsrContext() == pdFALSE);
*eventGroup = xEventGroupCreate();
}
static inline void event_group_destruct(EventGroupHandle_t* eventGroup) {
check(xPortInIsrContext() == pdFALSE);
check(*eventGroup != NULL);
vEventGroupDelete(*eventGroup);
*eventGroup = NULL;
}
/**
* Set the flags.
*
* @param[in] eventGroup the event group
* @param[in] flags the flags to set
* @retval ERROR_RESOURCE when setting failed
* @retval ERROR_NONE
*/
error_t event_group_set(EventGroupHandle_t eventGroup, uint32_t flags);
/**
* Clear flags
*
* @param[in] eventGroup the event group
* @param[in] flags the flags to clear
* @retval ERROR_RESOURCE when clearing failed
* @retval ERROR_NONE
*/
error_t event_group_clear(EventGroupHandle_t eventGroup, uint32_t flags);
/**
* @param[in] eventGroup the event group
* @return the bitset (always succeeds)
*/
uint32_t event_group_get(EventGroupHandle_t eventGroup);
/**
* Wait for flags to be set
*
* @param[in] eventGroup the event group
* @param[in] inFlags the flags to await
* @param[in] awaitAll If true, await for all bits to be set. Otherwise, await for any.
* @param[in] clearOnExit If true, clears all the bits on exit, otherwise don't clear.
* @param[out] outFlags If set to non-NULL value, this will hold the resulting flags. Only set when return value is ERROR_NONE
* @param[in] timeout the maximum amount of ticks to wait for flags to be set
* @retval ERROR_ISR_STATUS when the function was called from an ISR context
* @retval ERROR_TIMEOUT
* @retval ERROR_RESOURCE when flags were triggered, but not in a way that was expected (e.g. waiting for all flags, but was only partially set)
* @retval ERROR_NONE
*/
error_t event_group_wait(
EventGroupHandle_t eventGroup,
uint32_t inFlags,
bool awaitAll,
bool clearOnExit,
uint32_t* outFlags,
TickType_t timeout
);
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,55 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <assert.h>
#include <stdbool.h>
#include <tactility/freertos/semphr.h>
#include <tactility/check.h>
#ifdef __cplusplus
extern "C" {
#endif
struct Mutex {
QueueHandle_t handle;
// TODO: Debugging functionality
};
inline static void mutex_construct(struct Mutex* mutex) {
mutex->handle = xSemaphoreCreateMutex();
}
inline static void mutex_destruct(struct Mutex* mutex) {
vPortAssertIfInISR();
vSemaphoreDelete(mutex->handle);
mutex->handle = NULL;
}
inline static void mutex_lock(struct Mutex* mutex) {
check(xPortInIsrContext() != pdTRUE);
xSemaphoreTake(mutex->handle, portMAX_DELAY);
}
inline static bool mutex_try_lock(struct Mutex* mutex, TickType_t timeout) {
check(xPortInIsrContext() != pdTRUE);
return xSemaphoreTake(mutex->handle, timeout) == pdTRUE;
}
inline static bool mutex_is_locked(struct Mutex* mutex) {
if (xPortInIsrContext() == pdTRUE) {
return xSemaphoreGetMutexHolderFromISR(mutex->handle) != NULL;
} else {
return xSemaphoreGetMutexHolder(mutex->handle) != NULL;
}
}
inline static void mutex_unlock(struct Mutex* mutex) {
check(xPortInIsrContext() != pdTRUE);
xSemaphoreGive(mutex->handle);
}
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,53 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <tactility/freertos/semphr.h>
#include <tactility/check.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
struct RecursiveMutex {
QueueHandle_t handle;
// TODO: Debugging functionality
};
inline static void recursive_mutex_construct(struct RecursiveMutex* mutex) {
mutex->handle = xSemaphoreCreateRecursiveMutex();
}
inline static void recursive_mutex_destruct(struct RecursiveMutex* mutex) {
check(xPortInIsrContext() != pdTRUE);
vSemaphoreDelete(mutex->handle);
mutex->handle = NULL;
}
inline static void recursive_mutex_lock(struct RecursiveMutex* mutex) {
check(xPortInIsrContext() != pdTRUE);
xSemaphoreTakeRecursive(mutex->handle, portMAX_DELAY);
}
inline static bool recursive_mutex_is_locked(struct RecursiveMutex* mutex) {
if (xPortInIsrContext() == pdTRUE) {
return xSemaphoreGetMutexHolderFromISR(mutex->handle) != NULL;
} else {
return xSemaphoreGetMutexHolder(mutex->handle) != NULL;
}
}
inline static bool recursive_mutex_try_lock(struct RecursiveMutex* mutex, TickType_t timeout) {
check(xPortInIsrContext() != pdTRUE);
return xSemaphoreTakeRecursive(mutex->handle, timeout) == pdTRUE;
}
inline static void recursive_mutex_unlock(struct RecursiveMutex* mutex) {
check(xPortInIsrContext() != pdTRUE);
xSemaphoreGiveRecursive(mutex->handle);
}
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,182 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "tactility/error.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef ESP_PLATFORM
#include <esp_log.h>
#endif
#include <tactility/freertos/task.h>
#include <tactility/concurrent/mutex.h>
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
typedef enum {
THREAD_STATE_STOPPED,
THREAD_STATE_STARTING,
THREAD_STATE_RUNNING,
} ThreadState;
/** ThreadPriority */
enum ThreadPriority {
THREAD_PRIORITY_NONE = 0U,
THREAD_PRIORITY_IDLE = 1U,
THREAD_PRIORITY_LOWER = 2U,
THREAD_PRIORITY_LOW = 3U,
THREAD_PRIORITY_NORMAL = 4U,
THREAD_PRIORITY_HIGH = 5U,
THREAD_PRIORITY_HIGHER = 6U,
THREAD_PRIORITY_CRITICAL = 7U
};
typedef int32_t (*thread_main_fn_t)(void* context);
typedef void (*thread_state_callback_t)(ThreadState state, void* context);
struct Thread;
typedef struct Thread Thread;
/**
* @brief Creates a new thread instance with default settings.
* @return A pointer to the created Thread instance, or NULL if allocation failed.
*/
Thread* thread_alloc(void);
/**
* @brief Creates a new thread instance with specified parameters.
* @param[in] name The name of the thread.
* @param[in] stack_size The size of the thread stack in bytes.
* @param[in] function The main function to be executed by the thread.
* @param[in] function_context A pointer to the context to be passed to the main function.
* @param[in] affinity The CPU core affinity for the thread (e.g., tskNO_AFFINITY).
* @return A pointer to the created Thread instance, or NULL if allocation failed.
*/
Thread* thread_alloc_full(
const char* name,
configSTACK_DEPTH_TYPE stack_size,
thread_main_fn_t function,
void* function_context,
portBASE_TYPE affinity
);
/**
* @brief Destroys a thread instance.
* @param[in] thread The thread instance to destroy.
* @note The thread must be in the STOPPED state.
*/
void thread_free(Thread* thread);
/**
* @brief Sets the name of the thread.
* @param[in] thread The thread instance.
* @param[in] name The new name for the thread.
* @note Can only be called when the thread is in the STOPPED state.
*/
void thread_set_name(Thread* thread, const char* name);
/**
* @brief Sets the stack size for the thread.
* @param[in] thread The thread instance.
* @param[in] stack_size The stack size in bytes. Must be a multiple of 4.
* @note Can only be called when the thread is in the STOPPED state.
*/
void thread_set_stack_size(Thread* thread, size_t stack_size);
/**
* @brief Sets the CPU core affinity for the thread.
* @param[in] thread The thread instance.
* @param[in] affinity The CPU core affinity.
* @note Can only be called when the thread is in the STOPPED state.
*/
void thread_set_affinity(Thread* thread, portBASE_TYPE affinity);
/**
* @brief Sets the main function and context for the thread.
* @param[in] thread The thread instance.
* @param[in] function The main function to be executed.
* @param[in] context A pointer to the context to be passed to the main function.
* @note Can only be called when the thread is in the STOPPED state.
*/
void thread_set_main_function(Thread* thread, thread_main_fn_t function, void* context);
/**
* @brief Sets the priority for the thread.
* @param[in] thread The thread instance.
* @param[in] priority The thread priority.
* @note Can only be called when the thread is in the STOPPED state.
*/
void thread_set_priority(Thread* thread, enum ThreadPriority priority);
/**
* @brief Sets a callback to be invoked when the thread state changes.
* @param[in] thread The thread instance.
* @param[in] callback The callback function.
* @param[in] context A pointer to the context to be passed to the callback function.
* @note Can only be called when the thread is in the STOPPED state.
*/
void thread_set_state_callback(Thread* thread, thread_state_callback_t callback, void* context);
/**
* @brief Gets the current state of the thread.
* @param[in] thread The thread instance.
* @return The current ThreadState.
*/
ThreadState thread_get_state(Thread* thread);
/**
* @brief Starts the thread execution.
* @param[in] thread The thread instance.
* @note The thread must be in the STOPPED state and have a main function set.
* @retval ERROR_NONE when the thread was started
* @retval ERROR_UNDEFINED when the thread failed to start
*/
error_t thread_start(Thread* thread);
/**
* @brief Waits for the thread to finish execution.
* @param[in] thread The thread instance.
* @param[in] timeout The maximum time to wait in ticks.
* @param[in] poll_interval The interval between status checks in ticks.
* @retval ERROR_NONE when the thread was stopped
* @retval ERROR_TIMEOUT when the thread was not stopped because the timeout has passed
* @note Cannot be called from the thread being joined.
*/
error_t thread_join(Thread* thread, TickType_t timeout, TickType_t poll_interval);
/**
* @brief Gets the FreeRTOS task handle associated with the thread.
* @param[in] thread The thread instance.
* @return The TaskHandle_t, or NULL if the thread is not running.
*/
TaskHandle_t thread_get_task_handle(Thread* thread);
/**
* @brief Gets the return code from the thread's main function.
* @param[in] thread The thread instance.
* @return The return code of the thread's main function.
* @note The thread must be in the STOPPED state.
*/
int32_t thread_get_return_code(Thread* thread);
/**
* @brief Gets the minimum remaining stack space for the thread since it started.
* @param[in] thread The thread instance.
* @return The minimum remaining stack space in bytes.
* @note The thread must be in the RUNNING state.
*/
uint32_t thread_get_stack_space(Thread* thread);
/**
* @brief Gets the current thread instance.
* @return A pointer to the current Thread instance, or NULL if not called from a thread created by this module.
*/
Thread* thread_get_current(void);
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,104 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "tactility/error.h"
#include "tactility/freertos/timers.h"
#include "tactility/concurrent/thread.h"
#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
enum TimerType {
TIMER_TYPE_ONCE = 0, // Timer triggers once after time has passed
TIMER_TYPE_PERIODIC = 1 // Timer triggers repeatedly after time has passed
};
typedef void (*timer_callback_t)(void* context);
typedef void (*timer_pending_callback_t)(void* context, uint32_t arg);
struct Timer;
/**
* @brief Creates a new timer instance.
* @param[in] type The timer type.
* @param[in] ticks The timer period in ticks.
* @param[in] callback The callback function.
* @param[in] context The context to pass to the callback function.
* @return A pointer to the created timer instance, or NULL if allocation failed.
*/
struct Timer* timer_alloc(enum TimerType type, TickType_t ticks, timer_callback_t callback, void* context);
/**
* @brief Destroys a timer instance.
* @param[in] timer The timer instance to destroy.
*/
void timer_free(struct Timer* timer);
/**
* @brief Starts the timer.
* @param[in] timer The timer instance.
* @return ERROR_NONE on success, ERROR_TIMEOUT if the command queue was full.
*/
error_t timer_start(struct Timer* timer);
/**
* @brief Stops the timer.
* @param[in] timer The timer instance.
* @return ERROR_NONE on success, ERROR_TIMEOUT if the command queue was full.
*/
error_t timer_stop(struct Timer* timer);
/**
* @brief Set a new interval and reset the timer.
* @param[in] timer The timer instance.
* @param[in] interval The new timer interval in ticks.
* @return ERROR_NONE on success, ERROR_TIMEOUT if the command queue was full.
*/
error_t timer_reset_with_interval(struct Timer* timer, TickType_t interval);
/**
* @brief Reset the timer.
* @param[in] timer The timer instance.
* @return ERROR_NONE on success, ERROR_TIMEOUT if the command queue was full.
*/
error_t timer_reset(struct Timer* timer);
/**
* @brief Check if the timer is running.
* @param[in] timer The timer instance.
* @return true when the timer is running.
*/
bool timer_is_running(struct Timer* timer);
/**
* @brief Gets the expiry time of the timer.
* @param[in] timer The timer instance.
* @return The expiry time in ticks.
*/
TickType_t timer_get_expiry_time(struct Timer* timer);
/**
* @brief Calls xTimerPendFunctionCall internally.
* @param[in] timer The timer instance.
* @param[in] callback the function to call
* @param[in] context the first function argument
* @param[in] arg the second function argument
* @param[in] timeout the function timeout (must set to 0 in ISR mode)
* @return ERROR_NONE on success, ERROR_TIMEOUT if the command queue was full.
*/
error_t timer_set_pending_callback(struct Timer* timer, timer_pending_callback_t callback, void* context, uint32_t arg, TickType_t timeout);
/**
* @brief Set callback priority (priority of the timer daemon task).
* @param[in] timer The timer instance.
* @param[in] priority The priority.
*/
void timer_set_callback_priority(struct Timer* timer, enum ThreadPriority priority);
#ifdef __cplusplus
}
#endif