5#include "esp_vfs_fat.h"
7#ifdef SOC_SDMMC_IO_POWER_EXTERNAL
8#include "sd_pwr_ctrl_by_on_chip_ldo.h"
11#if !defined(DEFAULT_CS)
12#if defined(AUDIOBOARD_SD)
14#define DEFAULT_MOSI 15
19#define DEFAULT_MOSI MOSI
20#define DEFAULT_MISO MISO
21#define DEFAULT_CLK SCK
25#ifndef DEFAULT_MAX_TRANSFER_SIZE
26#define DEFAULT_MAX_TRANSFER_SIZE 4000
51 void setPins(
int CS,
int MOSI,
int MISO,
int SCK) {
68 esp_vfs_fat_sdmmc_mount_config_t mount_config = {
72 LOGI(
"Initializing SD card");
78 LOGI(
"Using SPI peripheral");
84 host = SDSPI_HOST_DEFAULT();
91#ifdef CONFIG_SD_PWR_CTRL_LDO_IO_ID
93 sd_pwr_ctrl_ldo_config_t ldo_config = {
94 .ldo_chan_id = CONFIG_SD_PWR_CTRL_LDO_IO_ID,
100 LOGE(
"Failed to create a new on-chip LDO power control driver");
106 spi_bus_config_t bus_cfg = {
115 ret = spi_bus_initialize((spi_host_device_t)
host.slot, &bus_cfg,
118 LOGE(
"Failed to initialize bus.");
125 sdspi_device_config_t slot_config = SDSPI_DEVICE_CONFIG_DEFAULT();
126 slot_config.gpio_cs =
pin_cs;
127 slot_config.host_id = (spi_host_device_t)
host.slot;
131 &mount_config, &
card);
134 if (ret == ESP_FAIL) {
135 LOGE(
"Failed to mount filesystem");
137 LOGE(
"Failed to initialize the card (%s)", esp_err_to_name(ret));
141 LOGI(
"Filesystem mounted");
144 sdmmc_card_print_info(stdout,
card);
149 if (
card ==
nullptr)
return;
154 LOGI(
"Card unmounted");
157 spi_bus_free((spi_host_device_t)
host.slot);
160#ifdef CONFIG_SD_PWR_CTRL_LDO_IO_ID
164 LOGE(
"Failed to delete the on-chip LDO power control driver");
#define LOGI(...)
Definition AudioLoggerIDF.h:28
#define LOGE(...)
Definition AudioLoggerIDF.h:30
#define DEFAULT_CLK
Definition VFS_SDMMC.h:24
#define DEFAULT_MISO
Definition VFS_SDSPI.h:20
#define DEFAULT_MAX_TRANSFER_SIZE
Definition VFS_SDSPI.h:26
#define DEFAULT_MOSI
Definition VFS_SDSPI.h:19
#define DEFAULT_CS
Definition VFS_SDSPI.h:18