LPCOpen Platform
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)];
45 
47  {
48  .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),
50  .wValue = ((DTYPE_Configuration << 8) | (ConfigNumber - 1)),
51  .wIndex = 0,
52  .wLength = sizeof(USB_Descriptor_Configuration_Header_t),
53  };
54 
56 
57  if ((ErrorCode = USB_Host_SendControlRequest(corenum,ConfigHeader)) != HOST_SENDCONTROL_Successful)
58  return ErrorCode;
59 
61 
62  if (*ConfigSizePtr > BufferSize)
64 
65  USB_ControlRequest.wLength = *ConfigSizePtr;
66 
67  if ((ErrorCode = USB_Host_SendControlRequest(corenum,BufferPtr)) != HOST_SENDCONTROL_Successful)
68  return ErrorCode;
69 
70  if (DESCRIPTOR_TYPE(BufferPtr) != DTYPE_Configuration)
72 
74 }
75 #endif
76 
77 void USB_GetNextDescriptorOfType(uint16_t* const BytesRem,
78  void** const CurrConfigLoc,
79  const uint8_t Type)
80 {
81  while (*BytesRem)
82  {
83  USB_GetNextDescriptor(BytesRem, CurrConfigLoc);
84 
85  if (DESCRIPTOR_TYPE(*CurrConfigLoc) == Type)
86  return;
87  }
88 }
89 
90 void USB_GetNextDescriptorOfTypeBefore(uint16_t* const BytesRem,
91  void** const CurrConfigLoc,
92  const uint8_t Type,
93  const uint8_t BeforeType)
94 {
95  while (*BytesRem)
96  {
97  USB_GetNextDescriptor(BytesRem, CurrConfigLoc);
98 
99  if (DESCRIPTOR_TYPE(*CurrConfigLoc) == Type)
100  {
101  return;
102  }
103  else if (DESCRIPTOR_TYPE(*CurrConfigLoc) == BeforeType)
104  {
105  *BytesRem = 0;
106  return;
107  }
108  }
109 }
110 
111 void USB_GetNextDescriptorOfTypeAfter(uint16_t* const BytesRem,
112  void** const CurrConfigLoc,
113  const uint8_t Type,
114  const uint8_t AfterType)
115 {
116  USB_GetNextDescriptorOfType(BytesRem, CurrConfigLoc, AfterType);
117 
118  if (*BytesRem)
119  USB_GetNextDescriptorOfType(BytesRem, CurrConfigLoc, Type);
120 }
121 
122 uint8_t USB_GetNextDescriptorComp(uint16_t* const BytesRem,
123  void** const CurrConfigLoc,
124  ConfigComparatorPtr_t const ComparatorRoutine)
125 {
126  uint8_t ErrorCode;
127 
128  while (*BytesRem)
129  {
130  uint8_t* PrevDescLoc = *CurrConfigLoc;
131  uint16_t PrevBytesRem = *BytesRem;
132 
133  USB_GetNextDescriptor(BytesRem, CurrConfigLoc);
134 
135  if ((ErrorCode = ComparatorRoutine(*CurrConfigLoc)) != DESCRIPTOR_SEARCH_NotFound)
136  {
137  if (ErrorCode == DESCRIPTOR_SEARCH_Fail)
138  {
139  *CurrConfigLoc = PrevDescLoc;
140  *BytesRem = PrevBytesRem;
141  }
142 
143  return ErrorCode;
144  }
145  }
146 
148 }
149