M5stack CoreS3 support (#71)

This commit is contained in:
Ken Van Hoeylandt
2024-11-07 23:17:26 +01:00
committed by GitHub
parent 68aa34ad14
commit 67b9fc710a
30 changed files with 355 additions and 334 deletions
+6
View File
@@ -0,0 +1,6 @@
idf_component_register(
SRC_DIRS "source"
INCLUDE_DIRS "include"
PRIV_INCLUDE_DIRS "private"
REQUIRES tactility m5stack_shared vfs fatfs M5Unified
)
@@ -0,0 +1,13 @@
#pragma once
#include "hardware_config.h"
#ifdef __cplusplus
extern "C" {
#endif
extern const HardwareConfig m5stack_cores3;
#ifdef __cplusplus
}
#endif
+13
View File
@@ -0,0 +1,13 @@
#pragma once
#include "driver/spi_common.h"
#include "driver/gpio.h"
// SD Card
#define CORES3_SDCARD_SPI_HOST SPI2_HOST
#define CORES3_SDCARD_PIN_CS GPIO_NUM_4
#define CORES3_SDCARD_SPI_FREQUENCY 800000U
#define CORES3_SDCARD_FORMAT_ON_MOUNT_FAILED false
#define CORES3_SDCARD_MAX_OPEN_FILES 4
#define CORES3_SDCARD_ALLOC_UNIT_SIZE (16 * 1024)
#define CORES3_SDCARD_STATUS_CHECK_ENABLED false
@@ -0,0 +1,12 @@
#include "m5stack_cores3.h"
#include "m5stack_shared.h"
const HardwareConfig m5stack_cores3 = {
.bootstrap = &m5stack_bootstrap,
.display = {
.set_backlight_duty = NULL
},
.init_graphics = &m5stack_lvgl_init,
.sdcard = &m5stack_sdcard,
.power = &m5stack_power
};
@@ -0,0 +1,79 @@
#include "sdcard.h"
#include "check.h"
#include "log.h"
#include "config.h"
#include "esp_vfs_fat.h"
#include "sdmmc_cmd.h"
#define TAG "m5stack_cores3_sdcard"
typedef struct {
const char* mount_point;
sdmmc_card_t* card;
} MountData;
static void* sdcard_mount(const char* mount_point) {
TT_LOG_I(TAG, "Mounting %s", mount_point);
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
.format_if_mount_failed = CORES3_SDCARD_FORMAT_ON_MOUNT_FAILED,
.max_files = CORES3_SDCARD_MAX_OPEN_FILES,
.allocation_unit_size = CORES3_SDCARD_ALLOC_UNIT_SIZE,
.disk_status_check_enable = CORES3_SDCARD_STATUS_CHECK_ENABLED
};
sdmmc_card_t* card;
// Init without card detect (CD) and write protect (WD)
sdspi_device_config_t slot_config = SDSPI_DEVICE_CONFIG_DEFAULT();
slot_config.gpio_cs = CORES3_SDCARD_PIN_CS;
slot_config.host_id = CORES3_SDCARD_SPI_HOST;
sdmmc_host_t host = SDSPI_HOST_DEFAULT();
host.max_freq_khz = CORES3_SDCARD_SPI_FREQUENCY;
esp_err_t ret = esp_vfs_fat_sdspi_mount(mount_point, &host, &slot_config, &mount_config, &card);
if (ret != ESP_OK) {
if (ret == ESP_FAIL) {
TT_LOG_E(TAG, "Mounting failed. Ensure the card is formatted with FAT.");
} else {
TT_LOG_E(TAG, "Mounting failed (%s)", esp_err_to_name(ret));
}
return NULL;
}
MountData* data = malloc(sizeof(MountData));
*data = (MountData) {
.card = card,
.mount_point = mount_point
};
sdmmc_card_print_info(stdout, data->card);
return data;
}
static void sdcard_unmount(void* context) {
MountData* data = (MountData*)context;
TT_LOG_I(TAG, "Unmounting %s", data->mount_point);
tt_assert(data != NULL);
if (esp_vfs_fat_sdcard_unmount(data->mount_point, data->card) != ESP_OK) {
TT_LOG_E(TAG, "Unmount failed for %s", data->mount_point);
}
free(data);
}
static bool sdcard_is_mounted(void* context) {
MountData* data = (MountData*)context;
return (data != NULL) && (sdmmc_get_status(data->card) == ESP_OK);
}
const SdCard m5stack_sdcard = {
.mount = &sdcard_mount,
.unmount = &sdcard_unmount,
.is_mounted = &sdcard_is_mounted,
.mount_behaviour = SdcardMountBehaviourAnytime
};