2016-09-21 10:21:44 +02:00
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2016 */
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
/* If a working storage control module is available, it should be */
|
|
|
|
/* attached to the FatFs via a glue function rather than modifying it. */
|
|
|
|
/* This is an example of glue functions to attach various exsisting */
|
|
|
|
/* storage control modules to the FatFs module with a defined API. */
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
|
2019-01-17 00:04:03 +01:00
|
|
|
#include "ff.h" /* Obtains integer types */
|
2016-09-21 10:21:44 +02:00
|
|
|
#include "diskio.h" /* FatFs lower layer API */
|
2017-04-15 17:38:20 +02:00
|
|
|
#include "sdmmc_cmd.h"
|
|
|
|
|
|
|
|
// defined in components/modules/sdmmc.c
|
|
|
|
extern sdmmc_card_t lsdmmc_card[2];
|
|
|
|
|
2016-09-21 10:21:44 +02:00
|
|
|
|
|
|
|
static DSTATUS m_status = STA_NOINIT;
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
/* Get Drive Status */
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
DSTATUS disk_status (
|
|
|
|
BYTE pdrv /* Physical drive nmuber to identify the drive */
|
|
|
|
)
|
|
|
|
{
|
2017-04-15 17:38:20 +02:00
|
|
|
(void)pdrv;
|
|
|
|
|
2016-09-21 10:21:44 +02:00
|
|
|
return m_status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
/* Inidialize a Drive */
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
DSTATUS disk_initialize (
|
|
|
|
BYTE pdrv /* Physical drive nmuber to identify the drive */
|
|
|
|
)
|
|
|
|
{
|
2017-04-15 17:38:20 +02:00
|
|
|
(void)pdrv;
|
|
|
|
|
|
|
|
m_status &= ~STA_NOINIT;
|
2016-09-21 10:21:44 +02:00
|
|
|
|
|
|
|
return m_status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
/* Read Sector(s) */
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
DRESULT disk_read (
|
|
|
|
BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
|
|
|
BYTE *buff, /* Data buffer to store read data */
|
|
|
|
DWORD sector, /* Sector address in LBA */
|
|
|
|
UINT count /* Number of sectors to read */
|
|
|
|
)
|
|
|
|
{
|
2017-04-15 17:38:20 +02:00
|
|
|
if (sdmmc_read_sectors( &(lsdmmc_card[pdrv]), buff, sector, count ) == ESP_OK)
|
|
|
|
return RES_OK;
|
2016-09-21 10:21:44 +02:00
|
|
|
|
2017-04-15 17:38:20 +02:00
|
|
|
return RES_ERROR;
|
2016-09-21 10:21:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
/* Write Sector(s) */
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
|
2019-01-17 00:04:03 +01:00
|
|
|
#if FF_FS_READONLY == 0
|
|
|
|
|
2016-09-21 10:21:44 +02:00
|
|
|
DRESULT disk_write (
|
|
|
|
BYTE pdrv, /* Physical drive nmuber to identify the drive */
|
|
|
|
const BYTE *buff, /* Data to be written */
|
|
|
|
DWORD sector, /* Sector address in LBA */
|
|
|
|
UINT count /* Number of sectors to write */
|
|
|
|
)
|
|
|
|
{
|
2017-04-15 17:38:20 +02:00
|
|
|
if (sdmmc_write_sectors( &(lsdmmc_card[pdrv]), buff, sector, count ) == ESP_OK)
|
|
|
|
return RES_OK;
|
2016-09-21 10:21:44 +02:00
|
|
|
|
2017-04-15 17:38:20 +02:00
|
|
|
return RES_ERROR;
|
2016-09-21 10:21:44 +02:00
|
|
|
}
|
|
|
|
|
2019-01-17 00:04:03 +01:00
|
|
|
#endif
|
2016-09-21 10:21:44 +02:00
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
/* Miscellaneous Functions */
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
DRESULT disk_ioctl (
|
|
|
|
BYTE pdrv, /* Physical drive nmuber (0..) */
|
|
|
|
BYTE cmd, /* Control code */
|
|
|
|
void *buff /* Buffer to send/receive control data */
|
|
|
|
)
|
|
|
|
{
|
2017-04-15 17:38:20 +02:00
|
|
|
(void)pdrv;
|
|
|
|
(void)buff;
|
|
|
|
|
2016-09-21 10:21:44 +02:00
|
|
|
switch (cmd) {
|
|
|
|
case CTRL_TRIM: /* no-op */
|
|
|
|
case CTRL_SYNC: /* no-op */
|
|
|
|
return RES_OK;
|
|
|
|
|
|
|
|
default: /* anything else throws parameter error */
|
|
|
|
return RES_PARERR;
|
|
|
|
}
|
|
|
|
}
|