Added STM32F4 discovery demo sources and make file
[fw/stlink] / example / stm32f4 / Projects / discovery_demo / usbd_desc.c
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
10   *
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.
17   *
18   * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
19   ******************************************************************************
20   */ 
21
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
29 /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
30   * @{
31   */
32
33
34 /** @defgroup USBD_DESC 
35   * @brief USBD descriptors module
36   * @{
37   */ 
38
39 /** @defgroup USBD_DESC_Private_TypesDefinitions
40   * @{
41   */ 
42 /**
43   * @}
44   */ 
45
46
47 /** @defgroup USBD_DESC_Private_Defines
48   * @{
49   */ 
50
51 #define USBD_VID                     0x0483
52 #define USBD_PID                     0x5710
53
54 #define USBD_LANGID_STRING            0x409
55 #define USBD_MANUFACTURER_STRING      "STMicroelectronics"
56
57 #define USBD_PRODUCT_HS_STRING        "Joystick in HS mode"
58 #define USBD_SERIALNUMBER_HS_STRING   "00000000011B"
59
60 #define USBD_PRODUCT_FS_STRING        "Joystick in FS Mode"
61 #define USBD_SERIALNUMBER_FS_STRING   "00000000011C"
62
63 #define USBD_CONFIGURATION_HS_STRING  "HID Config"
64 #define USBD_INTERFACE_HS_STRING      "HID Interface"
65
66 #define USBD_CONFIGURATION_FS_STRING  "HID Config"
67 #define USBD_INTERFACE_FS_STRING      "HID Interface"
68 /**
69   * @}
70   */ 
71
72
73 /** @defgroup USBD_DESC_Private_Macros
74   * @{
75   */ 
76 /**
77   * @}
78   */ 
79
80
81 /** @defgroup USBD_DESC_Private_Variables
82   * @{
83   */ 
84
85 USBD_DEVICE USR_desc =
86 {
87   USBD_USR_DeviceDescriptor,
88   USBD_USR_LangIDStrDescriptor, 
89   USBD_USR_ManufacturerStrDescriptor,
90   USBD_USR_ProductStrDescriptor,
91   USBD_USR_SerialStrDescriptor,
92   USBD_USR_ConfigStrDescriptor,
93   USBD_USR_InterfaceStrDescriptor,
94   
95 };
96
97 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
98   #if defined ( __ICCARM__ ) /*!< IAR Compiler */
99     #pragma data_alignment=4   
100   #endif
101 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
102 /* USB Standard Device Descriptor */
103 __ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_SIZ_DEVICE_DESC] __ALIGN_END =
104   {
105     0x12,                       /*bLength */
106     USB_DEVICE_DESCRIPTOR_TYPE, /*bDescriptorType*/
107     0x00,                       /*bcdUSB */
108     0x02,
109     0x00,                       /*bDeviceClass*/
110     0x00,                       /*bDeviceSubClass*/
111     0x00,                       /*bDeviceProtocol*/
112     USB_OTG_MAX_EP0_SIZE,      /*bMaxPacketSize*/
113     LOBYTE(USBD_VID),           /*idVendor*/
114     HIBYTE(USBD_VID),           /*idVendor*/
115     LOBYTE(USBD_PID),           /*idVendor*/
116     HIBYTE(USBD_PID),           /*idVendor*/
117     0x00,                       /*bcdDevice rel. 2.00*/
118     0x02,
119     USBD_IDX_MFC_STR,           /*Index of manufacturer  string*/
120     USBD_IDX_PRODUCT_STR,       /*Index of product string*/
121     USBD_IDX_SERIAL_STR,        /*Index of serial number string*/
122     USBD_CFG_MAX_NUM            /*bNumConfigurations*/
123   } ; /* USB_DeviceDescriptor */
124
125 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
126   #if defined ( __ICCARM__ ) /*!< IAR Compiler */
127     #pragma data_alignment=4   
128   #endif
129 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
130 /* USB Standard Device Descriptor */
131 __ALIGN_BEGIN uint8_t USBD_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
132 {
133   USB_LEN_DEV_QUALIFIER_DESC,
134   USB_DESC_TYPE_DEVICE_QUALIFIER,
135   0x00,
136   0x02,
137   0x00,
138   0x00,
139   0x00,
140   0x40,
141   0x01,
142   0x00,
143 };
144
145 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
146   #if defined ( __ICCARM__ ) /*!< IAR Compiler */
147     #pragma data_alignment=4   
148   #endif
149 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
150 /* USB Standard Device Descriptor */
151 __ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_SIZ_STRING_LANGID] __ALIGN_END =
152 {
153      USB_SIZ_STRING_LANGID,         
154      USB_DESC_TYPE_STRING,       
155      LOBYTE(USBD_LANGID_STRING),
156      HIBYTE(USBD_LANGID_STRING), 
157 };
158 /**
159   * @}
160   */ 
161
162
163 /** @defgroup USBD_DESC_Private_FunctionPrototypes
164   * @{
165   */ 
166 /**
167   * @}
168   */ 
169
170
171 /** @defgroup USBD_DESC_Private_Functions
172   * @{
173   */ 
174
175 /**
176 * @brief  USBD_USR_DeviceDescriptor 
177 *         return the device descriptor
178 * @param  speed : current device speed
179 * @param  length : pointer to data length variable
180 * @retval pointer to descriptor buffer
181 */
182 uint8_t *  USBD_USR_DeviceDescriptor( uint8_t speed , uint16_t *length)
183 {
184   *length = sizeof(USBD_DeviceDesc);
185   return USBD_DeviceDesc;
186 }
187
188 /**
189 * @brief  USBD_USR_LangIDStrDescriptor 
190 *         return the LangID string descriptor
191 * @param  speed : current device speed
192 * @param  length : pointer to data length variable
193 * @retval pointer to descriptor buffer
194 */
195 uint8_t *  USBD_USR_LangIDStrDescriptor( uint8_t speed , uint16_t *length)
196 {
197   *length =  sizeof(USBD_LangIDDesc);  
198   return USBD_LangIDDesc;
199 }
200
201
202 /**
203 * @brief  USBD_USR_ProductStrDescriptor 
204 *         return the product string descriptor
205 * @param  speed : current device speed
206 * @param  length : pointer to data length variable
207 * @retval pointer to descriptor buffer
208 */
209 uint8_t *  USBD_USR_ProductStrDescriptor( uint8_t speed , uint16_t *length)
210 {
211  
212   
213   if(speed == 0)
214   {   
215     USBD_GetString (USBD_PRODUCT_HS_STRING, USBD_StrDesc, length);
216   }
217   else
218   {
219     USBD_GetString (USBD_PRODUCT_FS_STRING, USBD_StrDesc, length);    
220   }
221   return USBD_StrDesc;
222 }
223
224 /**
225 * @brief  USBD_USR_ManufacturerStrDescriptor 
226 *         return the manufacturer string descriptor
227 * @param  speed : current device speed
228 * @param  length : pointer to data length variable
229 * @retval pointer to descriptor buffer
230 */
231 uint8_t *  USBD_USR_ManufacturerStrDescriptor( uint8_t speed , uint16_t *length)
232 {
233   USBD_GetString (USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
234   return USBD_StrDesc;
235 }
236
237 /**
238 * @brief  USBD_USR_SerialStrDescriptor 
239 *         return the serial number string descriptor
240 * @param  speed : current device speed
241 * @param  length : pointer to data length variable
242 * @retval pointer to descriptor buffer
243 */
244 uint8_t *  USBD_USR_SerialStrDescriptor( uint8_t speed , uint16_t *length)
245 {
246   if(speed  == USB_OTG_SPEED_HIGH)
247   {    
248     USBD_GetString (USBD_SERIALNUMBER_HS_STRING, USBD_StrDesc, length);
249   }
250   else
251   {
252     USBD_GetString (USBD_SERIALNUMBER_FS_STRING, USBD_StrDesc, length);    
253   }
254   return USBD_StrDesc;
255 }
256
257 /**
258 * @brief  USBD_USR_ConfigStrDescriptor 
259 *         return the configuration string descriptor
260 * @param  speed : current device speed
261 * @param  length : pointer to data length variable
262 * @retval pointer to descriptor buffer
263 */
264 uint8_t *  USBD_USR_ConfigStrDescriptor( uint8_t speed , uint16_t *length)
265 {
266   if(speed  == USB_OTG_SPEED_HIGH)
267   {  
268     USBD_GetString (USBD_CONFIGURATION_HS_STRING, USBD_StrDesc, length);
269   }
270   else
271   {
272     USBD_GetString (USBD_CONFIGURATION_FS_STRING, USBD_StrDesc, length); 
273   }
274   return USBD_StrDesc;  
275 }
276
277
278 /**
279 * @brief  USBD_USR_InterfaceStrDescriptor 
280 *         return the interface string descriptor
281 * @param  speed : current device speed
282 * @param  length : pointer to data length variable
283 * @retval pointer to descriptor buffer
284 */
285 uint8_t *  USBD_USR_InterfaceStrDescriptor( uint8_t speed , uint16_t *length)
286 {
287   if(speed == 0)
288   {
289     USBD_GetString (USBD_INTERFACE_HS_STRING, USBD_StrDesc, length);
290   }
291   else
292   {
293     USBD_GetString (USBD_INTERFACE_FS_STRING, USBD_StrDesc, length);
294   }
295   return USBD_StrDesc;  
296 }
297
298 /**
299   * @}
300   */ 
301
302
303 /**
304   * @}
305   */ 
306
307
308 /**
309   * @}
310   */ 
311
312 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
313