1
2
3
4
5
6
7
8
9
10
11
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
65
66
67
68
69
70
75
76
79
80
81
82
83
84
85
86
90
94
98
102
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <sys/time.h>
#include "diskio_impl.h"
#include "ffconf.h"
#include "ff.h"7 includes
static ff_diskio_impl_t * s_impls[FF_VOLUMES] = { NULL };
#if FF_MULTI_PARTITION
const PARTITION VolToPart[FF_VOLUMES] = {
{0, 0},
#if FF_VOLUMES > 1
{1, 0},
#endif
#if FF_VOLUMES > 2
{2, 0},
#endif
#if FF_VOLUMES > 3
{3, 0},
#endif
#if FF_VOLUMES > 4
{4, 0},
#endif
#if FF_VOLUMES > 5
{5, 0},
#endif
#if FF_VOLUMES > 6
{6, 0},
#endif
#if FF_VOLUMES > 7
{7, 0},
#endif
#if FF_VOLUMES > 8
{8, 0},
#endif
#if FF_VOLUMES > 9
{9, 0},
#endif
}{...};
/* ... */#endif
esp_err_t ff_diskio_get_drive(BYTE* out_pdrv)
{
BYTE i;
for(i=0; i<FF_VOLUMES; i++) {
if (!s_impls[i]) {
*out_pdrv = i;
return ESP_OK;
}{...}
}{...}
return ESP_ERR_NOT_FOUND;
}{ ... }
void ff_diskio_register(BYTE pdrv, const ff_diskio_impl_t* discio_impl)
{
assert(pdrv < FF_VOLUMES);
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;
}{ ... }
DSTATUS ff_disk_initialize (BYTE pdrv)
{
return s_impls[pdrv]->init(pdrv);
}{ ... }
DSTATUS ff_disk_status (BYTE pdrv)
{
return s_impls[pdrv]->status(pdrv);
}{ ... }
DRESULT ff_disk_read (BYTE pdrv, BYTE* buff, LBA_t sector, UINT count)
{
return s_impls[pdrv]->read(pdrv, buff, sector, count);
}{ ... }
DRESULT ff_disk_write (BYTE pdrv, const BYTE* buff, LBA_t sector, UINT count)
{
return s_impls[pdrv]->write(pdrv, buff, sector, count);
}{ ... }
DRESULT ff_disk_ioctl (BYTE pdrv, BYTE cmd, void* buff)
{
return s_impls[pdrv]->ioctl(pdrv, cmd, buff);
}{ ... }
DWORD get_fattime(void)
{
time_t t = time(NULL);
struct tm tmr;
localtime_r(&t, &tmr);
int year = tmr.tm_year < 80 ? 0 : tmr.tm_year - 80;
return ((DWORD)(year) << 25)
| ((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);
}{ ... }