]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/fs/fat/ChaN/diskio.cpp
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / fs / fat / ChaN / diskio.cpp
1 /*-----------------------------------------------------------------------*/
2 /* Low level disk I/O module skeleton for FatFs     (C)ChaN, 2007        */
3 /*-----------------------------------------------------------------------*/
4 /* This is a stub disk I/O module that acts as front end of the existing */
5 /* disk I/O modules and attach it to FatFs module with common interface. */
6 /*-----------------------------------------------------------------------*/
7 #include "ffconf.h"
8 #include "diskio.h"
9
10 #include "mbed_debug.h"
11 #include "FATFileSystem.h"
12
13 using namespace mbed;
14
15 DSTATUS disk_initialize (
16     BYTE drv                /* Physical drive nmuber (0..) */
17 )
18 {
19     debug_if(FFS_DBG, "disk_initialize on drv [%d]\n", drv);
20     return (DSTATUS)FATFileSystem::_ffs[drv]->disk_initialize();
21 }
22
23 DSTATUS disk_status (
24     BYTE drv        /* Physical drive nmuber (0..) */
25 )
26 {
27     debug_if(FFS_DBG, "disk_status on drv [%d]\n", drv);
28     return (DSTATUS)FATFileSystem::_ffs[drv]->disk_status();
29 }
30
31 DRESULT disk_read (
32     BYTE drv,        /* Physical drive nmuber (0..) */
33     BYTE *buff,        /* Data buffer to store read data */
34     DWORD sector,    /* Sector address (LBA) */
35     BYTE count        /* Number of sectors to read (1..255) */
36 )
37 {
38     debug_if(FFS_DBG, "disk_read(sector %d, count %d) on drv [%d]\n", sector, count, drv);
39     if (FATFileSystem::_ffs[drv]->disk_read((uint8_t*)buff, sector, count))
40         return RES_PARERR;
41     else
42         return RES_OK;
43 }
44
45 #if _READONLY == 0
46 DRESULT disk_write (
47     BYTE drv,            /* Physical drive nmuber (0..) */
48     const BYTE *buff,    /* Data to be written */
49     DWORD sector,        /* Sector address (LBA) */
50     BYTE count            /* Number of sectors to write (1..255) */
51 )
52 {
53     debug_if(FFS_DBG, "disk_write(sector %d, count %d) on drv [%d]\n", sector, count, drv);
54     if (FATFileSystem::_ffs[drv]->disk_write((uint8_t*)buff, sector, count))
55         return RES_PARERR;
56     else
57         return RES_OK;
58 }
59 #endif /* _READONLY */
60
61 DRESULT disk_ioctl (
62     BYTE drv,        /* Physical drive nmuber (0..) */
63     BYTE ctrl,        /* Control code */
64     void *buff        /* Buffer to send/receive control data */
65 )
66 {
67     debug_if(FFS_DBG, "disk_ioctl(%d)\n", ctrl);
68     switch(ctrl) {
69         case CTRL_SYNC:
70             if(FATFileSystem::_ffs[drv] == NULL) {
71                 return RES_NOTRDY;
72             } else if(FATFileSystem::_ffs[drv]->disk_sync()) {
73                 return RES_ERROR;
74             }
75             return RES_OK;
76         case GET_SECTOR_COUNT:
77             if(FATFileSystem::_ffs[drv] == NULL) {
78                 return RES_NOTRDY;
79             } else {
80                 DWORD res = FATFileSystem::_ffs[drv]->disk_sectors();
81                 if(res > 0) {
82                     *((DWORD*)buff) = res; // minimum allowed
83                     return RES_OK;
84                 } else {
85                     return RES_ERROR;
86                 }
87             }
88         case GET_BLOCK_SIZE:
89             *((DWORD*)buff) = 1; // default when not known
90             return RES_OK;
91
92     }
93     return RES_PARERR;
94 }