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
@@ -1,7 +1,6 @@
#pragma once
#include <Tactility/hal/sdcard/SdCardDevice.h>
#include <Tactility/hal/spi/Spi.h>
namespace tt::hal {
@@ -11,11 +10,6 @@ typedef std::vector<std::shared_ptr<Device>> DeviceVector;
typedef std::shared_ptr<Device> (*CreateDevice)();
enum class LvglInit {
Default,
None
};
/** Affects LVGL widget style */
enum class UiScale {
/** Ideal for very small non-touch screen devices (e.g. Waveshare S3 LCD 1.3") */
@@ -26,21 +20,14 @@ enum class UiScale {
struct Configuration {
/**
* Called before I2C/SPI/etc is initialized.
* Used for powering on the peripherals manually.
*/
const InitBoot initBoot = nullptr;
/** Init behaviour: default (esp_lvgl_port for ESP32, nothing for PC) or None (nothing on any platform). Only used in Tactility, not in TactilityHeadless. */
const LvglInit lvglInit = LvglInit::Default;
/** Modify LVGL widget size */
const UiScale uiScale = UiScale::Default;
std::function<DeviceVector()> createDevices = [] { return std::vector<std::shared_ptr<Device>>(); };
/** A list of SPI interface configurations */
const std::vector<spi::Configuration> spi = {};
const std::function<DeviceVector()> createDevices = [] { return DeviceVector(); };
};
} // namespace
@@ -24,7 +24,6 @@ public:
virtual uint16_t getPixelWidth() const = 0;
virtual uint16_t getPixelHeight() const = 0;
virtual bool drawBitmap(int xStart, int yStart, int xEnd, int yEnd, const void* pixelData) = 0;
virtual std::shared_ptr<Lock> getLock() const = 0;
};
}
@@ -6,7 +6,6 @@
#include <Tactility/RecursiveMutex.h>
#include <tactility/hal/Device.h>
#include <Tactility/hal/spi/Spi.h>
#include <sd_protocol_types.h>
#include <soc/gpio_num.h>
#include <utility>
@@ -3,14 +3,14 @@
#pragma once
#include "SdCardDevice.h"
#include "Tactility/kernel/SpiDeviceLock.h"
#include <Tactility/hal/spi/Spi.h>
#include <driver/gpio.h>
#include <driver/spi_common.h>
#include <sd_protocol_types.h>
#include <utility>
#include <vector>
#include <hal/spi_types.h>
#include <soc/gpio_num.h>
namespace tt::hal::sdcard {
@@ -64,15 +64,23 @@ private:
std::string mountPath;
sdmmc_card_t* card = nullptr;
std::shared_ptr<Config> config;
std::shared_ptr<Lock> lock;
bool applyGpioWorkAround();
bool mountInternal(const std::string& mountPath);
public:
explicit SpiSdCardDevice(std::unique_ptr<Config> config) : SdCardDevice(config->mountBehaviourAtBoot),
config(std::move(config))
{}
explicit SpiSdCardDevice(std::unique_ptr<Config> newConfig, ::Device* spiController) : SdCardDevice(newConfig->mountBehaviourAtBoot),
config(std::move(newConfig))
{
if (config->customLock == nullptr) {
auto spi_lock = std::make_shared<SpiDeviceLock>(spiController);
lock = std::static_pointer_cast<Lock>(spi_lock);
} else {
lock = config->customLock;
}
}
std::string getName() const override { return "SD Card"; }
std::string getDescription() const override { return "SD card via SPI interface"; }
@@ -82,11 +90,7 @@ public:
std::string getMountPath() const override { return mountPath; }
std::shared_ptr<Lock> getLock() const override {
if (config->customLock != nullptr) {
return config->customLock;
} else {
return spi::getLock(config->spiHost);
}
return lock;
}
State getState(TickType_t timeout) const override;
-51
View File
@@ -1,51 +0,0 @@
#pragma once
#include "SpiCompat.h"
#include <Tactility/Lock.h>
#include <Tactility/freertoscompat/RTOS.h>
namespace tt::hal::spi {
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
};
struct Configuration {
spi_host_device_t device;
spi_common_dma_t dma;
spi_bus_config_t config;
/** Whether this bus should be initialized when device starts up */
InitMode initMode;
/** Whether configuration can be changed. */
bool isMutable;
/** Optional custom lock - otherwise creates one internally */
std::shared_ptr<Lock> lock;
};
enum class Status {
Started,
Stopped,
Unknown
};
/** Start communications */
bool start(spi_host_device_t device);
/** Stop communications */
bool stop(spi_host_device_t device);
/** @return true if communications were started successfully */
bool isStarted(spi_host_device_t device);
/**
* Return the lock for the specified SPI device. Never returns nullptr.
* @return the lock that represents the specified device. Can be used with third party SPI implementations or native API calls (e.g. ESP-IDF).
*/
std::shared_ptr<Lock> getLock(spi_host_device_t device);
} // namespace tt::hal::spi
@@ -1,21 +0,0 @@
#pragma once
#include "../gpio/Gpio.h"
#ifdef ESP_PLATFORM
#include <driver/spi_common.h>
#else
#define SPI_HOST_MAX 3
typedef tt::hal::gpio::Pin gpio_num_t;
typedef int spi_host_device_t;
struct spi_bus_config_t {
gpio_num_t miso_io_num;
gpio_num_t mosi_io_num;
gpio_num_t sclk_io_num;
};
struct spi_common_dma_t {};
#endif