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_HID_CLASS_HOST_C
37 uint8_t HID_Host_ConfigurePipes(USB_ClassInfo_HID_Host_t
* HIDInterfaceInfo
, uint16_t ConfigDescriptorSize
,
38 uint8_t* ConfigDescriptorData
)
40 uint8_t FoundEndpoints
= 0;
42 memset(&HIDInterfaceInfo
->State
, 0x00, sizeof(HIDInterfaceInfo
->State
));
44 if (DESCRIPTOR_TYPE(ConfigDescriptorData
) != DTYPE_Configuration
)
45 return HID_ENUMERROR_InvalidConfigDescriptor
;
49 if (USB_GetNextDescriptorComp(&ConfigDescriptorSize
, &ConfigDescriptorData
,
50 DComp_HID_Host_NextHIDInterface
) != DESCRIPTOR_SEARCH_COMP_Found
)
52 return HID_ENUMERROR_NoHIDInterfaceFound
;
54 } while (HIDInterfaceInfo
->Config
.MatchInterfaceProtocol
&&
55 DESCRIPTOR_PCAST(ConfigDescriptorData
,
56 USB_Descriptor_Interface_t
)->Protocol
!= HIDInterfaceInfo
->Config
.HIDInterfaceProtocol
);
58 while (FoundEndpoints
!= ((1 << HID_FOUND_DATAPIPE_IN
) | (1 << HID_FOUND_DATAPIPE_OUT
)))
60 if (USB_GetNextDescriptorComp(&ConfigDescriptorSize
, &ConfigDescriptorData
,
61 DComp_HID_Host_NextInterfaceHIDDataEndpoint
) != DESCRIPTOR_SEARCH_COMP_Found
)
63 if (FoundEndpoints
== (1 << HID_FOUND_DATAPIPE_IN
))
66 return HID_ENUMERROR_EndpointsNotFound
;
69 USB_Descriptor_Endpoint_t
* EndpointData
= DESCRIPTOR_PCAST(ConfigDescriptorData
, USB_Descriptor_Endpoint_t
);
71 if (EndpointData
->EndpointAddress
& ENDPOINT_DESCRIPTOR_DIR_IN
)
73 Pipe_ConfigurePipe(HIDInterfaceInfo
->Config
.DataINPipeNumber
, EP_TYPE_INTERRUPT
, PIPE_TOKEN_IN
,
74 EndpointData
->EndpointAddress
, EndpointData
->EndpointSize
, PIPE_BANK_SINGLE
);
76 FoundEndpoints
|= (1 << HID_FOUND_DATAPIPE_IN
);
80 Pipe_ConfigurePipe(HIDInterfaceInfo
->Config
.DataOUTPipeNumber
, EP_TYPE_INTERRUPT
, PIPE_TOKEN_OUT
,
81 EndpointData
->EndpointAddress
, EndpointData
->EndpointSize
, PIPE_BANK_SINGLE
);
83 FoundEndpoints
|= (1 << HID_FOUND_DATAPIPE_OUT
);
87 return HID_ENUMERROR_NoError
;
90 static uint8_t DComp_HID_Host_NextHIDInterface(void* CurrentDescriptor
)
92 if (DESCRIPTOR_TYPE(CurrentDescriptor
) == DTYPE_Interface
)
94 USB_Descriptor_Interface_t
* CurrentInterface
= DESCRIPTOR_PCAST(CurrentDescriptor
,
95 USB_Descriptor_Interface_t
);
97 if (CurrentInterface
->Class
== HID_INTERFACE_CLASS
)
98 return DESCRIPTOR_SEARCH_Found
;
101 return DESCRIPTOR_SEARCH_NotFound
;
104 static uint8_t DComp_HID_Host_NextInterfaceHIDDataEndpoint(void* CurrentDescriptor
)
106 if (DESCRIPTOR_TYPE(CurrentDescriptor
) == DTYPE_Endpoint
)
108 USB_Descriptor_Endpoint_t
* CurrentEndpoint
= DESCRIPTOR_PCAST(CurrentDescriptor
,
109 USB_Descriptor_Endpoint_t
);
111 if (!(Pipe_IsEndpointBound(CurrentEndpoint
->EndpointAddress
)))
112 return DESCRIPTOR_SEARCH_Found
;
114 else if (DESCRIPTOR_TYPE(CurrentDescriptor
) == DTYPE_Interface
)
116 return DESCRIPTOR_SEARCH_Fail
;
119 return DESCRIPTOR_SEARCH_NotFound
;
122 void HID_Host_USBTask(USB_ClassInfo_HID_Host_t
* HIDInterfaceInfo
)