3 Copyright (C) Dean Camera, 2012.
\r
5 dean [at] fourwalledcubicle [dot] com
\r
10 Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)
\r
12 Permission to use, copy, modify, distribute, and sell this
\r
13 software and its documentation for any purpose is hereby granted
\r
14 without fee, provided that the above copyright notice appear in
\r
15 all copies and that both that the copyright notice and this
\r
16 permission notice and warranty disclaimer appear in supporting
\r
17 documentation, and that the name of the author not be used in
\r
18 advertising or publicity pertaining to distribution of the
\r
19 software without specific, written prior permission.
\r
21 The author disclaim all warranties with regard to this
\r
22 software, including all implied warranties of merchantability
\r
23 and fitness. In no event shall the author be liable for any
\r
24 special, indirect or consequential damages or any damages
\r
25 whatsoever resulting from loss of use, data or profits, whether
\r
26 in an action of contract, negligence or other tortious action,
\r
27 arising out of or in connection with the use or performance of
\r
31 #define __INCLUDE_FROM_USB_DRIVER
\r
32 #include "ConfigDescriptors.h"
\r
34 #if defined(USB_CAN_BE_HOST)
\r
35 uint8_t USB_Host_GetDeviceConfigDescriptor(const uint8_t ConfigNumber,
\r
36 uint16_t* const ConfigSizePtr,
\r
37 void* const BufferPtr,
\r
38 const uint16_t BufferSize)
\r
41 uint8_t ConfigHeader[sizeof(USB_Descriptor_Configuration_Header_t)];
\r
43 USB_ControlRequest = (USB_Request_Header_t)
\r
45 .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),
\r
46 .bRequest = REQ_GetDescriptor,
\r
47 .wValue = ((DTYPE_Configuration << 8) | (ConfigNumber - 1)),
\r
49 .wLength = sizeof(USB_Descriptor_Configuration_Header_t),
\r
52 Pipe_SelectPipe(PIPE_CONTROLPIPE);
\r
54 if ((ErrorCode = USB_Host_SendControlRequest(ConfigHeader)) != HOST_SENDCONTROL_Successful)
\r
57 *ConfigSizePtr = le16_to_cpu(DESCRIPTOR_PCAST(ConfigHeader, USB_Descriptor_Configuration_Header_t)->TotalConfigurationSize);
\r
59 if (*ConfigSizePtr > BufferSize)
\r
60 return HOST_GETCONFIG_BuffOverflow;
\r
62 USB_ControlRequest.wLength = *ConfigSizePtr;
\r
64 if ((ErrorCode = USB_Host_SendControlRequest(BufferPtr)) != HOST_SENDCONTROL_Successful)
\r
67 if (DESCRIPTOR_TYPE(BufferPtr) != DTYPE_Configuration)
\r
68 return HOST_GETCONFIG_InvalidData;
\r
70 return HOST_GETCONFIG_Successful;
\r
74 void USB_GetNextDescriptorOfType(uint16_t* const BytesRem,
\r
75 void** const CurrConfigLoc,
\r
80 USB_GetNextDescriptor(BytesRem, CurrConfigLoc);
\r
82 if (DESCRIPTOR_TYPE(*CurrConfigLoc) == Type)
\r
87 void USB_GetNextDescriptorOfTypeBefore(uint16_t* const BytesRem,
\r
88 void** const CurrConfigLoc,
\r
90 const uint8_t BeforeType)
\r
94 USB_GetNextDescriptor(BytesRem, CurrConfigLoc);
\r
96 if (DESCRIPTOR_TYPE(*CurrConfigLoc) == Type)
\r
100 else if (DESCRIPTOR_TYPE(*CurrConfigLoc) == BeforeType)
\r
108 void USB_GetNextDescriptorOfTypeAfter(uint16_t* const BytesRem,
\r
109 void** const CurrConfigLoc,
\r
110 const uint8_t Type,
\r
111 const uint8_t AfterType)
\r
113 USB_GetNextDescriptorOfType(BytesRem, CurrConfigLoc, AfterType);
\r
116 USB_GetNextDescriptorOfType(BytesRem, CurrConfigLoc, Type);
\r
119 uint8_t USB_GetNextDescriptorComp(uint16_t* const BytesRem,
\r
120 void** const CurrConfigLoc,
\r
121 ConfigComparatorPtr_t const ComparatorRoutine)
\r
127 uint8_t* PrevDescLoc = *CurrConfigLoc;
\r
128 uint16_t PrevBytesRem = *BytesRem;
\r
130 USB_GetNextDescriptor(BytesRem, CurrConfigLoc);
\r
132 if ((ErrorCode = ComparatorRoutine(*CurrConfigLoc)) != DESCRIPTOR_SEARCH_NotFound)
\r
134 if (ErrorCode == DESCRIPTOR_SEARCH_Fail)
\r
136 *CurrConfigLoc = PrevDescLoc;
\r
137 *BytesRem = PrevBytesRem;
\r
144 return DESCRIPTOR_SEARCH_COMP_EndOfDescriptor;
\r