Skip to content

Commit ed1ddd8

Browse files
author
fpr
committed
Update USB descriptor to allow to use USBMicrophone library
Signed-off-by: fpr <[email protected]>
1 parent dd63aec commit ed1ddd8

File tree

2 files changed

+47
-61
lines changed

2 files changed

+47
-61
lines changed

variants/DISCO_L475VG_IOT/usb/usbd_desc.c

Lines changed: 39 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "usbd_core.h"
5050
#include "usbd_desc.h"
5151
#include "usbd_conf.h"
52+
#include "utils.h"
5253

5354
/* Private typedef -----------------------------------------------------------*/
5455
/* Private define ------------------------------------------------------------*/
@@ -64,22 +65,15 @@
6465
#elif !defined(USB_MANUFACTURER)
6566
// Fall through to unknown if no manufacturer name was provided in a macro
6667
#define USBD_MANUFACTURER_STRING "Unknown"
67-
#endif
68+
#endif /* USBD_VID */
6869
#ifdef USBD_USE_HID_COMPOSITE
69-
#define USBD_HID_PRODUCT_HS_STRING "HID in HS Mode"
70-
#define USBD_HID_PRODUCT_FS_STRING "HID in FS Mode"
71-
#define USBD_HID_CONFIGURATION_HS_STRING "HID Config"
72-
#define USBD_HID_INTERFACE_HS_STRING "HID Interface"
73-
#define USBD_HID_CONFIGURATION_FS_STRING "HID Config"
74-
#define USBD_HID_INTERFACE_FS_STRING "HID Interface"
70+
#define USBD_HID_PRODUCT_FS_STRING CONCATS(USB_PRODUCT, "HID in FS Mode")
71+
#define USBD_HID_CONFIGURATION_FS_STRING CONCATS(USB_PRODUCT, "HID Config")
72+
#define USBD_HID_INTERFACE_FS_STRING CONCATS(USB_PRODUCT, "HID Interface")
7573

7674
/* Private macro -------------------------------------------------------------*/
77-
/* Private function prototypes -----------------------------------------------*/
78-
static uint8_t *USBD_HID_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
79-
static uint8_t *USBD_HID_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
80-
static uint8_t *USBD_HID_ManufacturerStrDescriptor (USBD_SpeedTypeDef speed, uint16_t *length);
75+
/* Private function prototypes -----------------------------------------------*/;
8176
static uint8_t *USBD_HID_ProductStrDescriptor (USBD_SpeedTypeDef speed, uint16_t *length);
82-
static uint8_t *USBD_HID_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
8377
static uint8_t *USBD_HID_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
8478
static uint8_t *USBD_HID_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
8579
#ifdef USB_SUPPORT_USER_STRING_DESC
@@ -88,15 +82,15 @@ static uint8_t *USBD_HID_USRStringDesc (USBD_SpeedTypeDef speed, uint8_t idx, ui
8882

8983
/* Private variables ---------------------------------------------------------*/
9084
USBD_DescriptorsTypeDef HID_Desc = {
91-
USBD_HID_DeviceDescriptor,
92-
USBD_HID_LangIDStrDescriptor,
93-
USBD_HID_ManufacturerStrDescriptor,
85+
USBD_DeviceDescriptor,
86+
USBD_LangIDStrDescriptor,
87+
USBD_ManufacturerStrDescriptor,
9488
USBD_HID_ProductStrDescriptor,
95-
USBD_HID_SerialStrDescriptor,
89+
USBD_SerialStrDescriptor,
9690
USBD_HID_ConfigStrDescriptor,
9791
USBD_HID_InterfaceStrDescriptor,
9892
};
99-
#endif //USBD_USE_HID_COMPOSITE
93+
#endif /* USBD_USE_HID_COMPOSITE */
10094

10195
/* USB Standard Device Descriptor */
10296
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
@@ -105,8 +99,8 @@ USBD_DescriptorsTypeDef HID_Desc = {
10599
__ALIGN_BEGIN static uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = {
106100
0x12, /* bLength */
107101
USB_DESC_TYPE_DEVICE, /* bDescriptorType */
108-
0x00, /* bcdUSB */
109-
0x02,
102+
0x01, /* bcdUSB */
103+
0x01,
110104
0x00, /* bDeviceClass */
111105
0x00, /* bDeviceSubClass */
112106
0x00, /* bDeviceProtocol */
@@ -115,8 +109,8 @@ __ALIGN_BEGIN static uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = {
115109
HIBYTE(USBD_VID), /* idVendor */
116110
LOBYTE(USBD_PID), /* idVendor */
117111
HIBYTE(USBD_PID), /* idVendor */
118-
0x00, /* bcdDevice rel. 2.00 */
119-
0x02,
112+
0x01, /* bcdDevice rel. 1.1 */
113+
0x01,
120114
USBD_IDX_MFC_STR, /* Index of manufacturer string */
121115
USBD_IDX_PRODUCT_STR, /* Index of product string */
122116
USBD_IDX_SERIAL_STR, /* Index of serial number string */
@@ -149,14 +143,13 @@ __ALIGN_BEGIN static uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
149143
static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len);
150144
static void Get_SerialNum(void);
151145

152-
#ifdef USBD_USE_HID_COMPOSITE
153146
/**
154147
* @brief Returns the device descriptor.
155148
* @param speed: Current device speed
156149
* @param length: Pointer to data length variable
157150
* @retval Pointer to descriptor buffer
158151
*/
159-
uint8_t *USBD_HID_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
152+
uint8_t *USBD_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
160153
{
161154
UNUSED(speed);
162155
*length = sizeof(USBD_DeviceDesc);
@@ -169,39 +162,20 @@ uint8_t *USBD_HID_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
169162
* @param length: Pointer to data length variable
170163
* @retval Pointer to descriptor buffer
171164
*/
172-
uint8_t *USBD_HID_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
165+
uint8_t *USBD_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
173166
{
174167
UNUSED(speed);
175168
*length = sizeof(USBD_LangIDDesc);
176169
return (uint8_t*)USBD_LangIDDesc;
177170
}
178171

179-
/**
180-
* @brief Returns the product string descriptor.
181-
* @param speed: Current device speed
182-
* @param length: Pointer to data length variable
183-
* @retval Pointer to descriptor buffer
184-
*/
185-
uint8_t *USBD_HID_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
186-
{
187-
if(speed == USBD_SPEED_HIGH)
188-
{
189-
USBD_GetString((uint8_t *)USBD_HID_PRODUCT_HS_STRING, USBD_StrDesc, length);
190-
}
191-
else
192-
{
193-
USBD_GetString((uint8_t *)USBD_HID_PRODUCT_FS_STRING, USBD_StrDesc, length);
194-
}
195-
return USBD_StrDesc;
196-
}
197-
198172
/**
199173
* @brief Returns the manufacturer string descriptor.
200174
* @param speed: Current device speed
201175
* @param length: Pointer to data length variable
202176
* @retval Pointer to descriptor buffer
203177
*/
204-
uint8_t *USBD_HID_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
178+
uint8_t *USBD_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
205179
{
206180
UNUSED(speed);
207181
USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
@@ -214,7 +188,7 @@ uint8_t *USBD_HID_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *l
214188
* @param length: Pointer to data length variable
215189
* @retval Pointer to descriptor buffer
216190
*/
217-
uint8_t *USBD_HID_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
191+
uint8_t *USBD_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
218192
{
219193
UNUSED(speed);
220194
*length = USB_SIZ_STRING_SERIAL;
@@ -225,6 +199,21 @@ uint8_t *USBD_HID_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
225199
return (uint8_t*)USBD_StringSerial;
226200
}
227201

202+
#ifdef USBD_USE_HID_COMPOSITE
203+
204+
/**
205+
* @brief Returns the product string descriptor.
206+
* @param speed: Current device speed
207+
* @param length: Pointer to data length variable
208+
* @retval Pointer to descriptor buffer
209+
*/
210+
uint8_t *USBD_HID_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
211+
{
212+
UNUSED(speed);
213+
USBD_GetString((uint8_t *)USBD_HID_PRODUCT_FS_STRING, USBD_StrDesc, length);
214+
return USBD_StrDesc;
215+
}
216+
228217
/**
229218
* @brief Returns the configuration string descriptor.
230219
* @param speed: Current device speed
@@ -233,14 +222,8 @@ uint8_t *USBD_HID_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
233222
*/
234223
uint8_t *USBD_HID_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
235224
{
236-
if(speed == USBD_SPEED_HIGH)
237-
{
238-
USBD_GetString((uint8_t *)USBD_HID_CONFIGURATION_HS_STRING, USBD_StrDesc, length);
239-
}
240-
else
241-
{
242-
USBD_GetString((uint8_t *)USBD_HID_CONFIGURATION_FS_STRING, USBD_StrDesc, length);
243-
}
225+
UNUSED(speed);
226+
USBD_GetString((uint8_t *)USBD_HID_CONFIGURATION_FS_STRING, USBD_StrDesc, length);
244227
return USBD_StrDesc;
245228
}
246229

@@ -252,17 +235,12 @@ uint8_t *USBD_HID_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
252235
*/
253236
uint8_t *USBD_HID_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
254237
{
255-
if(speed == USBD_SPEED_HIGH)
256-
{
257-
USBD_GetString((uint8_t *)USBD_HID_INTERFACE_HS_STRING, USBD_StrDesc, length);
258-
}
259-
else
260-
{
261-
USBD_GetString((uint8_t *)USBD_HID_INTERFACE_FS_STRING, USBD_StrDesc, length);
262-
}
238+
UNUSED(speed);
239+
USBD_GetString((uint8_t *)USBD_HID_INTERFACE_FS_STRING, USBD_StrDesc, length);
263240
return USBD_StrDesc;
264241
}
265242
#endif //USBD_USE_HID_COMPOSITE
243+
266244
/**
267245
* @brief Create the serial number string descriptor
268246
* @param None

variants/DISCO_L475VG_IOT/usb/usbd_desc.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,15 @@
6161
#define USB_SIZ_STRING_SERIAL 0x1A
6262
/* Exported macro ------------------------------------------------------------*/
6363
/* Exported functions ------------------------------------------------------- */
64+
#ifdef USBD_USE_HID_COMPOSITE
6465
extern USBD_DescriptorsTypeDef HID_Desc;
66+
#endif
67+
68+
uint8_t *USBD_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
69+
uint8_t *USBD_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
70+
uint8_t *USBD_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
71+
uint8_t *USBD_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
72+
6573
#endif // USBCON
6674
#endif /* __USBD_DESC_H */
6775

0 commit comments

Comments
 (0)