Merge develop into main (#365)

### TactilityC
- Create UART HAL
- Refactor locking APIs
- Bind new C++ functionality
- Bind new LVGL functionality

### Apps
- Remove Serial Console as it has been ported as an external app
This commit is contained in:
Ken Van Hoeylandt
2025-10-08 23:16:45 +02:00
committed by GitHub
parent 17b4fc6a47
commit d25603166a
26 changed files with 391 additions and 702 deletions
-13
View File
@@ -1,13 +0,0 @@
#pragma once
#include "tt_lock.h"
#ifdef __cplusplus
extern "C" {
#endif
LockHandle tt_lock_alloc_for_file(const char* path);
#ifdef __cplusplus
}
#endif
+152
View File
@@ -0,0 +1,152 @@
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include <tt_kernel.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @file tt_hal_uart.h
* @brief C HAL interface for UART devices used by Tactility C modules.
*
* This header exposes a minimal, C-compatible UART API that mirrors the higher-level
* C++ UART interface (see Tactility/hal/uart).
*
* General notes:
* - Start the UART before I/O using tt_hal_uart_start(); stop it with tt_hal_uart_stop().
*/
typedef void* UartHandle; /**< Opaque handle to an underlying UART instance. */
/**
* @brief Get the number of UART devices available on this platform.
* @return Count of discoverable UARTs (0 if none).
*/
size_t tt_hal_uart_get_count();
/**
* @brief Get the user-friendly name of a UART by index.
* @param index Zero-based UART index in the range [0, tt_hal_uart_get_count()).
* @param[out] name Destination buffer to receive a null-terminated name.
* @param nameSizeLimit Size in bytes of the destination buffer. The name will be
* truncated to fit and always null-terminated if the size
* is greater than 0.
* @return true if a name was written to the buffer; false if the index is out of range
* or on other failure.
*/
bool tt_hal_uart_get_name(size_t index, char* name, size_t nameSizeLimit);
/**
* @brief Allocate an opaque UART handle by index.
*
* Allocation does not start the hardware; call tt_hal_uart_start() to begin I/O.
*
* @param index Zero-based UART index.
* @return A valid UartHandle on success; NULL on failure (e.g., invalid index or already in use).
*/
UartHandle tt_hal_uart_alloc(size_t index);
/**
* @brief Release a previously allocated UART handle and any associated resources.
* @param handle Handle returned by tt_hal_uart_alloc()
*/
void tt_hal_uart_free(UartHandle handle);
/**
* @brief Start the UART so it can perform I/O.
* @param handle A valid UART handle.
* @return true on success; false on failure.
*/
bool tt_hal_uart_start(UartHandle handle);
/**
* @brief Query whether the UART has been started.
* @param handle A valid UART handle.
* @return true if started; false otherwise.
*/
bool tt_hal_uart_is_started(UartHandle handle);
/**
* @brief Stop the UART
* @param handle A valid UART handle.
* @return true on success; false on failure.
*/
bool tt_hal_uart_stop(UartHandle handle);
/**
* @brief Read up to bufferSize bytes into buffer.
*
* This call may block up to timeout ticks waiting for data. It returns the actual
* number of bytes placed into the buffer, which can be less than bufferSize if
* fewer bytes became available before the timeout expired.
*
* @param handle A valid UART handle.
* @param[out] buffer Destination buffer.
* @param bufferSize Capacity of the destination buffer in bytes.
* @param timeout Maximum time to wait in ticks. Use 0 for non-blocking; use TT_MAX_TICKS
* 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);
/**
* @brief Read a single byte.
*
* @param handle A valid UART handle.
* @param[out] output Where to store the read byte.
* @param timeout Maximum time to wait in ticks. Use 0 for non-blocking; use TT_MAX_TICKS
* 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);
/**
* @brief Write up to bufferSize bytes from buffer.
*
* This call may block up to timeout ticks waiting for transmit queue space. It returns
* the number of bytes accepted for transmission.
*
* @param handle A valid UART handle.
* @param[in] buffer Source buffer containing bytes to write.
* @param bufferSize Number of bytes to write from buffer.
* @param timeout Maximum time to wait in ticks. Use 0 for non-blocking; use TT_MAX_TICKS
* 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);
/**
* @brief Get the number of bytes currently available to read without blocking.
* @param handle A valid UART handle.
* @return The count of bytes available in the receive buffer.
*/
size_t tt_hal_uart_available(UartHandle handle);
/**
* @brief Set the UART baud rate.
* @param handle A valid UART handle.
* @param baud_rate Desired baud rate in bits per second (e.g., 115200).
* @return true on success; false if the rate is unsupported or on error.
*/
bool tt_hal_uart_set_baud_rate(UartHandle handle, size_t baud_rate);
/**
* @brief Get the current UART baud rate.
* @param handle A valid UART handle.
* @return The configured baud rate in bits per second.
*/
uint32_t tt_hal_uart_get_baud_rate(UartHandle handle);
/**
* @brief Flush the UART input (receive) buffer, discarding any unread data.
* @param handle A valid UART handle.
*/
void tt_hal_uart_flush_input(UartHandle handle);
#ifdef __cplusplus
}
#endif
+21
View File
@@ -10,6 +10,26 @@ extern "C" {
/** A handle that represents a lock instance. A lock could be a Mutex or similar construct */
typedef void* LockHandle;
enum TtMutexType {
MutexTypeNormal,
MutexTypeRecursive
};
/**
* 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(enum 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)
* @param path the path to create the lock for
* @return the allocated lock handle
*/
LockHandle tt_lock_alloc_for_path(const char* path);
/**
* Attempt to lock the lock.
* @param[in] handle the handle that represents the mutex instance
@@ -26,6 +46,7 @@ bool tt_lock_acquire(LockHandle handle, TickType timeout);
bool tt_lock_release(LockHandle handle);
/** Free the memory for this lock
* This does not auto-release the lock.
* @param[in] handle the handle that represents the mutex instance
*/
void tt_lock_free(LockHandle handle);
+3 -1
View File
@@ -6,6 +6,8 @@
extern "C" {
#endif
#define TT_LVGL_DEFAULT_LOCK_TIME 500 // 500 ticks = 500 ms
/** @return true if LVGL is started and active */
bool tt_lvgl_is_started();
@@ -16,7 +18,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 */
void tt_lvgl_lock();
bool tt_lvgl_lock(TickType timeout);
/** Unlock the LVGL context */
void tt_lvgl_unlock();
-48
View File
@@ -1,48 +0,0 @@
#pragma once
#include "tt_kernel.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 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