Blackbox device type 'file' (SITL) considered working when file handler is available
[inav.git] / src / main / msc / usbd_msc_desc.c
bloba72c8b83c437be659a9349b29aca4f3625c0d8c7
1 /**
2 ******************************************************************************
3 * @file usbd_desc.c
4 * @author MCD Application Team
5 * @version V1.2.0
6 * @date 09-November-2015
7 * @brief This file provides the USBD descriptors and string formating method.
8 ******************************************************************************
9 * @attention
11 * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
13 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
14 * You may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at:
17 * http://www.st.com/software_license_agreement_liberty_v2
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
25 ******************************************************************************
28 /* Includes ------------------------------------------------------------------*/
29 #include "usbd_core.h"
30 #include "usbd_desc.h"
31 #include "usbd_req.h"
32 #include "usbd_conf.h"
33 #include "usb_regs.h"
34 #include "platform.h"
36 #define DEVICE_ID1 (0x1FFFF7E8)
37 #define DEVICE_ID2 (0x1FFFF7EA)
38 #define DEVICE_ID3 (0x1FFFF7EC)
39 #define USB_SIZ_STRING_SERIAL 0x1A
41 /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
42 * @{
46 /** @defgroup USBD_DESC
47 * @brief USBD descriptors module
48 * @{
51 /** @defgroup USBD_DESC_Private_TypesDefinitions
52 * @{
54 /**
55 * @}
59 /** @defgroup USBD_DESC_Private_Defines
60 * @{
63 #define USBD_VID 0x0483
64 #define USBD_PID 0x5720
66 #define USBD_LANGID_STRING 0x409
67 #define USBD_MANUFACTURER_STRING "STMicroelectronics"
68 #define USBD_PRODUCT_HS_STRING "Mass Storage in HS Mode"
69 #define USBD_PRODUCT_FS_STRING "Mass Storage in FS Mode"
70 #define USBD_CONFIGURATION_HS_STRING "MSC Config"
71 #define USBD_INTERFACE_HS_STRING "MSC Interface"
72 #define USBD_CONFIGURATION_FS_STRING "MSC Config"
73 #define USBD_INTERFACE_FS_STRING "MSC Interface"
74 /**
75 * @}
79 /** @defgroup USBD_DESC_Private_Macros
80 * @{
82 /**
83 * @}
87 /** @defgroup USBD_DESC_Private_Variables
88 * @{
91 USBD_DEVICE MSC_desc =
93 USBD_MSC_DeviceDescriptor,
94 USBD_MSC_LangIDStrDescriptor,
95 USBD_MSC_ManufacturerStrDescriptor,
96 USBD_MSC_ProductStrDescriptor,
97 USBD_MSC_SerialStrDescriptor,
98 USBD_MSC_ConfigStrDescriptor,
99 USBD_MSC_InterfaceStrDescriptor,
102 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
103 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
104 #pragma data_alignment=4
105 #endif
106 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
107 /* USB Standard Device Descriptor */
108 __ALIGN_BEGIN uint8_t USBD_DeviceDesc_MSC[USB_SIZ_DEVICE_DESC] __ALIGN_END =
110 0x12, /*bLength */
111 USB_DEVICE_DESCRIPTOR_TYPE, /*bDescriptorType*/
112 0x00, /*bcdUSB */
113 0x02,
114 0x00, /*bDeviceClass*/
115 0x00, /*bDeviceSubClass*/
116 0x00, /*bDeviceProtocol*/
117 USB_OTG_MAX_EP0_SIZE, /*bMaxPacketSize*/
118 LOBYTE(USBD_VID), /*idVendor*/
119 HIBYTE(USBD_VID), /*idVendor*/
120 LOBYTE(USBD_PID), /*idVendor*/
121 HIBYTE(USBD_PID), /*idVendor*/
122 0x00, /*bcdDevice rel. 2.00*/
123 0x02,
124 USBD_IDX_MFC_STR, /*Index of manufacturer string*/
125 USBD_IDX_PRODUCT_STR, /*Index of product string*/
126 USBD_IDX_SERIAL_STR, /*Index of serial number string*/
127 USBD_CFG_MAX_NUM /*bNumConfigurations*/
128 } ; /* USB_DeviceDescriptor */
130 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
131 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
132 #pragma data_alignment=4
133 #endif
134 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
135 /* USB Standard Device Descriptor */
136 __ALIGN_BEGIN uint8_t USBD_DeviceQualifierDesc_MSC[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
138 USB_LEN_DEV_QUALIFIER_DESC,
139 USB_DESC_TYPE_DEVICE_QUALIFIER,
140 0x00,
141 0x02,
142 0x00,
143 0x00,
144 0x00,
145 0x40,
146 0x01,
147 0x00,
150 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
151 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
152 #pragma data_alignment=4
153 #endif
154 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
155 /* USB Standard Device Descriptor */
156 __ALIGN_BEGIN uint8_t USBD_LangIDDesc_MSC[USB_SIZ_STRING_LANGID] __ALIGN_END =
158 USB_SIZ_STRING_LANGID,
159 USB_DESC_TYPE_STRING,
160 LOBYTE(USBD_LANGID_STRING),
161 HIBYTE(USBD_LANGID_STRING),
164 uint8_t USBD_StringSerial_MSC[USB_SIZ_STRING_SERIAL] =
166 USB_SIZ_STRING_SERIAL,
167 USB_DESC_TYPE_STRING,
170 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
171 #if defined ( __ICCARM__ ) /*!< IAR Compiler */
172 #pragma data_alignment=4
173 #endif
174 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
175 __ALIGN_BEGIN uint8_t USBD_StrDesc_MSC[USB_MAX_STR_DESC_SIZ] __ALIGN_END ;
178 * @}
182 /** @defgroup USBD_DESC_Private_FunctionPrototypes
183 * @{
185 static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len);
186 static void Get_SerialNum(void);
188 * @}
192 /** @defgroup USBD_DESC_Private_Functions
193 * @{
197 * @brief USBD_USR_DeviceDescriptor
198 * return the device descriptor
199 * @param speed : current device speed
200 * @param length : pointer to data length variable
201 * @retval pointer to descriptor buffer
203 uint8_t * USBD_MSC_DeviceDescriptor( uint8_t speed , uint16_t *length)
205 (void)(speed);
206 *length = sizeof(USBD_DeviceDesc_MSC);
207 return (uint8_t*)USBD_DeviceDesc_MSC;
211 * @brief USBD_USR_LangIDStrDescriptor
212 * return the LangID string descriptor
213 * @param speed : current device speed
214 * @param length : pointer to data length variable
215 * @retval pointer to descriptor buffer
217 uint8_t * USBD_MSC_LangIDStrDescriptor( uint8_t speed , uint16_t *length)
219 (void)(speed);
220 *length = sizeof(USBD_LangIDDesc_MSC);
221 return (uint8_t*)USBD_LangIDDesc_MSC;
226 * @brief USBD_USR_ProductStrDescriptor
227 * return the product string descriptor
228 * @param speed : current device speed
229 * @param length : pointer to data length variable
230 * @retval pointer to descriptor buffer
232 uint8_t * USBD_MSC_ProductStrDescriptor( uint8_t speed , uint16_t *length)
234 if(speed == 0)
236 USBD_GetString((uint8_t *)(uint8_t *)USBD_PRODUCT_HS_STRING, USBD_StrDesc_MSC, length);
238 else
240 USBD_GetString((uint8_t *)(uint8_t *)USBD_PRODUCT_FS_STRING, USBD_StrDesc_MSC, length);
242 return USBD_StrDesc_MSC;
246 * @brief USBD_USR_ManufacturerStrDescriptor
247 * return the manufacturer string descriptor
248 * @param speed : current device speed
249 * @param length : pointer to data length variable
250 * @retval pointer to descriptor buffer
252 uint8_t * USBD_MSC_ManufacturerStrDescriptor( uint8_t speed , uint16_t *length)
254 (void)(speed);
255 USBD_GetString((uint8_t *)(uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc_MSC, length);
256 return USBD_StrDesc_MSC;
260 * @brief USBD_USR_SerialStrDescriptor
261 * return the serial number string descriptor
262 * @param speed : current device speed
263 * @param length : pointer to data length variable
264 * @retval pointer to descriptor buffer
266 uint8_t * USBD_MSC_SerialStrDescriptor( uint8_t speed , uint16_t *length)
268 (void)(speed);
269 *length = USB_SIZ_STRING_SERIAL;
271 /* Update the serial number string descriptor with the data from the unique ID*/
272 Get_SerialNum();
274 return (uint8_t*)USBD_StringSerial_MSC;
278 * @brief USBD_USR_ConfigStrDescriptor
279 * return the configuration string descriptor
280 * @param speed : current device speed
281 * @param length : pointer to data length variable
282 * @retval pointer to descriptor buffer
284 uint8_t * USBD_MSC_ConfigStrDescriptor( uint8_t speed , uint16_t *length)
286 if(speed == USB_OTG_SPEED_HIGH)
288 USBD_GetString((uint8_t *)(uint8_t *)USBD_CONFIGURATION_HS_STRING, USBD_StrDesc_MSC, length);
290 else
292 USBD_GetString((uint8_t *)(uint8_t *)USBD_CONFIGURATION_FS_STRING, USBD_StrDesc_MSC, length);
294 return USBD_StrDesc_MSC;
299 * @brief USBD_USR_InterfaceStrDescriptor
300 * return the interface string descriptor
301 * @param speed : current device speed
302 * @param length : pointer to data length variable
303 * @retval pointer to descriptor buffer
305 uint8_t * USBD_MSC_InterfaceStrDescriptor( uint8_t speed , uint16_t *length)
307 if(speed == 0)
309 USBD_GetString((uint8_t *)(uint8_t *)USBD_INTERFACE_HS_STRING, USBD_StrDesc_MSC, length);
311 else
313 USBD_GetString((uint8_t *)(uint8_t *)USBD_INTERFACE_FS_STRING, USBD_StrDesc_MSC, length);
315 return USBD_StrDesc_MSC;
319 * @brief Create the serial number string descriptor
320 * @param None
321 * @retval None
323 static void Get_SerialNum(void)
325 uint32_t deviceserial0, deviceserial1, deviceserial2;
327 deviceserial0 = *(uint32_t*)DEVICE_ID1;
328 deviceserial1 = *(uint32_t*)DEVICE_ID2;
329 deviceserial2 = *(uint32_t*)DEVICE_ID3;
331 deviceserial0 += deviceserial2;
333 if (deviceserial0 != 0)
335 IntToUnicode (deviceserial0, &USBD_StringSerial_MSC[2] ,8);
336 IntToUnicode (deviceserial1, &USBD_StringSerial_MSC[18] ,4);
341 * @brief Convert Hex 32Bits value into char
342 * @param value: value to convert
343 * @param pbuf: pointer to the buffer
344 * @param len: buffer length
345 * @retval None
347 static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len)
349 uint8_t idx = 0;
351 for( idx = 0 ; idx < len ; idx ++)
353 if( ((value >> 28)) < 0xA )
355 pbuf[ 2* idx] = (value >> 28) + '0';
357 else
359 pbuf[2* idx] = (value >> 28) + 'A' - 10;
362 value = value << 4;
364 pbuf[ 2* idx + 1] = 0;
370 * @}
375 * @}
380 * @}
383 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/