]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Demo/FreeRTOS_Plus_UDP_and_CLI_LPC1830_GCC/ThirdParty/LPCOpen/LPCUSBLib/Drivers/USB/Core/ConfigDescriptor.c
Update LPC18xx FreeRTOS+UDP demo to use LPCOpen USB and Ethernet drivers.
[freertos] / FreeRTOS-Plus / Demo / FreeRTOS_Plus_UDP_and_CLI_LPC1830_GCC / ThirdParty / LPCOpen / LPCUSBLib / Drivers / USB / Core / ConfigDescriptor.c
1 /*\r
2  * @brief USB Configuration Descriptor definitions\r
3  *\r
4  * @note\r
5  * Copyright(C) NXP Semiconductors, 2012\r
6  * Copyright(C) Dean Camera, 2011, 2012\r
7  * All rights reserved.\r
8  *\r
9  * @par\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
23  *\r
24  * @par\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
30  * this code.\r
31  */\r
32 \r
33 #define  __INCLUDE_FROM_USB_DRIVER\r
34 #include "ConfigDescriptor.h"\r
35 \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
42 {\r
43         uint8_t ErrorCode;\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
46 \r
47         USB_ControlRequest = (USB_Request_Header_t)\r
48                 {\r
49                         .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),\r
50                         .bRequest      = REQ_GetDescriptor,\r
51                         .wValue        = ((DTYPE_Configuration << 8) | (ConfigNumber - 1)),\r
52                         .wIndex        = 0,\r
53                         .wLength       = sizeof(USB_Descriptor_Configuration_Header_t),\r
54                 };\r
55 \r
56         Pipe_SelectPipe(corenum,PIPE_CONTROLPIPE);\r
57 \r
58         if ((ErrorCode = USB_Host_SendControlRequest(corenum,ConfigHeader)) != HOST_SENDCONTROL_Successful)\r
59           return ErrorCode;\r
60 \r
61         *ConfigSizePtr = le16_to_cpu(pCfgHeader->TotalConfigurationSize);\r
62 \r
63         if (*ConfigSizePtr > BufferSize)\r
64           return HOST_GETCONFIG_BuffOverflow;\r
65 \r
66         USB_ControlRequest.wLength = *ConfigSizePtr;\r
67 \r
68         if ((ErrorCode = USB_Host_SendControlRequest(corenum,BufferPtr)) != HOST_SENDCONTROL_Successful)\r
69           return ErrorCode;\r
70 \r
71         if (DESCRIPTOR_TYPE(BufferPtr) != DTYPE_Configuration)\r
72           return HOST_GETCONFIG_InvalidData;\r
73 \r
74         return HOST_GETCONFIG_Successful;\r
75 }\r
76 #endif\r
77 \r
78 void USB_GetNextDescriptorOfType(uint16_t* const BytesRem,\r
79                                  void** const CurrConfigLoc,\r
80                                  const uint8_t Type)\r
81 {\r
82         while (*BytesRem)\r
83         {\r
84                 USB_GetNextDescriptor(BytesRem, CurrConfigLoc);\r
85 \r
86                 if (DESCRIPTOR_TYPE(*CurrConfigLoc) == Type)\r
87                   return;\r
88         }\r
89 }\r
90 \r
91 void USB_GetNextDescriptorOfTypeBefore(uint16_t* const BytesRem,\r
92                                        void** const CurrConfigLoc,\r
93                                        const uint8_t Type,\r
94                                        const uint8_t BeforeType)\r
95 {\r
96         while (*BytesRem)\r
97         {\r
98                 USB_GetNextDescriptor(BytesRem, CurrConfigLoc);\r
99 \r
100                 if (DESCRIPTOR_TYPE(*CurrConfigLoc) == Type)\r
101                 {\r
102                         return;\r
103                 }\r
104                 else if (DESCRIPTOR_TYPE(*CurrConfigLoc) == BeforeType)\r
105                 {\r
106                         *BytesRem = 0;\r
107                         return;\r
108                 }\r
109         }\r
110 }\r
111 \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
116 {\r
117         USB_GetNextDescriptorOfType(BytesRem, CurrConfigLoc, AfterType);\r
118 \r
119         if (*BytesRem)\r
120           USB_GetNextDescriptorOfType(BytesRem, CurrConfigLoc, Type);\r
121 }\r
122 \r
123 uint8_t USB_GetNextDescriptorComp(uint16_t* const BytesRem,\r
124                                   void** const CurrConfigLoc,\r
125                                   ConfigComparatorPtr_t const ComparatorRoutine)\r
126 {\r
127         uint8_t ErrorCode;\r
128 \r
129         while (*BytesRem)\r
130         {\r
131                 uint8_t* PrevDescLoc  = *CurrConfigLoc;\r
132                 uint16_t PrevBytesRem = *BytesRem;\r
133 \r
134                 USB_GetNextDescriptor(BytesRem, CurrConfigLoc);\r
135 \r
136                 if ((ErrorCode = ComparatorRoutine(*CurrConfigLoc)) != DESCRIPTOR_SEARCH_NotFound)\r
137                 {\r
138                         if (ErrorCode == DESCRIPTOR_SEARCH_Fail)\r
139                         {\r
140                                 *CurrConfigLoc = PrevDescLoc;\r
141                                 *BytesRem      = PrevBytesRem;\r
142                         }\r
143 \r
144                         return ErrorCode;\r
145                 }\r
146         }\r
147 \r
148         return DESCRIPTOR_SEARCH_COMP_EndOfDescriptor;\r
149 }\r
150 \r