STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
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 0x5730
37 #define USBD_LANGID_STRING 0x409
38 #define USBD_MANUFACTURER_STRING "STMicroelectronics"
39 #define USBD_PRODUCT_HS_STRING "STM32 AUDIO Streaming in HS Mode"
40 #define USBD_PRODUCT_FS_STRING "STM32 AUDIO Streaming in FS Mode"
41 #define USBD_CONFIGURATION_HS_STRING "AUDIO Config"
42 #define USBD_INTERFACE_HS_STRING "AUDIO Interface"
43 #define USBD_CONFIGURATION_FS_STRING "AUDIO Config"
44 #define USBD_INTERFACE_FS_STRING "AUDIO Interface"
45 
46 /* Private macro -------------------------------------------------------------*/
47 /* Private function prototypes -----------------------------------------------*/
48 uint8_t *USBD_AUDIO_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
49 uint8_t *USBD_AUDIO_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
50 uint8_t *USBD_AUDIO_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
51 uint8_t *USBD_AUDIO_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
52 uint8_t *USBD_AUDIO_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
53 uint8_t *USBD_AUDIO_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
54 uint8_t *USBD_AUDIO_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
55 #ifdef USB_SUPPORT_USER_STRING_DESC
56 uint8_t *USBD_AUDIO_USRStringDesc(USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length);
57 #endif /* USB_SUPPORT_USER_STRING_DESC */
58 
59 /* Private variables ---------------------------------------------------------*/
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  0x10, /* bcdUSB */
78  0x01,
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, //0x01,
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 = {
104 };
105 
106 
108 {
111 };
112 
113 #if defined ( __ICCARM__ )
114  #pragma data_alignment=4
115 #endif
116 __ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
117 
118 /* Private functions ---------------------------------------------------------*/
119 static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len);
120 static void Get_SerialNum(void);
121 
128 uint8_t *USBD_AUDIO_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
129 {
130  *length = sizeof(USBD_DeviceDesc);
131  return (uint8_t*)USBD_DeviceDesc;
132 }
133 
140 uint8_t *USBD_AUDIO_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
141 {
142  *length = sizeof(USBD_LangIDDesc);
143  return (uint8_t*)USBD_LangIDDesc;
144 }
145 
152 uint8_t *USBD_AUDIO_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
153 {
154  if(speed == USBD_SPEED_HIGH)
155  {
156  USBD_GetString((uint8_t *)USBD_PRODUCT_HS_STRING, USBD_StrDesc, length);
157  }
158  else
159  {
160  USBD_GetString((uint8_t *)USBD_PRODUCT_FS_STRING, USBD_StrDesc, length);
161  }
162  return USBD_StrDesc;
163 }
164 
172 {
173  USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
174  return USBD_StrDesc;
175 }
176 
183 uint8_t *USBD_AUDIO_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
184 {
185  *length = USB_SIZ_STRING_SERIAL;
186 
187  /* Update the serial number string descriptor with the data from the unique ID*/
188  Get_SerialNum();
189 
190  return (uint8_t*)USBD_StringSerial;
191 }
192 
199 uint8_t *USBD_AUDIO_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
200 {
201  if(speed == USBD_SPEED_HIGH)
202  {
203  USBD_GetString((uint8_t *)USBD_CONFIGURATION_HS_STRING, USBD_StrDesc, length);
204  }
205  else
206  {
207  USBD_GetString((uint8_t *)USBD_CONFIGURATION_FS_STRING, USBD_StrDesc, length);
208  }
209  return USBD_StrDesc;
210 }
211 
218 uint8_t *USBD_AUDIO_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
219 {
220  if(speed == USBD_SPEED_HIGH)
221  {
222  USBD_GetString((uint8_t *)USBD_INTERFACE_HS_STRING, USBD_StrDesc, length);
223  }
224  else
225  {
226  USBD_GetString((uint8_t *)USBD_INTERFACE_FS_STRING, USBD_StrDesc, length);
227  }
228  return USBD_StrDesc;
229 }
230 
236 static void Get_SerialNum(void)
237 {
238  uint32_t deviceserial0, deviceserial1, deviceserial2;
239 
240  deviceserial0 = *(uint32_t*)DEVICE_ID1;
241  deviceserial1 = *(uint32_t*)DEVICE_ID2;
242  deviceserial2 = *(uint32_t*)DEVICE_ID3;
243 
244  deviceserial0 += deviceserial2;
245 
246  if (deviceserial0 != 0)
247  {
248  IntToUnicode (deviceserial0, &USBD_StringSerial[2] ,8);
249  IntToUnicode (deviceserial1, &USBD_StringSerial[18] ,4);
250  }
251 }
252 
260 static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len)
261 {
262  uint8_t idx = 0;
263 
264  for( idx = 0; idx < len; idx ++)
265  {
266  if( ((value >> 28)) < 0xA )
267  {
268  pbuf[ 2* idx] = (value >> 28) + '0';
269  }
270  else
271  {
272  pbuf[2* idx] = (value >> 28) + 'A' - 10;
273  }
274 
275  value = value << 4;
276 
277  pbuf[ 2* idx + 1] = 0;
278  }
279 }
280 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
#define USBD_VID
Definition: usbd_desc.c:35
#define USBD_MAX_STR_DESC_SIZ
Definition: usbd_conf.h:63
#define DEVICE_ID1
Definition: usbd_desc.h:37
#define DEVICE_ID3
Definition: usbd_desc.h:39
uint8_t * USBD_AUDIO_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
Returns the configuration string descriptor.
Definition: usbd_desc.c:199
USBD_SpeedTypeDef
Definition: usbd_def.h:186
#define LOBYTE(x)
Definition: usbd_def.h:263
uint32_t idx
Definition: lcd_log.c:247
#define USBD_INTERFACE_FS_STRING
Definition: usbd_desc.c:44
#define USBD_PRODUCT_HS_STRING
Definition: usbd_desc.c:39
uint8_t * USBD_AUDIO_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
Returns the manufacturer string descriptor.
Definition: usbd_desc.c:171
#define USBD_PID
Definition: usbd_desc.c:36
#define USBD_LANGID_STRING
Definition: usbd_desc.c:37
#define USB_SIZ_STRING_SERIAL
Definition: usbd_desc.h:41
#define USBD_MAX_NUM_CONFIGURATION
Definition: usbd_conf.h:62
uint8_t * USBD_AUDIO_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
Returns the interface string descriptor.
Definition: usbd_desc.c:218
uint8_t * USBD_AUDIO_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
Returns the serial number string descriptor.
Definition: usbd_desc.c:183
uint8_t * USBD_AUDIO_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
Returns the LangID string descriptor.
Definition: usbd_desc.c:140
#define USB_LEN_DEV_DESC
Definition: usbd_def.h:58
#define USBD_PRODUCT_FS_STRING
Definition: usbd_desc.c:40
#define USBD_IDX_PRODUCT_STR
Definition: usbd_def.h:68
__ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END
Definition: usbd_desc.c:74
Definition: pbuf.h:108
uint8_t * USBD_AUDIO_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
Returns the device descriptor.
Definition: usbd_desc.c:128
void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len)
USBD_GetString Convert Ascii string into unicode one.
Definition: usbd_ctlreq.c:732
USBD_DescriptorsTypeDef AUDIO_Desc
Definition: usbd_desc.c:60
#define USB_DESC_TYPE_DEVICE
Definition: usbd_def.h:95
#define USBD_MANUFACTURER_STRING
Definition: usbd_desc.c:38
#define USB_MAX_EP0_SIZE
Definition: usbd_def.h:115
#define USB_LEN_LANGID_STR_DESC
Definition: usbd_def.h:63
#define HIBYTE(x)
Definition: usbd_def.h:264
#define USBD_CONFIGURATION_FS_STRING
Definition: usbd_desc.c:43
#define USB_DESC_TYPE_STRING
Definition: usbd_def.h:97
uint8_t * USBD_AUDIO_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
Returns the product string descriptor.
Definition: usbd_desc.c:152
#define DEVICE_ID2
Definition: usbd_desc.h:38
#define USBD_IDX_SERIAL_STR
Definition: usbd_def.h:69
uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL]
Definition: usbd_desc.c:107
#define USBD_CONFIGURATION_HS_STRING
Definition: usbd_desc.c:41
#define USBD_INTERFACE_HS_STRING
Definition: usbd_desc.c:42
Header file for usbd_core.c file.
#define USBD_IDX_MFC_STR
Definition: usbd_def.h:67