cac0bd957e9e18d9647dffe1d68a26970b4195d6
[pub/lufa.git] / Projects / Incomplete / StandaloneProgrammer / Lib / PetiteFATFs / diskio.c
1 /*-----------------------------------------------------------------------*/
2 /* Low level disk I/O module skeleton for Petit FatFs (C)ChaN, 2009 */
3 /*-----------------------------------------------------------------------*/
4
5 #include "diskio.h"
6
7 #include <string.h>
8 #include <LUFA/Drivers/USB/Class/MassStorage.h>
9 #include "../DataflashManager.h"
10 #include "../../DiskHost.h"
11
12 /*-----------------------------------------------------------------------*/
13 /* Initialize Disk Drive */
14 /*-----------------------------------------------------------------------*/
15
16 DSTATUS disk_initialize (void)
17 {
18 return RES_OK;
19 }
20
21
22
23 /*-----------------------------------------------------------------------*/
24 /* Read Partial Sector */
25 /*-----------------------------------------------------------------------*/
26
27 DRESULT disk_readp (
28 BYTE* dest, /* Pointer to the destination object */
29 DWORD sector, /* Sector number (LBA) */
30 WORD sofs, /* Offset in the sector */
31 WORD count /* Byte count (bit15:destination) */
32 )
33 {
34 DRESULT ErrorCode = RES_OK;
35 uint8_t BlockTemp[512];
36
37 if (USB_CurrentMode == USB_MODE_Host)
38 {
39 #if defined(USB_CAN_BE_HOST)
40 if (USB_HostState != HOST_STATE_Configured)
41 ErrorCode = RES_NOTRDY;
42 else if (MS_Host_ReadDeviceBlocks(&DiskHost_MS_Interface, 0, sector, 1, 512, BlockTemp))
43 ErrorCode = RES_ERROR;
44 #endif
45 }
46 else
47 {
48 #if defined(USB_CAN_BE_DEVICE)
49 DataflashManager_ReadBlocks_RAM(sector, 1, BlockTemp);
50 #endif
51 }
52
53 memcpy(dest, &BlockTemp[sofs], count);
54
55 return ErrorCode;
56 }
57