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"
33 #if defined(USB_CAN_BE_HOST)
35 #include "ConfigDescriptor.h"
37 uint8_t USB_Host_GetDeviceConfigDescriptor(uint16_t* const ConfigSizePtr
, void* BufferPtr
)
41 USB_HostRequest
= (USB_Host_Request_Header_t
)
43 bmRequestType
: (REQDIR_DEVICETOHOST
| REQTYPE_STANDARD
| REQREC_DEVICE
),
44 bRequest
: REQ_GetDescriptor
,
45 wValue
: (DTYPE_Configuration
<< 8),
47 wLength
: sizeof(USB_Descriptor_Configuration_Header_t
),
50 Pipe_SelectPipe(PIPE_CONTROLPIPE
);
52 if (BufferPtr
== NULL
)
54 uint8_t ConfigHeader
[sizeof(USB_Descriptor_Configuration_Header_t
)];
56 ErrorCode
= USB_Host_SendControlRequest(ConfigHeader
);
58 #if defined(USE_NONSTANDARD_DESCRIPTOR_NAMES)
59 *ConfigSizePtr
= DESCRIPTOR_CAST(ConfigHeader
, USB_Descriptor_Configuration_Header_t
).TotalConfigurationSize
;
61 *ConfigSizePtr
= DESCRIPTOR_CAST(ConfigHeader
, USB_Descriptor_Configuration_Header_t
).wTotalLength
;
66 USB_HostRequest
.wLength
= *ConfigSizePtr
;
68 ErrorCode
= USB_Host_SendControlRequest(BufferPtr
);
74 void USB_Host_GetNextDescriptorOfType(uint16_t* const BytesRem
,
75 uint8_t** const CurrConfigLoc
,
80 USB_Host_GetNextDescriptor(BytesRem
, CurrConfigLoc
);
82 if (DESCRIPTOR_TYPE(*CurrConfigLoc
) == Type
)
87 void USB_Host_GetNextDescriptorOfTypeBefore(uint16_t* const BytesRem
,
88 uint8_t** const CurrConfigLoc
,
90 const uint8_t BeforeType
)
94 USB_Host_GetNextDescriptor(BytesRem
, CurrConfigLoc
);
96 if (DESCRIPTOR_TYPE(*CurrConfigLoc
) == Type
)
100 else if (DESCRIPTOR_TYPE(*CurrConfigLoc
) == BeforeType
)
108 void USB_Host_GetNextDescriptorOfTypeAfter(uint16_t* const BytesRem
,
109 uint8_t** const CurrConfigLoc
,
111 const uint8_t AfterType
)
113 USB_Host_GetNextDescriptorOfType(BytesRem
, CurrConfigLoc
, AfterType
);
116 USB_Host_GetNextDescriptorOfType(BytesRem
, CurrConfigLoc
, Type
);
119 uint8_t USB_Host_GetNextDescriptorComp_P(uint16_t* BytesRem
, uint8_t** CurrConfigLoc
,
120 uint8_t (* const ComparatorRoutine
)(void*))
126 uint8_t* PrevDescLoc
= *CurrConfigLoc
;
127 uint16_t PrevBytesRem
= *BytesRem
;
129 USB_Host_GetNextDescriptor(BytesRem
, CurrConfigLoc
);
131 if ((ErrorCode
= ComparatorRoutine(*CurrConfigLoc
)) != Descriptor_Search_NotFound
)
133 if (ErrorCode
== Descriptor_Search_Fail
)
135 *CurrConfigLoc
= PrevDescLoc
;
136 *BytesRem
= PrevBytesRem
;
143 return Descriptor_Search_Comp_EndOfDescriptor
;