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_SI_CLASS_HOST_C
35 #include "StillImage.h"
37 #warning The Still Image Host mode Class driver is currently incomplete and is for preview purposes only.
39 uint8_t SI_Host_ConfigurePipes(USB_ClassInfo_SI_Host_t
* SIInterfaceInfo
, uint16_t ConfigDescriptorSize
,
40 uint8_t* ConfigDescriptorData
)
42 uint8_t FoundEndpoints
= 0;
44 memset(&SIInterfaceInfo
->State
, 0x00, sizeof(SIInterfaceInfo
->State
));
46 if (DESCRIPTOR_TYPE(ConfigDescriptorData
) != DTYPE_Configuration
)
47 return SI_ENUMERROR_InvalidConfigDescriptor
;
49 if (USB_GetNextDescriptorComp(&ConfigDescriptorSize
, &ConfigDescriptorData
,
50 DComp_SI_Host_NextSIInterface
) != DESCRIPTOR_SEARCH_COMP_Found
)
52 return SI_ENUMERROR_NoSIInterfaceFound
;
55 while (FoundEndpoints
!= (SI_FOUND_EVENTS_IN
| SI_FOUND_DATAPIPE_IN
| SI_FOUND_DATAPIPE_OUT
))
57 if (USB_GetNextDescriptorComp(&ConfigDescriptorSize
, &ConfigDescriptorData
,
58 DComp_SI_Host_NextSIInterfaceEndpoint
) != DESCRIPTOR_SEARCH_COMP_Found
)
60 return SI_ENUMERROR_EndpointsNotFound
;
63 USB_Descriptor_Endpoint_t
* EndpointData
= DESCRIPTOR_PCAST(ConfigDescriptorData
, USB_Descriptor_Endpoint_t
);
65 if ((EndpointData
->Attributes
& EP_TYPE_MASK
) == EP_TYPE_INTERRUPT
)
67 if (EndpointData
->EndpointAddress
& ENDPOINT_DESCRIPTOR_DIR_IN
)
69 Pipe_ConfigurePipe(SIInterfaceInfo
->Config
.EventsPipeNumber
, EP_TYPE_INTERRUPT
, PIPE_TOKEN_IN
,
70 EndpointData
->EndpointAddress
, EndpointData
->EndpointSize
,
72 SIInterfaceInfo
->State
.EventsPipeSize
= EndpointData
->EndpointSize
;
74 Pipe_SetInterruptPeriod(EndpointData
->PollingIntervalMS
);
76 FoundEndpoints
|= SI_FOUND_EVENTS_IN
;
81 if (EndpointData
->EndpointAddress
& ENDPOINT_DESCRIPTOR_DIR_IN
)
83 Pipe_ConfigurePipe(SIInterfaceInfo
->Config
.DataINPipeNumber
, EP_TYPE_BULK
, PIPE_TOKEN_IN
,
84 EndpointData
->EndpointAddress
, EndpointData
->EndpointSize
,
86 SIInterfaceInfo
->State
.DataINPipeSize
= EndpointData
->EndpointSize
;
88 FoundEndpoints
|= SI_FOUND_DATAPIPE_IN
;
92 Pipe_ConfigurePipe(SIInterfaceInfo
->Config
.DataOUTPipeNumber
, EP_TYPE_BULK
, PIPE_TOKEN_OUT
,
93 EndpointData
->EndpointAddress
, EndpointData
->EndpointSize
,
95 SIInterfaceInfo
->State
.DataOUTPipeSize
= EndpointData
->EndpointSize
;
97 FoundEndpoints
|= SI_FOUND_DATAPIPE_OUT
;
102 return SI_ENUMERROR_NoError
;
105 uint8_t DComp_SI_Host_NextSIInterface(void* CurrentDescriptor
)
107 if (DESCRIPTOR_TYPE(CurrentDescriptor
) == DTYPE_Interface
)
109 if ((DESCRIPTOR_CAST(CurrentDescriptor
, USB_Descriptor_Interface_t
).Class
== STILL_IMAGE_CLASS
) &&
110 (DESCRIPTOR_CAST(CurrentDescriptor
, USB_Descriptor_Interface_t
).SubClass
== STILL_IMAGE_SUBCLASS
) &&
111 (DESCRIPTOR_CAST(CurrentDescriptor
, USB_Descriptor_Interface_t
).Protocol
== STILL_IMAGE_PROTOCOL
))
113 return DESCRIPTOR_SEARCH_Found
;
117 return DESCRIPTOR_SEARCH_NotFound
;
120 uint8_t DComp_SI_Host_NextSIInterfaceEndpoint(void* CurrentDescriptor
)
122 if (DESCRIPTOR_TYPE(CurrentDescriptor
) == DTYPE_Endpoint
)
124 USB_Descriptor_Endpoint_t
* CurrentEndpoint
= DESCRIPTOR_PCAST(CurrentDescriptor
,
125 USB_Descriptor_Endpoint_t
);
127 uint8_t EndpointType
= (CurrentEndpoint
->Attributes
& EP_TYPE_MASK
);
129 if (((EndpointType
== EP_TYPE_BULK
) || (EndpointType
== EP_TYPE_INTERRUPT
)) &&
130 (!(Pipe_IsEndpointBound(CurrentEndpoint
->EndpointAddress
))))
132 return DESCRIPTOR_SEARCH_Found
;
135 else if (DESCRIPTOR_TYPE(CurrentDescriptor
) == DTYPE_Interface
)
137 return DESCRIPTOR_SEARCH_Fail
;
140 return DESCRIPTOR_SEARCH_NotFound
;
143 void SI_Host_USBTask(USB_ClassInfo_SI_Host_t
* SIInterfaceInfo
)