SPI device migration (#490)

- Implement SPI devices in dts files for all devices
- Removed `tt::hal::spi` HAL and its configurations
- Fix for devicetree generator "boolean" support
- Remove unused custom locks in all `DisplayDevice` implementations
- Fixed some bugs with devices
- Updated XPT2046 driver
- Fix for `WifiEsp` deadlock
- Export a lot of new `math.h` symbols with `tt_init.cpp`
- Created `SpiDeviceLock` in `TactilityCore` as a wrapper for kernel SPI locking
- Improved `TactilityKernel` SPI driver.
This commit is contained in:
Ken Van Hoeylandt
2026-02-08 22:14:18 +01:00
committed by GitHub
parent 74127a5f6c
commit d27404964a
177 changed files with 1091 additions and 2205 deletions
-3
View File
@@ -3,7 +3,6 @@
#include <tactility/check.h>
#include <Tactility/hal/Configuration.h>
#include <tactility/hal/Device.h>
#include <Tactility/hal/spi/SpiInit.h>
#include <Tactility/hal/display/DisplayDevice.h>
#include <Tactility/hal/sdcard/SdCardMounting.h>
@@ -64,8 +63,6 @@ static void startDisplays() {
void init(const Configuration& configuration) {
kernel::publishSystemEvent(kernel::SystemEvent::BootInitHalBegin);
check(spi::init(configuration.spi), "SPI init failed");
if (configuration.initBoot != nullptr) {
check(configuration.initBoot(), "Init boot failed");
}
-146
View File
@@ -1,146 +0,0 @@
#include <Tactility/hal/spi/Spi.h>
#include <Tactility/Logger.h>
#include <Tactility/RecursiveMutex.h>
namespace tt::hal::spi {
static const auto LOGGER = Logger("SPI");
struct Data {
std::shared_ptr<Lock> lock;
bool isConfigured = false;
bool isStarted = false;
Configuration configuration;
};
static Data dataArray[SPI_HOST_MAX];
bool init(const std::vector<Configuration>& configurations) {
LOGGER.info("Init");
for (const auto& configuration: configurations) {
Data& data = dataArray[configuration.device];
data.configuration = configuration;
data.isConfigured = true;
if (configuration.lock != nullptr) {
data.lock = configuration.lock;
} else {
data.lock = std::make_shared<RecursiveMutex>();
}
}
for (const auto& config: configurations) {
if (config.initMode == InitMode::ByTactility) {
if (!start(config.device)) {
return false;
}
} else if (config.initMode == InitMode::ByExternal) {
dataArray[config.device].isStarted = true;
}
}
return true;
}
bool configure(spi_host_device_t device, const spi_bus_config_t& configuration) {
auto lock = getLock(device)->asScopedLock();
lock.lock();
Data& data = dataArray[device];
if (data.isStarted) {
LOGGER.error("({}) Cannot reconfigure while interface is started", static_cast<int>(device));
return false;
} else if (!data.configuration.isMutable) {
LOGGER.error("({}) Mutation not allowed by original configuration", static_cast<int>(device));
return false;
} else {
data.configuration.config = configuration;
return true;
}
}
bool start(spi_host_device_t device) {
auto lock = getLock(device)->asScopedLock();
lock.lock();
Data& data = dataArray[device];
if (data.isStarted) {
LOGGER.error("({}) Starting: Already started", static_cast<int>(device));
return false;
}
if (!data.isConfigured) {
LOGGER.error("({}) Starting: Not configured", static_cast<int>(device));
return false;
}
#ifdef ESP_PLATFORM
auto result = spi_bus_initialize(device, &data.configuration.config, data.configuration.dma);
if (result != ESP_OK) {
LOGGER.error("({}) Starting: Failed to initialize: {}", static_cast<int>(device), esp_err_to_name(result));
return false;
} else {
data.isStarted = true;
}
#else
data.isStarted = true;
#endif
LOGGER.info("({}) Started", static_cast<int>(device));
return true;
}
bool stop(spi_host_device_t device) {
auto lock = getLock(device)->asScopedLock();
lock.lock();
Data& data = dataArray[device];
Configuration& config = data.configuration;
if (!config.isMutable) {
LOGGER.error("({}) Stopping: Not allowed, immutable", static_cast<int>(device));
return false;
}
if (!data.isStarted) {
LOGGER.error("({}) Stopping: Not started", static_cast<int>(device));
return false;
}
#ifdef ESP_PLATFORM
auto result = spi_bus_free(device);
if (result != ESP_OK) {
LOGGER.error("({}) Stopping: Failed to free device: {}", static_cast<int>(device), esp_err_to_name(result));
return false;
} else {
data.isStarted = false;
}
#else
data.isStarted = false;
#endif
LOGGER.info("({}) Stopped", static_cast<int>(device));
return true;
}
bool isStarted(spi_host_device_t device) {
auto lock = getLock(device)->asScopedLock();
lock.lock();
return dataArray[device].isStarted;
}
std::shared_ptr<Lock> getLock(spi_host_device_t device) {
return dataArray[device].lock;
}
}