LPCOpen Platform  v1.03
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ConfigDescriptor.c
Go to the documentation of this file.
1 /*
2  * @brief USB Configuration Descriptor definitions
3  *
4  * @note
5  * Copyright(C) NXP Semiconductors, 2012
6  * Copyright(C) Dean Camera, 2011, 2012
7  * All rights reserved.
8  *
9  * @par
10  * Software that is described herein is for illustrative purposes only
11  * which provides customers with programming information regarding the
12  * LPC products. This software is supplied "AS IS" without any warranties of
13  * any kind, and NXP Semiconductors and its licensor disclaim any and
14  * all warranties, express or implied, including all implied warranties of
15  * merchantability, fitness for a particular purpose and non-infringement of
16  * intellectual property rights. NXP Semiconductors assumes no responsibility
17  * or liability for the use of the software, conveys no license or rights under any
18  * patent, copyright, mask work right, or any other intellectual property rights in
19  * or to any products. NXP Semiconductors reserves the right to make changes
20  * in the software without notification. NXP Semiconductors also makes no
21  * representation or warranty that such application will be suitable for the
22  * specified use without further testing or modification.
23  *
24  * @par
25  * Permission to use, copy, modify, and distribute this software and its
26  * documentation is hereby granted, under NXP Semiconductors' and its
27  * licensor's relevant copyrights in the software, without fee, provided that it
28  * is used in conjunction with NXP Semiconductors microcontrollers. This
29  * copyright, permission, and disclaimer notice must appear in all copies of
30  * this code.
31  */
32 
33 #define __INCLUDE_FROM_USB_DRIVER
34 #include "ConfigDescriptor.h"
35 
36 #if defined(USB_CAN_BE_HOST)
37 uint8_t USB_Host_GetDeviceConfigDescriptor(const uint8_t corenum,
38  const uint8_t ConfigNumber,
39  uint16_t* const ConfigSizePtr,
40  void* const BufferPtr,
41  const uint16_t BufferSize)
42 {
43  uint8_t ErrorCode;
44  uint8_t ConfigHeader[sizeof(USB_Descriptor_Configuration_Header_t)];
46 
48  {
49  .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),
51  .wValue = ((DTYPE_Configuration << 8) | (ConfigNumber - 1)),
52  .wIndex = 0,
53  .wLength = sizeof(USB_Descriptor_Configuration_Header_t),
54  };
55 
57 
58  if ((ErrorCode = USB_Host_SendControlRequest(corenum,ConfigHeader)) != HOST_SENDCONTROL_Successful)
59  return ErrorCode;
60 
61  *ConfigSizePtr = le16_to_cpu(pCfgHeader->TotalConfigurationSize);
62 
63  if (*ConfigSizePtr > BufferSize)
65 
66  USB_ControlRequest.wLength = *ConfigSizePtr;
67 
68  if ((ErrorCode = USB_Host_SendControlRequest(corenum,BufferPtr)) != HOST_SENDCONTROL_Successful)
69  return ErrorCode;
70 
71  if (DESCRIPTOR_TYPE(BufferPtr) != DTYPE_Configuration)
73 
75 }
76 #endif
77 
78 void USB_GetNextDescriptorOfType(uint16_t* const BytesRem,
79  void** const CurrConfigLoc,
80  const uint8_t Type)
81 {
82  while (*BytesRem)
83  {
84  USB_GetNextDescriptor(BytesRem, CurrConfigLoc);
85 
86  if (DESCRIPTOR_TYPE(*CurrConfigLoc) == Type)
87  return;
88  }
89 }
90 
91 void USB_GetNextDescriptorOfTypeBefore(uint16_t* const BytesRem,
92  void** const CurrConfigLoc,
93  const uint8_t Type,
94  const uint8_t BeforeType)
95 {
96  while (*BytesRem)
97  {
98  USB_GetNextDescriptor(BytesRem, CurrConfigLoc);
99 
100  if (DESCRIPTOR_TYPE(*CurrConfigLoc) == Type)
101  {
102  return;
103  }
104  else if (DESCRIPTOR_TYPE(*CurrConfigLoc) == BeforeType)
105  {
106  *BytesRem = 0;
107  return;
108  }
109  }
110 }
111 
112 void USB_GetNextDescriptorOfTypeAfter(uint16_t* const BytesRem,
113  void** const CurrConfigLoc,
114  const uint8_t Type,
115  const uint8_t AfterType)
116 {
117  USB_GetNextDescriptorOfType(BytesRem, CurrConfigLoc, AfterType);
118 
119  if (*BytesRem)
120  USB_GetNextDescriptorOfType(BytesRem, CurrConfigLoc, Type);
121 }
122 
123 uint8_t USB_GetNextDescriptorComp(uint16_t* const BytesRem,
124  void** const CurrConfigLoc,
125  ConfigComparatorPtr_t const ComparatorRoutine)
126 {
127  uint8_t ErrorCode;
128 
129  while (*BytesRem)
130  {
131  uint8_t* PrevDescLoc = *CurrConfigLoc;
132  uint16_t PrevBytesRem = *BytesRem;
133 
134  USB_GetNextDescriptor(BytesRem, CurrConfigLoc);
135 
136  if ((ErrorCode = ComparatorRoutine(*CurrConfigLoc)) != DESCRIPTOR_SEARCH_NotFound)
137  {
138  if (ErrorCode == DESCRIPTOR_SEARCH_Fail)
139  {
140  *CurrConfigLoc = PrevDescLoc;
141  *BytesRem = PrevBytesRem;
142  }
143 
144  return ErrorCode;
145  }
146  }
147 
149 }
150