2 * @brief USB Configuration Descriptor definitions
\r
5 * Copyright(C) NXP Semiconductors, 2012
\r
6 * Copyright(C) Dean Camera, 2011, 2012
\r
7 * All rights reserved.
\r
10 * Software that is described herein is for illustrative purposes only
\r
11 * which provides customers with programming information regarding the
\r
12 * LPC products. This software is supplied "AS IS" without any warranties of
\r
13 * any kind, and NXP Semiconductors and its licensor disclaim any and
\r
14 * all warranties, express or implied, including all implied warranties of
\r
15 * merchantability, fitness for a particular purpose and non-infringement of
\r
16 * intellectual property rights. NXP Semiconductors assumes no responsibility
\r
17 * or liability for the use of the software, conveys no license or rights under any
\r
18 * patent, copyright, mask work right, or any other intellectual property rights in
\r
19 * or to any products. NXP Semiconductors reserves the right to make changes
\r
20 * in the software without notification. NXP Semiconductors also makes no
\r
21 * representation or warranty that such application will be suitable for the
\r
22 * specified use without further testing or modification.
\r
25 * Permission to use, copy, modify, and distribute this software and its
\r
26 * documentation is hereby granted, under NXP Semiconductors' and its
\r
27 * licensor's relevant copyrights in the software, without fee, provided that it
\r
28 * is used in conjunction with NXP Semiconductors microcontrollers. This
\r
29 * copyright, permission, and disclaimer notice must appear in all copies of
\r
33 #define __INCLUDE_FROM_USB_DRIVER
\r
34 #include "ConfigDescriptor.h"
\r
36 #if defined(USB_CAN_BE_HOST)
\r
37 uint8_t USB_Host_GetDeviceConfigDescriptor(const uint8_t corenum,
\r
38 const uint8_t ConfigNumber,
\r
39 uint16_t* const ConfigSizePtr,
\r
40 void* const BufferPtr,
\r
41 const uint16_t BufferSize)
\r
44 uint8_t ConfigHeader[sizeof(USB_Descriptor_Configuration_Header_t)];
\r
45 USB_Descriptor_Configuration_Header_t *pCfgHeader = (USB_Descriptor_Configuration_Header_t*)ConfigHeader;
\r
47 USB_ControlRequest = (USB_Request_Header_t)
\r
49 .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),
\r
50 .bRequest = REQ_GetDescriptor,
\r
51 .wValue = ((DTYPE_Configuration << 8) | (ConfigNumber - 1)),
\r
53 .wLength = sizeof(USB_Descriptor_Configuration_Header_t),
\r
56 Pipe_SelectPipe(corenum,PIPE_CONTROLPIPE);
\r
58 if ((ErrorCode = USB_Host_SendControlRequest(corenum,ConfigHeader)) != HOST_SENDCONTROL_Successful)
\r
61 *ConfigSizePtr = le16_to_cpu(pCfgHeader->TotalConfigurationSize);
\r
63 if (*ConfigSizePtr > BufferSize)
\r
64 return HOST_GETCONFIG_BuffOverflow;
\r
66 USB_ControlRequest.wLength = *ConfigSizePtr;
\r
68 if ((ErrorCode = USB_Host_SendControlRequest(corenum,BufferPtr)) != HOST_SENDCONTROL_Successful)
\r
71 if (DESCRIPTOR_TYPE(BufferPtr) != DTYPE_Configuration)
\r
72 return HOST_GETCONFIG_InvalidData;
\r
74 return HOST_GETCONFIG_Successful;
\r
78 void USB_GetNextDescriptorOfType(uint16_t* const BytesRem,
\r
79 void** const CurrConfigLoc,
\r
84 USB_GetNextDescriptor(BytesRem, CurrConfigLoc);
\r
86 if (DESCRIPTOR_TYPE(*CurrConfigLoc) == Type)
\r
91 void USB_GetNextDescriptorOfTypeBefore(uint16_t* const BytesRem,
\r
92 void** const CurrConfigLoc,
\r
94 const uint8_t BeforeType)
\r
98 USB_GetNextDescriptor(BytesRem, CurrConfigLoc);
\r
100 if (DESCRIPTOR_TYPE(*CurrConfigLoc) == Type)
\r
104 else if (DESCRIPTOR_TYPE(*CurrConfigLoc) == BeforeType)
\r
112 void USB_GetNextDescriptorOfTypeAfter(uint16_t* const BytesRem,
\r
113 void** const CurrConfigLoc,
\r
114 const uint8_t Type,
\r
115 const uint8_t AfterType)
\r
117 USB_GetNextDescriptorOfType(BytesRem, CurrConfigLoc, AfterType);
\r
120 USB_GetNextDescriptorOfType(BytesRem, CurrConfigLoc, Type);
\r
123 uint8_t USB_GetNextDescriptorComp(uint16_t* const BytesRem,
\r
124 void** const CurrConfigLoc,
\r
125 ConfigComparatorPtr_t const ComparatorRoutine)
\r
131 uint8_t* PrevDescLoc = *CurrConfigLoc;
\r
132 uint16_t PrevBytesRem = *BytesRem;
\r
134 USB_GetNextDescriptor(BytesRem, CurrConfigLoc);
\r
136 if ((ErrorCode = ComparatorRoutine(*CurrConfigLoc)) != DESCRIPTOR_SEARCH_NotFound)
\r
138 if (ErrorCode == DESCRIPTOR_SEARCH_Fail)
\r
140 *CurrConfigLoc = PrevDescLoc;
\r
141 *BytesRem = PrevBytesRem;
\r
148 return DESCRIPTOR_SEARCH_COMP_EndOfDescriptor;
\r