3 Copyright (C) Dean Camera, 2009.
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12 Permission to use, copy, modify, and distribute this software
13 and its documentation for any purpose and without fee is hereby
14 granted, provided that the above copyright notice appear in all
15 copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
31 #include "../../HighLevel/USBMode.h"
32 #if defined(USB_CAN_BE_HOST)
34 #define INCLUDE_FROM_MS_CLASS_HOST_C
35 #include "MassStorage.h"
37 #warning The Mass Storage Host mode Class driver is currently incomplete and is for preview purposes only.
39 uint8_t MS_Host_ConfigurePipes(USB_ClassInfo_MS_Host_t
* MSInterfaceInfo
, uint16_t ConfigDescriptorLength
,
40 uint8_t* DeviceConfigDescriptor
)
42 uint8_t FoundEndpoints
= 0;
44 memset(&MSInterfaceInfo
->State
, 0x00, sizeof(MSInterfaceInfo
->State
));
46 if (DESCRIPTOR_TYPE(DeviceConfigDescriptor
) != DTYPE_Configuration
)
47 return MS_ENUMERROR_InvalidConfigDescriptor
;
49 if (USB_GetNextDescriptorComp(&ConfigDescriptorLength
, &DeviceConfigDescriptor
,
50 DComp_NextMassStorageInterface
) != DESCRIPTOR_SEARCH_COMP_Found
)
52 return MS_ENUMERROR_NoMSInterfaceFound
;
55 MSInterfaceInfo
->State
.InterfaceNumber
=
56 #if defined(USE_NONSTANDARD_DESCRIPTOR_NAMES)
57 DESCRIPTOR_PCAST(DeviceConfigDescriptor
, USB_Descriptor_Interface_t
)->InterfaceNumber
;
59 DESCRIPTOR_PCAST(DeviceConfigDescriptor
, USB_Descriptor_Interface_t
)->bInterfaceNumber
;
62 while (FoundEndpoints
!= (MS_FOUND_DATAPIPE_IN
| MS_FOUND_DATAPIPE_OUT
))
64 if (USB_GetNextDescriptorComp(&ConfigDescriptorLength
, &DeviceConfigDescriptor
,
65 DComp_NextInterfaceBulkDataEndpoint
) != DESCRIPTOR_SEARCH_COMP_Found
)
67 return MS_ENUMERROR_EndpointsNotFound
;
70 USB_Descriptor_Endpoint_t
* EndpointData
= DESCRIPTOR_PCAST(DeviceConfigDescriptor
, USB_Descriptor_Endpoint_t
);
72 if (EndpointData
->EndpointAddress
& ENDPOINT_DESCRIPTOR_DIR_IN
)
74 Pipe_ConfigurePipe(MSInterfaceInfo
->Config
.DataINPipeNumber
, EP_TYPE_BULK
, PIPE_TOKEN_IN
,
75 EndpointData
->EndpointAddress
, EndpointData
->EndpointSize
,
77 MSInterfaceInfo
->State
.DataINPipeSize
= EndpointData
->EndpointSize
;
79 FoundEndpoints
|= MS_FOUND_DATAPIPE_IN
;
83 Pipe_ConfigurePipe(MSInterfaceInfo
->Config
.DataOUTPipeNumber
, EP_TYPE_BULK
, PIPE_TOKEN_OUT
,
84 EndpointData
->EndpointAddress
, EndpointData
->EndpointSize
,
86 MSInterfaceInfo
->State
.DataOUTPipeSize
= EndpointData
->EndpointSize
;
88 FoundEndpoints
|= MS_FOUND_DATAPIPE_OUT
;
92 MSInterfaceInfo
->State
.Active
= true;
93 return MS_ENUMERROR_NoError
;
96 static uint8_t DComp_NextMassStorageInterface(void* CurrentDescriptor
)
98 if (DESCRIPTOR_TYPE(CurrentDescriptor
) == DTYPE_Interface
)
100 if ((DESCRIPTOR_CAST(CurrentDescriptor
, USB_Descriptor_Interface_t
).Class
== MASS_STORE_CLASS
) &&
101 (DESCRIPTOR_CAST(CurrentDescriptor
, USB_Descriptor_Interface_t
).SubClass
== MASS_STORE_SUBCLASS
) &&
102 (DESCRIPTOR_CAST(CurrentDescriptor
, USB_Descriptor_Interface_t
).Protocol
== MASS_STORE_PROTOCOL
))
104 return DESCRIPTOR_SEARCH_Found
;
108 return DESCRIPTOR_SEARCH_NotFound
;
111 static uint8_t DComp_NextInterfaceBulkDataEndpoint(void* CurrentDescriptor
)
113 if (DESCRIPTOR_TYPE(CurrentDescriptor
) == DTYPE_Endpoint
)
115 uint8_t EndpointType
= (DESCRIPTOR_CAST(CurrentDescriptor
,
116 USB_Descriptor_Endpoint_t
).Attributes
& EP_TYPE_MASK
);
118 if (EndpointType
== EP_TYPE_BULK
)
119 return DESCRIPTOR_SEARCH_Found
;
121 else if (DESCRIPTOR_TYPE(CurrentDescriptor
) == DTYPE_Interface
)
123 return DESCRIPTOR_SEARCH_Fail
;
126 return DESCRIPTOR_SEARCH_NotFound
;
129 void MS_Host_USBTask(USB_ClassInfo_MS_Host_t
* MSInterfaceInfo
)