forked from borgestrand/sdr-widget
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuac1_usb_descriptors.h
368 lines (321 loc) · 14.6 KB
/
uac1_usb_descriptors.h
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
/* -*- mode: c++; tab-width: 4; c-basic-offset: 4 -*- */
/*
*
* Copyright (C) Alex Lee 2010, 2011
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Modified by Alex Lee 20 Feb 2010
* To enumerate as a USB composite device with 4 interfaces:
* CDC
* HID (generic HID interface, compatible with Jan Axelson's generichid.exe test programs
* DG8SAQ (libusb API compatible interface for implementing DG8SAQ EP0 type of interface)
* Audio (USB Audio Class V2)
*
* For SDR-Widget and SDR-Widget-lite, custom boards based on the AT32UC3A3256
*
* See http://code.google.com/p/sdr-widget/
*
* Rearranged by Roger Critchlow 21 Feb 2011.
*/
#ifndef _UAC1_DESCRIPTORS_H_
#define _UAC1_DESCRIPTORS_H_
//_____ I N C L U D E S ____________________________________________________
#include "conf_usb.h"
#include "features.h"
#if USB_DEVICE_FEATURE == DISABLED
#error uac1_descriptors.h is #included although USB_DEVICE_FEATURE is disabled
#endif
#include "usb_standard_request.h"
#include "usb_task.h"
#include "usb_descriptors.h"
#include "hid.h"
//_____ M A C R O S ________________________________________________________
//_____ U S B D E F I N E S _____________________________________________
// CONFIGURATION
#define NB_INTERFACE 4 //! DG8SAQ, Audio (3)
#define CONF_NB 1 //! Number of this configuration
#define CONF_INDEX 0
#define CONF_ATTRIBUTES USB_CONFIG_SELFPOWERED
#define MAX_POWER 250 // 500 mA
// IAD for Audio
#define FIRST_INTERFACE1 1
#define INTERFACE_COUNT1 3
//Audio Streaming (AS) interface descriptor
#define STD_AS_INTERFACE_OUT 0x02
#define STD_AS_INTERFACE_IN 0x03
// USB DG8SAQ Interface descriptor
#define INTERFACE_NB0 0
#define ALTERNATE_NB0 0 //! The alt setting nb of this interface
#define NB_ENDPOINT0 0 //! The number of endpoints this interface has
#define INTERFACE_CLASS0 NO_CLASS //! No Class
#define INTERFACE_SUB_CLASS0 NO_SUBCLASS //! No Subclass
#define INTERFACE_PROTOCOL0 NO_PROTOCOL //! No Protocol
#define INTERFACE_INDEX0 0
#define DSC_INTERFACE_DG8SAQ INTERFACE_NB0
/*
// USB HID Interface descriptor
#define INTERFACE_NB1 1
#define ALTERNATE_NB1 0 //! The alt setting nb of this interface
#define NB_ENDPOINT1 2 //! The number of endpoints this interface has
#define INTERFACE_CLASS1 HID_CLASS //! HID Class
#define INTERFACE_SUB_CLASS1 NO_SUBCLASS //! No Subclass
#define INTERFACE_PROTOCOL1 NO_PROTOCOL //! No Protocol
#define INTERFACE_INDEX1 0
#define DSC_INTERFACE_HID INTERFACE_NB1
// HID descriptor
#define HID_VERSION 0x0111 //! HID Class Specification release number
#define HID_COUNTRY_CODE 0x00 //! Hardware target country
#define HID_NUM_DESCRIPTORS 0x01 //! Number of HID class descriptors to follow
// USB Endpoint 1 descriptor
#define ENDPOINT_NB_1 (UAC1_EP_HID_TX| MSK_EP_DIR)
#define EP_ATTRIBUTES_1 TYPE_INTERRUPT
#define EP_IN_LENGTH_1_FS 8
#define EP_SIZE_1_FS EP_IN_LENGTH_1_FS
#define EP_IN_LENGTH_1_HS 8
#define EP_SIZE_1_HS EP_IN_LENGTH_1_HS
#define EP_INTERVAL_1 5 //! Interrupt polling interval from host
// USB Endpoint 2 descriptor
#define ENDPOINT_NB_2 (UAC1_EP_HID_RX)
#define EP_ATTRIBUTES_2 TYPE_INTERRUPT
#define EP_OUT_LENGTH_2_FS 8
#define EP_SIZE_2_FS EP_OUT_LENGTH_2_FS
#define EP_OUT_LENGTH_2_HS 8
#define EP_SIZE_2_HS EP_OUT_LENGTH_2_HS
#define EP_INTERVAL_2 5 //! Interrupt polling interval from host
*/
// Standard Audio Control (AC) interface descriptor
#define INTERFACE_NB2 1
#define ALTERNATE_NB2 0
#define NB_ENDPOINT2 0 //! No endpoint for AC interface
#define INTERFACE_CLASS2 AUDIO_CLASS //! Audio Class
#define INTERFACE_SUB_CLASS2 0x01 //! Audio_control sub class
#define INTERFACE_PROTOCOL2 0x00 //! Unused
#define INTERFACE_INDEX2 0
#define DSC_INTERFACE_AUDIO INTERFACE_NB2
// USB Endpoint 3 descriptor
#define ENDPOINT_NB_3 ( UAC1_EP_AUDIO_OUT )
#define EP_ATTRIBUTES_3 0b00000101 // ISOCHRONOUS ASYNCHRONOUS EXPLICIT FEEDBACK
//#define EP_ATTRIBUTES_3 0b00001101 // ISOCHRONOUS SYNCHRONOUS
#define EP_IN_LENGTH_3_HS 294 // 3 bytes * 48 khz * stereo + 6 bytes for add sample
#define EP_IN_LENGTH_3_FS 294
#define EP_SIZE_3_FS EP_IN_LENGTH_3_FS
#define EP_SIZE_3_HS EP_IN_LENGTH_3_HS
#define EP_INTERVAL_3_FS 0x01 // one packet per uframe
#define EP_INTERVAL_3_HS 0x04 // One packet per 8 uframe
#define EP_REFRESH_3_FS 0x01
#define EP_REFRESH_3_HS 0x04
#define EP_BSYNC_ADDRESS_3 0x84 // feedback EP is EP 4, need to explicitly set it to IN endpoint
//#define EP_BSYNC_ADDRESS_3 0x04 // feedback EP is EP 4 - using audio input pipe to sync
//#define EP_BSYNC_ADDRESS_3 0x00
/* Note: The EPs have to be re-arranged. Feedback EP has to be immediately following the OUT EP
// USB Endpoint 4 descriptor*/
#define ENDPOINT_NB_4 ( UAC1_EP_AUDIO_OUT_FB | MSK_EP_DIR )
#define EP_ATTRIBUTES_4 0b00010001 // ISOCHROUNOUS FEEDBACK
#define EP_IN_LENGTH_4_FS 3 // 3 bytes
#define EP_IN_LENGTH_4_HS 4 // 4 bytes
#define EP_SIZE_4_FS EP_IN_LENGTH_4_FS
#define EP_SIZE_4_HS EP_IN_LENGTH_4_HS
#define EP_INTERVAL_4_FS 0x01
#define EP_INTERVAL_4_HS 0x04
#define EP_REFRESH_4_FS 0x05 // 64ms
#define EP_REFRESH_4_HS 0x05 // 2^(10-1) = 512 uframe = 64ms
// USB Endpoint 5 descriptor
#define ENDPOINT_NB_5 ( UAC1_EP_AUDIO_IN | MSK_EP_DIR )
#define EP_ATTRIBUTES_5 0b00100101 // ISOCHROUNOUS ASYNCHRONOUS IMPLICIT FEEDBACK
#define EP_IN_LENGTH_5_HS 294 // 3 bytes * 48 khz * stereo + 6 bytes for add sample
#define EP_IN_LENGTH_5_FS 294
#define EP_SIZE_5_FS EP_IN_LENGTH_5_FS
#define EP_SIZE_5_HS EP_IN_LENGTH_5_HS
#define EP_INTERVAL_5_FS 0x01 // one packet per uframe
#define EP_INTERVAL_5_HS 0x04 // One packet per 8 uframe
// AC interface descriptor Audio specific
#define AUDIO_CLASS_REVISION 0x0100
#define NB_OF_STREAMING_INTERFACE 0x02 // one for speaker out, one for mic in
#define BELONGS_AUDIO_INTERFACE_OUT STD_AS_INTERFACE_OUT
#define BELONGS_AUDIO_INTERFACE_IN STD_AS_INTERFACE_IN
// Input Terminal descriptor
#define INPUT_TERMINAL_ID 0x01
#define INPUT_TERMINAL_TYPE 0x0201 // Terminal is microphone
#define INPUT_TERMINAL_ASSOCIATION 0x00 // No association
#define INPUT_TERMINAL_NB_CHANNELS 0x02 // Two channels for input terminal
#define INPUT_TERMINAL_CHANNEL_CONF 0x0003 // Two channels at front left and front right positions
#define INPUT_TERMINAL_CH_NAME_ID 0x00 // No channel name
//MIC Feature Unit descriptor
#define MIC_FEATURE_UNIT_ID 0x02
#define MIC_FEATURE_UNIT_SOURCE_ID 0x01
#define MIC_FEATURE_UNIT_CONTROL_SIZE 0x02 // 2 bytes for each control
#define MIC_BMA_CONTROLS_0 0x0001 // Mute for master channel
#define MIC_BMA_CONTROLS_1 0x0002 // Volume control on left channel
#define MIC_BMA_CONTROLS_2 0x0002 // Volume control on right channel
#define MIC_FEATURE_UNIT_CH_NAME_ID 0x00
// Output Terminal descriptor
#define OUTPUT_TERMINAL_ID 0x03
#define OUTPUT_TERMINAL_TYPE 0x0101 // USB Streaming
#define OUTPUT_TERMINAL_ASSOCIATION 0x00 // No association
#define OUTPUT_TERMINAL_SOURCE_ID 0x02 // From Feature Unit Terminal
// Speaker Input Terminal
#define SPK_INPUT_TERMINAL_ID 0x11
#define SPK_INPUT_TERMINAL_TYPE 0x0101 // USB Streaming
#define SPK_INPUT_TERMINAL_ASSOCIATION 0x00 // No association
#define SPK_INPUT_TERMINAL_NB_CHANNELS 0x02 // Two channels - stereo
#define SPK_INPUT_TERMINAL_CHANNEL_CONF 0x0003 // left front and right front
#define SPK_INPUT_TERMINAL_CH_NAME_ID 0x00 // No channel name
// SPK Feature Unit
#define SPK_FEATURE_UNIT_ID 0x12
#define SPK_FEATURE_UNIT_SOURCE_ID 0x11
#define SPK_FEATURE_UNIT_CONTROL_SIZE 0x02 // 2 bytes for each control
#define SPK_FEATURE_UNIT_BMA_CONTROLS_0 0x0001 // Mute
#define SPK_FEATURE_UNIT_BMA_CONTROLS_1 0x0002 // Volume control on left front
#define SPK_FEATURE_UNIT_BMA_CONTROLS_2 0x0002 // Volume control on right front
#define SPK_FEATURE_UNIT_CH_NAME_ID 0x00 // No name
// SPK Output Terminal
#define SPK_OUTPUT_TERMINAL_ID 0x13
#define SPK_OUTPUT_TERMINAL_TYPE 0x0302 // Headphones
#define SPK_OUTPUT_TERMINAL_ASSOCIATION 0x00 // No association
#define SPK_OUTPUT_TERMINAL_SOURCE_ID 0x12 // From Feature Unit
#define SPK_ALT1_AS_NB_ENDPOINT 0x02 // OUT EP and FB EP
//#define SPK_ALT1_AS_NB_ENDPOINT 0x01 // OUT EP
#define SPK_AS_TERMINAL_LINK 0x11 // Unit Id of the speaker input terminal
#define SPK_AS_DELAY 0x04 // Interface delay
#define SPK_AS_FORMAT_TAG 0x0001 // PCM
//Alternate O Audio Streaming (AS) interface descriptor
#define ALT0_AS_INTERFACE_INDEX 0x00 // Index of Std AS interface Alt0
#define ALT0_AS_NB_ENDPOINT 0x00 // Nb of endpoints for alt0 interface
#define ALT0_AS_INTERFACE_CLASS 0x01 // Audio class
#define ALT0_AS_INTERFACE_SUB_CLASS 0x02 // Audio streamn sub class
#define ALT0_AS_INTERFACE_PROTOCOL 0x00 // Unused
//Alternate 1 Audio Streaming (AS) interface descriptor
#define ALT1_AS_INTERFACE_INDEX 0x01 // Index of Std AS interface Alt1
#define ALT1_AS_NB_ENDPOINT 0x01 // Nb of endpoints for alt1 interface
#define ALT1_AS_INTERFACE_CLASS 0x01 // Audio class
#define ALT1_AS_INTERFACE_SUB_CLASS 0x02 // Audio streamn sub class
#define ALT1_AS_INTERFACE_PROTOCOL 0x00 // Unused
//AS general Interface descriptor
#define AS_TERMINAL_LINK 0x03 // Unit Id of the output terminal
#define AS_DELAY 0x01 // Interface delay
#define AS_FORMAT_TAG 0x0001 // PCM Format
// Format type for ALT1
#define FORMAT_TYPE 0x01 // Format TypeI
#define FORMAT_NB_CHANNELS 0x02 // Two Channels
#define FORMAT_FRAME_SIZE 0x03 // 3 bytes per audio sample
#define FORMAT_BIT_RESOLUTION 0x18 // 24 bits per sample
#define FORMAT_SAMPLE_FREQ_NB 0x02 // Two frequency supported
#define FORMAT_LSBYTE_SAMPLE_FREQ_441 0xac44 // 44.1khz
#define FORMAT_LSBYTE_SAMPLE_FREQ_48 0xbb80 // 48khz
#define FORMAT_MSBYTE_SAMPLE_FREQ 0x00 // MsByte
//#define FORMAT_LSBYTE_SAMPLE_FREQ 0x7700 // 96khz
//#define FORMAT_MSBYTE_SAMPLE_FREQ 0x01 // MsByte
//Audio endpoint specific descriptor field
#define AUDIO_EP_ATRIBUTES 0x01 // sampling freq, no pitch, no pading
#define AUDIO_EP_DELAY_UNIT 0x00 // Unused
#define AUDIO_EP_LOCK_DELAY 0x0000 // Unused
typedef
#if (defined __ICCAVR32__)
#pragma pack(1)
#endif
struct
#if (defined __GNUC__)
__attribute__((__packed__))
#endif
{
S_usb_configuration_descriptor cfg;
S_usb_interface_descriptor ifc0;
/*
S_usb_interface_descriptor ifc1;
S_usb_hid_descriptor hid;
S_usb_endpoint_descriptor ep1;
S_usb_endpoint_descriptor ep2;
*/
S_usb_interface_association_descriptor iad1;
S_usb_interface_descriptor ifc2;
S_usb_ac_interface_descriptor_1 audioac;
S_usb_in_ter_descriptor_1 mic_in_ter;
S_usb_feature_unit_descriptor_1 mic_fea_unit;
S_usb_out_ter_descriptor_1 mic_out_ter;
S_usb_in_ter_descriptor_1 spk_in_ter;
S_usb_feature_unit_descriptor_1 spk_fea_unit;
S_usb_out_ter_descriptor_1 spk_out_ter;
S_usb_as_interface_descriptor spk_as_alt0;
S_usb_as_interface_descriptor spk_as_alt1;
S_usb_as_g_interface_descriptor_1 spk_g_as;
S_usb_format_type_1 spk_format_type;
S_usb_endpoint_audio_descriptor_1 ep3;
S_usb_endpoint_audio_specific_1 ep3_s;
S_usb_endpoint_audio_descriptor_1 ep4;
S_usb_as_interface_descriptor mic_as_alt0;
S_usb_as_interface_descriptor mic_as_alt1;
S_usb_as_g_interface_descriptor_1 mic_g_as;
S_usb_format_type_1 mic_format_type;
S_usb_endpoint_audio_descriptor_1 ep5;
S_usb_endpoint_audio_specific_1 ep5_s;
}
#if (defined __ICCAVR32__)
#pragma pack()
#endif
S_usb_user_configuration_descriptor;
typedef
#if (defined __ICCAVR32__)
#pragma pack(1)
#endif
struct
#if (defined __GNUC__)
__attribute__((__packed__))
#endif
{
S_usb_configuration_descriptor cfg;
S_usb_interface_descriptor ifc0;
/*
S_usb_interface_descriptor ifc1;
S_usb_hid_descriptor hid;
S_usb_endpoint_descriptor ep1;
S_usb_endpoint_descriptor ep2;
*/
S_usb_interface_association_descriptor iad1;
S_usb_interface_descriptor ifc2;
S_usb_ac_interface_descriptor_1 audioac;
S_usb_in_ter_descriptor_1 mic_in_ter;
S_usb_feature_unit_descriptor_1 mic_fea_unit;
S_usb_out_ter_descriptor_1 mic_out_ter;
S_usb_in_ter_descriptor_1 spk_in_ter;
S_usb_feature_unit_descriptor_1 spk_fea_unit;
S_usb_out_ter_descriptor_1 spk_out_ter;
S_usb_as_interface_descriptor spk_as_alt0;
S_usb_as_interface_descriptor spk_as_alt1;
S_usb_as_g_interface_descriptor_1 spk_g_as;
S_usb_format_type_1_one_freq spk_format_type;
S_usb_endpoint_audio_descriptor_1 ep3;
S_usb_endpoint_audio_specific_1 ep3_s;
S_usb_endpoint_audio_descriptor_1 ep4;
S_usb_as_interface_descriptor mic_as_alt0;
S_usb_as_interface_descriptor mic_as_alt1;
S_usb_as_g_interface_descriptor_1 mic_g_as;
S_usb_format_type_1_one_freq mic_format_type;
S_usb_endpoint_audio_descriptor_1 ep5;
S_usb_endpoint_audio_specific_1 ep5_s;
}
#if (defined __ICCAVR32__)
#pragma pack()
#endif
S_usb_user_configuration_descriptor_one_freq;
extern const S_usb_device_descriptor uac1_audio_usb_dev_desc;
extern const S_usb_device_descriptor uac1_dg8saq_usb_dev_desc;
extern const S_usb_device_qualifier_descriptor uac1_usb_qualifier_desc;
extern const S_usb_user_configuration_descriptor uac1_usb_conf_desc_fs;
extern const S_usb_user_configuration_descriptor_one_freq uac1_usb_conf_desc_fs_widget;
extern const S_usb_user_configuration_descriptor uac1_usb_conf_desc_hs;
extern const S_usb_user_configuration_descriptor_one_freq uac1_usb_conf_desc_hs_widget;
extern const S_usb_device_qualifier_descriptor uac1_usb_qualifier_desc;
#endif // _UAC1_USB_DESCRIPTORS_H_