mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-04-18 09:25:06 +00:00
SDMMC driver WIP
This commit is contained in:
parent
1ea2f97305
commit
d63a401cd5
@ -7,7 +7,7 @@
|
||||
#include "tactility/drivers/gpio_descriptor.h"
|
||||
#include <new>
|
||||
#include <tactility/drivers/esp32_gpio_helpers.h>
|
||||
#include <tactility/drivers/file_system.h>
|
||||
#include <tactility/drivers/esp32_gpio_fs.h>
|
||||
|
||||
#define TAG "esp32_sdmmc"
|
||||
|
||||
@ -16,32 +16,16 @@
|
||||
|
||||
extern "C" {
|
||||
|
||||
error_t mount(Device* device) {
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
error_t unmount(Device* device) {
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
bool is_mounted(Device* device) {
|
||||
return true;
|
||||
}
|
||||
|
||||
error_t get_mount_path(Device*, char* out_path) {
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static const FileSystemApi sdmmc_filesystem_api = {
|
||||
.mount = mount,
|
||||
.unmount = unmount,
|
||||
.is_mounted = is_mounted,
|
||||
.get_mount_path = get_mount_path
|
||||
};
|
||||
|
||||
struct Esp32SdmmcInternal {
|
||||
RecursiveMutex mutex = {};
|
||||
bool initialized = false;
|
||||
char fs_device_name[16] = "esp32_sdmmc_fs0";
|
||||
Device fs_device = {
|
||||
.name = fs_device_name,
|
||||
.config = nullptr,
|
||||
.parent = nullptr,
|
||||
.internal = nullptr
|
||||
};
|
||||
|
||||
// Pin descriptors
|
||||
GpioDescriptor* pin_clk_descriptor = nullptr;
|
||||
@ -122,7 +106,11 @@ static error_t start(Device* device) {
|
||||
return ERROR_RESOURCE;
|
||||
}
|
||||
|
||||
// TODO: filesystem
|
||||
// Create filesystem child device
|
||||
auto* fs_device = &data->fs_device;
|
||||
fs_device->parent = device;
|
||||
fs_device->config = sdmmc_config;
|
||||
check(device_construct_add_start(fs_device, "espressif,esp32-sdmmc-fs") == ERROR_NONE);
|
||||
|
||||
data->initialized = true;
|
||||
return ERROR_NONE;
|
||||
@ -130,14 +118,18 @@ static error_t start(Device* device) {
|
||||
|
||||
static error_t stop(Device* device) {
|
||||
ESP_LOGI(TAG, "stop %s", device->name);
|
||||
auto* driver_data = GET_DATA(device);
|
||||
auto* data = GET_DATA(device);
|
||||
auto* dts_config = GET_CONFIG(device);
|
||||
|
||||
// TODO: filesystem
|
||||
// Create filesystem child device
|
||||
auto* fs_device = &data->fs_device;
|
||||
check(device_stop(fs_device) == ERROR_NONE);
|
||||
check(device_remove(fs_device) == ERROR_NONE);
|
||||
check(device_destruct(fs_device) == ERROR_NONE);
|
||||
|
||||
driver_data->cleanup_pins();
|
||||
data->cleanup_pins();
|
||||
device_set_driver_data(device, nullptr);
|
||||
delete driver_data;
|
||||
delete data;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
|
||||
@ -74,7 +74,7 @@ error_t mount(Device* device, const char* mount_path) {
|
||||
} else {
|
||||
LOG_E(TAG, "Mounting failed: %s", esp_err_to_name(result));
|
||||
}
|
||||
return false;
|
||||
return ERROR_UNDEFINED;
|
||||
}
|
||||
|
||||
data->mount_path = mount_path;
|
||||
@ -117,7 +117,9 @@ static error_t start(Device* device) {
|
||||
|
||||
device_set_driver_data(device, data);
|
||||
|
||||
// TODO: filesystem
|
||||
if (mount(device, "/sdcard") != ERROR_NONE) {
|
||||
LOG_E(TAG, "Failed to mount SD card");
|
||||
}
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
@ -126,7 +128,11 @@ static error_t stop(Device* device) {
|
||||
ESP_LOGI(TAG, "stop %s", device->name);
|
||||
auto* driver_data = GET_DATA(device);
|
||||
|
||||
// TODO: filesystem
|
||||
if (is_mounted(device)) {
|
||||
if (unmount(device) != ERROR_NONE) {
|
||||
LOG_E(TAG, "Failed to unmount SD card");
|
||||
}
|
||||
}
|
||||
|
||||
device_set_driver_data(device, nullptr);
|
||||
delete driver_data;
|
||||
|
||||
@ -7,6 +7,8 @@ extern "C" {
|
||||
extern Driver esp32_gpio_driver;
|
||||
extern Driver esp32_i2c_driver;
|
||||
extern Driver esp32_i2s_driver;
|
||||
extern Driver esp32_sdmmc_driver;
|
||||
extern Driver esp32_sdmmc_fs_driver;
|
||||
extern Driver esp32_spi_driver;
|
||||
extern Driver esp32_uart_driver;
|
||||
|
||||
@ -16,6 +18,8 @@ static error_t start() {
|
||||
check(driver_construct_add(&esp32_gpio_driver) == ERROR_NONE);
|
||||
check(driver_construct_add(&esp32_i2c_driver) == ERROR_NONE);
|
||||
check(driver_construct_add(&esp32_i2s_driver) == ERROR_NONE);
|
||||
check(driver_construct_add(&esp32_sdmmc_driver) == ERROR_NONE);
|
||||
check(driver_construct_add(&esp32_sdmmc_fs_driver) == ERROR_NONE);
|
||||
check(driver_construct_add(&esp32_spi_driver) == ERROR_NONE);
|
||||
check(driver_construct_add(&esp32_uart_driver) == ERROR_NONE);
|
||||
return ERROR_NONE;
|
||||
@ -27,12 +31,14 @@ static error_t stop() {
|
||||
check(driver_remove_destruct(&esp32_gpio_driver) == ERROR_NONE);
|
||||
check(driver_remove_destruct(&esp32_i2c_driver) == ERROR_NONE);
|
||||
check(driver_remove_destruct(&esp32_i2s_driver) == ERROR_NONE);
|
||||
check(driver_remove_destruct(&esp32_sdmmc_driver) == ERROR_NONE);
|
||||
check(driver_remove_destruct(&esp32_sdmmc_fs_driver) == ERROR_NONE);
|
||||
check(driver_remove_destruct(&esp32_spi_driver) == ERROR_NONE);
|
||||
check(driver_remove_destruct(&esp32_uart_driver) == ERROR_NONE);
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
struct Module platform_esp32_module = {
|
||||
Module platform_esp32_module = {
|
||||
.name = "platform-esp32",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user