diskio.c 1.63 KB
Newer Older
1
/*-----------------------------------------------------------------------*/
Dean Camera's avatar
Dean Camera committed
2
/* Low level disk I/O module skeleton for Petit FatFs (C)ChaN, 2010      */
3
4
5
6
7
/*-----------------------------------------------------------------------*/

#include "diskio.h"

#include <string.h>
8
#include <LUFA/Drivers/USB/Class/MassStorage.h>
9
#include "../DataflashManager.h"
10
#include "../../DiskHost.h"
11
12
13
14
15
16
17

/*-----------------------------------------------------------------------*/
/* Initialize Disk Drive                                                 */
/*-----------------------------------------------------------------------*/

DSTATUS disk_initialize (void)
{
18
	return RES_OK;
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
}



/*-----------------------------------------------------------------------*/
/* Read Partial Sector                                                   */
/*-----------------------------------------------------------------------*/

DRESULT disk_readp (
	void* dest,			/* Pointer to the destination object */
	DWORD sector,		/* Sector number (LBA) */
	WORD sofs,			/* Offset in the sector */
	WORD count			/* Byte count (bit15:destination) */
)
{
34
	DRESULT ErrorCode = RES_OK;
35
36
	uint8_t BlockTemp[512];

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
	if (USB_CurrentMode == USB_MODE_HOST)
	{
		#if defined(USB_CAN_BE_HOST)
		if (USB_HostState != HOST_STATE_Configured)
		  ErrorCode = RES_NOTRDY;
		else if (MS_Host_ReadDeviceBlocks(&DiskHost_MS_Interface, 0, sector, 1, 512, BlockTemp))
		  ErrorCode = RES_ERROR;
		#endif
	}
	else
	{
		#if defined(USB_CAN_BE_DEVICE)
		DataflashManager_ReadBlocks_RAM(sector, 1, BlockTemp);
		#endif
	}

	memcpy(dest, &BlockTemp[sofs], count);
54

55
	return ErrorCode;
56
57
}