-
Notifications
You must be signed in to change notification settings - Fork 496
/
usb_desc.c
235 lines (213 loc) · 8.64 KB
/
usb_desc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/**
******************************************************************************
* @file usb_desc.c
* @author MCD Application Team
* @version V4.0.0
* @date 21-January-2013
* @brief Descriptors for Audio Speaker Demo
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
#include "usb_lib.h"
#include "usb_desc.h"
// Private constants
// USB Standard Device Descriptor
const uint8_t USB_DeviceDescriptor[] = {
USB_DESC_SIZE_DEVICE, // bLength
USB_DESC_TYPE_DEVICE, // bDescriptorType: device descriptor (0x01)
0x00, // bcdUSB: USB version 2.00 (0x0200)
0x02,
0x00, // bDeviceClass: interface level (0x0000)
0x00, // bDeviceSubclass: unused
0x00, // bDeviceProtocaol: unused
0x40, // bMaxPacketSize: control pipe max size
USB_VID & 0xFF, // idVendor: USB VID
USB_VID >> 8,
USB_PID & 0xFF, // idProduct: USB PID
USB_PID >> 8,
USB_REV & 0xFF, // bcdDevice: device release
USB_REV >> 8,
0x01, // iManufacturer: index of string descriptor describing manufacturer
0x02, // iProduct: index of string descriptor describing product
0x03, // iSerialNumber: index of string descriptor describing the device serial number
0x01 // bNumConfigurations: one configuration
};
// USB string descriptor zero
const uint8_t USB_StringLangID[] = {
USB_STRING_SIZE_LANGID, // Descriptor length
USB_DESC_TYPE_STRING, // String descriptor
0x09, // U.S. English (0x0409)
0x04
};
// USB string descriptor: Vendor
const uint8_t USB_StringVendor[] = {
USB_STRING_SIZE_VENDOR, // Descriptor length
USB_DESC_TYPE_STRING, // String descriptor
// "Wolk"
'W', 0, 'o', 0, 'l', 0, 'k', 0
};
// USB string descriptor: Product
const uint8_t USB_StringProduct[] = {
USB_STRING_SIZE_PRODUCT, // Descriptor length
USB_DESC_TYPE_STRING, // String descriptor
// "Wolk USB Microphone"
'W', 0, 'o', 0, 'l', 0, 'k', 0, ' ', 0,
'U', 0, 'S', 0, 'B', 0, ' ', 0,
'M', 0, 'i', 0, 'c', 0, 'r', 0, 'o', 0, 'p', 0, 'h', 0, 'o', 0, 'n', 0, 'e', 0
};
// USB string descriptor: Serial number
uint8_t USB_StringSerial[] = {
USB_STRING_SIZE_SERIAL, // Descriptor length
USB_DESC_TYPE_STRING, // String descriptor
// Dummy data for serial number
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
// USB microphone configuration descriptor
const uint8_t Mic_ConfigDescriptor[] = {
// Configuration 1
USB_DESC_SIZE_CONFIG, // bLength
USB_DESC_TYPE_CONFIGURATION, // bDescriptorType
MIC_DESC_SIZE_CONFIG & 0xFF, // wTotalLength: length of the total configuration block,
MIC_DESC_SIZE_CONFIG >> 8, // including this descriptor
0x02, // 2 interfaces
0x01, // configuration ID
0x00, // iConfiguration (unused)
0x80, // bmAttributes: bus powered device
0x7D, // 250mA maximum power consumption
// AC (AudioControl) interface descriptor
// Standard AC interface descriptor
USB_DESC_SIZE_INTERFACE, // bLength
USB_DESC_TYPE_INTERFACE, // bDescriptorType: interface
0x00, // bInterfaceNumber: interface 0 (index of this interface)
0x00, // bAlternateSetting: index of this alternate setting
0x00, // bNumEndpoints: 0 endpoints
USB_IF_CLASS_AUDIO, // bInterfaceClass: AUDIO
USB_IF_SUBCLASS_AUDIO_CONTROL, // bInterfaceSubclass: AUDIO_CONTROL
0x00, // bInterfaceProtocol: unused
0x00, // iInterface: unused
// Class-specific AC interface descriptor
0x09, // bLength
USB_DESC_TYPE_CS_INTERFACE, // bDescriptorType: class-specific interface
0x01, // bDescriptorSubtype: HEADER subtype
0x00, // bcdADC: revision of class specification 1.00 (0x0100)
0x01,
0x27, // wTotalLength: total size of class specific descriptors (0x0027)
0x00,
0x01, // bInCollection: 1 streaming interface
0x01, // baInterfaceNr(1): AudioStreaming interface 1 belongs to this AC interface
// Microphone input terminal descriptor
0x0C, // bLength
USB_DESC_TYPE_CS_INTERFACE, // bDescriptorType: class-specific interface
0x02, // bDescriptorSubtype: INPUT_TERMINAL subtype
0x01, // bTerminalID: ID of this terminal
0x01, // wTerminalType: microphone (0x0201)
0x02,
0x00, // bAssocTerminal: no association
0x01, // bNrChannels: single channel
0x00, // wChannelConfig: mono (0x0000)
0x00,
0x00, // iChannelNames: unused
0x00, // iTerminal: unused
// Microphone output terminal descriptor
0x09, // bLength
USB_DESC_TYPE_CS_INTERFACE, // bDescriptorType: class-specific interface
0x03, // bDescriptorSubtype: OUTPUT_TERMINAL subtype
0x02, // bTerminalID: ID of this terminal
0x01, // wTerminalType: USB streaming (0x0101)
0x01,
0x00, // bAssocTerminal: unused
0x01, // bSourceID: from input terminal
0x00, // iTerminal: unused
// Microphone audio FU (feature unit) descriptor
0x09, // bLength
USB_DESC_TYPE_CS_INTERFACE, // bDescriptorType: class-specific interface
USB_IF_SUBCLASS_AUDIO_FEATURE, // bDescriptorSubtype: FEATURE_UNIT
0x03, // bUnitID: unique ID of this unit within the audio function
0x01, // bSourceID: ID of the terminal to which this FU connected
0x01, // bControlSize: bmaControls are one byte size
0x03, // bmaControls(0): controls for master channel (mute, volume)
0x00, // bmaControls(1): controls for channel 1 (no controls)
0x00, // iFeature: string descriptor of this FU, unused
// AS (AudioStreaming) interface descriptor
// Microphone standard AS interface descriptor (Alt. Set. 0)
USB_DESC_SIZE_INTERFACE, // bLength
USB_DESC_TYPE_INTERFACE, // bDescriptorType: interface
0x01, // bInterfaceNumber: interface 1 (index of this interface)
0x00, // bAlternateSetting: index of this alternate setting
0x00, // bNumEndpoints: 0 endpoints
USB_IF_CLASS_AUDIO, // bInterfaceClass: AUDIO
USB_IF_SUBCLASS_AUDIO_STREAMING, // bInterfaceSubclass: AUDIO_STREAMING
0x00, // bInterfaceProtocol: unused
0x00, // iInterface: unused
// Microphone standard AS interface descriptor
USB_DESC_SIZE_INTERFACE, // bLength
USB_DESC_TYPE_INTERFACE, // bDescriptorType: interface
0x01, // bInterfaceNumber: index of this interface
0x01, // bAlternateSetting: index of this alternate setting
0x01, // bNumEndpoints: one endpoint
USB_IF_CLASS_AUDIO, // bInterfaceClass: AUDIO
USB_IF_SUBCLASS_AUDIO_STREAMING, // bInterfaceSubclass: AUDIO_STREAMING
0x00, // bInterfaceProtocol: unused
0x00, // iInterface: unused
// Microphone class-specific AS general interface descriptor
0x07, // bLength
USB_DESC_TYPE_CS_INTERFACE, // bDescriptorType: class-specific interface
0x01, // bDescriptorSubtype: GENERAL subtype
0x02, // bTerminalLink: uint ID of the output terminal
0x01, // bDelay: interface delay
0x01, // wFormatTag: PCM format (0x0001)
0x00,
// Microphone Type-I format type descriptor
0x11, // bLength
USB_DESC_TYPE_CS_INTERFACE, // bDescriptorType: class-specific interface
0x02, // bDescriptorSubtype: FORMAT_TYPE subtype
0x01, // bFormatType: FORMAT_TYPE_I
0x01, // bNrChannels: single channel
0x02, // bSubFrameSize: two bytes per audio subframe
0x10, // bBitResolution: 16 bit per sample
0x03, // bSamFreqType: three frequencies supported
0x40, // tSamFreq: 8000Hz (0x001F40)
0x1F,
0x00,
0x22, // tSamFreq: 22050Hz (0x005622)
0x56,
0x00,
0x44, // tSamFreq: 44100Hz (0x00AC44)
0xAC,
0x00,
// Microphone standard endpoint descriptor
USB_DESC_SIZE_ENDPOINT, // bLength
USB_DESC_TYPE_ENDPOINT, // bDescriptorType: endpoint
0x81, // bEndpointAddress: IN endpoint 1
0x01, // bmAttributes: isochronous, not shared
0x10, // wMaxPacketSize: 16 bytes per packet (0x0010)
0x00,
0x01, // bInterval: one packet per frame
0x00, // bRefresh: unused
0x00, // bSynchAddress: unused
// Microphone class-specific isochronous audio data endpoint descriptor
0x07, // bLength
USB_DESC_TYPE_CS_ENDPOINT, // bDescriptorType: class-specific endpoint
0x01, // bDescriptorSubtype: GENERAL subtype
0x01, // bmAttributes: sampling control, no pitch control, no packet padding
0x00, // bLockDelayUnits: unused
0x00, // wLockDelay: unused (0x0000)
0x00
};