mirror of
https://github.com/m5stack/esp-bsp.git
synced 2026-05-20 11:26:31 -07:00
feat(bsp): New SD card API
This commit is contained in:
@@ -2,6 +2,6 @@ idf_component_register(
|
||||
SRCS "esp-box-3.c" "esp-box-3_idf5.c"
|
||||
INCLUDE_DIRS "include"
|
||||
PRIV_INCLUDE_DIRS "priv_include"
|
||||
REQUIRES driver spiffs
|
||||
PRIV_REQUIRES fatfs esp_lcd
|
||||
REQUIRES driver spiffs fatfs
|
||||
PRIV_REQUIRES esp_lcd
|
||||
)
|
||||
|
||||
+165
-20
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/ledc.h"
|
||||
#include "driver/spi_master.h"
|
||||
@@ -60,7 +61,8 @@ static esp_lcd_panel_handle_t panel_handle = NULL;
|
||||
#endif // (BSP_CONFIG_NO_GRAPHIC_LIB == 0)
|
||||
|
||||
static esp_lcd_touch_handle_t tp; // LCD touch handle
|
||||
sdmmc_card_t *bsp_sdcard = NULL; // Global SD card handler
|
||||
static sdmmc_card_t *bsp_sdcard = NULL; // Global uSD card handler
|
||||
static bool spi_sd_initialized = false;
|
||||
|
||||
/**
|
||||
* @brief I2C handle for BSP usage
|
||||
@@ -185,17 +187,67 @@ esp_err_t bsp_spiffs_unmount(void)
|
||||
return esp_vfs_spiffs_unregister(CONFIG_BSP_SPIFFS_PARTITION_LABEL);
|
||||
}
|
||||
|
||||
esp_err_t bsp_sdcard_mount(void)
|
||||
sdmmc_card_t *bsp_sdcard_get_handle(void)
|
||||
{
|
||||
gpio_config_t power_gpio_config = {
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pin_bit_mask = 1ULL << BSP_SD_POWER
|
||||
};
|
||||
ESP_ERROR_CHECK(gpio_config(&power_gpio_config));
|
||||
return bsp_sdcard;
|
||||
}
|
||||
|
||||
/* SD card power on first */
|
||||
ESP_ERROR_CHECK(gpio_set_level(BSP_SD_POWER, 0));
|
||||
void bsp_sdcard_get_sdmmc_host(const int slot, sdmmc_host_t *config)
|
||||
{
|
||||
assert(config);
|
||||
|
||||
sdmmc_host_t host_config = SDMMC_HOST_DEFAULT();
|
||||
|
||||
memcpy(config, &host_config, sizeof(sdmmc_host_t));
|
||||
}
|
||||
|
||||
void bsp_sdcard_get_sdspi_host(const int slot, sdmmc_host_t *config)
|
||||
{
|
||||
assert(config);
|
||||
|
||||
sdmmc_host_t host_config = SDSPI_HOST_DEFAULT();
|
||||
host_config.slot = slot;
|
||||
|
||||
memcpy(config, &host_config, sizeof(sdmmc_host_t));
|
||||
}
|
||||
|
||||
void bsp_sdcard_sdmmc_get_slot(const int slot, sdmmc_slot_config_t *config)
|
||||
{
|
||||
assert(config);
|
||||
memset(config, 0, sizeof(sdmmc_slot_config_t));
|
||||
|
||||
/* SD card is connected to Slot 0 pins. Slot 0 uses IO MUX, so not specifying the pins here */
|
||||
config->cd = SDMMC_SLOT_NO_CD;
|
||||
config->wp = SDMMC_SLOT_NO_WP;
|
||||
config->cmd = BSP_SD_CMD;
|
||||
config->clk = BSP_SD_CLK;
|
||||
config->d0 = BSP_SD_D0;
|
||||
config->d1 = BSP_SD_D1;
|
||||
config->d2 = BSP_SD_D2;
|
||||
config->d3 = BSP_SD_D3;
|
||||
config->width = 4;
|
||||
config->flags = 0;
|
||||
}
|
||||
|
||||
void bsp_sdcard_sdspi_get_slot(const spi_host_device_t spi_host, sdspi_device_config_t *config)
|
||||
{
|
||||
assert(config);
|
||||
memset(config, 0, sizeof(sdspi_device_config_t));
|
||||
|
||||
config->gpio_cs = BSP_SD_SPI_CS;
|
||||
config->gpio_cd = SDSPI_SLOT_NO_CD;
|
||||
config->gpio_wp = SDSPI_SLOT_NO_WP;
|
||||
config->gpio_int = GPIO_NUM_NC;
|
||||
config->host_id = spi_host;
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
|
||||
config->gpio_wp_polarity = SDSPI_IO_ACTIVE_LOW;
|
||||
#endif
|
||||
}
|
||||
|
||||
esp_err_t bsp_sdcard_sdmmc_mount(bsp_sdcard_cfg_t *cfg)
|
||||
{
|
||||
sdmmc_host_t sdhost = {0};
|
||||
sdmmc_slot_config_t sdslot = {0};
|
||||
const esp_vfs_fat_sdmmc_mount_config_t mount_config = {
|
||||
#ifdef CONFIG_BSP_SD_FORMAT_ON_MOUNT_FAIL
|
||||
.format_if_mount_failed = true,
|
||||
@@ -205,23 +257,116 @@ esp_err_t bsp_sdcard_mount(void)
|
||||
.max_files = 5,
|
||||
.allocation_unit_size = 16 * 1024
|
||||
};
|
||||
assert(cfg);
|
||||
|
||||
sdmmc_host_t host = SDMMC_HOST_DEFAULT();
|
||||
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
|
||||
slot_config.width = 4;
|
||||
slot_config.cmd = BSP_SD_CMD;
|
||||
slot_config.clk = BSP_SD_CLK;
|
||||
slot_config.d0 = BSP_SD_D0;
|
||||
slot_config.d1 = BSP_SD_D1;
|
||||
slot_config.d2 = BSP_SD_D2;
|
||||
slot_config.d3 = BSP_SD_D3;
|
||||
gpio_config_t power_gpio_config = {
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pin_bit_mask = 1ULL << BSP_SD_POWER
|
||||
};
|
||||
ESP_ERROR_CHECK(gpio_config(&power_gpio_config));
|
||||
|
||||
return esp_vfs_fat_sdmmc_mount(BSP_SD_MOUNT_POINT, &host, &slot_config, &mount_config, &bsp_sdcard);
|
||||
/* SD card power on first */
|
||||
ESP_ERROR_CHECK(gpio_set_level(BSP_SD_POWER, 0));
|
||||
|
||||
if (!cfg->mount) {
|
||||
cfg->mount = &mount_config;
|
||||
}
|
||||
|
||||
if (!cfg->host) {
|
||||
bsp_sdcard_get_sdmmc_host(SDMMC_HOST_SLOT_0, &sdhost);
|
||||
cfg->host = &sdhost;
|
||||
}
|
||||
|
||||
if (!cfg->slot.sdmmc) {
|
||||
bsp_sdcard_sdmmc_get_slot(SDMMC_HOST_SLOT_0, &sdslot);
|
||||
cfg->slot.sdmmc = &sdslot;
|
||||
}
|
||||
|
||||
#if !CONFIG_FATFS_LONG_FILENAMES
|
||||
ESP_LOGW(TAG, "Warning: Long filenames on SD card are disabled in menuconfig!");
|
||||
#endif
|
||||
|
||||
return esp_vfs_fat_sdmmc_mount(BSP_SD_MOUNT_POINT, cfg->host, cfg->slot.sdmmc, cfg->mount, &bsp_sdcard);
|
||||
}
|
||||
|
||||
esp_err_t bsp_sdcard_sdspi_mount(bsp_sdcard_cfg_t *cfg)
|
||||
{
|
||||
sdmmc_host_t sdhost = {0};
|
||||
sdspi_device_config_t sdslot = {0};
|
||||
const esp_vfs_fat_sdmmc_mount_config_t mount_config = {
|
||||
#ifdef CONFIG_BSP_SD_FORMAT_ON_MOUNT_FAIL
|
||||
.format_if_mount_failed = true,
|
||||
#else
|
||||
.format_if_mount_failed = false,
|
||||
#endif
|
||||
.max_files = 5,
|
||||
.allocation_unit_size = 16 * 1024
|
||||
};
|
||||
assert(cfg);
|
||||
|
||||
gpio_config_t power_gpio_config = {
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pin_bit_mask = 1ULL << BSP_SD_POWER
|
||||
};
|
||||
ESP_ERROR_CHECK(gpio_config(&power_gpio_config));
|
||||
|
||||
/* SD card power on first */
|
||||
ESP_ERROR_CHECK(gpio_set_level(BSP_SD_POWER, 0));
|
||||
|
||||
ESP_LOGD(TAG, "Initialize SPI bus");
|
||||
const spi_bus_config_t buscfg = {
|
||||
.sclk_io_num = BSP_SD_SPI_CLK,
|
||||
.mosi_io_num = BSP_SD_SPI_MOSI,
|
||||
.miso_io_num = BSP_SD_SPI_MISO,
|
||||
.quadwp_io_num = GPIO_NUM_NC,
|
||||
.quadhd_io_num = GPIO_NUM_NC,
|
||||
.max_transfer_sz = 4000,
|
||||
};
|
||||
ESP_RETURN_ON_ERROR(spi_bus_initialize(BSP_SDSPI_HOST, &buscfg, SPI_DMA_CH_AUTO), TAG, "SPI init failed");
|
||||
spi_sd_initialized = true;
|
||||
|
||||
if (!cfg->mount) {
|
||||
cfg->mount = &mount_config;
|
||||
}
|
||||
|
||||
if (!cfg->host) {
|
||||
bsp_sdcard_get_sdspi_host(SDMMC_HOST_SLOT_0, &sdhost);
|
||||
cfg->host = &sdhost;
|
||||
}
|
||||
|
||||
if (!cfg->slot.sdspi) {
|
||||
bsp_sdcard_sdspi_get_slot(BSP_SDSPI_HOST, &sdslot);
|
||||
cfg->slot.sdspi = &sdslot;
|
||||
}
|
||||
|
||||
#if !CONFIG_FATFS_LONG_FILENAMES
|
||||
ESP_LOGW(TAG, "Warning: Long filenames on SD card are disabled in menuconfig!");
|
||||
#endif
|
||||
|
||||
return esp_vfs_fat_sdspi_mount(BSP_SD_MOUNT_POINT, cfg->host, cfg->slot.sdspi, cfg->mount, &bsp_sdcard);
|
||||
}
|
||||
|
||||
esp_err_t bsp_sdcard_mount(void)
|
||||
{
|
||||
bsp_sdcard_cfg_t cfg = {0};
|
||||
return bsp_sdcard_sdmmc_mount(&cfg);
|
||||
}
|
||||
|
||||
esp_err_t bsp_sdcard_unmount(void)
|
||||
{
|
||||
return esp_vfs_fat_sdcard_unmount(BSP_SD_MOUNT_POINT, bsp_sdcard);
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
ret |= esp_vfs_fat_sdcard_unmount(BSP_SD_MOUNT_POINT, bsp_sdcard);
|
||||
bsp_sdcard = NULL;
|
||||
|
||||
if (spi_sd_initialized) {
|
||||
ret |= spi_bus_free(BSP_SDSPI_HOST);
|
||||
spi_sd_initialized = false;
|
||||
}
|
||||
|
||||
gpio_reset_pin(BSP_SD_POWER);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_codec_dev_handle_t bsp_audio_codec_speaker_init(void)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
version: "2.0.1"
|
||||
version: "3.0.0"
|
||||
description: Board Support Package (BSP) for ESP32-S3-BOX-3
|
||||
url: https://github.com/espressif/esp-bsp/tree/master/bsp/esp-box-3
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
#include "driver/i2s_std.h"
|
||||
#include "driver/i2c_master.h"
|
||||
#include "driver/sdmmc_host.h"
|
||||
#include "driver/sdspi_host.h"
|
||||
#include "esp_vfs_fat.h"
|
||||
#include "esp_codec_dev.h"
|
||||
#include "iot_button.h"
|
||||
#include "bsp/config.h"
|
||||
@@ -73,7 +75,7 @@
|
||||
#define BSP_BUTTON_CONFIG_IO (GPIO_NUM_0)
|
||||
#define BSP_BUTTON_MUTE_IO (GPIO_NUM_1)
|
||||
|
||||
/* SD card */
|
||||
/* uSD card MMC */
|
||||
#define BSP_SD_D0 (GPIO_NUM_9)
|
||||
#define BSP_SD_D1 (GPIO_NUM_13)
|
||||
#define BSP_SD_D2 (GPIO_NUM_42)
|
||||
@@ -83,6 +85,12 @@
|
||||
#define BSP_SD_DET (GPIO_NUM_NC)
|
||||
#define BSP_SD_POWER (GPIO_NUM_43)
|
||||
|
||||
/* uSD card SPI */
|
||||
#define BSP_SD_SPI_MISO (GPIO_NUM_9)
|
||||
#define BSP_SD_SPI_CS (GPIO_NUM_12)
|
||||
#define BSP_SD_SPI_MOSI (GPIO_NUM_14)
|
||||
#define BSP_SD_SPI_CLK (GPIO_NUM_11)
|
||||
|
||||
/* PMOD */
|
||||
/*
|
||||
* PMOD interface (peripheral module interface) is an open standard defined by Digilent Inc.
|
||||
@@ -284,7 +292,16 @@ esp_err_t bsp_spiffs_unmount(void);
|
||||
* @attention IO2 is also routed to RGB LED and push button
|
||||
**************************************************************************************************/
|
||||
#define BSP_SD_MOUNT_POINT CONFIG_BSP_SD_MOUNT_POINT
|
||||
extern sdmmc_card_t *bsp_sdcard;
|
||||
#define BSP_SDSPI_HOST (SPI2_HOST)
|
||||
|
||||
typedef struct {
|
||||
const esp_vfs_fat_sdmmc_mount_config_t *mount;
|
||||
sdmmc_host_t *host;
|
||||
union {
|
||||
const sdmmc_slot_config_t *sdmmc;
|
||||
const sdspi_device_config_t *sdspi;
|
||||
} slot;
|
||||
} bsp_sdcard_cfg_t;
|
||||
|
||||
/**
|
||||
* @brief Mount microSD card to virtual file system
|
||||
@@ -311,6 +328,73 @@ esp_err_t bsp_sdcard_mount(void);
|
||||
*/
|
||||
esp_err_t bsp_sdcard_unmount(void);
|
||||
|
||||
/**
|
||||
* @brief Get SD card handle
|
||||
*
|
||||
* @return SD card handle
|
||||
*/
|
||||
sdmmc_card_t *bsp_sdcard_get_handle(void);
|
||||
|
||||
/**
|
||||
* @brief Get SD card MMC host config
|
||||
*
|
||||
* @param slot SD card slot
|
||||
* @param config Structure which will be filled
|
||||
*/
|
||||
void bsp_sdcard_get_sdmmc_host(const int slot, sdmmc_host_t *config);
|
||||
|
||||
/**
|
||||
* @brief Get SD card SPI host config
|
||||
*
|
||||
* @param slot SD card slot
|
||||
* @param config Structure which will be filled
|
||||
*/
|
||||
void bsp_sdcard_get_sdspi_host(const int slot, sdmmc_host_t *config);
|
||||
|
||||
/**
|
||||
* @brief Get SD card MMC slot config
|
||||
*
|
||||
* @param slot SD card slot
|
||||
* @param config Structure which will be filled
|
||||
*/
|
||||
void bsp_sdcard_sdmmc_get_slot(const int slot, sdmmc_slot_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Get SD card SPI slot config
|
||||
*
|
||||
* @param spi_host SPI host ID
|
||||
* @param config Structure which will be filled
|
||||
*/
|
||||
void bsp_sdcard_sdspi_get_slot(const spi_host_device_t spi_host, sdspi_device_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Mount microSD card to virtual file system (MMC mode)
|
||||
*
|
||||
* @param cfg SD card configuration
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_STATE if esp_vfs_fat_sdmmc_mount was already called
|
||||
* - ESP_ERR_NO_MEM if memory cannot be allocated
|
||||
* - ESP_FAIL if partition cannot be mounted
|
||||
* - other error codes from SDMMC or SPI drivers, SDMMC protocol, or FATFS drivers
|
||||
*/
|
||||
esp_err_t bsp_sdcard_sdmmc_mount(bsp_sdcard_cfg_t *cfg);
|
||||
|
||||
/**
|
||||
* @brief Mount microSD card to virtual file system (SPI mode)
|
||||
*
|
||||
* @param cfg SD card configuration
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_STATE if esp_vfs_fat_sdmmc_mount was already called
|
||||
* - ESP_ERR_NO_MEM if memory cannot be allocated
|
||||
* - ESP_FAIL if partition cannot be mounted
|
||||
* - other error codes from SDMMC or SPI drivers, SDMMC protocol, or FATFS drivers
|
||||
*/
|
||||
esp_err_t bsp_sdcard_sdspi_mount(bsp_sdcard_cfg_t *cfg);
|
||||
|
||||
/**************************************************************************************************
|
||||
*
|
||||
* LCD interface
|
||||
|
||||
@@ -2,6 +2,6 @@ idf_component_register(
|
||||
SRCS "esp32_azure_iot_kit.c"
|
||||
INCLUDE_DIRS "include"
|
||||
PRIV_INCLUDE_DIRS "priv_include"
|
||||
REQUIRES driver esp_lcd
|
||||
PRIV_REQUIRES fatfs spiffs
|
||||
REQUIRES driver esp_lcd fatfs
|
||||
PRIV_REQUIRES spiffs
|
||||
)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "esp_err.h"
|
||||
#include "esp_vfs_fat.h"
|
||||
#include "driver/ledc.h"
|
||||
@@ -21,7 +22,8 @@
|
||||
static const char *TAG = "Azure-IoT";
|
||||
|
||||
static lv_display_t *disp;
|
||||
sdmmc_card_t *bsp_sdcard = NULL; // Global uSD card handler
|
||||
static sdmmc_card_t *bsp_sdcard = NULL; // Global uSD card handler
|
||||
static bool spi_sd_initialized = false;
|
||||
static bool i2c_initialized = false;
|
||||
|
||||
static const button_gpio_config_t bsp_button_config[BSP_BUTTON_NUM] = {
|
||||
@@ -160,9 +162,62 @@ esp_err_t bsp_spiffs_unmount(void)
|
||||
return esp_vfs_spiffs_unregister(CONFIG_BSP_SPIFFS_PARTITION_LABEL);
|
||||
}
|
||||
|
||||
esp_err_t bsp_sdcard_mount(void)
|
||||
sdmmc_card_t *bsp_sdcard_get_handle(void)
|
||||
{
|
||||
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
|
||||
return bsp_sdcard;
|
||||
}
|
||||
|
||||
void bsp_sdcard_get_sdmmc_host(const int slot, sdmmc_host_t *config)
|
||||
{
|
||||
assert(config);
|
||||
|
||||
sdmmc_host_t host_config = SDMMC_HOST_DEFAULT();
|
||||
|
||||
memcpy(config, &host_config, sizeof(sdmmc_host_t));
|
||||
}
|
||||
|
||||
void bsp_sdcard_get_sdspi_host(const int slot, sdmmc_host_t *config)
|
||||
{
|
||||
assert(config);
|
||||
|
||||
sdmmc_host_t host_config = SDSPI_HOST_DEFAULT();
|
||||
host_config.slot = slot;
|
||||
|
||||
memcpy(config, &host_config, sizeof(sdmmc_host_t));
|
||||
}
|
||||
|
||||
void bsp_sdcard_sdmmc_get_slot(const int slot, sdmmc_slot_config_t *config)
|
||||
{
|
||||
assert(config);
|
||||
memset(config, 0, sizeof(sdmmc_slot_config_t));
|
||||
|
||||
/* SD card is connected to Slot 0 pins. Slot 0 uses IO MUX, so not specifying the pins here */
|
||||
config->cd = SDMMC_SLOT_NO_CD;
|
||||
config->wp = SDMMC_SLOT_NO_WP;
|
||||
config->width = 1;
|
||||
config->flags = SDMMC_SLOT_FLAG_INTERNAL_PULLUP;
|
||||
}
|
||||
|
||||
void bsp_sdcard_sdspi_get_slot(const spi_host_device_t spi_host, sdspi_device_config_t *config)
|
||||
{
|
||||
assert(config);
|
||||
memset(config, 0, sizeof(sdspi_device_config_t));
|
||||
|
||||
config->gpio_cs = BSP_SD_SPI_CS;
|
||||
config->gpio_cd = SDSPI_SLOT_NO_CD;
|
||||
config->gpio_wp = SDSPI_SLOT_NO_WP;
|
||||
config->gpio_int = GPIO_NUM_NC;
|
||||
config->host_id = spi_host;
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
|
||||
config->gpio_wp_polarity = SDSPI_IO_ACTIVE_LOW;
|
||||
#endif
|
||||
}
|
||||
|
||||
esp_err_t bsp_sdcard_sdmmc_mount(bsp_sdcard_cfg_t *cfg)
|
||||
{
|
||||
sdmmc_host_t sdhost = {0};
|
||||
sdmmc_slot_config_t sdslot = {0};
|
||||
const esp_vfs_fat_sdmmc_mount_config_t mount_config = {
|
||||
#ifdef CONFIG_BSP_SD_FORMAT_ON_MOUNT_FAIL
|
||||
.format_if_mount_failed = true,
|
||||
#else
|
||||
@@ -171,17 +226,96 @@ esp_err_t bsp_sdcard_mount(void)
|
||||
.max_files = 5,
|
||||
.allocation_unit_size = 16 * 1024
|
||||
};
|
||||
assert(cfg);
|
||||
|
||||
sdmmc_host_t host = SDMMC_HOST_DEFAULT();
|
||||
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
|
||||
slot_config.width = 1;
|
||||
if (!cfg->mount) {
|
||||
cfg->mount = &mount_config;
|
||||
}
|
||||
|
||||
return esp_vfs_fat_sdmmc_mount(BSP_SD_MOUNT_POINT, &host, &slot_config, &mount_config, &bsp_sdcard);
|
||||
if (!cfg->host) {
|
||||
bsp_sdcard_get_sdmmc_host(SDMMC_HOST_SLOT_0, &sdhost);
|
||||
cfg->host = &sdhost;
|
||||
}
|
||||
|
||||
if (!cfg->slot.sdmmc) {
|
||||
bsp_sdcard_sdmmc_get_slot(SDMMC_HOST_SLOT_0, &sdslot);
|
||||
cfg->slot.sdmmc = &sdslot;
|
||||
}
|
||||
|
||||
#if !CONFIG_FATFS_LONG_FILENAMES
|
||||
ESP_LOGW(TAG, "Warning: Long filenames on SD card are disabled in menuconfig!");
|
||||
#endif
|
||||
|
||||
return esp_vfs_fat_sdmmc_mount(BSP_SD_MOUNT_POINT, cfg->host, cfg->slot.sdmmc, cfg->mount, &bsp_sdcard);
|
||||
}
|
||||
|
||||
esp_err_t bsp_sdcard_sdspi_mount(bsp_sdcard_cfg_t *cfg)
|
||||
{
|
||||
sdmmc_host_t sdhost = {0};
|
||||
sdspi_device_config_t sdslot = {0};
|
||||
const esp_vfs_fat_sdmmc_mount_config_t mount_config = {
|
||||
#ifdef CONFIG_BSP_SD_FORMAT_ON_MOUNT_FAIL
|
||||
.format_if_mount_failed = true,
|
||||
#else
|
||||
.format_if_mount_failed = false,
|
||||
#endif
|
||||
.max_files = 5,
|
||||
.allocation_unit_size = 16 * 1024
|
||||
};
|
||||
assert(cfg);
|
||||
|
||||
ESP_LOGD(TAG, "Initialize SPI bus");
|
||||
const spi_bus_config_t buscfg = {
|
||||
.sclk_io_num = BSP_SD_SPI_CLK,
|
||||
.mosi_io_num = BSP_SD_SPI_MOSI,
|
||||
.miso_io_num = BSP_SD_SPI_MISO,
|
||||
.quadwp_io_num = GPIO_NUM_NC,
|
||||
.quadhd_io_num = GPIO_NUM_NC,
|
||||
.max_transfer_sz = 4000,
|
||||
};
|
||||
ESP_RETURN_ON_ERROR(spi_bus_initialize(BSP_SDSPI_HOST, &buscfg, SPI_DMA_CH_AUTO), TAG, "SPI init failed");
|
||||
spi_sd_initialized = true;
|
||||
|
||||
if (!cfg->mount) {
|
||||
cfg->mount = &mount_config;
|
||||
}
|
||||
|
||||
if (!cfg->host) {
|
||||
bsp_sdcard_get_sdspi_host(SDMMC_HOST_SLOT_0, &sdhost);
|
||||
cfg->host = &sdhost;
|
||||
}
|
||||
|
||||
if (!cfg->slot.sdspi) {
|
||||
bsp_sdcard_sdspi_get_slot(BSP_SDSPI_HOST, &sdslot);
|
||||
cfg->slot.sdspi = &sdslot;
|
||||
}
|
||||
|
||||
#if !CONFIG_FATFS_LONG_FILENAMES
|
||||
ESP_LOGW(TAG, "Warning: Long filenames on SD card are disabled in menuconfig!");
|
||||
#endif
|
||||
|
||||
return esp_vfs_fat_sdspi_mount(BSP_SD_MOUNT_POINT, cfg->host, cfg->slot.sdspi, cfg->mount, &bsp_sdcard);
|
||||
}
|
||||
|
||||
esp_err_t bsp_sdcard_mount(void)
|
||||
{
|
||||
bsp_sdcard_cfg_t cfg = {0};
|
||||
return bsp_sdcard_sdmmc_mount(&cfg);
|
||||
}
|
||||
|
||||
esp_err_t bsp_sdcard_unmount(void)
|
||||
{
|
||||
return esp_vfs_fat_sdcard_unmount(BSP_SD_MOUNT_POINT, bsp_sdcard);
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
ret |= esp_vfs_fat_sdcard_unmount(BSP_SD_MOUNT_POINT, bsp_sdcard);
|
||||
bsp_sdcard = NULL;
|
||||
|
||||
if (spi_sd_initialized) {
|
||||
ret |= spi_bus_free(BSP_SDSPI_HOST);
|
||||
spi_sd_initialized = false;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t bsp_display_brightness_init(void)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
version: "2.1.0"
|
||||
version: "3.0.0"
|
||||
description: Board Support Package (BSP) for ESP32-Azure-IoT-Kit
|
||||
url: https://github.com/espressif/esp-bsp/tree/master/bsp/esp32_azure_iot_kit
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -14,6 +14,8 @@
|
||||
#include "driver/i2c.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/sdmmc_host.h"
|
||||
#include "driver/sdspi_host.h"
|
||||
#include "esp_vfs_fat.h"
|
||||
#include "sdkconfig.h"
|
||||
#include "iot_button.h"
|
||||
#include "esp_lvgl_port.h"
|
||||
@@ -52,6 +54,18 @@
|
||||
/* Buttons */
|
||||
#define BSP_BUTTON_MAIN_IO (GPIO_NUM_0)
|
||||
|
||||
/* uSD card MMC */
|
||||
#define BSP_SD_D0 (GPIO_NUM_2)
|
||||
#define BSP_SD_CMD (GPIO_NUM_15)
|
||||
#define BSP_SD_CLK (GPIO_NUM_14)
|
||||
#define BSP_SD_DET (GPIO_NUM_21)
|
||||
|
||||
/* uSD card SPI */
|
||||
#define BSP_SD_SPI_MISO (GPIO_NUM_2)
|
||||
#define BSP_SD_SPI_CS (GPIO_NUM_13)
|
||||
#define BSP_SD_SPI_MOSI (GPIO_NUM_15)
|
||||
#define BSP_SD_SPI_CLK (GPIO_NUM_14)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -172,7 +186,16 @@ esp_err_t bsp_spiffs_unmount(void);
|
||||
* \endcode
|
||||
**************************************************************************************************/
|
||||
#define BSP_SD_MOUNT_POINT CONFIG_BSP_SD_MOUNT_POINT
|
||||
extern sdmmc_card_t *bsp_sdcard;
|
||||
#define BSP_SDSPI_HOST (SDSPI_DEFAULT_HOST)
|
||||
|
||||
typedef struct {
|
||||
const esp_vfs_fat_sdmmc_mount_config_t *mount;
|
||||
sdmmc_host_t *host;
|
||||
union {
|
||||
const sdmmc_slot_config_t *sdmmc;
|
||||
const sdspi_device_config_t *sdspi;
|
||||
} slot;
|
||||
} bsp_sdcard_cfg_t;
|
||||
|
||||
/**
|
||||
* @brief Mount microSD card to virtual file system
|
||||
@@ -199,6 +222,73 @@ esp_err_t bsp_sdcard_mount(void);
|
||||
*/
|
||||
esp_err_t bsp_sdcard_unmount(void);
|
||||
|
||||
/**
|
||||
* @brief Get SD card handle
|
||||
*
|
||||
* @return SD card handle
|
||||
*/
|
||||
sdmmc_card_t *bsp_sdcard_get_handle(void);
|
||||
|
||||
/**
|
||||
* @brief Get SD card MMC host config
|
||||
*
|
||||
* @param slot SD card slot
|
||||
* @param config Structure which will be filled
|
||||
*/
|
||||
void bsp_sdcard_get_sdmmc_host(const int slot, sdmmc_host_t *config);
|
||||
|
||||
/**
|
||||
* @brief Get SD card SPI host config
|
||||
*
|
||||
* @param slot SD card slot
|
||||
* @param config Structure which will be filled
|
||||
*/
|
||||
void bsp_sdcard_get_sdspi_host(const int slot, sdmmc_host_t *config);
|
||||
|
||||
/**
|
||||
* @brief Get SD card MMC slot config
|
||||
*
|
||||
* @param slot SD card slot
|
||||
* @param config Structure which will be filled
|
||||
*/
|
||||
void bsp_sdcard_sdmmc_get_slot(const int slot, sdmmc_slot_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Get SD card SPI slot config
|
||||
*
|
||||
* @param spi_host SPI host ID
|
||||
* @param config Structure which will be filled
|
||||
*/
|
||||
void bsp_sdcard_sdspi_get_slot(const spi_host_device_t spi_host, sdspi_device_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Mount microSD card to virtual file system (MMC mode)
|
||||
*
|
||||
* @param cfg SD card configuration
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_STATE if esp_vfs_fat_sdmmc_mount was already called
|
||||
* - ESP_ERR_NO_MEM if memory cannot be allocated
|
||||
* - ESP_FAIL if partition cannot be mounted
|
||||
* - other error codes from SDMMC or SPI drivers, SDMMC protocol, or FATFS drivers
|
||||
*/
|
||||
esp_err_t bsp_sdcard_sdmmc_mount(bsp_sdcard_cfg_t *cfg);
|
||||
|
||||
/**
|
||||
* @brief Mount microSD card to virtual file system (SPI mode)
|
||||
*
|
||||
* @param cfg SD card configuration
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_STATE if esp_vfs_fat_sdmmc_mount was already called
|
||||
* - ESP_ERR_NO_MEM if memory cannot be allocated
|
||||
* - ESP_FAIL if partition cannot be mounted
|
||||
* - other error codes from SDMMC or SPI drivers, SDMMC protocol, or FATFS drivers
|
||||
*/
|
||||
esp_err_t bsp_sdcard_sdspi_mount(bsp_sdcard_cfg_t *cfg);
|
||||
|
||||
/**************************************************************************************************
|
||||
*
|
||||
* LCD interface
|
||||
|
||||
@@ -9,6 +9,5 @@ idf_component_register(
|
||||
SRCS "esp32_lyrat.c" ${SRC_VER}
|
||||
INCLUDE_DIRS "include"
|
||||
PRIV_INCLUDE_DIRS "priv_include"
|
||||
REQUIRES driver spiffs
|
||||
PRIV_REQUIRES fatfs
|
||||
REQUIRES driver spiffs fatfs
|
||||
)
|
||||
|
||||
+141
-10
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
@@ -17,7 +18,8 @@
|
||||
|
||||
static const char *TAG = "LyraT";
|
||||
|
||||
sdmmc_card_t *bsp_sdcard = NULL; // Global uSD card handler
|
||||
static sdmmc_card_t *bsp_sdcard = NULL; // Global uSD card handler
|
||||
static bool spi_sd_initialized = false;
|
||||
|
||||
static esp_err_t bsp_touchpad_custom_deinit(button_driver_t *button_driver);
|
||||
static uint8_t bsp_touchpad_custom_get_key_value(button_driver_t *button_driver);
|
||||
@@ -161,8 +163,61 @@ esp_err_t bsp_spiffs_unmount(void)
|
||||
return esp_vfs_spiffs_unregister(CONFIG_BSP_SPIFFS_PARTITION_LABEL);
|
||||
}
|
||||
|
||||
esp_err_t bsp_sdcard_mount(void)
|
||||
sdmmc_card_t *bsp_sdcard_get_handle(void)
|
||||
{
|
||||
return bsp_sdcard;
|
||||
}
|
||||
|
||||
void bsp_sdcard_get_sdmmc_host(const int slot, sdmmc_host_t *config)
|
||||
{
|
||||
assert(config);
|
||||
|
||||
sdmmc_host_t host_config = SDMMC_HOST_DEFAULT();
|
||||
|
||||
memcpy(config, &host_config, sizeof(sdmmc_host_t));
|
||||
}
|
||||
|
||||
void bsp_sdcard_get_sdspi_host(const int slot, sdmmc_host_t *config)
|
||||
{
|
||||
assert(config);
|
||||
|
||||
sdmmc_host_t host_config = SDSPI_HOST_DEFAULT();
|
||||
host_config.slot = slot;
|
||||
|
||||
memcpy(config, &host_config, sizeof(sdmmc_host_t));
|
||||
}
|
||||
|
||||
void bsp_sdcard_sdmmc_get_slot(const int slot, sdmmc_slot_config_t *config)
|
||||
{
|
||||
assert(config);
|
||||
memset(config, 0, sizeof(sdmmc_slot_config_t));
|
||||
|
||||
/* SD card is connected to Slot 0 pins. Slot 0 uses IO MUX, so not specifying the pins here */
|
||||
config->cd = SDMMC_SLOT_NO_CD;
|
||||
config->wp = SDMMC_SLOT_NO_WP;
|
||||
config->width = 1;
|
||||
config->flags = SDMMC_SLOT_FLAG_INTERNAL_PULLUP;
|
||||
}
|
||||
|
||||
void bsp_sdcard_sdspi_get_slot(const spi_host_device_t spi_host, sdspi_device_config_t *config)
|
||||
{
|
||||
assert(config);
|
||||
memset(config, 0, sizeof(sdspi_device_config_t));
|
||||
|
||||
config->gpio_cs = BSP_SD_SPI_CS;
|
||||
config->gpio_cd = SDSPI_SLOT_NO_CD;
|
||||
config->gpio_wp = SDSPI_SLOT_NO_WP;
|
||||
config->gpio_int = GPIO_NUM_NC;
|
||||
config->host_id = spi_host;
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
|
||||
config->gpio_wp_polarity = SDSPI_IO_ACTIVE_LOW;
|
||||
#endif
|
||||
}
|
||||
|
||||
esp_err_t bsp_sdcard_sdmmc_mount(bsp_sdcard_cfg_t *cfg)
|
||||
{
|
||||
sdmmc_host_t sdhost = {0};
|
||||
sdmmc_slot_config_t sdslot = {0};
|
||||
const esp_vfs_fat_sdmmc_mount_config_t mount_config = {
|
||||
#ifdef CONFIG_BSP_SD_FORMAT_ON_MOUNT_FAIL
|
||||
.format_if_mount_failed = true,
|
||||
@@ -172,21 +227,97 @@ esp_err_t bsp_sdcard_mount(void)
|
||||
.max_files = 5,
|
||||
.allocation_unit_size = 16 * 1024
|
||||
};
|
||||
assert(cfg);
|
||||
|
||||
const sdmmc_host_t host = SDMMC_HOST_DEFAULT();
|
||||
const sdmmc_slot_config_t slot_config = {
|
||||
.cd = SDMMC_SLOT_NO_CD,
|
||||
.wp = SDMMC_SLOT_NO_WP,
|
||||
.width = 1,
|
||||
.flags = 0,
|
||||
if (!cfg->mount) {
|
||||
cfg->mount = &mount_config;
|
||||
}
|
||||
|
||||
if (!cfg->host) {
|
||||
bsp_sdcard_get_sdmmc_host(SDMMC_HOST_SLOT_0, &sdhost);
|
||||
cfg->host = &sdhost;
|
||||
}
|
||||
|
||||
if (!cfg->slot.sdmmc) {
|
||||
bsp_sdcard_sdmmc_get_slot(SDMMC_HOST_SLOT_0, &sdslot);
|
||||
cfg->slot.sdmmc = &sdslot;
|
||||
}
|
||||
|
||||
#if !CONFIG_FATFS_LONG_FILENAMES
|
||||
ESP_LOGW(TAG, "Warning: Long filenames on SD card are disabled in menuconfig!");
|
||||
#endif
|
||||
|
||||
return esp_vfs_fat_sdmmc_mount(BSP_SD_MOUNT_POINT, cfg->host, cfg->slot.sdmmc, cfg->mount, &bsp_sdcard);
|
||||
}
|
||||
|
||||
esp_err_t bsp_sdcard_sdspi_mount(bsp_sdcard_cfg_t *cfg)
|
||||
{
|
||||
sdmmc_host_t sdhost = {0};
|
||||
sdspi_device_config_t sdslot = {0};
|
||||
const esp_vfs_fat_sdmmc_mount_config_t mount_config = {
|
||||
#ifdef CONFIG_BSP_SD_FORMAT_ON_MOUNT_FAIL
|
||||
.format_if_mount_failed = true,
|
||||
#else
|
||||
.format_if_mount_failed = false,
|
||||
#endif
|
||||
.max_files = 5,
|
||||
.allocation_unit_size = 16 * 1024
|
||||
};
|
||||
assert(cfg);
|
||||
|
||||
return esp_vfs_fat_sdmmc_mount(BSP_SD_MOUNT_POINT, &host, &slot_config, &mount_config, &bsp_sdcard);
|
||||
ESP_LOGD(TAG, "Initialize SPI bus");
|
||||
const spi_bus_config_t buscfg = {
|
||||
.sclk_io_num = BSP_SD_SPI_CLK,
|
||||
.mosi_io_num = BSP_SD_SPI_MOSI,
|
||||
.miso_io_num = BSP_SD_SPI_MISO,
|
||||
.quadwp_io_num = GPIO_NUM_NC,
|
||||
.quadhd_io_num = GPIO_NUM_NC,
|
||||
.max_transfer_sz = 4000,
|
||||
};
|
||||
ESP_RETURN_ON_ERROR(spi_bus_initialize(BSP_SDSPI_HOST, &buscfg, SPI_DMA_CH_AUTO), TAG, "SPI init failed");
|
||||
spi_sd_initialized = true;
|
||||
|
||||
if (!cfg->mount) {
|
||||
cfg->mount = &mount_config;
|
||||
}
|
||||
|
||||
if (!cfg->host) {
|
||||
bsp_sdcard_get_sdspi_host(SDMMC_HOST_SLOT_0, &sdhost);
|
||||
cfg->host = &sdhost;
|
||||
}
|
||||
|
||||
if (!cfg->slot.sdspi) {
|
||||
bsp_sdcard_sdspi_get_slot(BSP_SDSPI_HOST, &sdslot);
|
||||
cfg->slot.sdspi = &sdslot;
|
||||
}
|
||||
|
||||
#if !CONFIG_FATFS_LONG_FILENAMES
|
||||
ESP_LOGW(TAG, "Warning: Long filenames on SD card are disabled in menuconfig!");
|
||||
#endif
|
||||
|
||||
ESP_RETURN_ON_ERROR(esp_vfs_fat_sdspi_mount(BSP_SD_MOUNT_POINT, cfg->host, cfg->slot.sdspi, cfg->mount, &bsp_sdcard), TAG, "SD card SPI mount failed, please check JP8. Pin 2 must be switched to ON.");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t bsp_sdcard_mount(void)
|
||||
{
|
||||
bsp_sdcard_cfg_t cfg = {0};
|
||||
return bsp_sdcard_sdmmc_mount(&cfg);
|
||||
}
|
||||
|
||||
esp_err_t bsp_sdcard_unmount(void)
|
||||
{
|
||||
return esp_vfs_fat_sdcard_unmount(BSP_SD_MOUNT_POINT, bsp_sdcard);
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
ret |= esp_vfs_fat_sdcard_unmount(BSP_SD_MOUNT_POINT, bsp_sdcard);
|
||||
bsp_sdcard = NULL;
|
||||
|
||||
if (spi_sd_initialized) {
|
||||
ret |= spi_bus_free(BSP_SDSPI_HOST);
|
||||
spi_sd_initialized = false;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static esp_codec_dev_handle_t bsp_audio_codec_init(void)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
version: "1.0.0~3"
|
||||
version: "2.0.0"
|
||||
description: Board Support Package (BSP) for ESP32-LyraT
|
||||
url: https://github.com/espressif/esp-bsp/tree/master/bsp/esp32_lyrat
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -10,6 +10,8 @@
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/i2c.h"
|
||||
#include "driver/sdmmc_host.h"
|
||||
#include "driver/sdspi_host.h"
|
||||
#include "esp_vfs_fat.h"
|
||||
#include "esp_codec_dev.h"
|
||||
#include "driver/touch_pad.h"
|
||||
#include "iot_button.h"
|
||||
@@ -49,14 +51,17 @@
|
||||
#define BSP_I2S_DSIN (GPIO_NUM_35) // From ADC ES8388
|
||||
#define BSP_POWER_AMP_IO (GPIO_NUM_21)
|
||||
|
||||
/* uSD card */
|
||||
/* uSD card MMC */
|
||||
#define BSP_SD_D0 (GPIO_NUM_2)
|
||||
#define BSP_SD_D1 (GPIO_NUM_4)
|
||||
#define BSP_SD_D2 (GPIO_NUM_12)
|
||||
#define BSP_SD_D3 (GPIO_NUM_13)
|
||||
#define BSP_SD_CMD (GPIO_NUM_15)
|
||||
#define BSP_SD_CLK (GPIO_NUM_14)
|
||||
|
||||
/* uSD card SPI */
|
||||
#define BSP_SD_SPI_MISO (GPIO_NUM_2)
|
||||
#define BSP_SD_SPI_CS (GPIO_NUM_13)
|
||||
#define BSP_SD_SPI_MOSI (GPIO_NUM_15)
|
||||
#define BSP_SD_SPI_CLK (GPIO_NUM_14)
|
||||
|
||||
/* Buttons */
|
||||
#define BSP_BUTTON_REC_IO (GPIO_NUM_36)
|
||||
#define BSP_BUTTON_MODE_IO (GPIO_NUM_39)
|
||||
@@ -257,7 +262,16 @@ esp_err_t bsp_spiffs_unmount(void);
|
||||
* \endcode
|
||||
**************************************************************************************************/
|
||||
#define BSP_SD_MOUNT_POINT CONFIG_BSP_SD_MOUNT_POINT
|
||||
extern sdmmc_card_t *bsp_sdcard;
|
||||
#define BSP_SDSPI_HOST (SDSPI_DEFAULT_HOST)
|
||||
|
||||
typedef struct {
|
||||
const esp_vfs_fat_sdmmc_mount_config_t *mount;
|
||||
sdmmc_host_t *host;
|
||||
union {
|
||||
const sdmmc_slot_config_t *sdmmc;
|
||||
const sdspi_device_config_t *sdspi;
|
||||
} slot;
|
||||
} bsp_sdcard_cfg_t;
|
||||
|
||||
/**
|
||||
* @brief Mount microSD card to virtual file system
|
||||
@@ -284,6 +298,73 @@ esp_err_t bsp_sdcard_mount(void);
|
||||
*/
|
||||
esp_err_t bsp_sdcard_unmount(void);
|
||||
|
||||
/**
|
||||
* @brief Get SD card handle
|
||||
*
|
||||
* @return SD card handle
|
||||
*/
|
||||
sdmmc_card_t *bsp_sdcard_get_handle(void);
|
||||
|
||||
/**
|
||||
* @brief Get SD card MMC host config
|
||||
*
|
||||
* @param slot SD card slot
|
||||
* @param config Structure which will be filled
|
||||
*/
|
||||
void bsp_sdcard_get_sdmmc_host(const int slot, sdmmc_host_t *config);
|
||||
|
||||
/**
|
||||
* @brief Get SD card SPI host config
|
||||
*
|
||||
* @param slot SD card slot
|
||||
* @param config Structure which will be filled
|
||||
*/
|
||||
void bsp_sdcard_get_sdspi_host(const int slot, sdmmc_host_t *config);
|
||||
|
||||
/**
|
||||
* @brief Get SD card MMC slot config
|
||||
*
|
||||
* @param slot SD card slot
|
||||
* @param config Structure which will be filled
|
||||
*/
|
||||
void bsp_sdcard_sdmmc_get_slot(const int slot, sdmmc_slot_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Get SD card SPI slot config
|
||||
*
|
||||
* @param spi_host SPI host ID
|
||||
* @param config Structure which will be filled
|
||||
*/
|
||||
void bsp_sdcard_sdspi_get_slot(const spi_host_device_t spi_host, sdspi_device_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Mount microSD card to virtual file system (MMC mode)
|
||||
*
|
||||
* @param cfg SD card configuration
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_STATE if esp_vfs_fat_sdmmc_mount was already called
|
||||
* - ESP_ERR_NO_MEM if memory cannot be allocated
|
||||
* - ESP_FAIL if partition cannot be mounted
|
||||
* - other error codes from SDMMC or SPI drivers, SDMMC protocol, or FATFS drivers
|
||||
*/
|
||||
esp_err_t bsp_sdcard_sdmmc_mount(bsp_sdcard_cfg_t *cfg);
|
||||
|
||||
/**
|
||||
* @brief Mount microSD card to virtual file system (SPI mode)
|
||||
*
|
||||
* @param cfg SD card configuration
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_STATE if esp_vfs_fat_sdmmc_mount was already called
|
||||
* - ESP_ERR_NO_MEM if memory cannot be allocated
|
||||
* - ESP_FAIL if partition cannot be mounted
|
||||
* - other error codes from SDMMC or SPI drivers, SDMMC protocol, or FATFS drivers
|
||||
*/
|
||||
esp_err_t bsp_sdcard_sdspi_mount(bsp_sdcard_cfg_t *cfg);
|
||||
|
||||
/**************************************************************************************************
|
||||
*
|
||||
* LEDs
|
||||
|
||||
@@ -204,6 +204,10 @@ esp_err_t bsp_sdcard_sdmmc_mount(bsp_sdcard_cfg_t *cfg)
|
||||
}
|
||||
cfg->host->pwr_ctrl_handle = pwr_ctrl_handle;
|
||||
|
||||
#if !CONFIG_FATFS_LONG_FILENAMES
|
||||
ESP_LOGW(TAG, "Warning: Long filenames on SD card are disabled in menuconfig!");
|
||||
#endif
|
||||
|
||||
return esp_vfs_fat_sdmmc_mount(BSP_SD_MOUNT_POINT, cfg->host, cfg->slot.sdmmc, cfg->mount, &bsp_sdcard);
|
||||
}
|
||||
|
||||
@@ -258,6 +262,10 @@ esp_err_t bsp_sdcard_sdspi_mount(bsp_sdcard_cfg_t *cfg)
|
||||
}
|
||||
cfg->host->pwr_ctrl_handle = pwr_ctrl_handle;
|
||||
|
||||
#if !CONFIG_FATFS_LONG_FILENAMES
|
||||
ESP_LOGW(TAG, "Warning: Long filenames on SD card are disabled in menuconfig!");
|
||||
#endif
|
||||
|
||||
return esp_vfs_fat_sdspi_mount(BSP_SD_MOUNT_POINT, cfg->host, cfg->slot.sdspi, cfg->mount, &bsp_sdcard);
|
||||
}
|
||||
|
||||
|
||||
@@ -188,7 +188,6 @@ esp_codec_dev_handle_t bsp_audio_codec_microphone_init(void);
|
||||
* \endcode
|
||||
**************************************************************************************************/
|
||||
#define BSP_SPIFFS_MOUNT_POINT CONFIG_BSP_SPIFFS_MOUNT_POINT
|
||||
#define BSP_SDSPI_HOST (SDSPI_DEFAULT_HOST)
|
||||
|
||||
/**
|
||||
* @brief Mount SPIFFS to virtual file system
|
||||
@@ -227,6 +226,7 @@ esp_err_t bsp_spiffs_unmount(void);
|
||||
* \endcode
|
||||
**************************************************************************************************/
|
||||
#define BSP_SD_MOUNT_POINT CONFIG_BSP_SD_MOUNT_POINT
|
||||
#define BSP_SDSPI_HOST (SDSPI_DEFAULT_HOST)
|
||||
|
||||
typedef struct {
|
||||
const esp_vfs_fat_sdmmc_mount_config_t *mount;
|
||||
|
||||
@@ -2,6 +2,6 @@ idf_component_register(
|
||||
SRCS "esp32_s3_eye.c" "esp32_s3_eye_idf5.c"
|
||||
INCLUDE_DIRS "include"
|
||||
PRIV_INCLUDE_DIRS "priv_include"
|
||||
REQUIRES esp_driver_gpio esp_driver_sdmmc spiffs esp_driver_i2c
|
||||
PRIV_REQUIRES fatfs esp_lcd esp_driver_ledc esp_driver_spi
|
||||
REQUIRES esp_driver_gpio esp_driver_sdmmc spiffs esp_driver_i2c fatfs
|
||||
PRIV_REQUIRES esp_lcd esp_driver_ledc esp_driver_spi
|
||||
)
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "esp_vfs_fat.h"
|
||||
#include "esp_lcd_panel_io.h"
|
||||
#include "esp_lcd_panel_vendor.h"
|
||||
@@ -40,7 +41,7 @@ static const char *TAG = "S3-EYE";
|
||||
static i2c_master_bus_handle_t i2c_handle = NULL;
|
||||
static bool i2c_initialized = false;
|
||||
static adc_oneshot_unit_handle_t bsp_adc_handle = NULL;
|
||||
sdmmc_card_t *bsp_sdcard = NULL; // Global uSD card handler
|
||||
static sdmmc_card_t *bsp_sdcard = NULL; // Global uSD card handler
|
||||
|
||||
typedef enum {
|
||||
BSP_BUTTON_TYPE_GPIO,
|
||||
@@ -171,8 +172,59 @@ esp_err_t bsp_spiffs_unmount(void)
|
||||
return esp_vfs_spiffs_unregister(CONFIG_BSP_SPIFFS_PARTITION_LABEL);
|
||||
}
|
||||
|
||||
esp_err_t bsp_sdcard_mount(void)
|
||||
sdmmc_card_t *bsp_sdcard_get_handle(void)
|
||||
{
|
||||
return bsp_sdcard;
|
||||
}
|
||||
|
||||
void bsp_sdcard_get_sdmmc_host(const int slot, sdmmc_host_t *config)
|
||||
{
|
||||
assert(config);
|
||||
|
||||
sdmmc_host_t host_config = SDMMC_HOST_DEFAULT();
|
||||
|
||||
memcpy(config, &host_config, sizeof(sdmmc_host_t));
|
||||
}
|
||||
|
||||
void bsp_sdcard_get_sdspi_host(const int slot, sdmmc_host_t *config)
|
||||
{
|
||||
assert(config);
|
||||
memset(config, 0, sizeof(sdmmc_host_t));
|
||||
ESP_LOGE(TAG, "SD card SPI mode is not supported by HW!");
|
||||
}
|
||||
|
||||
void bsp_sdcard_sdmmc_get_slot(const int slot, sdmmc_slot_config_t *config)
|
||||
{
|
||||
assert(config);
|
||||
memset(config, 0, sizeof(sdmmc_slot_config_t));
|
||||
|
||||
config->clk = BSP_SD_CLK;
|
||||
config->cmd = BSP_SD_CMD;
|
||||
config->d0 = BSP_SD_D0;
|
||||
config->d1 = GPIO_NUM_NC;
|
||||
config->d2 = GPIO_NUM_NC;
|
||||
config->d3 = GPIO_NUM_NC;
|
||||
config->d4 = GPIO_NUM_NC;
|
||||
config->d5 = GPIO_NUM_NC;
|
||||
config->d6 = GPIO_NUM_NC;
|
||||
config->d7 = GPIO_NUM_NC;
|
||||
config->cd = SDMMC_SLOT_NO_CD;
|
||||
config->wp = SDMMC_SLOT_NO_WP;
|
||||
config->width = 1;
|
||||
config->flags = SDMMC_SLOT_FLAG_INTERNAL_PULLUP;
|
||||
}
|
||||
|
||||
void bsp_sdcard_sdspi_get_slot(const spi_host_device_t spi_host, sdspi_device_config_t *config)
|
||||
{
|
||||
assert(config);
|
||||
memset(config, 0, sizeof(sdspi_device_config_t));
|
||||
ESP_LOGE(TAG, "SD card SPI mode is not supported by HW!");
|
||||
}
|
||||
|
||||
esp_err_t bsp_sdcard_sdmmc_mount(bsp_sdcard_cfg_t *cfg)
|
||||
{
|
||||
sdmmc_host_t sdhost = {0};
|
||||
sdmmc_slot_config_t sdslot = {0};
|
||||
const esp_vfs_fat_sdmmc_mount_config_t mount_config = {
|
||||
#ifdef CONFIG_BSP_SD_FORMAT_ON_MOUNT_FAIL
|
||||
.format_if_mount_failed = true,
|
||||
@@ -182,35 +234,49 @@ esp_err_t bsp_sdcard_mount(void)
|
||||
.max_files = 5,
|
||||
.allocation_unit_size = 16 * 1024
|
||||
};
|
||||
assert(cfg);
|
||||
|
||||
const sdmmc_host_t host = SDMMC_HOST_DEFAULT();
|
||||
const sdmmc_slot_config_t slot_config = {
|
||||
.clk = BSP_SD_CLK,
|
||||
.cmd = BSP_SD_CMD,
|
||||
.d0 = BSP_SD_D0,
|
||||
.d1 = GPIO_NUM_NC,
|
||||
.d2 = GPIO_NUM_NC,
|
||||
.d3 = GPIO_NUM_NC,
|
||||
.d4 = GPIO_NUM_NC,
|
||||
.d5 = GPIO_NUM_NC,
|
||||
.d6 = GPIO_NUM_NC,
|
||||
.d7 = GPIO_NUM_NC,
|
||||
.cd = SDMMC_SLOT_NO_CD,
|
||||
.wp = SDMMC_SLOT_NO_WP,
|
||||
.width = 1,
|
||||
.flags = 0,
|
||||
};
|
||||
if (!cfg->mount) {
|
||||
cfg->mount = &mount_config;
|
||||
}
|
||||
|
||||
if (!cfg->host) {
|
||||
bsp_sdcard_get_sdmmc_host(SDMMC_HOST_SLOT_0, &sdhost);
|
||||
cfg->host = &sdhost;
|
||||
}
|
||||
|
||||
if (!cfg->slot.sdmmc) {
|
||||
bsp_sdcard_sdmmc_get_slot(SDMMC_HOST_SLOT_0, &sdslot);
|
||||
cfg->slot.sdmmc = &sdslot;
|
||||
}
|
||||
|
||||
#if !CONFIG_FATFS_LONG_FILENAMES
|
||||
ESP_LOGW(TAG, "Warning: Long filenames on SD card are disabled in menuconfig!");
|
||||
#endif
|
||||
|
||||
return esp_vfs_fat_sdmmc_mount(BSP_SD_MOUNT_POINT, &host, &slot_config, &mount_config, &bsp_sdcard);
|
||||
return esp_vfs_fat_sdmmc_mount(BSP_SD_MOUNT_POINT, cfg->host, cfg->slot.sdmmc, cfg->mount, &bsp_sdcard);
|
||||
}
|
||||
|
||||
esp_err_t bsp_sdcard_sdspi_mount(bsp_sdcard_cfg_t *cfg)
|
||||
{
|
||||
ESP_LOGE(TAG, "SD card SPI mode is not supported by HW!");
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
esp_err_t bsp_sdcard_mount(void)
|
||||
{
|
||||
bsp_sdcard_cfg_t cfg = {0};
|
||||
return bsp_sdcard_sdmmc_mount(&cfg);
|
||||
}
|
||||
|
||||
esp_err_t bsp_sdcard_unmount(void)
|
||||
{
|
||||
return esp_vfs_fat_sdcard_unmount(BSP_SD_MOUNT_POINT, bsp_sdcard);
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
ret |= esp_vfs_fat_sdcard_unmount(BSP_SD_MOUNT_POINT, bsp_sdcard);
|
||||
bsp_sdcard = NULL;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define LCD_CMD_BITS (8)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
version: "4.0.2"
|
||||
version: "5.0.0"
|
||||
description: Board Support Package (BSP) for ESP32-S3-EYE
|
||||
url: https://github.com/espressif/esp-bsp/tree/master/bsp/esp32_s3_eye
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include "sdkconfig.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/sdmmc_host.h"
|
||||
#include "driver/sdspi_host.h"
|
||||
#include "esp_vfs_fat.h"
|
||||
#include "esp_codec_dev.h"
|
||||
#include "iot_button.h"
|
||||
#include "bsp/config.h"
|
||||
@@ -76,7 +78,7 @@
|
||||
#define BSP_CAMERA_D6 (GPIO_NUM_17)
|
||||
#define BSP_CAMERA_D7 (GPIO_NUM_16)
|
||||
|
||||
/* uSD card */
|
||||
/* uSD card MMC */
|
||||
#define BSP_SD_D0 (GPIO_NUM_40)
|
||||
#define BSP_SD_CMD (GPIO_NUM_38)
|
||||
#define BSP_SD_CLK (GPIO_NUM_39)
|
||||
@@ -270,7 +272,16 @@ esp_err_t bsp_spiffs_unmount(void);
|
||||
* \endcode
|
||||
**************************************************************************************************/
|
||||
#define BSP_SD_MOUNT_POINT CONFIG_BSP_SD_MOUNT_POINT
|
||||
extern sdmmc_card_t *bsp_sdcard;
|
||||
#define BSP_SDSPI_HOST (SPI3_HOST)
|
||||
|
||||
typedef struct {
|
||||
const esp_vfs_fat_sdmmc_mount_config_t *mount;
|
||||
sdmmc_host_t *host;
|
||||
union {
|
||||
const sdmmc_slot_config_t *sdmmc;
|
||||
const sdspi_device_config_t *sdspi;
|
||||
} slot;
|
||||
} bsp_sdcard_cfg_t;
|
||||
|
||||
/**
|
||||
* @brief Mount microSD card to virtual file system
|
||||
@@ -297,6 +308,73 @@ esp_err_t bsp_sdcard_mount(void);
|
||||
*/
|
||||
esp_err_t bsp_sdcard_unmount(void);
|
||||
|
||||
/**
|
||||
* @brief Get SD card handle
|
||||
*
|
||||
* @return SD card handle
|
||||
*/
|
||||
sdmmc_card_t *bsp_sdcard_get_handle(void);
|
||||
|
||||
/**
|
||||
* @brief Get SD card MMC host config
|
||||
*
|
||||
* @param slot SD card slot
|
||||
* @param config Structure which will be filled
|
||||
*/
|
||||
void bsp_sdcard_get_sdmmc_host(const int slot, sdmmc_host_t *config);
|
||||
|
||||
/**
|
||||
* @brief Get SD card SPI host config
|
||||
*
|
||||
* @param slot SD card slot
|
||||
* @param config Structure which will be filled
|
||||
*/
|
||||
void bsp_sdcard_get_sdspi_host(const int slot, sdmmc_host_t *config);
|
||||
|
||||
/**
|
||||
* @brief Get SD card MMC slot config
|
||||
*
|
||||
* @param slot SD card slot
|
||||
* @param config Structure which will be filled
|
||||
*/
|
||||
void bsp_sdcard_sdmmc_get_slot(const int slot, sdmmc_slot_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Get SD card SPI slot config
|
||||
*
|
||||
* @param spi_host SPI host ID
|
||||
* @param config Structure which will be filled
|
||||
*/
|
||||
void bsp_sdcard_sdspi_get_slot(const spi_host_device_t spi_host, sdspi_device_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Mount microSD card to virtual file system (MMC mode)
|
||||
*
|
||||
* @param cfg SD card configuration
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_STATE if esp_vfs_fat_sdmmc_mount was already called
|
||||
* - ESP_ERR_NO_MEM if memory cannot be allocated
|
||||
* - ESP_FAIL if partition cannot be mounted
|
||||
* - other error codes from SDMMC or SPI drivers, SDMMC protocol, or FATFS drivers
|
||||
*/
|
||||
esp_err_t bsp_sdcard_sdmmc_mount(bsp_sdcard_cfg_t *cfg);
|
||||
|
||||
/**
|
||||
* @brief Mount microSD card to virtual file system (SPI mode)
|
||||
*
|
||||
* @param cfg SD card configuration
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_STATE if esp_vfs_fat_sdmmc_mount was already called
|
||||
* - ESP_ERR_NO_MEM if memory cannot be allocated
|
||||
* - ESP_FAIL if partition cannot be mounted
|
||||
* - other error codes from SDMMC or SPI drivers, SDMMC protocol, or FATFS drivers
|
||||
*/
|
||||
esp_err_t bsp_sdcard_sdspi_mount(bsp_sdcard_cfg_t *cfg);
|
||||
|
||||
/**************************************************************************************************
|
||||
*
|
||||
* LCD interface
|
||||
|
||||
@@ -4,7 +4,7 @@ if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_LESS "5.0")
|
||||
set(REQ driver spiffs fatfs)
|
||||
else()
|
||||
set(SRC_VER "esp32_s3_korvo_1_idf5.c")
|
||||
set(REQ driver spiffs fatfs esp_adc)
|
||||
set(REQ driver spiffs fatfs esp_adc vfs)
|
||||
endif()
|
||||
|
||||
idf_component_register(
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/spi_master.h"
|
||||
#include "driver/i2c.h"
|
||||
@@ -23,7 +24,8 @@
|
||||
static const char *TAG = "S3-Korvo-1";
|
||||
|
||||
static bool i2c_initialized = false;
|
||||
sdmmc_card_t *bsp_sdcard = NULL; // Global uSD card handler
|
||||
static sdmmc_card_t *bsp_sdcard = NULL; // Global uSD card handler
|
||||
static bool spi_sd_initialized = false;
|
||||
|
||||
esp_err_t bsp_i2c_init(void)
|
||||
{
|
||||
@@ -311,40 +313,167 @@ esp_err_t bsp_spiffs_unmount(void)
|
||||
return esp_vfs_spiffs_unregister(CONFIG_BSP_SPIFFS_PARTITION_LABEL);
|
||||
}
|
||||
|
||||
esp_err_t bsp_sdcard_mount(void)
|
||||
sdmmc_card_t *bsp_sdcard_get_handle(void)
|
||||
{
|
||||
return bsp_sdcard;
|
||||
}
|
||||
|
||||
void bsp_sdcard_get_sdmmc_host(const int slot, sdmmc_host_t *config)
|
||||
{
|
||||
assert(config);
|
||||
|
||||
sdmmc_host_t host_config = SDMMC_HOST_DEFAULT();
|
||||
|
||||
memcpy(config, &host_config, sizeof(sdmmc_host_t));
|
||||
}
|
||||
|
||||
void bsp_sdcard_get_sdspi_host(const int slot, sdmmc_host_t *config)
|
||||
{
|
||||
assert(config);
|
||||
|
||||
sdmmc_host_t host_config = SDSPI_HOST_DEFAULT();
|
||||
host_config.slot = slot;
|
||||
|
||||
memcpy(config, &host_config, sizeof(sdmmc_host_t));
|
||||
}
|
||||
|
||||
void bsp_sdcard_sdmmc_get_slot(const int slot, sdmmc_slot_config_t *config)
|
||||
{
|
||||
assert(config);
|
||||
memset(config, 0, sizeof(sdmmc_slot_config_t));
|
||||
|
||||
config->cd = SDMMC_SLOT_NO_CD;
|
||||
config->wp = SDMMC_SLOT_NO_WP;
|
||||
config->clk = BSP_SD_CLK;
|
||||
config->cmd = BSP_SD_CMD;
|
||||
config->d0 = BSP_SD_D0;
|
||||
config->d1 = GPIO_NUM_NC;
|
||||
config->d2 = GPIO_NUM_NC;
|
||||
config->d3 = GPIO_NUM_NC;
|
||||
config->d4 = GPIO_NUM_NC;
|
||||
config->d5 = GPIO_NUM_NC;
|
||||
config->d6 = GPIO_NUM_NC;
|
||||
config->d7 = GPIO_NUM_NC;
|
||||
config->width = 1;
|
||||
config->flags = SDMMC_SLOT_FLAG_INTERNAL_PULLUP;
|
||||
}
|
||||
|
||||
void bsp_sdcard_sdspi_get_slot(const spi_host_device_t spi_host, sdspi_device_config_t *config)
|
||||
{
|
||||
assert(config);
|
||||
memset(config, 0, sizeof(sdspi_device_config_t));
|
||||
|
||||
config->gpio_cs = BSP_SD_SPI_CS;
|
||||
config->gpio_cd = SDSPI_SLOT_NO_CD;
|
||||
config->gpio_wp = SDSPI_SLOT_NO_WP;
|
||||
config->gpio_int = GPIO_NUM_NC;
|
||||
config->host_id = spi_host;
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
|
||||
config->gpio_wp_polarity = SDSPI_IO_ACTIVE_LOW;
|
||||
#endif
|
||||
}
|
||||
|
||||
esp_err_t bsp_sdcard_sdmmc_mount(bsp_sdcard_cfg_t *cfg)
|
||||
{
|
||||
sdmmc_host_t sdhost = {0};
|
||||
sdmmc_slot_config_t sdslot = {0};
|
||||
const esp_vfs_fat_sdmmc_mount_config_t mount_config = {
|
||||
#ifdef CONFIG_BSP_SD_FORMAT_ON_MOUNT_FAIL
|
||||
.format_if_mount_failed = true,
|
||||
#else
|
||||
.format_if_mount_failed = false,
|
||||
#endif
|
||||
.max_files = CONFIG_BSP_SD_MAX_FILES,
|
||||
.max_files = 5,
|
||||
.allocation_unit_size = 16 * 1024
|
||||
};
|
||||
assert(cfg);
|
||||
|
||||
const sdmmc_host_t host = SDMMC_HOST_DEFAULT();
|
||||
const sdmmc_slot_config_t slot_config = {
|
||||
.clk = BSP_SD_CLK,
|
||||
.cmd = BSP_SD_CMD,
|
||||
.d0 = BSP_SD_D0,
|
||||
.d1 = GPIO_NUM_NC,
|
||||
.d2 = GPIO_NUM_NC,
|
||||
.d3 = GPIO_NUM_NC,
|
||||
.d4 = GPIO_NUM_NC,
|
||||
.d5 = GPIO_NUM_NC,
|
||||
.d6 = GPIO_NUM_NC,
|
||||
.d7 = GPIO_NUM_NC,
|
||||
.cd = SDMMC_SLOT_NO_CD,
|
||||
.wp = SDMMC_SLOT_NO_WP,
|
||||
.width = 1,
|
||||
.flags = 0,
|
||||
if (!cfg->mount) {
|
||||
cfg->mount = &mount_config;
|
||||
}
|
||||
|
||||
if (!cfg->host) {
|
||||
bsp_sdcard_get_sdmmc_host(SDMMC_HOST_SLOT_0, &sdhost);
|
||||
cfg->host = &sdhost;
|
||||
}
|
||||
|
||||
if (!cfg->slot.sdmmc) {
|
||||
bsp_sdcard_sdmmc_get_slot(SDMMC_HOST_SLOT_0, &sdslot);
|
||||
cfg->slot.sdmmc = &sdslot;
|
||||
}
|
||||
|
||||
#if !CONFIG_FATFS_LONG_FILENAMES
|
||||
ESP_LOGW(TAG, "Warning: Long filenames on SD card are disabled in menuconfig!");
|
||||
#endif
|
||||
|
||||
return esp_vfs_fat_sdmmc_mount(BSP_SD_MOUNT_POINT, cfg->host, cfg->slot.sdmmc, cfg->mount, &bsp_sdcard);
|
||||
}
|
||||
|
||||
esp_err_t bsp_sdcard_sdspi_mount(bsp_sdcard_cfg_t *cfg)
|
||||
{
|
||||
sdmmc_host_t sdhost = {0};
|
||||
sdspi_device_config_t sdslot = {0};
|
||||
const esp_vfs_fat_sdmmc_mount_config_t mount_config = {
|
||||
#ifdef CONFIG_BSP_SD_FORMAT_ON_MOUNT_FAIL
|
||||
.format_if_mount_failed = true,
|
||||
#else
|
||||
.format_if_mount_failed = false,
|
||||
#endif
|
||||
.max_files = 5,
|
||||
.allocation_unit_size = 16 * 1024
|
||||
};
|
||||
assert(cfg);
|
||||
|
||||
return esp_vfs_fat_sdmmc_mount(BSP_SD_MOUNT_POINT, &host, &slot_config, &mount_config, &bsp_sdcard);
|
||||
ESP_LOGD(TAG, "Initialize SPI bus");
|
||||
const spi_bus_config_t buscfg = {
|
||||
.sclk_io_num = BSP_SD_SPI_CLK,
|
||||
.mosi_io_num = BSP_SD_SPI_MOSI,
|
||||
.miso_io_num = BSP_SD_SPI_MISO,
|
||||
.quadwp_io_num = GPIO_NUM_NC,
|
||||
.quadhd_io_num = GPIO_NUM_NC,
|
||||
.max_transfer_sz = 4000,
|
||||
};
|
||||
ESP_RETURN_ON_ERROR(spi_bus_initialize(BSP_SDSPI_HOST, &buscfg, SPI_DMA_CH_AUTO), TAG, "SPI init failed");
|
||||
spi_sd_initialized = true;
|
||||
|
||||
if (!cfg->mount) {
|
||||
cfg->mount = &mount_config;
|
||||
}
|
||||
|
||||
if (!cfg->host) {
|
||||
bsp_sdcard_get_sdspi_host(SDMMC_HOST_SLOT_0, &sdhost);
|
||||
cfg->host = &sdhost;
|
||||
}
|
||||
|
||||
if (!cfg->slot.sdspi) {
|
||||
bsp_sdcard_sdspi_get_slot(BSP_SDSPI_HOST, &sdslot);
|
||||
cfg->slot.sdspi = &sdslot;
|
||||
}
|
||||
|
||||
#if !CONFIG_FATFS_LONG_FILENAMES
|
||||
ESP_LOGW(TAG, "Warning: Long filenames on SD card are disabled in menuconfig!");
|
||||
#endif
|
||||
|
||||
return esp_vfs_fat_sdspi_mount(BSP_SD_MOUNT_POINT, cfg->host, cfg->slot.sdspi, cfg->mount, &bsp_sdcard);
|
||||
}
|
||||
|
||||
esp_err_t bsp_sdcard_mount(void)
|
||||
{
|
||||
bsp_sdcard_cfg_t cfg = {0};
|
||||
return bsp_sdcard_sdmmc_mount(&cfg);
|
||||
}
|
||||
|
||||
esp_err_t bsp_sdcard_unmount(void)
|
||||
{
|
||||
return esp_vfs_fat_sdcard_unmount(BSP_SD_MOUNT_POINT, bsp_sdcard);
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
ret |= esp_vfs_fat_sdcard_unmount(BSP_SD_MOUNT_POINT, bsp_sdcard);
|
||||
bsp_sdcard = NULL;
|
||||
|
||||
if (spi_sd_initialized) {
|
||||
ret |= spi_bus_free(BSP_SDSPI_HOST);
|
||||
spi_sd_initialized = false;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user