nodemcu-firmware/components/fatfs/diskio.c

113 lines
3.4 KiB
C
Raw Normal View History

/*-----------------------------------------------------------------------*/
/* 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 */
#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];
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;
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;
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;
2017-04-15 17:38:20 +02:00
return RES_ERROR;
}
/*-----------------------------------------------------------------------*/
/* Write Sector(s) */
/*-----------------------------------------------------------------------*/
2019-01-17 00:04:03 +01:00
#if FF_FS_READONLY == 0
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;
2017-04-15 17:38:20 +02:00
return RES_ERROR;
}
2019-01-17 00:04:03 +01:00
#endif
/*-----------------------------------------------------------------------*/
/* 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;
switch (cmd) {
case CTRL_TRIM: /* no-op */
case CTRL_SYNC: /* no-op */
return RES_OK;
default: /* anything else throws parameter error */
return RES_PARERR;
}
}