diff options
| author | jacqueline <me@jacqueline.id.au> | 2022-10-04 14:45:56 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2022-10-04 14:45:56 +1100 |
| commit | f6f49034429b31f9d084df4aec847b20c62030b0 (patch) | |
| tree | 5450b5a58e663b2918daf68c5662fe11afa88f91 /main/storage.cpp | |
| parent | 6d20efc702b488c8f347a115a41dde9d0abdd883 (diff) | |
| download | tangara-fw-f6f49034429b31f9d084df4aec847b20c62030b0.tar.gz | |
Basic fat32 mounting!
Diffstat (limited to 'main/storage.cpp')
| -rw-r--r-- | main/storage.cpp | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/main/storage.cpp b/main/storage.cpp index b1d5aa6c..378bc3cf 100644 --- a/main/storage.cpp +++ b/main/storage.cpp @@ -1,8 +1,12 @@ #include "storage.h" -#include "esp_check.h" +#include "diskio_impl.h" +#include "diskio_sdmmc.h" #include "driver/sdspi_host.h" +#include "esp_check.h" #include "esp_err.h" +#include "esp_vfs_fat.h" +#include "ff.h" #include "gpio-expander.h" #include "hal/gpio_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 // TODO: use our own error code 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. - gpio_->set_sd_cs(true); - gpio_->Write(); + //gpio_->set_sd_cs(true); + //gpio_->Write(); return ret; } @@ -59,6 +79,13 @@ esp_err_t SdStorage::Release(void) { gpio_->set_sd_cs(false); 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_deinit(); |
