feat: SPI flash driver (#4012)
Co-authored-by: Richard Li <richard.li@ces.hk>
This commit is contained in:
co-authored by
Richard Li
parent
7400a598a1
commit
cb16786a74
@@ -58,6 +58,21 @@ int fatfsRegisterDriver(const diskio_driver_t* drv, uint8_t lun)
|
||||
return 1;
|
||||
}
|
||||
|
||||
void fatfsUnregisterDrivers()
|
||||
{
|
||||
for (uint8_t i = 0; i < _fatfs_n_drives; i++) {
|
||||
auto& drive = _fatfs_drives[i];
|
||||
if (drive.initialized) {
|
||||
disk_ioctl(i, CTRL_SYNC, 0);
|
||||
if (drive.drv->deinit) {
|
||||
drive.drv->deinit(drive.lun);
|
||||
}
|
||||
drive.initialized = false;
|
||||
}
|
||||
}
|
||||
_fatfs_n_drives = 0;
|
||||
}
|
||||
|
||||
const diskio_driver_t* fatfsGetDriver(uint8_t pdrv)
|
||||
{
|
||||
if (pdrv >= _fatfs_n_drives) {
|
||||
|
||||
@@ -28,6 +28,8 @@ struct diskio_driver_t
|
||||
{
|
||||
DSTATUS (*initialize)(BYTE pdrv);
|
||||
|
||||
DSTATUS (*deinit)(BYTE pdrv);
|
||||
|
||||
DSTATUS (*status)(BYTE pdrv);
|
||||
|
||||
DRESULT (*read)(BYTE pdrv, BYTE* buff, DWORD sector, UINT count);
|
||||
@@ -40,6 +42,9 @@ struct diskio_driver_t
|
||||
// returns 1 if successful, 0 otherwise
|
||||
int fatfsRegisterDriver(const diskio_driver_t* drv, uint8_t lun);
|
||||
|
||||
// gracefully tear down all drivers
|
||||
void fatfsUnregisterDrivers();
|
||||
|
||||
// returns a pyhsical disk driver or NULL
|
||||
const diskio_driver_t* fatfsGetDriver(uint8_t pdrv);
|
||||
|
||||
|
||||
@@ -30,6 +30,9 @@
|
||||
#elif defined(STORAGE_USE_SDCARD_SPI)
|
||||
#include "diskio_spi.h"
|
||||
#define _STORAGE_DRIVER sdcard_spi_driver
|
||||
#elif defined(STORAGE_USE_SPI_FLASH)
|
||||
#include "diskio_spi_flash.h"
|
||||
#define _STORAGE_DRIVER spi_flash_diskio_driver
|
||||
#else
|
||||
#error "No supported storage driver configured"
|
||||
#endif
|
||||
@@ -62,6 +65,11 @@ void storageInit()
|
||||
}
|
||||
}
|
||||
|
||||
void storageDeInit()
|
||||
{
|
||||
fatfsUnregisterDrivers();
|
||||
}
|
||||
|
||||
void storagePreMountHook()
|
||||
{
|
||||
#if defined(DISK_CACHE)
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
// Note: can be used to attach the pyhsical volume driver
|
||||
// to the generic FatFs driver
|
||||
void storageInit();
|
||||
void storageDeInit();
|
||||
|
||||
// Called before the storage is mounted
|
||||
void storagePreMountHook();
|
||||
|
||||
Reference in New Issue
Block a user