]> mj.ucw.cz Git - home-hw.git/blob - Src/usbd_desc.c
USB cleanup
[home-hw.git] / Src / usbd_desc.c
1 /**
2   ******************************************************************************
3   * @file           : usbd_desc.c
4   * @version        : v2.0_Cube
5   * @brief          : This file implements the USB device descriptors.
6   ******************************************************************************
7   * This notice applies to any and all portions of this file
8   * that are not between comment pairs USER CODE BEGIN and
9   * USER CODE END. Other portions of this file, whether 
10   * inserted by the user or by software development tools
11   * are owned by their respective copyright owners.
12   *
13   * Copyright (c) 2018 STMicroelectronics International N.V. 
14   * All rights reserved.
15   *
16   * Redistribution and use in source and binary forms, with or without 
17   * modification, are permitted, provided that the following conditions are met:
18   *
19   * 1. Redistribution of source code must retain the above copyright notice, 
20   *    this list of conditions and the following disclaimer.
21   * 2. Redistributions in binary form must reproduce the above copyright notice,
22   *    this list of conditions and the following disclaimer in the documentation
23   *    and/or other materials provided with the distribution.
24   * 3. Neither the name of STMicroelectronics nor the names of other 
25   *    contributors to this software may be used to endorse or promote products 
26   *    derived from this software without specific written permission.
27   * 4. This software, including modifications and/or derivative works of this 
28   *    software, must execute solely and exclusively on microcontroller or
29   *    microprocessor devices manufactured by or for STMicroelectronics.
30   * 5. Redistribution and use of this software other than as permitted under 
31   *    this license is void and will automatically terminate your rights under 
32   *    this license. 
33   *
34   * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 
35   * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 
36   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 
37   * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
38   * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 
39   * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
40   * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
42   * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
43   * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
44   * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
45   * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46   *
47   ******************************************************************************
48   */
49
50 /* Includes ------------------------------------------------------------------*/
51 #include "usbd_core.h"
52 #include "usbd_desc.h"
53 #include "usbd_conf.h"
54
55 /* USER CODE BEGIN INCLUDE */
56
57 /* USER CODE END INCLUDE */
58
59 /* Private typedef -----------------------------------------------------------*/
60 /* Private define ------------------------------------------------------------*/
61 /* Private macro -------------------------------------------------------------*/
62
63 /* USER CODE BEGIN PV */
64 /* Private variables ---------------------------------------------------------*/
65
66 /* USER CODE END PV */
67
68 /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
69   * @{
70   */
71
72 /** @addtogroup USBD_DESC
73   * @{
74   */
75
76 /** @defgroup USBD_DESC_Private_TypesDefinitions USBD_DESC_Private_TypesDefinitions
77   * @brief Private types.
78   * @{
79   */
80
81 /* USER CODE BEGIN PRIVATE_TYPES */
82
83 /* USER CODE END PRIVATE_TYPES */
84
85 /**
86   * @}
87   */
88
89 /** @defgroup USBD_DESC_Private_Defines USBD_DESC_Private_Defines
90   * @brief Private defines.
91   * @{
92   */
93
94 #define USBD_VID     0x4242
95 #define USBD_LANGID_STRING     1033
96 #define USBD_MANUFACTURER_STRING     "UCW"
97 #define USBD_PID_FS     0x0001
98 #define USBD_PRODUCT_STRING_FS     "Mysterious Gadget"
99 #define USBD_SERIALNUMBER_STRING_FS     "00000000002A"
100 #define USBD_CONFIGURATION_STRING_FS     "Default Config"
101 #define USBD_INTERFACE_STRING_FS     "Default Interface"
102
103 /* USER CODE BEGIN PRIVATE_DEFINES */
104
105 /* USER CODE END PRIVATE_DEFINES */
106
107 /**
108   * @}
109   */
110
111 /* USER CODE BEGIN 0 */
112
113 /* USER CODE END 0 */
114
115 /** @defgroup USBD_DESC_Private_Macros USBD_DESC_Private_Macros
116   * @brief Private macros.
117   * @{
118   */
119
120 /* USER CODE BEGIN PRIVATE_MACRO */
121
122 /* USER CODE END PRIVATE_MACRO */
123
124 /**
125   * @}
126   */
127
128 /** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes
129   * @brief Private functions declaration.
130   * @{
131   */
132
133 uint8_t * USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
134 uint8_t * USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
135 uint8_t * USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
136 uint8_t * USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
137 uint8_t * USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
138 uint8_t * USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
139 uint8_t * USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
140
141 #ifdef USB_SUPPORT_USER_STRING_DESC
142 uint8_t * USBD_FS_USRStringDesc(USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length);
143 #endif /* USB_SUPPORT_USER_STRING_DESC */
144
145 /**
146   * @}
147   */
148
149 /** @defgroup USBD_DESC_Private_Variables USBD_DESC_Private_Variables
150   * @brief Private variables.
151   * @{
152   */
153
154 USBD_DescriptorsTypeDef FS_Desc =
155 {
156   USBD_FS_DeviceDescriptor
157 , USBD_FS_LangIDStrDescriptor
158 , USBD_FS_ManufacturerStrDescriptor
159 , USBD_FS_ProductStrDescriptor
160 , USBD_FS_SerialStrDescriptor
161 , USBD_FS_ConfigStrDescriptor
162 , USBD_FS_InterfaceStrDescriptor
163 };
164
165 #if defined ( __ICCARM__ ) /* IAR Compiler */
166   #pragma data_alignment=4
167 #endif /* defined ( __ICCARM__ ) */
168 /** USB standard device descriptor. */
169 __ALIGN_BEGIN uint8_t USBD_FS_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
170 {
171   0x12,                       /*bLength */
172   USB_DESC_TYPE_DEVICE,       /*bDescriptorType*/
173   0x00,                       /*bcdUSB */
174   0x02,
175   0x00,                       /*bDeviceClass*/
176   0x00,                       /*bDeviceSubClass*/
177   0x00,                       /*bDeviceProtocol*/
178   USB_MAX_EP0_SIZE,           /*bMaxPacketSize*/
179   LOBYTE(USBD_VID),           /*idVendor*/
180   HIBYTE(USBD_VID),           /*idVendor*/
181   LOBYTE(USBD_PID_FS),        /*idProduct*/
182   HIBYTE(USBD_PID_FS),        /*idProduct*/
183   0x00,                       /*bcdDevice rel. 2.00*/
184   0x02,
185   USBD_IDX_MFC_STR,           /*Index of manufacturer  string*/
186   USBD_IDX_PRODUCT_STR,       /*Index of product string*/
187   USBD_IDX_SERIAL_STR,        /*Index of serial number string*/
188   USBD_MAX_NUM_CONFIGURATION  /*bNumConfigurations*/
189 };
190
191 /* USB_DeviceDescriptor */
192
193 /**
194   * @}
195   */
196
197 /** @defgroup USBD_DESC_Private_Variables USBD_DESC_Private_Variables
198   * @brief Private variables.
199   * @{
200   */
201
202 #if defined ( __ICCARM__ ) /* IAR Compiler */
203   #pragma data_alignment=4
204 #endif /* defined ( __ICCARM__ ) */
205
206 /** USB lang indentifier descriptor. */
207 __ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END =
208 {
209      USB_LEN_LANGID_STR_DESC,
210      USB_DESC_TYPE_STRING,
211      LOBYTE(USBD_LANGID_STRING),
212      HIBYTE(USBD_LANGID_STRING)
213 };
214
215 #if defined ( __ICCARM__ ) /* IAR Compiler */
216   #pragma data_alignment=4
217 #endif /* defined ( __ICCARM__ ) */
218 /* Internal string descriptor. */
219 __ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
220
221 /**
222   * @}
223   */
224
225 /** @defgroup USBD_DESC_Private_Functions USBD_DESC_Private_Functions
226   * @brief Private functions.
227   * @{
228   */
229
230 /**
231   * @brief  Return the device descriptor
232   * @param  speed : Current device speed
233   * @param  length : Pointer to data length variable
234   * @retval Pointer to descriptor buffer
235   */
236 uint8_t * USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
237 {
238   *length = sizeof(USBD_FS_DeviceDesc);
239   return USBD_FS_DeviceDesc;
240 }
241
242 /**
243   * @brief  Return the LangID string descriptor
244   * @param  speed : Current device speed
245   * @param  length : Pointer to data length variable
246   * @retval Pointer to descriptor buffer
247   */
248 uint8_t * USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
249 {
250   *length = sizeof(USBD_LangIDDesc);
251   return USBD_LangIDDesc;
252 }
253
254 /**
255   * @brief  Return the product string descriptor
256   * @param  speed : Current device speed
257   * @param  length : Pointer to data length variable
258   * @retval Pointer to descriptor buffer
259   */
260 uint8_t * USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
261 {
262   if(speed == 0)
263   {
264     USBD_GetString((uint8_t *)USBD_PRODUCT_STRING_FS, USBD_StrDesc, length);
265   }
266   else
267   {
268     USBD_GetString((uint8_t *)USBD_PRODUCT_STRING_FS, USBD_StrDesc, length);
269   }
270   return USBD_StrDesc;
271 }
272
273 /**
274   * @brief  Return the manufacturer string descriptor
275   * @param  speed : Current device speed
276   * @param  length : Pointer to data length variable
277   * @retval Pointer to descriptor buffer
278   */
279 uint8_t * USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
280 {
281   USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
282   return USBD_StrDesc;
283 }
284
285 /**
286   * @brief  Return the serial number string descriptor
287   * @param  speed : Current device speed
288   * @param  length : Pointer to data length variable
289   * @retval Pointer to descriptor buffer
290   */
291 uint8_t * USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
292 {
293   if(speed == USBD_SPEED_HIGH)
294   {
295     USBD_GetString((uint8_t *)USBD_SERIALNUMBER_STRING_FS, USBD_StrDesc, length);
296   }
297   else
298   {
299     USBD_GetString((uint8_t *)USBD_SERIALNUMBER_STRING_FS, USBD_StrDesc, length);
300   }
301   return USBD_StrDesc;
302 }
303
304 /**
305   * @brief  Return the configuration string descriptor
306   * @param  speed : Current device speed
307   * @param  length : Pointer to data length variable
308   * @retval Pointer to descriptor buffer
309   */
310 uint8_t * USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
311 {
312   if(speed == USBD_SPEED_HIGH)
313   {
314     USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length);
315   }
316   else
317   {
318     USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING_FS, USBD_StrDesc, length);
319   }
320   return USBD_StrDesc;
321 }
322
323 /**
324   * @brief  Return the interface string descriptor
325   * @param  speed : Current device speed
326   * @param  length : Pointer to data length variable
327   * @retval Pointer to descriptor buffer
328   */
329 uint8_t * USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
330 {
331   if(speed == 0)
332   {
333     USBD_GetString((uint8_t *)USBD_INTERFACE_STRING_FS, USBD_StrDesc, length);
334   }
335   else
336   {
337     USBD_GetString((uint8_t *)USBD_INTERFACE_STRING_FS, USBD_StrDesc, length);
338   }
339   return USBD_StrDesc;
340 }
341
342 /**
343   * @}
344   */
345
346 /**
347   * @}
348   */
349
350 /**
351   * @}
352   */
353
354 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/