-
Notifications
You must be signed in to change notification settings - Fork 1
/
diskio.cpp
80 lines (80 loc) · 1.58 KB
/
diskio.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "diskio.h"
#include "FATFileSystem.h"
using namespace mbed;
DSTATUS disk_status(
B pdrv)
{
return (DSTATUS)FATFileSystem::_ffs[pdrv]->disk_status();
}
DSTATUS disk_initialize(
B pdrv)
{
return (DSTATUS)FATFileSystem::_ffs[pdrv]->disk_initialize();
}
DRESULT disk_read(
B pdrv,
B *buff,
DW sector,
UI count)
{
if (FATFileSystem::_ffs[pdrv]->disk_read((uint8_t *)buff, sector, count))
return RES_PARERR;
else
return RES_OK;
}
#if _USE_WRITE
DRESULT disk_write(
B pdrv,
const B *buff,
DW sector,
UI count)
{
if (FATFileSystem::_ffs[pdrv]->disk_write((uint8_t *)buff, sector, count))
return RES_PARERR;
else
return RES_OK;
}
#endif
#if _USE_IOCTL
DRESULT disk_ioctl(
B pdrv,
B cmd,
void *buff)
{
switch (cmd)
{
case CTRL_SYNC:
if (FATFileSystem::_ffs[pdrv] == NULL)
{
return RES_NOTRDY;
}
else if (FATFileSystem::_ffs[pdrv]->disk_sync())
{
return RES_ERROR;
}
return RES_OK;
case GET_SECTOR_COUNT:
if (FATFileSystem::_ffs[pdrv] == NULL)
{
return RES_NOTRDY;
}
else
{
DW res = FATFileSystem::_ffs[pdrv]->disk_sectors();
if (res > 0)
{
*((DW *)buff) = res;
return RES_OK;
}
else
{
return RES_ERROR;
}
}
case GET_BLOCK_SIZE:
*((DW *)buff) = 1;
return RES_OK;
}
return RES_PARERR;
}
#endif