Add kernel drivers for SPI and UART and make locking APIs more consistent (#489)

- Add kernel support for SPI driver
- Add kernel support for UART driver
- Implemented ESP32 UART kernel driver
- Update existing UART-related code in Tactility to use new kernel driver
- Remove UART from tt::hal::Configuration
- Remove tt_hal_uart functionality but keep functions for now
- Update devicetrees for UART changes
- Kernel mutex and recursive mutex: improved locking API design
- Other kernel improvements
- Added device_exists_of_type() and device_find_by_name()
This commit is contained in:
Ken Van Hoeylandt
2026-02-07 21:28:11 +01:00
committed by GitHub
parent 7e24105d0c
commit 74127a5f6c
119 changed files with 1679 additions and 1792 deletions
+12 -35
View File
@@ -1,84 +1,61 @@
#include "tt_hal_uart.h"
#include <Tactility/hal/uart/Uart.h>
#include <cstring>
using namespace tt::hal;
struct UartWrapper {
std::shared_ptr<uart::Uart> uart;
};
#define HANDLE_AS_UART(handle) static_cast<UartWrapper*>(handle)->uart
extern "C" {
size_t tt_hal_uart_get_count() {
return uart::getNames().size();
return 0;
}
bool tt_hal_uart_get_name(size_t index, char* name, size_t nameSizeLimit) {
assert(index < uart::getNames().size());
auto source_name = uart::getNames()[index];
return strncpy(name, source_name.c_str(), nameSizeLimit) != nullptr;
return false;
}
UartHandle tt_hal_uart_alloc(size_t index) {
assert(index < uart::getNames().size());
auto* wrapper = new UartWrapper();
auto name = uart::getNames()[index];
wrapper->uart = uart::open(name);
assert(wrapper->uart != nullptr);
return wrapper;
return nullptr;
}
void tt_hal_uart_free(UartHandle handle) {
auto* wrapper = static_cast<UartWrapper*>(handle);
assert(wrapper->uart != nullptr);
if (wrapper->uart->isStarted()) {
wrapper->uart->stop();
}
delete wrapper;
}
bool tt_hal_uart_start(UartHandle handle) {
return HANDLE_AS_UART(handle)->start();
return false;
}
bool tt_hal_uart_is_started(UartHandle handle) {
return HANDLE_AS_UART(handle)->isStarted();
return false;
}
bool tt_hal_uart_stop(UartHandle handle) {
return HANDLE_AS_UART(handle)->stop();
return false;
}
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);
return 0;
}
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);
return false;
}
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);
return 0;
}
size_t tt_hal_uart_available(UartHandle handle) {
return HANDLE_AS_UART(handle)->available();
return 0;
}
bool tt_hal_uart_set_baud_rate(UartHandle handle, size_t baud_rate) {
return HANDLE_AS_UART(handle)->setBaudRate(baud_rate);
return false;
}
uint32_t tt_hal_uart_get_baud_rate(UartHandle handle) {
return HANDLE_AS_UART(handle)->getBaudRate();
return 0;
}
void tt_hal_uart_flush_input(UartHandle handle) {
HANDLE_AS_UART(handle)->flushInput();
}
}