The incomplete StandaloneProgrammer project now uses Host and Device Mass storage...
[pub/USBasp.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 DSTATUS stat;
19
20 stat = RES_OK;
21
22 return stat;
23 }
24
25
26
27 /*-----------------------------------------------------------------------*/
28 /* Read Partial Sector */
29 /*-----------------------------------------------------------------------*/
30
31 DRESULT disk_readp (
32 void* dest, /* Pointer to the destination object */
33 DWORD sector, /* Sector number (LBA) */
34 WORD sofs, /* Offset in the sector */
35 WORD count /* Byte count (bit15:destination) */
36 )
37 {
38 DRESULT ErrorCode = RES_OK;
39 uint8_t BlockTemp[512];
40
41 if (USB_CurrentMode == USB_MODE_HOST)
42 {
43 #if defined(USB_CAN_BE_HOST)
44 if (USB_HostState != HOST_STATE_Configured)
45 ErrorCode = RES_NOTRDY;
46 else if (MS_Host_ReadDeviceBlocks(&DiskHost_MS_Interface, 0, sector, 1, 512, BlockTemp))
47 ErrorCode = RES_ERROR;
48
49 printf("BLOCK READ #%lu Ret %d\r\n", sector, MS_Host_ReadDeviceBlocks(&DiskHost_MS_Interface, 0, sector, 1, 512, BlockTemp));
50 #endif
51 }
52 else
53 {
54 #if defined(USB_CAN_BE_DEVICE)
55 DataflashManager_ReadBlocks_RAM(sector, 1, BlockTemp);
56 #endif
57 }
58
59 memcpy(dest, &BlockTemp[sofs], count);
60
61 return ErrorCode;
62 }
63