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:
committed by
GitHub
parent
2de35b2d2d
commit
aa7530e515
@@ -14,22 +14,25 @@
|
||||
extern "C" {
|
||||
|
||||
struct GpioControllerData {
|
||||
struct Mutex mutex {};
|
||||
Mutex mutex {};
|
||||
uint32_t pin_count;
|
||||
struct GpioDescriptor* descriptors = nullptr;
|
||||
GpioDescriptor* descriptors = nullptr;
|
||||
void* controller_context;
|
||||
|
||||
explicit GpioControllerData(uint32_t pin_count) : pin_count(pin_count) {
|
||||
explicit GpioControllerData(
|
||||
uint32_t pin_count, void* controller_context
|
||||
) : pin_count(pin_count), controller_context(controller_context) {
|
||||
mutex_construct(&mutex);
|
||||
}
|
||||
|
||||
error_t init_descriptors(Device* device, void* controller_context) {
|
||||
descriptors = (struct GpioDescriptor*)calloc(pin_count, sizeof(struct GpioDescriptor));
|
||||
error_t init_descriptors(Device* device) {
|
||||
descriptors = static_cast<GpioDescriptor*>(calloc(pin_count, sizeof(GpioDescriptor)));
|
||||
if (!descriptors) return ERROR_OUT_OF_MEMORY;
|
||||
for (uint32_t i = 0; i < pin_count; ++i) {
|
||||
descriptors[i].controller = device;
|
||||
descriptors[i].pin = (gpio_pin_t)i;
|
||||
descriptors[i].pin = static_cast<gpio_pin_t>(i);
|
||||
descriptors[i].owner_type = GPIO_OWNER_NONE;
|
||||
descriptors[i].controller_context = controller_context;
|
||||
descriptors[i].controller_context = this->controller_context;
|
||||
}
|
||||
return ERROR_NONE;
|
||||
}
|
||||
@@ -42,14 +45,14 @@ struct GpioControllerData {
|
||||
}
|
||||
};
|
||||
|
||||
struct GpioDescriptor* gpio_descriptor_acquire(
|
||||
struct Device* controller,
|
||||
GpioDescriptor* gpio_descriptor_acquire(
|
||||
Device* controller,
|
||||
gpio_pin_t pin_number,
|
||||
enum GpioOwnerType owner
|
||||
GpioOwnerType owner
|
||||
) {
|
||||
check(owner != GPIO_OWNER_NONE);
|
||||
|
||||
auto* data = (struct GpioControllerData*)device_get_driver_data(controller);
|
||||
auto* data = static_cast<struct GpioControllerData*>(device_get_driver_data(controller));
|
||||
|
||||
mutex_lock(&data->mutex);
|
||||
if (pin_number >= data->pin_count) {
|
||||
@@ -57,7 +60,7 @@ struct GpioDescriptor* gpio_descriptor_acquire(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
struct GpioDescriptor* desc = &data->descriptors[pin_number];
|
||||
GpioDescriptor* desc = &data->descriptors[pin_number];
|
||||
if (desc->owner_type != GPIO_OWNER_NONE) {
|
||||
mutex_unlock(&data->mutex);
|
||||
return nullptr;
|
||||
@@ -69,22 +72,27 @@ struct GpioDescriptor* gpio_descriptor_acquire(
|
||||
return desc;
|
||||
}
|
||||
|
||||
error_t gpio_descriptor_release(struct GpioDescriptor* descriptor) {
|
||||
error_t gpio_descriptor_release(GpioDescriptor* descriptor) {
|
||||
auto* data = static_cast<struct GpioControllerData*>(device_get_driver_data(descriptor->controller));
|
||||
mutex_lock(&data->mutex);
|
||||
descriptor->owner_type = GPIO_OWNER_NONE;
|
||||
mutex_unlock(&data->mutex);
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
error_t gpio_controller_get_pin_count(struct Device* device, uint32_t* count) {
|
||||
auto* data = (struct GpioControllerData*)device_get_driver_data(device);
|
||||
error_t gpio_controller_get_pin_count(Device* device, uint32_t* count) {
|
||||
auto* data = static_cast<struct GpioControllerData*>(device_get_driver_data(device));
|
||||
mutex_lock(&data->mutex);
|
||||
*count = data->pin_count;
|
||||
mutex_unlock(&data->mutex);
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
error_t gpio_controller_init_descriptors(struct Device* device, uint32_t pin_count, void* controller_context) {
|
||||
auto* data = new(std::nothrow) GpioControllerData(pin_count);
|
||||
error_t gpio_controller_init_descriptors(Device* device, uint32_t pin_count, void* controller_context) {
|
||||
auto* data = new(std::nothrow) GpioControllerData(pin_count, controller_context);
|
||||
if (!data) return ERROR_OUT_OF_MEMORY;
|
||||
|
||||
if (data->init_descriptors(device, controller_context) != ERROR_NONE) {
|
||||
if (data->init_descriptors(device) != ERROR_NONE) {
|
||||
delete data;
|
||||
return ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
@@ -93,49 +101,82 @@ error_t gpio_controller_init_descriptors(struct Device* device, uint32_t pin_cou
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
error_t gpio_controller_deinit_descriptors(struct Device* device) {
|
||||
error_t gpio_controller_deinit_descriptors(Device* device) {
|
||||
auto* data = static_cast<struct GpioControllerData*>(device_get_driver_data(device));
|
||||
delete data;
|
||||
device_set_driver_data(device, nullptr);
|
||||
delete data;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
error_t gpio_descriptor_set_level(struct GpioDescriptor* descriptor, bool high) {
|
||||
void* gpio_controller_get_controller_context(Device* device) {
|
||||
auto* data = static_cast<struct GpioControllerData*>(device_get_driver_data(device));
|
||||
return data->controller_context;
|
||||
}
|
||||
|
||||
error_t gpio_descriptor_set_level(GpioDescriptor* descriptor, bool high) {
|
||||
const auto* driver = device_get_driver(descriptor->controller);
|
||||
return GPIO_INTERNAL_API(driver)->set_level(descriptor, high);
|
||||
}
|
||||
|
||||
error_t gpio_descriptor_get_level(struct GpioDescriptor* descriptor, bool* high) {
|
||||
error_t gpio_descriptor_get_level(GpioDescriptor* descriptor, bool* high) {
|
||||
const auto* driver = device_get_driver(descriptor->controller);
|
||||
return GPIO_INTERNAL_API(driver)->get_level(descriptor, high);
|
||||
}
|
||||
|
||||
error_t gpio_descriptor_set_flags(struct GpioDescriptor* descriptor, gpio_flags_t flags) {
|
||||
error_t gpio_descriptor_set_flags(GpioDescriptor* descriptor, gpio_flags_t flags) {
|
||||
const auto* driver = device_get_driver(descriptor->controller);
|
||||
return GPIO_INTERNAL_API(driver)->set_flags(descriptor, flags);
|
||||
}
|
||||
|
||||
error_t gpio_descriptor_get_flags(struct GpioDescriptor* descriptor, gpio_flags_t* flags) {
|
||||
error_t gpio_descriptor_get_flags(GpioDescriptor* descriptor, gpio_flags_t* flags) {
|
||||
const auto* driver = device_get_driver(descriptor->controller);
|
||||
return GPIO_INTERNAL_API(driver)->get_flags(descriptor, flags);
|
||||
}
|
||||
|
||||
error_t gpio_descriptor_get_pin_number(struct GpioDescriptor* descriptor, gpio_pin_t* pin) {
|
||||
error_t gpio_descriptor_get_pin_number(GpioDescriptor* descriptor, gpio_pin_t* pin) {
|
||||
*pin = descriptor->pin;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
error_t gpio_descriptor_get_native_pin_number(struct GpioDescriptor* descriptor, void* pin_number) {
|
||||
error_t gpio_descriptor_get_native_pin_number(GpioDescriptor* descriptor, void* pin_number) {
|
||||
const auto* driver = device_get_driver(descriptor->controller);
|
||||
return GPIO_INTERNAL_API(driver)->get_native_pin_number(descriptor, pin_number);
|
||||
}
|
||||
|
||||
error_t gpio_descriptor_get_owner_type(struct GpioDescriptor* descriptor, GpioOwnerType* owner_type) {
|
||||
error_t gpio_descriptor_add_callback(GpioDescriptor* descriptor, void (*callback)(void*), void* arg) {
|
||||
const auto* driver = device_get_driver(descriptor->controller);
|
||||
auto* api = GPIO_INTERNAL_API(driver);
|
||||
if (!api->add_callback) return ERROR_NOT_SUPPORTED;
|
||||
return api->add_callback(descriptor, callback, arg);
|
||||
}
|
||||
|
||||
error_t gpio_descriptor_remove_callback(GpioDescriptor* descriptor) {
|
||||
const auto* driver = device_get_driver(descriptor->controller);
|
||||
auto* api = GPIO_INTERNAL_API(driver);
|
||||
if (!api->remove_callback) return ERROR_NOT_SUPPORTED;
|
||||
return api->remove_callback(descriptor);
|
||||
}
|
||||
|
||||
error_t gpio_descriptor_enable_interrupt(GpioDescriptor* descriptor) {
|
||||
const auto* driver = device_get_driver(descriptor->controller);
|
||||
auto* api = GPIO_INTERNAL_API(driver);
|
||||
if (!api->enable_interrupt) return ERROR_NOT_SUPPORTED;
|
||||
return api->enable_interrupt(descriptor);
|
||||
}
|
||||
|
||||
error_t gpio_descriptor_disable_interrupt(GpioDescriptor* descriptor) {
|
||||
const auto* driver = device_get_driver(descriptor->controller);
|
||||
auto* api = GPIO_INTERNAL_API(driver);
|
||||
if (!api->disable_interrupt) return ERROR_NOT_SUPPORTED;
|
||||
return api->disable_interrupt(descriptor);
|
||||
}
|
||||
|
||||
error_t gpio_descriptor_get_owner_type(GpioDescriptor* descriptor, GpioOwnerType* owner_type) {
|
||||
*owner_type = descriptor->owner_type;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
const struct DeviceType GPIO_CONTROLLER_TYPE {
|
||||
const DeviceType GPIO_CONTROLLER_TYPE {
|
||||
.name = "gpio-controller"
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#include <algorithm>
|
||||
#include <tactility/concurrent/mutex.h>
|
||||
#include <tactility/concurrent/recursive_mutex.h>
|
||||
#include <tactility/filesystem/file_system.h>
|
||||
#include <vector>
|
||||
|
||||
// Define the internal FileSystem structure
|
||||
struct FileSystem {
|
||||
const FileSystemApi* api;
|
||||
void* data;
|
||||
};
|
||||
|
||||
// Global list of file systems and its mutex
|
||||
struct FileSystemsLedger {
|
||||
std::vector<FileSystem*> file_systems;
|
||||
// Use recursive mutex so that file_system_for_each() can lock within the callback
|
||||
RecursiveMutex mutex {};
|
||||
|
||||
FileSystemsLedger() { recursive_mutex_construct(&mutex); }
|
||||
~FileSystemsLedger() { recursive_mutex_destruct(&mutex); }
|
||||
|
||||
void lock() { recursive_mutex_lock(&mutex); }
|
||||
bool is_locked() { return recursive_mutex_is_locked(&mutex); }
|
||||
void unlock() { recursive_mutex_unlock(&mutex); }
|
||||
};
|
||||
|
||||
static FileSystemsLedger& get_ledger() {
|
||||
static FileSystemsLedger ledger;
|
||||
return ledger;
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
FileSystem* file_system_add(const FileSystemApi* fs_api, void* data) {
|
||||
auto& ledger = get_ledger();
|
||||
check(!ledger.is_locked()); // ensure file_system_for_each() doesn't add a filesystem while iterating
|
||||
ledger.lock();
|
||||
|
||||
auto* fs = new(std::nothrow) struct FileSystem();
|
||||
check(fs != nullptr);
|
||||
fs->api = fs_api;
|
||||
fs->data = data;
|
||||
ledger.file_systems.push_back(fs);
|
||||
|
||||
ledger.unlock();
|
||||
return fs;
|
||||
}
|
||||
|
||||
void file_system_remove(FileSystem* fs) {
|
||||
check(!file_system_is_mounted(fs));
|
||||
auto& ledger = get_ledger();
|
||||
check(!ledger.is_locked()); // ensure file_system_for_each() doesn't remove a filesystem while iterating
|
||||
ledger.lock();
|
||||
|
||||
auto it = std::ranges::find(ledger.file_systems, fs);
|
||||
if (it != ledger.file_systems.end()) {
|
||||
ledger.file_systems.erase(it);
|
||||
delete fs;
|
||||
}
|
||||
|
||||
ledger.unlock();
|
||||
}
|
||||
|
||||
void file_system_for_each(void* callback_context, bool (*callback)(FileSystem* fs, void* context)) {
|
||||
auto& ledger = get_ledger();
|
||||
ledger.lock();
|
||||
for (auto* fs : ledger.file_systems) {
|
||||
if (!callback(fs, callback_context)) break;
|
||||
}
|
||||
ledger.unlock();
|
||||
}
|
||||
|
||||
error_t file_system_mount(FileSystem* fs) {
|
||||
// Assuming 'device' is accessible or passed via a different mechanism
|
||||
// as it's required by the FileSystemApi signatures.
|
||||
return fs->api->mount(fs->data);
|
||||
}
|
||||
|
||||
error_t file_system_unmount(FileSystem* fs) {
|
||||
return fs->api->unmount(fs->data);
|
||||
}
|
||||
|
||||
bool file_system_is_mounted(FileSystem* fs) {
|
||||
return fs->api->is_mounted(fs->data);
|
||||
}
|
||||
|
||||
error_t file_system_get_path(FileSystem* fs, char* out_path, size_t out_path_size) {
|
||||
return fs->api->get_path(fs->data, out_path, out_path_size);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,3 +1,7 @@
|
||||
#include <tactility/concurrent/dispatcher.h>
|
||||
#include <tactility/concurrent/event_group.h>
|
||||
#include <tactility/concurrent/thread.h>
|
||||
#include <tactility/concurrent/timer.h>
|
||||
#include <tactility/device.h>
|
||||
#include <tactility/driver.h>
|
||||
#include <tactility/drivers/gpio_controller.h>
|
||||
@@ -6,14 +10,14 @@
|
||||
#include <tactility/drivers/root.h>
|
||||
#include <tactility/drivers/spi_controller.h>
|
||||
#include <tactility/drivers/uart_controller.h>
|
||||
#include <tactility/concurrent/dispatcher.h>
|
||||
#include <tactility/concurrent/event_group.h>
|
||||
#include <tactility/concurrent/thread.h>
|
||||
#include <tactility/concurrent/timer.h>
|
||||
#include <tactility/error.h>
|
||||
#include <tactility/log.h>
|
||||
#include <tactility/filesystem/file_system.h>
|
||||
#include <tactility/module.h>
|
||||
|
||||
#ifndef ESP_PLATFORM
|
||||
#include <tactility/log.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This file is a C file instead of C++, so we can import all headers as C code.
|
||||
* The intent is to catch errors that only show up when compiling as C and not as C++.
|
||||
@@ -153,6 +157,11 @@ const struct ModuleSymbol KERNEL_SYMBOLS[] = {
|
||||
DEFINE_MODULE_SYMBOL(timer_set_callback_priority),
|
||||
// error
|
||||
DEFINE_MODULE_SYMBOL(error_to_string),
|
||||
// file system
|
||||
DEFINE_MODULE_SYMBOL(file_system_mount),
|
||||
DEFINE_MODULE_SYMBOL(file_system_unmount),
|
||||
DEFINE_MODULE_SYMBOL(file_system_is_mounted),
|
||||
DEFINE_MODULE_SYMBOL(file_system_get_path),
|
||||
// log
|
||||
#ifndef ESP_PLATFORM
|
||||
DEFINE_MODULE_SYMBOL(log_generic),
|
||||
|
||||
@@ -12,8 +12,8 @@ struct ModuleInternal {
|
||||
};
|
||||
|
||||
struct ModuleLedger {
|
||||
std::vector<struct Module*> modules;
|
||||
struct Mutex mutex {};
|
||||
std::vector<Module*> modules;
|
||||
Mutex mutex {};
|
||||
|
||||
ModuleLedger() { mutex_construct(&mutex); }
|
||||
~ModuleLedger() { mutex_destruct(&mutex); }
|
||||
@@ -23,36 +23,37 @@ static ModuleLedger ledger;
|
||||
|
||||
extern "C" {
|
||||
|
||||
error_t module_construct(struct Module* module) {
|
||||
error_t module_construct(Module* module) {
|
||||
module->internal = new (std::nothrow) ModuleInternal();
|
||||
if (module->internal == nullptr) return ERROR_OUT_OF_MEMORY;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
error_t module_destruct(struct Module* module) {
|
||||
error_t module_destruct(Module* module) {
|
||||
delete static_cast<ModuleInternal*>(module->internal);
|
||||
module->internal = nullptr;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
error_t module_add(struct Module* module) {
|
||||
error_t module_add(Module* module) {
|
||||
mutex_lock(&ledger.mutex);
|
||||
ledger.modules.push_back(module);
|
||||
mutex_unlock(&ledger.mutex);
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
error_t module_remove(struct Module* module) {
|
||||
error_t module_remove(Module* module) {
|
||||
mutex_lock(&ledger.mutex);
|
||||
ledger.modules.erase(std::remove(ledger.modules.begin(), ledger.modules.end(), module), ledger.modules.end());
|
||||
mutex_unlock(&ledger.mutex);
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
error_t module_start(struct Module* module) {
|
||||
error_t module_start(Module* module) {
|
||||
LOG_I(TAG, "start %s", module->name);
|
||||
|
||||
auto* internal = static_cast<ModuleInternal*>(module->internal);
|
||||
auto* internal = module->internal;
|
||||
if (internal == nullptr) return ERROR_INVALID_STATE;
|
||||
if (internal->started) return ERROR_NONE;
|
||||
|
||||
error_t error = module->start();
|
||||
@@ -61,13 +62,15 @@ error_t module_start(struct Module* module) {
|
||||
}
|
||||
|
||||
bool module_is_started(struct Module* module) {
|
||||
return static_cast<ModuleInternal*>(module->internal)->started;
|
||||
auto* internal = module->internal;
|
||||
return internal != nullptr && internal->started;
|
||||
}
|
||||
|
||||
error_t module_stop(struct Module* module) {
|
||||
LOG_I(TAG, "stop %s", module->name);
|
||||
|
||||
auto* internal = static_cast<ModuleInternal*>(module->internal);
|
||||
auto* internal = module->internal;
|
||||
if (internal == nullptr) return ERROR_INVALID_STATE;
|
||||
if (!internal->started) return ERROR_NONE;
|
||||
|
||||
error_t error = module->stop();
|
||||
|
||||
Reference in New Issue
Block a user