| MAXREFDES82# Code Documentation V01.00 Maxim Smart Force Sensor

- Main Page
- Modules
- Files

- File List
- Globals

All Files Functions Variables Macros Groups Pages
usbd_desc.c
Go to the documentation of this file.
1
28 /* Includes ------------------------------------------------------------------*/
29 #include "usbd_core.h"
30 #include "usbd_desc.h"
31 #include "usbd_conf.h"
32
33 /* Private typedef -----------------------------------------------------------*/
34 /* Private define ------------------------------------------------------------*/
35 #define USBD_VID 0x0483
36 #define USBD_PID 0x5740
37 #define USBD_LANGID_STRING 0x409
38 #define USBD_MANUFACTURER_STRING "STMicroelectronics"
39 #define USBD_PRODUCT_HS_STRING "STM32 Virtual ComPort in HS Mode"
40 #define USBD_PRODUCT_FS_STRING "STM32 Virtual ComPort in FS Mode"
41 #define USBD_CONFIGURATION_HS_STRING "VCP Config"
42 #define USBD_INTERFACE_HS_STRING "VCP Interface"
43 #define USBD_CONFIGURATION_FS_STRING "VCP Config"
44 #define USBD_INTERFACE_FS_STRING "VCP Interface"
45
46 /* Private macro -------------------------------------------------------------*/
47 /* Private function prototypes -----------------------------------------------*/
48 uint8_t *USBD_VCP_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
49 uint8_t *USBD_VCP_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
50 uint8_t *USBD_VCP_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
51 uint8_t *USBD_VCP_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
52 uint8_t *USBD_VCP_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
53 uint8_t *USBD_VCP_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
54 uint8_t *USBD_VCP_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
55 #ifdef USB_SUPPORT_USER_STRING_DESC
56 uint8_t *USBD_VCP_USRStringDesc (USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length);
57 #endif /* USB_SUPPORT_USER_STRING_DESC */
58
59 /* Private variables ---------------------------------------------------------*/
60 USBD_DescriptorsTypeDef VCP_Desc = {
61 USBD_VCP_DeviceDescriptor,
62 USBD_VCP_LangIDStrDescriptor,
63 USBD_VCP_ManufacturerStrDescriptor,
64 USBD_VCP_ProductStrDescriptor,
65 USBD_VCP_SerialStrDescriptor,
66 USBD_VCP_ConfigStrDescriptor,
67 USBD_VCP_InterfaceStrDescriptor,
68 };
69
70 /* USB Standard Device Descriptor */
71 #if defined ( __ICCARM__ )
72 #pragma data_alignment=4
73 #endif
74 __ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = {
75 0x12, /* bLength */
76 USB_DESC_TYPE_DEVICE, /* bDescriptorType */
77 0x00, /* bcdUSB */
78 0x02,
79 0x00, /* bDeviceClass */
80 0x00, /* bDeviceSubClass */
81 0x00, /* bDeviceProtocol */
82 USB_MAX_EP0_SIZE, /* bMaxPacketSize */
83 LOBYTE(USBD_VID), /* idVendor */
84 HIBYTE(USBD_VID), /* idVendor */
85 LOBYTE(USBD_PID), /* idVendor */
86 HIBYTE(USBD_PID), /* idVendor */
87 0x00, /* bcdDevice rel. 2.00 */
88 0x02,
89 USBD_IDX_MFC_STR, /* Index of manufacturer string */
90 USBD_IDX_PRODUCT_STR, /* Index of product string */
91 USBD_IDX_SERIAL_STR, /* Index of serial number string */
92 USBD_MAX_NUM_CONFIGURATION /* bNumConfigurations */
93 }; /* USB_DeviceDescriptor */
94
95 /* USB Standard Device Descriptor */
96 #if defined ( __ICCARM__ )
97 #pragma data_alignment=4
98 #endif
99 __ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = {
100 USB_LEN_LANGID_STR_DESC,
101 USB_DESC_TYPE_STRING,
102 LOBYTE(USBD_LANGID_STRING),
103 HIBYTE(USBD_LANGID_STRING),
104 };
105
106 uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] =
107 {
108 USB_SIZ_STRING_SERIAL,
109 USB_DESC_TYPE_STRING,
110 };
111
112 #if defined ( __ICCARM__ )
113 #pragma data_alignment=4
114 #endif
115 __ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
116
117 /* Private functions ---------------------------------------------------------*/
118 static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len);
119 static void Get_SerialNum(void);
120
127 uint8_t *USBD_VCP_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
128 {
129 *length = sizeof(USBD_DeviceDesc);
130 return (uint8_t*)USBD_DeviceDesc;
131 }
132
139 uint8_t *USBD_VCP_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
140 {
141 *length = sizeof(USBD_LangIDDesc);
142 return (uint8_t*)USBD_LangIDDesc;
143 }
144
151 uint8_t *USBD_VCP_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
152 {
153 if(speed == 0)
154 {
155 USBD_GetString((uint8_t *)USBD_PRODUCT_HS_STRING, USBD_StrDesc, length);
156 }
157 else
158 {
159 USBD_GetString((uint8_t *)USBD_PRODUCT_FS_STRING, USBD_StrDesc, length);
160 }
161 return USBD_StrDesc;
162 }
163
170 uint8_t *USBD_VCP_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
171 {
172 USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
173 return USBD_StrDesc;
174 }
175
182 uint8_t *USBD_VCP_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
183 {
184 *length = USB_SIZ_STRING_SERIAL;
185
186 /* Update the serial number string descriptor with the data from the unique ID*/
187 Get_SerialNum();
188
189 return (uint8_t*)USBD_StringSerial;
190 }
191
198 uint8_t *USBD_VCP_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
199 {
200 if(speed == USBD_SPEED_HIGH)
201 {
202 USBD_GetString((uint8_t *)USBD_CONFIGURATION_HS_STRING, USBD_StrDesc, length);
203 }
204 else
205 {
206 USBD_GetString((uint8_t *)USBD_CONFIGURATION_FS_STRING, USBD_StrDesc, length);
207 }
208 return USBD_StrDesc;
209 }
210
217 uint8_t *USBD_VCP_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
218 {
219 if(speed == 0)
220 {
221 USBD_GetString((uint8_t *)USBD_INTERFACE_HS_STRING, USBD_StrDesc, length);
222 }
223 else
224 {
225 USBD_GetString((uint8_t *)USBD_INTERFACE_FS_STRING, USBD_StrDesc, length);
226 }
227 return USBD_StrDesc;
228 }
229
235 static void Get_SerialNum(void)
236 {
237 uint32_t deviceserial0, deviceserial1, deviceserial2;
238
239 deviceserial0 = *(uint32_t*)DEVICE_ID1;
240 deviceserial1 = *(uint32_t*)DEVICE_ID2;
241 deviceserial2 = *(uint32_t*)DEVICE_ID3;
242
243 deviceserial0 += deviceserial2;
244
245 if (deviceserial0 != 0)
246 {
247 IntToUnicode (deviceserial0, &USBD_StringSerial[2] ,8);
248 IntToUnicode (deviceserial1, &USBD_StringSerial[18] ,4);
249 }
250 }
251
259 static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len)
260 {
261 uint8_t idx = 0;
262
263 for( idx = 0; idx < len; idx ++)
264 {
265 if( ((value >> 28)) < 0xA )
266 {
267 pbuf[ 2* idx] = (value >> 28) + '0';
268 }
269 else
270 {
271 pbuf[2* idx] = (value >> 28) + 'A' - 10;
272 }
273
274 value = value << 4;
275
276 pbuf[ 2* idx + 1] = 0;
277 }
278 }
279 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
280