New kernel drivers, filesystem API, and more (#513)

* **New Features**
  * BMI270 6-axis IMU driver added; new unified filesystem abstraction for mounted filesystems.
  * Public Wi‑Fi API surface (no implementation yet)
  * SDMMC driver added (kernel drive$)
  * expanded GPIO interrupt/callback support
* **Improvements**
  * M5Stack Tab5: revamped GPIO/power initialization and IMU integration.
  * LVGL updates including device fontSize configuration.
  * Updated all code related to SD card device/fs handling
  * Rename LilyGO T-HMI S3 to LilyGO T-HMI
* **Bug Fixes**
  * Simplified and consolidated SD card handling and mount discovery.
This commit is contained in:
Ken Van Hoeylandt
2026-03-07 16:13:39 +01:00
committed by GitHub
parent 2de35b2d2d
commit aa7530e515
88 changed files with 2792 additions and 846 deletions
@@ -0,0 +1,52 @@
#include <Tactility/hal/sdcard/SdCardDevice.h>
#include <tactility/filesystem/file_system.h>
#include <cstring>
namespace tt::hal::sdcard {
static error_t mount(void* data) {
auto* device = static_cast<SdCardDevice*>(data);
auto path = device->getMountPath();
if (!device->mount(path)) return ERROR_UNDEFINED;
return ERROR_NONE;
}
static error_t unmount(void* data) {
auto* device = static_cast<SdCardDevice*>(data);
if (!device->unmount()) return ERROR_UNDEFINED;
return ERROR_NONE;
}
static bool is_mounted(void* data) {
auto* device = static_cast<SdCardDevice*>(data);
return device->isMounted();
}
static error_t get_path(void* data, char* out_path, size_t out_path_size) {
auto* device = static_cast<SdCardDevice*>(data);
const auto mount_path = device->getMountPath();
if (mount_path.size() >= out_path_size) return ERROR_BUFFER_OVERFLOW;
if (mount_path.empty()) return ERROR_INVALID_STATE;
strncpy(out_path, mount_path.c_str(), out_path_size);
return ERROR_NONE;
}
FileSystemApi sdCardDeviceApi = {
.mount = mount,
.unmount = unmount,
.is_mounted = is_mounted,
.get_path = get_path
};
SdCardDevice::SdCardDevice(MountBehaviour mountBehaviour) : mountBehaviour(mountBehaviour) {
fileSystem = file_system_add(&sdCardDeviceApi, this);
check(fileSystem != nullptr);
}
SdCardDevice::~SdCardDevice() {
file_system_remove(fileSystem);
}
}
-123
View File
@@ -1,123 +0,0 @@
#ifdef ESP_PLATFORM
#include <soc/soc_caps.h>
#endif
#if defined(ESP_PLATFORM) && defined(SOC_SDMMC_HOST_SUPPORTED)
#include <Tactility/hal/sdcard/SdmmcDevice.h>
#include <Tactility/Logger.h>
#include <esp_vfs_fat.h>
#include <sdmmc_cmd.h>
#include <driver/sdmmc_host.h>
namespace tt::hal::sdcard {
static const auto LOGGER = Logger("SdmmcDevice");
bool SdmmcDevice::mountInternal(const std::string& newMountPath) {
LOGGER.info("Mounting {}", newMountPath);
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
.format_if_mount_failed = config->formatOnMountFailed,
.max_files = config->maxOpenFiles,
.allocation_unit_size = config->allocUnitSize,
.disk_status_check_enable = config->statusCheckEnabled,
.use_one_fat = false
};
sdmmc_host_t host = SDMMC_HOST_DEFAULT();
sdmmc_slot_config_t slot_config = {
.clk = config->pinClock,
.cmd = config->pinCmd,
.d0 = config->pinD0,
.d1 = config->pinD1,
.d2 = config->pinD2,
.d3 = config->pinD3,
.d4 = static_cast<gpio_num_t>(0),
.d5 = static_cast<gpio_num_t>(0),
.d6 = static_cast<gpio_num_t>(0),
.d7 = static_cast<gpio_num_t>(0),
.cd = GPIO_NUM_NC,
.wp = GPIO_NUM_NC,
.width = config->busWidth,
.flags = 0
};
esp_err_t result = esp_vfs_fat_sdmmc_mount(newMountPath.c_str(), &host, &slot_config, &mount_config, &card);
if (result != ESP_OK || card == nullptr) {
if (result == ESP_FAIL) {
LOGGER.error("Mounting failed. Ensure the card is formatted with FAT.");
} else {
LOGGER.error("Mounting failed ({})", esp_err_to_name(result));
}
return false;
}
mountPath = newMountPath;
return true;
}
bool SdmmcDevice::mount(const std::string& newMountPath) {
auto lock = getLock()->asScopedLock();
lock.lock();
if (mountInternal(newMountPath)) {
LOGGER.info("Mounted at {}", newMountPath);
sdmmc_card_print_info(stdout, card);
return true;
} else {
LOGGER.error("Mount failed for {}", newMountPath);
return false;
}
}
bool SdmmcDevice::unmount() {
auto lock = getLock()->asScopedLock();
lock.lock();
if (card == nullptr) {
LOGGER.error("Can't unmount: not mounted");
return false;
}
if (esp_vfs_fat_sdcard_unmount(mountPath.c_str(), card) != ESP_OK) {
LOGGER.error("Unmount failed for {}", mountPath);
return false;
}
LOGGER.info("Unmounted {}", mountPath);
mountPath = "";
card = nullptr;
return true;
}
SdmmcDevice::State SdmmcDevice::getState(TickType_t timeout) const {
if (card == nullptr) {
return State::Unmounted;
}
/**
* The SD card and the screen are on the same SPI bus.
* Writing and reading to the bus from 2 devices at the same time causes crashes.
* This work-around ensures that this check is only happening when LVGL isn't rendering.
*/
auto lock = getLock()->asScopedLock();
bool locked = lock.lock(timeout);
if (!locked) {
return State::Timeout;
}
if (sdmmc_get_status(card) != ESP_OK) {
return State::Error;
}
return State::Mounted;
}
}
#endif
+31 -16
View File
@@ -1,10 +1,13 @@
#ifdef ESP_PLATFORM
#include <soc/soc_caps.h>
#include <Tactility/hal/usb/Usb.h>
#include <Tactility/hal/sdcard/SpiSdCardDevice.h>
#include <Tactility/hal/usb/UsbTusb.h>
#include <Tactility/Logger.h>
#include <tactility/drivers/esp32_sdmmc.h>
namespace tt::hal::usb {
@@ -21,29 +24,41 @@ static Mode currentMode = Mode::Default;
static RTC_NOINIT_ATTR BootModeData bootModeData;
sdmmc_card_t* getCard() {
auto sdcards = findDevices<sdcard::SpiSdCardDevice>(Device::Type::SdCard);
sdmmc_card_t* sdcard = nullptr;
std::shared_ptr<sdcard::SpiSdCardDevice> usable_sdcard;
for (auto& sdcard : sdcards) {
auto sdcard_candidate = std::static_pointer_cast<sdcard::SpiSdCardDevice>(sdcard);
if (sdcard_candidate != nullptr && sdcard_candidate->isMounted() && sdcard_candidate->getCard() != nullptr) {
usable_sdcard = sdcard_candidate;
// Find old HAL SD card device:
auto sdcards = findDevices<sdcard::SpiSdCardDevice>(Device::Type::SdCard);
for (auto& device : sdcards) {
auto sdcard_device= std::static_pointer_cast<sdcard::SpiSdCardDevice>(device);
if (sdcard_device != nullptr && sdcard_device->isMounted() && sdcard_device->getCard() != nullptr) {
sdcard = sdcard_device->getCard();
break;
}
}
if (usable_sdcard == nullptr) {
LOGGER.warn("Couldn't find a mounted SpiSdCard");
return nullptr;
#if SOC_SDMMC_HOST_SUPPORTED
// Find ESP32 SDMMC device:
if (sdcard == nullptr) {
device_for_each(&sdcard, [](auto* device, void* context) {
if (device_is_ready(device) && device_is_compatible(device, "espressif,esp32-sdmmc")) {
auto** sdcard = static_cast<sdmmc_card_t**>(context);
auto* sdmmc_card = esp32_sdmmc_get_card(device);
if (sdmmc_card) {
*sdcard = sdmmc_card;
return false;
}
return true;
}
return true;
});
}
#endif
if (sdcard == nullptr) {
LOGGER.warn("Couldn't find a mounted SD card");
}
auto* sdmmc_card = usable_sdcard->getCard();
if (sdmmc_card == nullptr) {
LOGGER.warn("SD card has no card object available");
return nullptr;
}
return sdmmc_card;
return sdcard;
}
static bool canStartNewMode() {