Create release.yml
[betaflight.git] / src / main / vcpf4 / usbd_desc.c
blob2e6c40f4027447970b5dfd5c0a3ce677f6abe381
1 /**
2 ******************************************************************************
3 * @file usbd_desc.c
4 * @author MCD Application Team
5 * @version V1.0.0
6 * @date 19-September-2011
7 * @brief This file provides the USBD descriptors and string formating method.
8 ******************************************************************************
9 * @attention
11 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18 * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
19 ******************************************************************************
22 /* Includes ------------------------------------------------------------------*/
23 #include "usbd_core.h"
24 #include "usbd_desc.h"
25 #include "usbd_req.h"
26 #include "usbd_conf.h"
27 #include "usb_regs.h"
28 #include "platform.h"
29 #include "build/version.h"
31 #include "pg/pg.h"
32 #include "pg/usb.h"
34 /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
35 * @{
39 /** @defgroup USBD_DESC
40 * @brief USBD descriptors module
41 * @{
44 /** @defgroup USBD_DESC_Private_TypesDefinitions
45 * @{
47 /**
48 * @}
52 /** @defgroup USBD_DESC_Private_Defines
53 * @{
56 #define USBD_VID 0x0483
58 #ifdef USE_USB_CDC_HID
59 #define USBD_PID_COMPOSITE 0x3256
60 #endif
61 #define USBD_PID 0x5740
63 /** @defgroup USB_String_Descriptors
64 * @{
66 #define USBD_LANGID_STRING 0x409
67 #define USBD_MANUFACTURER_STRING FC_FIRMWARE_NAME
69 #ifdef USBD_PRODUCT_STRING
70 #define USBD_PRODUCT_HS_STRING USBD_PRODUCT_STRING
71 #define USBD_PRODUCT_FS_STRING USBD_PRODUCT_STRING
72 #else
73 #define USBD_PRODUCT_HS_STRING "STM32 Virtual ComPort in HS mode"
74 #define USBD_PRODUCT_FS_STRING "STM32 Virtual ComPort in FS Mode"
75 #endif /* USBD_PRODUCT_STRING */
77 #ifdef USBD_SERIALNUMBER_STRING
78 #define USBD_SERIALNUMBER_HS_STRING USBD_SERIALNUMBER_STRING
79 #define USBD_SERIALNUMBER_FS_STRING USBD_SERIALNUMBER_STRING
80 #else
81 // start of STM32 flash
82 #define USBD_SERIALNUMBER_HS_STRING "0x8000000"
83 #define USBD_SERIALNUMBER_FS_STRING "0x8000000"
84 #endif /* USBD_SERIALNUMBER_STRING */
86 #define USBD_CONFIGURATION_HS_STRING "VCP Config"
87 #define USBD_INTERFACE_HS_STRING "VCP Interface"
89 #define USBD_CONFIGURATION_FS_STRING "VCP Config"
90 #define USBD_INTERFACE_FS_STRING "VCP Interface"
91 /**
92 * @}
96 /** @defgroup USBD_DESC_Private_Macros
97 * @{
99 /**
100 * @}
104 /** @defgroup USBD_DESC_Private_Variables
105 * @{
108 USBD_DEVICE USR_desc =
110 USBD_USR_DeviceDescriptor,
111 USBD_USR_LangIDStrDescriptor,
112 USBD_USR_ManufacturerStrDescriptor,
113 USBD_USR_ProductStrDescriptor,
114 USBD_USR_SerialStrDescriptor,
115 USBD_USR_ConfigStrDescriptor,
116 USBD_USR_InterfaceStrDescriptor,
120 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
121 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
122 #pragma data_alignment=4
123 #endif
124 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
125 #ifdef USE_USB_CDC_HID
126 /* USB Standard Device Descriptor */
127 __ALIGN_BEGIN uint8_t USBD_DeviceDesc_Composite[USB_SIZ_DEVICE_DESC] __ALIGN_END =
129 0x12, /*bLength */
130 USB_DEVICE_DESCRIPTOR_TYPE, /*bDescriptorType*/
131 0x00, 0x02, /*bcdUSB */
132 0xEF, /*bDeviceClass*/
133 0x02, /*bDeviceSubClass*/
134 0x01, /*bDeviceProtocol*/
135 USB_OTG_MAX_EP0_SIZE, /*bMaxPacketSize*/
136 LOBYTE(USBD_VID), HIBYTE(USBD_VID), /*idVendor*/
137 LOBYTE(USBD_PID_COMPOSITE),
138 HIBYTE(USBD_PID_COMPOSITE), /*idProduct*/
139 0x00, 0x02, /*bcdDevice rel. 2.00*/
140 USBD_IDX_MFC_STR, /*Index of manufacturer string*/
141 USBD_IDX_PRODUCT_STR, /*Index of product string*/
142 USBD_IDX_SERIAL_STR, /*Index of serial number string*/
143 USBD_CFG_MAX_NUM /*bNumConfigurations*/
144 } ; /* USB_DeviceDescriptor */
145 #endif
146 /* USB Standard Device Descriptor */
147 __ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_SIZ_DEVICE_DESC] __ALIGN_END =
149 0x12, /*bLength */
150 USB_DEVICE_DESCRIPTOR_TYPE, /*bDescriptorType*/
151 0x00, 0x02, /*bcdUSB */
152 0x02, /*bDeviceClass*/
153 0x02, /*bDeviceSubClass*/
154 0x00, /*bDeviceProtocol*/
155 USB_OTG_MAX_EP0_SIZE, /*bMaxPacketSize*/
156 LOBYTE(USBD_VID), HIBYTE(USBD_VID), /*idVendor*/
157 LOBYTE(USBD_PID), HIBYTE(USBD_PID), /*idProduct*/
158 0x00, 0x02, /*bcdDevice rel. 2.00*/
159 USBD_IDX_MFC_STR, /*Index of manufacturer string*/
160 USBD_IDX_PRODUCT_STR, /*Index of product string*/
161 USBD_IDX_SERIAL_STR, /*Index of serial number string*/
162 USBD_CFG_MAX_NUM /*bNumConfigurations*/
163 } ; /* USB_DeviceDescriptor */
165 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
166 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
167 #pragma data_alignment=4
168 #endif
169 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
170 /* USB Standard Device Descriptor */
171 __ALIGN_BEGIN uint8_t USBD_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
173 USB_LEN_DEV_QUALIFIER_DESC,
174 USB_DESC_TYPE_DEVICE_QUALIFIER,
175 0x00,
176 0x02,
177 0x00,
178 0x00,
179 0x00,
180 0x40,
181 0x01,
182 0x00,
185 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
186 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
187 #pragma data_alignment=4
188 #endif
189 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
190 /* USB Standard Device Descriptor */
191 __ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_SIZ_STRING_LANGID] __ALIGN_END =
193 USB_SIZ_STRING_LANGID,
194 USB_DESC_TYPE_STRING,
195 LOBYTE(USBD_LANGID_STRING),
196 HIBYTE(USBD_LANGID_STRING),
199 * @}
203 /** @defgroup USBD_DESC_Private_FunctionPrototypes
204 * @{
207 * @}
211 /** @defgroup USBD_DESC_Private_Functions
212 * @{
216 * @brief USBD_USR_DeviceDescriptor
217 * return the device descriptor
218 * @param speed : current device speed
219 * @param length : pointer to data length variable
220 * @retval pointer to descriptor buffer
222 uint8_t * USBD_USR_DeviceDescriptor( uint8_t speed , uint16_t *length)
224 (void)speed;
225 #ifdef USE_USB_CDC_HID
226 if (usbDevConfig()->type == COMPOSITE) {
227 *length = sizeof(USBD_DeviceDesc_Composite);
228 return USBD_DeviceDesc_Composite;
230 #endif
231 *length = sizeof(USBD_DeviceDesc);
232 return USBD_DeviceDesc;
236 * @brief USBD_USR_LangIDStrDescriptor
237 * return the LangID string descriptor
238 * @param speed : current device speed
239 * @param length : pointer to data length variable
240 * @retval pointer to descriptor buffer
242 uint8_t * USBD_USR_LangIDStrDescriptor( uint8_t speed , uint16_t *length)
244 (void)speed;
245 *length = sizeof(USBD_LangIDDesc);
246 return USBD_LangIDDesc;
251 * @brief USBD_USR_ProductStrDescriptor
252 * return the product string descriptor
253 * @param speed : current device speed
254 * @param length : pointer to data length variable
255 * @retval pointer to descriptor buffer
257 uint8_t * USBD_USR_ProductStrDescriptor( uint8_t speed , uint16_t *length)
261 if (speed == 0)
262 USBD_GetString ((uint8_t*)USBD_PRODUCT_HS_STRING, USBD_StrDesc, length);
263 else
264 USBD_GetString ((uint8_t*)USBD_PRODUCT_FS_STRING, USBD_StrDesc, length);
266 return USBD_StrDesc;
270 * @brief USBD_USR_ManufacturerStrDescriptor
271 * return the manufacturer string descriptor
272 * @param speed : current device speed
273 * @param length : pointer to data length variable
274 * @retval pointer to descriptor buffer
276 uint8_t * USBD_USR_ManufacturerStrDescriptor( uint8_t speed , uint16_t *length)
278 (void)speed;
279 USBD_GetString ((uint8_t*)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
280 return USBD_StrDesc;
284 * @brief USBD_USR_SerialStrDescriptor
285 * return the serial number string descriptor
286 * @param speed : current device speed
287 * @param length : pointer to data length variable
288 * @retval pointer to descriptor buffer
290 uint8_t * USBD_USR_SerialStrDescriptor( uint8_t speed , uint16_t *length)
292 if (speed == USB_OTG_SPEED_HIGH)
293 USBD_GetString ((uint8_t*)USBD_SERIALNUMBER_HS_STRING, USBD_StrDesc, length);
294 else
295 USBD_GetString ((uint8_t*)USBD_SERIALNUMBER_FS_STRING, USBD_StrDesc, length);
297 return USBD_StrDesc;
301 * @brief USBD_USR_ConfigStrDescriptor
302 * return the configuration string descriptor
303 * @param speed : current device speed
304 * @param length : pointer to data length variable
305 * @retval pointer to descriptor buffer
307 uint8_t * USBD_USR_ConfigStrDescriptor( uint8_t speed , uint16_t *length)
309 if (speed == USB_OTG_SPEED_HIGH)
310 USBD_GetString ((uint8_t*)USBD_CONFIGURATION_HS_STRING, USBD_StrDesc, length);
311 else
312 USBD_GetString ((uint8_t*)USBD_CONFIGURATION_FS_STRING, USBD_StrDesc, length);
314 return USBD_StrDesc;
319 * @brief USBD_USR_InterfaceStrDescriptor
320 * return the interface string descriptor
321 * @param speed : current device speed
322 * @param length : pointer to data length variable
323 * @retval pointer to descriptor buffer
325 uint8_t * USBD_USR_InterfaceStrDescriptor( uint8_t speed , uint16_t *length)
327 if (speed == 0)
328 USBD_GetString ((uint8_t*)USBD_INTERFACE_HS_STRING, USBD_StrDesc, length);
329 else
330 USBD_GetString ((uint8_t*)USBD_INTERFACE_FS_STRING, USBD_StrDesc, length);
332 return USBD_StrDesc;
336 * @}
341 * @}
346 * @}
349 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/