Sonochan II 0.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
uac1_usb_descriptors.h
Go to the documentation of this file.
1 /* -*- mode: c++; tab-width: 4; c-basic-offset: 4 -*- */
2 /*
3 *
4 * Copyright (C) Alex Lee 2010, 2011
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 *
20 * Modified by Alex Lee 20 Feb 2010
21 * To enumerate as a USB composite device with 4 interfaces:
22 * CDC
23 * HID (generic HID interface, compatible with Jan Axelson's generichid.exe test programs
24 * DG8SAQ (libusb API compatible interface for implementing DG8SAQ EP0 type of interface)
25 * Audio (USB Audio Class V2)
26 *
27 * For SDR-Widget and SDR-Widget-lite, custom boards based on the AT32UC3A3256
28 *
29 * See http://code.google.com/p/sdr-widget/
30 *
31 * Rearranged by Roger Critchlow 21 Feb 2011.
32 */
33
34 #ifndef _UAC1_DESCRIPTORS_H_
35 #define _UAC1_DESCRIPTORS_H_
36
37
38 //_____ I N C L U D E S ____________________________________________________
39
40 #include "conf_usb.h"
41
42
43 #if USB_DEVICE_FEATURE == DISABLED
44 #error uac1_descriptors.h is #included although USB_DEVICE_FEATURE is disabled
45 #endif
46
47 #include "usb_standard_request.h"
48 #include "usb_task.h"
49 #include "usb_descriptors.h"
50 #include "hid.h"
51
52 //_____ M A C R O S ________________________________________________________
53
54
55 //_____ U S B D E F I N E S _____________________________________________
56
57
58 // CONFIGURATION
59 #define NB_INTERFACE 4
60 #define CONF_NB 1
61 #define CONF_INDEX 0
62 #define CONF_ATTRIBUTES USB_CONFIG_SELFPOWERED
63 #define MAX_POWER 130 // 260 mA
64
65
66
67 // IAD for Audio
68 #define FIRST_INTERFACE1 1
69 #define INTERFACE_COUNT1 3
70
71 //Audio Streaming (AS) interface descriptor
72 #define STD_AS_INTERFACE_OUT 0x02
73 #define STD_AS_INTERFACE_IN 0x03
74
75
76 // USB HID Interface descriptor
77 #define INTERFACE_NB0 0
78 #define ALTERNATE_NB0 0
79 #define NB_ENDPOINT0 2
80 #define INTERFACE_CLASS0 HID_CLASS
81 #define INTERFACE_SUB_CLASS0 NO_SUBCLASS
82 #define INTERFACE_PROTOCOL0 NO_PROTOCOL
83 #define INTERFACE_INDEX0 0
84
85 #define DSC_INTERFACE_HID INTERFACE_NB0
86
87 // HID descriptor
88 #define HID_VERSION 0x0111
89 #define HID_COUNTRY_CODE 0x00
90 #define HID_NUM_DESCRIPTORS 0x01
91
92 // USB Endpoint 1 descriptor
93 #define ENDPOINT_NB_1 (UAC1_EP_HID_TX| MSK_EP_DIR)
94 #define EP_ATTRIBUTES_1 TYPE_INTERRUPT
95 #define EP_IN_LENGTH_1_FS 8
96 #define EP_SIZE_1_FS EP_IN_LENGTH_1_FS
97 #define EP_IN_LENGTH_1_HS 8
98 #define EP_SIZE_1_HS EP_IN_LENGTH_1_HS
99 #define EP_INTERVAL_1 5
100
101 // USB Endpoint 2 descriptor
102 #define ENDPOINT_NB_2 (UAC1_EP_HID_RX)
103 #define EP_ATTRIBUTES_2 TYPE_INTERRUPT
104 #define EP_OUT_LENGTH_2_FS 8
105 #define EP_SIZE_2_FS EP_OUT_LENGTH_2_FS
106 #define EP_OUT_LENGTH_2_HS 8
107 #define EP_SIZE_2_HS EP_OUT_LENGTH_2_HS
108 #define EP_INTERVAL_2 5
109
110 // Standard Audio Control (AC) interface descriptor
111 #define INTERFACE_NB2 1
112 #define ALTERNATE_NB2 0
113 #define NB_ENDPOINT2 0
114 #define INTERFACE_CLASS2 AUDIO_CLASS
115 #define INTERFACE_SUB_CLASS2 0x01
116 #define INTERFACE_PROTOCOL2 0x00
117 #define INTERFACE_INDEX2 0
118
119 #define DSC_INTERFACE_AUDIO INTERFACE_NB2
120
121 // USB Endpoint 3 descriptor
122 #define ENDPOINT_NB_3 ( UAC1_EP_AUDIO_OUT )
123 #define EP_ATTRIBUTES_3 0b00000101 // ISOCHRONOUS ASYNCHRONOUS EXPLICIT FEEDBACK
124 //#define EP_ATTRIBUTES_3 0b00001101 // ISOCHRONOUS SYNCHRONOUS
125 #define EP_IN_LENGTH_3_HS 308 // 3 bytes * 48 khz * stereo + 6 bytes for add sample
126 #define EP_IN_LENGTH_3_FS 308 // 294
127 #define EP_SIZE_3_FS EP_IN_LENGTH_3_FS
128 #define EP_SIZE_3_HS EP_IN_LENGTH_3_HS
129 #define EP_INTERVAL_3_FS 0x01 // one packet per uframe
130 #define EP_INTERVAL_3_HS 0x04 // One packet per 8 uframe
131 #define EP_REFRESH_3_FS 0x01
132 #define EP_REFRESH_3_HS 0x04
133 #define EP_BSYNC_ADDRESS_3 0x84 // feedback EP is EP 4, need to explicitly set it to IN endpoint
134 //#define EP_BSYNC_ADDRESS_3 0x04 // feedback EP is EP 4 - using audio input pipe to sync
135 //#define EP_BSYNC_ADDRESS_3 0x00
136
137
138 /* Note: The EPs have to be re-arranged. Feedback EP has to be immediately following the OUT EP
139 // USB Endpoint 4 descriptor*/
140 #define ENDPOINT_NB_4 ( UAC1_EP_AUDIO_OUT_FB | MSK_EP_DIR )
141 #define EP_ATTRIBUTES_4 0b00010001 // ISOCHROUNOUS FEEDBACK
142 #define EP_IN_LENGTH_4_FS 3 // 3 bytes
143 #define EP_IN_LENGTH_4_HS 4 // 4 bytes
144 #define EP_SIZE_4_FS EP_IN_LENGTH_4_FS
145 #define EP_SIZE_4_HS EP_IN_LENGTH_4_HS
146 #define EP_INTERVAL_4_FS 0x01
147 #define EP_INTERVAL_4_HS 0x04
148 #define EP_REFRESH_4_FS 0x05 // 64ms
149 #define EP_REFRESH_4_HS 0x05 // 2^(10-1) = 512 uframe = 64ms
150
151 // USB Endpoint 5 descriptor
152 #define ENDPOINT_NB_5 ( UAC1_EP_AUDIO_IN | MSK_EP_DIR )
153 #define EP_ATTRIBUTES_5 0b00100101 // ISOCHROUNOUS ASYNCHRONOUS IMPLICIT FEEDBACK
154 #define EP_IN_LENGTH_5_HS 308 // 3 bytes * 48 khz * stereo + 6 bytes for add sample
155 #define EP_IN_LENGTH_5_FS 308
156 #define EP_SIZE_5_FS EP_IN_LENGTH_5_FS
157 #define EP_SIZE_5_HS EP_IN_LENGTH_5_HS
158 #define EP_INTERVAL_5_FS 0x01 // one packet per uframe
159 #define EP_INTERVAL_5_HS 0x04 // One packet per 8 uframe
160
161 // AC interface descriptor Audio specific
162 #define AUDIO_CLASS_REVISION 0x0100
163 #define NB_OF_STREAMING_INTERFACE 0x02 // one for speaker out, one for mic in
164 #define BELONGS_AUDIO_INTERFACE_OUT STD_AS_INTERFACE_OUT
165 #define BELONGS_AUDIO_INTERFACE_IN STD_AS_INTERFACE_IN
166
167 // Input Terminal descriptor
168 #define INPUT_TERMINAL_ID 0x01
169 #define INPUT_TERMINAL_TYPE 0x0201 // Terminal is microphone
170 #define INPUT_TERMINAL_ASSOCIATION 0x00 // No association
171 #define INPUT_TERMINAL_NB_CHANNELS 0x02 // Two channels for input terminal
172 #define INPUT_TERMINAL_CHANNEL_CONF 0x0003 // Two channels at front left and front right positions
173 #define INPUT_TERMINAL_CH_NAME_ID 0x00 // No channel name
174
175 //MIC Feature Unit descriptor
176 #define MIC_FEATURE_UNIT_ID 0x02
177 #define MIC_FEATURE_UNIT_SOURCE_ID 0x01
178 #define MIC_FEATURE_UNIT_CONTROL_SIZE 0x02 // 2 bytes for each control
179 #define MIC_BMA_CONTROLS_0 0x0001 // Mute for master channel
180 #define MIC_BMA_CONTROLS_1 0x0002 // Volume control on left channel
181 #define MIC_BMA_CONTROLS_2 0x0002 // Volume control on right channel
182 #define MIC_FEATURE_UNIT_CH_NAME_ID 0x00
183
184 // Output Terminal descriptor
185 #define OUTPUT_TERMINAL_ID 0x03
186 #define OUTPUT_TERMINAL_TYPE 0x0101 // USB Streaming
187 #define OUTPUT_TERMINAL_ASSOCIATION 0x00 // No association
188 #define OUTPUT_TERMINAL_SOURCE_ID 0x02 // From Feature Unit Terminal
189
190 // Speaker Input Terminal
191 #define SPK_INPUT_TERMINAL_ID 0x11
192 #define SPK_INPUT_TERMINAL_TYPE 0x0101 // USB Streaming
193 #define SPK_INPUT_TERMINAL_ASSOCIATION 0x00 // No association
194 #define SPK_INPUT_TERMINAL_NB_CHANNELS 0x02 // Two channels - stereo
195 #define SPK_INPUT_TERMINAL_CHANNEL_CONF 0x0003 // left front and right front
196 #define SPK_INPUT_TERMINAL_CH_NAME_ID 0x00 // No channel name
197
198 // SPK Feature Unit
199 #define SPK_FEATURE_UNIT_ID 0x12
200 #define SPK_FEATURE_UNIT_SOURCE_ID 0x11
201 #define SPK_FEATURE_UNIT_CONTROL_SIZE 0x02 // 2 bytes for each control
202 #define SPK_FEATURE_UNIT_BMA_CONTROLS_0 0x0001 // Mute
203 #define SPK_FEATURE_UNIT_BMA_CONTROLS_1 0x0002 // Volume control on left front
204 #define SPK_FEATURE_UNIT_BMA_CONTROLS_2 0x0002 // Volume control on right front
205 #define SPK_FEATURE_UNIT_CH_NAME_ID 0x00 // No name
206
207 // SPK Output Terminal
208 #define SPK_OUTPUT_TERMINAL_ID 0x13
209 #define SPK_OUTPUT_TERMINAL_TYPE 0x0302 // Headphones
210 #define SPK_OUTPUT_TERMINAL_ASSOCIATION 0x00 // No association
211 #define SPK_OUTPUT_TERMINAL_SOURCE_ID 0x12 // From Feature Unit
212
213 #define SPK_ALT1_AS_NB_ENDPOINT 0x02 // OUT EP and FB EP
214 //#define SPK_ALT1_AS_NB_ENDPOINT 0x01 // OUT EP
215
216 #define SPK_AS_TERMINAL_LINK 0x11 // Unit Id of the speaker input terminal
217 #define SPK_AS_DELAY 0x04 // Interface delay
218 #define SPK_AS_FORMAT_TAG 0x0001 // PCM
219
220 //Alternate O Audio Streaming (AS) interface descriptor
221 #define ALT0_AS_INTERFACE_INDEX 0x00 // Index of Std AS interface Alt0
222 #define ALT0_AS_NB_ENDPOINT 0x00 // Nb of endpoints for alt0 interface
223 #define ALT0_AS_INTERFACE_CLASS 0x01 // Audio class
224 #define ALT0_AS_INTERFACE_SUB_CLASS 0x02 // Audio streamn sub class
225 #define ALT0_AS_INTERFACE_PROTOCOL 0x00 // Unused
226
227 //Alternate 1 Audio Streaming (AS) interface descriptor
228 #define ALT1_AS_INTERFACE_INDEX 0x01 // Index of Std AS interface Alt1
229 #define ALT1_AS_NB_ENDPOINT 0x01 // Nb of endpoints for alt1 interface
230 #define ALT1_AS_INTERFACE_CLASS 0x01 // Audio class
231 #define ALT1_AS_INTERFACE_SUB_CLASS 0x02 // Audio streamn sub class
232 #define ALT1_AS_INTERFACE_PROTOCOL 0x00 // Unused
233
234 //AS general Interface descriptor
235 #define AS_TERMINAL_LINK 0x03 // Unit Id of the output terminal
236 #define AS_DELAY 0x01 // Interface delay
237 #define AS_FORMAT_TAG 0x0001 // PCM Format
238 // Format type for ALT1
239 #define FORMAT_TYPE 0x01 // Format TypeI
240 #define FORMAT_NB_CHANNELS 0x02 // Two Channels
241 #define FORMAT_FRAME_SIZE 0x03 // 3 bytes per audio sample
242 #define FORMAT_BIT_RESOLUTION 0x18 // 24 bits per sample
243 #define FORMAT_SAMPLE_FREQ_NB 0x08 // 8 frequency supported
244 #define FORMAT_LSBYTE_SAMPLE_FREQ_8 8000 // 8 kHz
245 #define FORMAT_LSBYTE_SAMPLE_FREQ_11025 11025 // 11 025 Hz
246 #define FORMAT_LSBYTE_SAMPLE_FREQ_16 16000 // 16 kHz
247 #define FORMAT_LSBYTE_SAMPLE_FREQ_2205 22050 // 22 050 Hz
248 #define FORMAT_LSBYTE_SAMPLE_FREQ_24 24000 // 24 kHz
249 #define FORMAT_LSBYTE_SAMPLE_FREQ_32 32000 // 32 kHz
250 #define FORMAT_LSBYTE_SAMPLE_FREQ_441 0xac44 // 44.1kHz
251 #define FORMAT_LSBYTE_SAMPLE_FREQ_48 0xbb80 // 48kHz
252 #define FORMAT_MSBYTE_SAMPLE_FREQ 0x00 // MsByte
253 //#define FORMAT_LSBYTE_SAMPLE_FREQ 0x7700 // 96khz
254 //#define FORMAT_MSBYTE_SAMPLE_FREQ 0x01 // MsByte
255
256
257 //Audio endpoint specific descriptor field
258 #define AUDIO_EP_ATRIBUTES 0x01 // sampling freq, no pitch, no pading
259 #define AUDIO_EP_DELAY_UNIT 0x00 // Unused
260 #define AUDIO_EP_LOCK_DELAY 0x0000 // Unused
261
262 typedef
263 #if (defined __ICCAVR32__)
264 #pragma pack(1)
265 #endif
266 struct
267 #if (defined __GNUC__)
268 __attribute__((__packed__))
269 #endif
270 {
271 S_usb_configuration_descriptor cfg;
272 S_usb_interface_descriptor ifc0;
273
274 //[Martin] HID commented
275 S_usb_hid_descriptor hid;
276 S_usb_endpoint_descriptor ep1;
277 S_usb_endpoint_descriptor ep2;
278
279 S_usb_interface_association_descriptor iad1;
280 S_usb_interface_descriptor ifc2;
281 S_usb_ac_interface_descriptor_1 audioac;
282 S_usb_in_ter_descriptor_1 mic_in_ter;
283 S_usb_feature_unit_descriptor_1 mic_fea_unit;
284 S_usb_out_ter_descriptor_1 mic_out_ter;
285 S_usb_in_ter_descriptor_1 spk_in_ter;
286 S_usb_feature_unit_descriptor_1 spk_fea_unit;
287 S_usb_out_ter_descriptor_1 spk_out_ter;
288 S_usb_as_interface_descriptor spk_as_alt0;
289 S_usb_as_interface_descriptor spk_as_alt1;
290 S_usb_as_g_interface_descriptor_1 spk_g_as;
291 S_usb_format_type_1 spk_format_type;
292 S_usb_endpoint_audio_descriptor_1 ep3;
293 S_usb_endpoint_audio_specific_1 ep3_s;
294 S_usb_endpoint_audio_descriptor_1 ep4;
295 S_usb_as_interface_descriptor mic_as_alt0;
296 S_usb_as_interface_descriptor mic_as_alt1;
297 S_usb_as_g_interface_descriptor_1 mic_g_as;
298 S_usb_format_type_1 mic_format_type;
299 S_usb_endpoint_audio_descriptor_1 ep5;
300 S_usb_endpoint_audio_specific_1 ep5_s;
301 }
302 #if (defined __ICCAVR32__)
303 #pragma pack()
304 #endif
305 S_usb_user_configuration_descriptor;
306
307 typedef
308 #if (defined __ICCAVR32__)
309 #pragma pack(1)
310 #endif
311 struct
312 #if (defined __GNUC__)
313 __attribute__((__packed__))
314 #endif
315 {
316 S_usb_configuration_descriptor cfg;
317 S_usb_interface_descriptor ifc0;
318
319 S_usb_hid_descriptor hid;
320 S_usb_endpoint_descriptor ep1;
321 S_usb_endpoint_descriptor ep2;
322
323 S_usb_interface_association_descriptor iad1;
324 S_usb_interface_descriptor ifc2;
325 S_usb_ac_interface_descriptor_1 audioac;
326 S_usb_in_ter_descriptor_1 mic_in_ter;
327 S_usb_feature_unit_descriptor_1 mic_fea_unit;
328 S_usb_out_ter_descriptor_1 mic_out_ter;
329 S_usb_in_ter_descriptor_1 spk_in_ter;
330 S_usb_feature_unit_descriptor_1 spk_fea_unit;
331 S_usb_out_ter_descriptor_1 spk_out_ter;
332 S_usb_as_interface_descriptor spk_as_alt0;
333 S_usb_as_interface_descriptor spk_as_alt1;
334 S_usb_as_g_interface_descriptor_1 spk_g_as;
335 S_usb_format_type_1_one_freq spk_format_type;
336 S_usb_endpoint_audio_descriptor_1 ep3;
337 S_usb_endpoint_audio_specific_1 ep3_s;
338 S_usb_endpoint_audio_descriptor_1 ep4;
339 S_usb_as_interface_descriptor mic_as_alt0;
340 S_usb_as_interface_descriptor mic_as_alt1;
341 S_usb_as_g_interface_descriptor_1 mic_g_as;
342 S_usb_format_type_1_one_freq mic_format_type;
343 S_usb_endpoint_audio_descriptor_1 ep5;
344 S_usb_endpoint_audio_specific_1 ep5_s;
345 }
346 #if (defined __ICCAVR32__)
347 #pragma pack()
348 #endif
349 S_usb_user_configuration_descriptor_one_freq;
350
351 extern const S_usb_device_descriptor uac1_audio_usb_dev_desc;
352 extern const S_usb_device_qualifier_descriptor uac1_usb_qualifier_desc;
353 extern const S_usb_user_configuration_descriptor uac1_usb_conf_desc_fs;
354 extern const S_usb_user_configuration_descriptor uac1_usb_conf_desc_hs;
355 extern const S_usb_device_qualifier_descriptor uac1_usb_qualifier_desc;
356
357 #endif // _UAC1_USB_DESCRIPTORS_H_