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
@@ -2,8 +2,6 @@
#include <Tactility/hal/sdcard/SdCardDevice.h>
#include <Tactility/hal/spi/Spi.h>
#include <Tactility/hal/uart/Uart.h>
#include "i2c/I2c.h"
namespace tt::hal {
@@ -43,9 +41,6 @@ struct Configuration {
/** A list of SPI interface configurations */
const std::vector<spi::Configuration> spi = {};
/** A list of UART interface configurations */
const std::vector<uart::Configuration> uart = {};
};
} // namespace
@@ -1,43 +0,0 @@
#pragma once
#include "UartCompat.h"
namespace tt::hal::uart {
#ifdef ESP_PLATFORM
struct Configuration {
/** The unique name for this UART */
std::string name;
/** The port identifier (e.g. UART_NUM_0) */
uart_port_t port;
/** Receive GPIO pin */
gpio_num_t rxPin;
/** Transmit GPIO pin */
gpio_num_t txPin;
/** Read-To-Send GPIO pin */
gpio_num_t rtsPin;
/** Clear-To-Send Send GPIO pin */
gpio_num_t ctsPin;
/** Receive buffer size in bytes */
unsigned int rxBufferSize;
/** Transmit buffer size in bytes */
unsigned int txBufferSize;
/** Native configuration */
uart_config_t config;
};
#else
struct Configuration {
/** The unique name for this UART */
std::string name;
/** The port identifier (e.g. UART_NUM_0) */
uart_port_t port;
/** Initial baud rate in bits per second */
uint32_t baudRate;
};
#endif
}
-131
View File
@@ -1,131 +0,0 @@
#pragma once
#include <Tactility/freertoscompat/RTOS.h>
#include "../gpio/Gpio.h"
#include "Tactility/Lock.h"
#include "UartCompat.h"
#include "Tactility/hal/uart/Configuration.h"
#include <memory>
#include <vector>
namespace tt::hal::uart {
constexpr TickType_t defaultTimeout = 10 / portTICK_PERIOD_MS;
enum class InitMode {
ByTactility, // Tactility will initialize it in the correct bootup phase
ByExternal, // The device is already initialized and Tactility should assume it works
Disabled // Not initialized by default
};
enum class Status {
Started,
Stopped,
Unknown
};
class Uart {
uint32_t id;
public:
Uart();
virtual ~Uart();
uint32_t getId() const { return id; }
virtual bool start() = 0;
virtual bool isStarted() const = 0;
virtual bool stop() = 0;
/**
* Read up to a specified amount of bytes
* @param[out] buffer
* @param[in] bufferSize
* @param[in] timeout
* @return the amount of bytes that were read
*/
virtual size_t readBytes(std::byte* buffer, size_t bufferSize, TickType_t timeout = defaultTimeout) = 0;
size_t readBytes(std::uint8_t* buffer, size_t bufferSize, TickType_t timeout = defaultTimeout) {
return readBytes(reinterpret_cast<std::byte*>(buffer), bufferSize, timeout);
}
/** Read a single byte */
virtual bool readByte(std::byte* output, TickType_t timeout = defaultTimeout) = 0;
bool readByte(char* output, TickType_t timeout = defaultTimeout) {
return readByte(reinterpret_cast<std::byte*>(output), timeout);
}
bool readByte(uint8_t* output, TickType_t timeout = defaultTimeout) {
return readByte(reinterpret_cast<std::byte*>(output), timeout);
}
/**
* Read up to a specified amount of bytes
* @param[in] buffer
* @param[in] bufferSize
* @param[in] timeout
* @return the amount of bytes that were read
*/
virtual size_t writeBytes(const std::byte* buffer, size_t bufferSize, TickType_t timeout = defaultTimeout) = 0;
size_t writeBytes(const std::uint8_t* buffer, size_t bufferSize, TickType_t timeout = defaultTimeout) {
return writeBytes(reinterpret_cast<const std::byte*>(buffer), bufferSize, timeout);
}
/** @return the amount of bytes available for reading */
virtual size_t available(TickType_t timeout = defaultTimeout) = 0;
/** Set the baud rate for the specified port */
virtual bool setBaudRate(uint32_t baudRate, TickType_t timeout = defaultTimeout) = 0;
/** Get the baud rate for the specified port */
virtual uint32_t getBaudRate() = 0;
/** Flush input buffers */
virtual void flushInput() = 0;
/**
* Write a string (excluding null terminator character)
* @param[in] buffer
* @param[in] timeout
* @return the amount of bytes that were written
*/
bool writeString(const char* buffer, TickType_t timeout = defaultTimeout);
/**
* Read a buffer as a string until the specified character (the "untilChar" is included in the result)
* @warning if the input data doesn't return "untilByte" then the device goes out of memory
*/
std::string readStringUntil(char untilChar, TickType_t timeout = defaultTimeout);
/**
* Read a buffer as a byte array until the specified character (the "untilChar" is included in the result)
* @return the amount of bytes read from UART
*/
size_t readUntil(std::byte* buffer, size_t bufferSize, uint8_t untilByte, TickType_t timeout = defaultTimeout, bool addNullTerminator = true);
};
/**
* Opens a UART.
* @param[in] name the UART name as specified in the board configuration.
* @return the UART when it was successfully opened, or nullptr when it is in use.
*/
std::unique_ptr<Uart> open(std::string name);
/**
* Opens a UART.
* @param[in] port the UART port as specified in the board configuration.
* @return the UART when it was successfully opened, or nullptr when it is in use.
*/
std::unique_ptr<Uart> open(uart_port_t port);
std::vector<std::string> getNames();
} // namespace tt::hal::uart
@@ -1,17 +0,0 @@
#pragma once
#ifdef ESP_PLATFORM
#include <driver/uart.h>
#include <driver/gpio.h>
#include <hal/uart_types.h>
#else
#define UART_NUM_MAX 3
typedef int uart_port_t;
typedef struct {
} uart_config_t;
#endif