Basic fat32 mounting!

custom
jacqueline 3 years ago
parent 6d20efc702
commit f6f4903442
  1. 6
      main/CMakeLists.txt
  2. 17
      main/gay-ipod-fw.cpp
  3. 33
      main/storage.cpp
  4. 9
      main/storage.h
  5. 11
      sdkconfig

@ -1,2 +1,4 @@
idf_component_register(SRCS "gay-ipod-fw.cpp" "gpio-expander.cpp" "battery.cpp" "storage.cpp" idf_component_register(
INCLUDE_DIRS ".") SRCS "gay-ipod-fw.cpp" "gpio-expander.cpp" "battery.cpp" "storage.cpp"
INCLUDE_DIRS "."
REQUIRES "esp_adc_cal" "fatfs")

@ -1,4 +1,5 @@
#include <stdio.h> #include <stdio.h>
#include <dirent.h>
#include "battery.h" #include "battery.h"
#include "driver/adc.h" #include "driver/adc.h"
@ -107,9 +108,23 @@ extern "C" void app_main(void)
gay_ipod::SdStorage storage(&expander); gay_ipod::SdStorage storage(&expander);
ESP_ERROR_CHECK(storage.Acquire()); ESP_ERROR_CHECK(storage.Acquire());
ESP_LOGI(TAG, "Looks okay? Let's list some files!");
vTaskDelay(pdMS_TO_TICKS(1000));
DIR *d;
struct dirent *dir;
d = opendir(gay_ipod::STORAGE_PATH);
if (d) {
while ((dir = readdir(d)) != NULL) {
ESP_LOGI(TAG, "file! %s", dir->d_name);
}
closedir(d);
} else {
ESP_LOGI(TAG, "nope!");
}
ESP_LOGI(TAG, "Looks okay? Trying to deinit now.");
vTaskDelay(pdMS_TO_TICKS(1000)); vTaskDelay(pdMS_TO_TICKS(1000));
ESP_LOGI(TAG, "Time to deinit.");
ESP_ERROR_CHECK(storage.Release()); ESP_ERROR_CHECK(storage.Release());
ESP_LOGI(TAG, "Hooray!"); ESP_LOGI(TAG, "Hooray!");

@ -1,8 +1,12 @@
#include "storage.h" #include "storage.h"
#include "esp_check.h" #include "diskio_impl.h"
#include "diskio_sdmmc.h"
#include "driver/sdspi_host.h" #include "driver/sdspi_host.h"
#include "esp_check.h"
#include "esp_err.h" #include "esp_err.h"
#include "esp_vfs_fat.h"
#include "ff.h"
#include "gpio-expander.h" #include "gpio-expander.h"
#include "hal/gpio_types.h" #include "hal/gpio_types.h"
#include "hal/spi_types.h" #include "hal/spi_types.h"
@ -47,10 +51,26 @@ esp_err_t SdStorage::Acquire(void) {
// Will return ESP_ERR_INVALID_RESPONSE if there is no card // Will return ESP_ERR_INVALID_RESPONSE if there is no card
// TODO: use our own error code // TODO: use our own error code
ret = sdmmc_card_init(&host_, &card_); ret = sdmmc_card_init(&host_, &card_);
if (ret != ESP_OK) {
gpio_->set_sd_cs(true);
gpio_->Write();
return ret;
}
ESP_ERROR_CHECK(
esp_vfs_fat_register(STORAGE_PATH, "", MAX_OPEN_FILES, &fs_));
ff_diskio_register_sdmmc(fs_->pdrv, &card_);
// Mount right now, not on first operation.
FRESULT fret = f_mount(fs_, "", 1);
if (fret != FR_OK) {
// TODO: Proper error handling
return ESP_ERR_INVALID_MAC;
}
// We're done chatting for now. // We're done chatting for now.
gpio_->set_sd_cs(true); //gpio_->set_sd_cs(true);
gpio_->Write(); //gpio_->Write();
return ret; return ret;
} }
@ -59,6 +79,13 @@ esp_err_t SdStorage::Release(void) {
gpio_->set_sd_cs(false); gpio_->set_sd_cs(false);
gpio_->Write(); gpio_->Write();
// Unmount and unregister the filesystem
f_unmount("");
ff_diskio_register(fs_->pdrv, NULL);
esp_vfs_fat_unregister_path(STORAGE_PATH);
fs_ = nullptr;
// Uninstall the SPI driver
sdspi_host_remove_device(this->handle_); sdspi_host_remove_device(this->handle_);
sdspi_host_deinit(); sdspi_host_deinit();

@ -4,10 +4,15 @@
#include "driver/sdmmc_types.h" #include "driver/sdmmc_types.h"
#include "driver/sdspi_host.h" #include "driver/sdspi_host.h"
#include "esp_err.h" #include "esp_err.h"
#include "esp_vfs_fat.h"
#include "gpio-expander.h" #include "gpio-expander.h"
#define MAX_OPEN_FILES (8)
namespace gay_ipod { namespace gay_ipod {
static const char *STORAGE_PATH = "/sd";
class SdStorage { class SdStorage {
public: public:
SdStorage(GpioExpander *gpio); SdStorage(GpioExpander *gpio);
@ -24,9 +29,13 @@ class SdStorage {
private: private:
GpioExpander *gpio_; GpioExpander *gpio_;
// SPI and SD driver info
sdspi_dev_handle_t handle_; sdspi_dev_handle_t handle_;
sdmmc_host_t host_; sdmmc_host_t host_;
sdmmc_card_t card_; sdmmc_card_t card_;
// Filesystem info
FATFS *fs_ = nullptr;
}; };
} // namespace gay_ipod } // namespace gay_ipod

@ -653,13 +653,18 @@ CONFIG_FATFS_CODEPAGE_437=y
# CONFIG_FATFS_CODEPAGE_949 is not set # CONFIG_FATFS_CODEPAGE_949 is not set
# CONFIG_FATFS_CODEPAGE_950 is not set # CONFIG_FATFS_CODEPAGE_950 is not set
CONFIG_FATFS_CODEPAGE=437 CONFIG_FATFS_CODEPAGE=437
CONFIG_FATFS_LFN_NONE=y # CONFIG_FATFS_LFN_NONE is not set
# CONFIG_FATFS_LFN_HEAP is not set CONFIG_FATFS_LFN_HEAP=y
# CONFIG_FATFS_LFN_STACK is not set # CONFIG_FATFS_LFN_STACK is not set
CONFIG_FATFS_MAX_LFN=255
# CONFIG_FATFS_API_ENCODING_ANSI_OEM is not set
# CONFIG_FATFS_API_ENCODING_UTF_16 is not set
CONFIG_FATFS_API_ENCODING_UTF_8=y
CONFIG_FATFS_FS_LOCK=0 CONFIG_FATFS_FS_LOCK=0
CONFIG_FATFS_TIMEOUT_MS=10000 CONFIG_FATFS_TIMEOUT_MS=10000
CONFIG_FATFS_PER_FILE_CACHE=y CONFIG_FATFS_PER_FILE_CACHE=y
# CONFIG_FATFS_USE_FASTSEEK is not set CONFIG_FATFS_USE_FASTSEEK=y
CONFIG_FATFS_FAST_SEEK_BUFFER_SIZE=64
# end of FAT Filesystem support # end of FAT Filesystem support
# #

Loading…
Cancel
Save