Be doubly-certain that the incomming CDC class driver's endpoint/pipe is flushed...
[pub/USBasp.git] / Projects / Incomplete / StandaloneProgrammer / Lib / PetiteFATFs / diskio.c
index 0084fa5..bcf1674 100644 (file)
@@ -1,11 +1,13 @@
 /*-----------------------------------------------------------------------*/\r
-/* Low level disk I/O module skeleton for Petit FatFs (C)ChaN, 2009      */\r
+/* Low level disk I/O module skeleton for Petit FatFs (C)ChaN, 2010      */\r
 /*-----------------------------------------------------------------------*/\r
 \r
 #include "diskio.h"\r
 \r
 #include <string.h>\r
+#include <LUFA/Drivers/USB/Class/MassStorage.h>\r
 #include "../DataflashManager.h"\r
+#include "../../DiskHost.h"\r
 \r
 /*-----------------------------------------------------------------------*/\r
 /* Initialize Disk Drive                                                 */\r
 \r
 DSTATUS disk_initialize (void)\r
 {\r
-       DSTATUS stat;\r
-\r
-       stat = RES_OK;\r
-\r
-       return stat;\r
+       return RES_OK;\r
 }\r
 \r
 \r
@@ -33,14 +31,29 @@ DRESULT disk_readp (
        WORD count                      /* Byte count (bit15:destination) */\r
 )\r
 {\r
-       DRESULT res;\r
-\r
+       DRESULT ErrorCode = RES_OK;\r
        uint8_t BlockTemp[512];\r
-       DataflashManager_ReadBlocks_RAM(sector, 1, BlockTemp);\r
-       memcpy(dest, &BlockTemp[sofs], count);\r
 \r
-       res = RES_OK;\r
+       if (USB_CurrentMode == USB_MODE_HOST)\r
+       {\r
+               #if defined(USB_CAN_BE_HOST)\r
+               if (USB_HostState != HOST_STATE_Configured)\r
+                 ErrorCode = RES_NOTRDY;\r
+               else if (MS_Host_ReadDeviceBlocks(&DiskHost_MS_Interface, 0, sector, 1, 512, BlockTemp))\r
+                 ErrorCode = RES_ERROR;\r
+\r
+               MS_Host_ReadDeviceBlocks(&DiskHost_MS_Interface, 0, sector, 1, 512, BlockTemp);\r
+               #endif\r
+       }\r
+       else\r
+       {\r
+               #if defined(USB_CAN_BE_DEVICE)\r
+               DataflashManager_ReadBlocks_RAM(sector, 1, BlockTemp);\r
+               #endif\r
+       }\r
+\r
+       memcpy(dest, &BlockTemp[sofs], count);\r
 \r
-       return res;\r
+       return ErrorCode;\r
 }\r
 \r