3 Copyright (C) Dean Camera, 2011.
5 dean [at] fourwalledcubicle [dot] com
10 Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all 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 #define __INCLUDE_FROM_USB_DRIVER
32 #include "ConfigDescriptor.h"
34 #if defined(USB_CAN_BE_HOST)
35 uint8_t USB_Host_GetDeviceConfigDescriptor(const uint8_t ConfigNumber
,
36 uint16_t* const ConfigSizePtr
,
37 void* const BufferPtr
,
38 const uint16_t BufferSize
)
41 uint8_t ConfigHeader
[sizeof(USB_Descriptor_Configuration_Header_t
)];
43 USB_ControlRequest
= (USB_Request_Header_t
)
45 .bmRequestType
= (REQDIR_DEVICETOHOST
| REQTYPE_STANDARD
| REQREC_DEVICE
),
46 .bRequest
= REQ_GetDescriptor
,
47 .wValue
= ((DTYPE_Configuration
<< 8) | (ConfigNumber
- 1)),
49 .wLength
= sizeof(USB_Descriptor_Configuration_Header_t
),
52 Pipe_SelectPipe(PIPE_CONTROLPIPE
);
54 if ((ErrorCode
= USB_Host_SendControlRequest(ConfigHeader
)) != HOST_SENDCONTROL_Successful
)
57 *ConfigSizePtr
= DESCRIPTOR_PCAST(ConfigHeader
, USB_Descriptor_Configuration_Header_t
)->TotalConfigurationSize
;
59 if (*ConfigSizePtr
> BufferSize
)
60 return HOST_GETCONFIG_BuffOverflow
;
62 USB_ControlRequest
.wLength
= *ConfigSizePtr
;
64 if ((ErrorCode
= USB_Host_SendControlRequest(BufferPtr
)) != HOST_SENDCONTROL_Successful
)
67 if (DESCRIPTOR_TYPE(BufferPtr
) != DTYPE_Configuration
)
68 return HOST_GETCONFIG_InvalidData
;
70 return HOST_GETCONFIG_Successful
;
74 void USB_GetNextDescriptorOfType(uint16_t* const BytesRem
,
75 void** const CurrConfigLoc
,
80 USB_GetNextDescriptor(BytesRem
, CurrConfigLoc
);
82 if (DESCRIPTOR_TYPE(*CurrConfigLoc
) == Type
)
87 void USB_GetNextDescriptorOfTypeBefore(uint16_t* const BytesRem
,
88 void** const CurrConfigLoc
,
90 const uint8_t BeforeType
)
94 USB_GetNextDescriptor(BytesRem
, CurrConfigLoc
);
96 if (DESCRIPTOR_TYPE(*CurrConfigLoc
) == Type
)
100 else if (DESCRIPTOR_TYPE(*CurrConfigLoc
) == BeforeType
)
108 void USB_GetNextDescriptorOfTypeAfter(uint16_t* const BytesRem
,
109 void** const CurrConfigLoc
,
111 const uint8_t AfterType
)
113 USB_GetNextDescriptorOfType(BytesRem
, CurrConfigLoc
, AfterType
);
116 USB_GetNextDescriptorOfType(BytesRem
, CurrConfigLoc
, Type
);
119 uint8_t USB_GetNextDescriptorComp(uint16_t* const BytesRem
,
120 void** const CurrConfigLoc
,
121 ConfigComparatorPtr_t
const ComparatorRoutine
)
127 uint8_t* PrevDescLoc
= *CurrConfigLoc
;
128 uint16_t PrevBytesRem
= *BytesRem
;
130 USB_GetNextDescriptor(BytesRem
, CurrConfigLoc
);
132 if ((ErrorCode
= ComparatorRoutine(*CurrConfigLoc
)) != DESCRIPTOR_SEARCH_NotFound
)
134 if (ErrorCode
== DESCRIPTOR_SEARCH_Fail
)
136 *CurrConfigLoc
= PrevDescLoc
;
137 *BytesRem
= PrevBytesRem
;
144 return DESCRIPTOR_SEARCH_COMP_EndOfDescriptor
;