2016-12-29 09:28:39 +00:00
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2016 */
|
2017-01-08 21:54:04 +00:00
|
|
|
/* ESP-IDF port Copyright 2016 Espressif Systems (Shanghai) PTE LTD */
|
2016-12-29 09:28:39 +00:00
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
/* 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. */
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
|
2016-12-29 09:33:38 +00:00
|
|
|
#include <string.h>
|
2017-05-04 11:50:13 +00:00
|
|
|
#include <time.h>
|
|
|
|
#include <sys/time.h>
|
2016-12-29 09:28:39 +00:00
|
|
|
#include "diskio.h" /* FatFs lower layer API */
|
2016-12-29 09:33:38 +00:00
|
|
|
#include "ffconf.h"
|
|
|
|
#include "ff.h"
|
|
|
|
|
2017-05-04 11:50:13 +00:00
|
|
|
static ff_diskio_impl_t * s_impls[_VOLUMES] = { NULL };
|
2016-12-29 09:33:38 +00:00
|
|
|
|
2017-05-02 16:23:45 +00:00
|
|
|
#if _MULTI_PARTITION /* Multiple partition configuration */
|
2016-12-29 09:33:38 +00:00
|
|
|
PARTITION VolToPart[] = {
|
2017-05-02 16:23:45 +00:00
|
|
|
{0, 0}, /* Logical drive 0 ==> Physical drive 0, auto detection */
|
2016-12-29 09:33:38 +00:00
|
|
|
{1, 0} /* Logical drive 1 ==> Physical drive 1, auto detection */
|
|
|
|
};
|
2017-05-02 16:23:45 +00:00
|
|
|
#endif
|
2016-12-29 09:33:38 +00:00
|
|
|
|
2017-02-01 15:55:25 +00:00
|
|
|
esp_err_t ff_diskio_get_drive(BYTE* out_pdrv)
|
2017-01-31 15:23:25 +00:00
|
|
|
{
|
|
|
|
BYTE i;
|
|
|
|
for(i=0; i<_VOLUMES; i++) {
|
|
|
|
if (!s_impls[i]) {
|
2017-02-01 15:55:25 +00:00
|
|
|
*out_pdrv = i;
|
|
|
|
return ESP_OK;
|
2017-01-31 15:23:25 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-01 15:55:25 +00:00
|
|
|
return ESP_ERR_NOT_FOUND;
|
2017-01-31 15:23:25 +00:00
|
|
|
}
|
|
|
|
|
2016-12-29 09:33:38 +00:00
|
|
|
void ff_diskio_register(BYTE pdrv, const ff_diskio_impl_t* discio_impl)
|
2016-12-29 09:28:39 +00:00
|
|
|
{
|
2016-12-29 09:33:38 +00:00
|
|
|
assert(pdrv < _VOLUMES);
|
2017-01-31 15:23:25 +00:00
|
|
|
|
|
|
|
if (s_impls[pdrv]) {
|
|
|
|
ff_diskio_impl_t* im = s_impls[pdrv];
|
|
|
|
s_impls[pdrv] = NULL;
|
|
|
|
free(im);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!discio_impl) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ff_diskio_impl_t * impl = (ff_diskio_impl_t *)malloc(sizeof(ff_diskio_impl_t));
|
|
|
|
assert(impl != NULL);
|
|
|
|
memcpy(impl, discio_impl, sizeof(ff_diskio_impl_t));
|
|
|
|
s_impls[pdrv] = impl;
|
2016-12-29 09:28:39 +00:00
|
|
|
}
|
|
|
|
|
2016-12-29 09:33:38 +00:00
|
|
|
DSTATUS ff_disk_initialize (BYTE pdrv)
|
2016-12-29 09:28:39 +00:00
|
|
|
{
|
2017-01-31 15:23:25 +00:00
|
|
|
return s_impls[pdrv]->init(pdrv);
|
2016-12-29 09:28:39 +00:00
|
|
|
}
|
2016-12-29 09:33:38 +00:00
|
|
|
DSTATUS ff_disk_status (BYTE pdrv)
|
2016-12-29 09:28:39 +00:00
|
|
|
{
|
2017-01-31 15:23:25 +00:00
|
|
|
return s_impls[pdrv]->status(pdrv);
|
2016-12-29 09:28:39 +00:00
|
|
|
}
|
2016-12-29 09:33:38 +00:00
|
|
|
DRESULT ff_disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count)
|
2016-12-29 09:28:39 +00:00
|
|
|
{
|
2017-01-31 15:23:25 +00:00
|
|
|
return s_impls[pdrv]->read(pdrv, buff, sector, count);
|
2016-12-29 09:28:39 +00:00
|
|
|
}
|
2016-12-29 09:33:38 +00:00
|
|
|
DRESULT ff_disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count)
|
2016-12-29 09:28:39 +00:00
|
|
|
{
|
2017-01-31 15:23:25 +00:00
|
|
|
return s_impls[pdrv]->write(pdrv, buff, sector, count);
|
2016-12-29 09:33:38 +00:00
|
|
|
}
|
|
|
|
DRESULT ff_disk_ioctl (BYTE pdrv, BYTE cmd, void* buff)
|
|
|
|
{
|
2017-01-31 15:23:25 +00:00
|
|
|
return s_impls[pdrv]->ioctl(pdrv, cmd, buff);
|
2016-12-29 09:33:38 +00:00
|
|
|
}
|
2016-12-29 09:28:39 +00:00
|
|
|
|
2016-12-29 09:33:38 +00:00
|
|
|
DWORD get_fattime(void)
|
|
|
|
{
|
|
|
|
time_t t = time(NULL);
|
|
|
|
struct tm *tmr = gmtime(&t);
|
2017-01-08 21:54:04 +00:00
|
|
|
int year = tmr->tm_year < 80 ? 0 : tmr->tm_year - 80;
|
|
|
|
return ((DWORD)(year) << 25)
|
2016-12-29 09:33:38 +00:00
|
|
|
| ((DWORD)(tmr->tm_mon + 1) << 21)
|
|
|
|
| ((DWORD)tmr->tm_mday << 16)
|
|
|
|
| (WORD)(tmr->tm_hour << 11)
|
|
|
|
| (WORD)(tmr->tm_min << 5)
|
|
|
|
| (WORD)(tmr->tm_sec >> 1);
|
|
|
|
}
|