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
uac2_usb_descriptors.h
Go to the documentation of this file.
1 /* -*- mode: c++; tab-width: 4; c-basic-offset: 4 -*- */
2 /*
3 * Copyright (C) Alex Lee
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 * Modified by Alex Lee 20 Feb 2010
20 * To enumerate as a USB composite device with 4 interfaces:
21 * CDC
22 * HID (generic HID interface, compatible with Jan Axelson's generichid.exe test programs
23 * DG8SAQ (libusb API compatible interface for implementing DG8SAQ EP0 type of interface)
24 * Audio (USB Audio Class V2)
25 *
26 * For SDR-Widget and SDR-Widget-lite, custom boards based on the AT32UC3A3256
27 *
28 * See http://code.google.com/p/sdr-widget/
29 *
30 */
31
32 #ifndef _UAC2_USB_DESCRIPTORS_H_
33 #define _UAC2_USB_DESCRIPTORS_H_
34
35
36 //_____ I N C L U D E S ____________________________________________________
37
38 #include "conf_usb.h"
39 #include "usb_descriptors.h"
40
41 #if USB_DEVICE_FEATURE == DISABLED
42 #error uac2_usb_descriptors.h is #included although USB_DEVICE_FEATURE is disabled
43 #endif
44
45
46 #include "usb_standard_request.h"
47 #include "usb_task.h"
48
49 //_____ U S B D E F I N E S _____________________________________________
50
51
52 // CONFIGURATION
53 #define NB_INTERFACE 4
54 #define CONF_NB 1
55 #define CONF_INDEX 0
56 #define CONF_ATTRIBUTES USB_CONFIG_SELFPOWERED
57 #define MAX_POWER 200 // 400 mA
58
59 // IAD for Audio
60 #define FIRST_INTERFACE1 1
61 #define INTERFACE_COUNT1 3
62 #define FUNCTION_CLASS AUDIO_CLASS
63 #define FUNCTION_SUB_CLASS 0
64 #define FUNCTION_PROTOCOL IP_VERSION_02_00
65 #define FUNCTION_INDEX 0
66
67
68 // USB DG8SAQ Interface descriptor
69 #define INTERFACE_NB0 0
70 #define ALTERNATE_NB0 0
71 #define NB_ENDPOINT0 0
72 #define INTERFACE_CLASS0 NO_CLASS
73 #define INTERFACE_SUB_CLASS0 NO_SUBCLASS
74 #define INTERFACE_PROTOCOL0 NO_PROTOCOL
75 #define INTERFACE_INDEX0 0
76
77 #define DSC_INTERFACE_DG8SAQ INTERFACE_NB0
78
79
80 // Audio Class V2.0 descriptor values
81
82 // Standard Audio Control (AC) interface descriptor
83 #define INTERFACE_NB1 1
84 #define ALTERNATE_NB1 0
85 #define NB_ENDPOINT1 0
86 #define INTERFACE_CLASS1 AUDIO_CLASS
87 #define INTERFACE_SUB_CLASS1 AUDIO_INTERFACE_SUBCLASS_AUDIOCONTROL
88 #define INTERFACE_PROTOCOL1 IP_VERSION_02_00
89 #define INTERFACE_INDEX1 WL_INDEX
90
91 #define DSC_INTERFACE_AUDIO INTERFACE_NB1
92
93
94 // USB Endpoint 1 descriptor
95 #define ENDPOINT_NB_1 ( UAC2_EP_AUDIO_IN | MSK_EP_DIR )
96 #define EP_ATTRIBUTES_1 0b00100101 // ISOCHROUNOUS ASYNCHRONOUS IMPLICIT FEEDBACK
97 #define EP_IN_LENGTH_1_FS 294 // 3 bytes * 49 samples * stereo
98 #define EP_IN_LENGTH_1_HS 294
99 #define EP_SIZE_1_FS EP_IN_LENGTH_1_FS
100 #define EP_SIZE_1_HS EP_IN_LENGTH_1_HS
101 #define EP_INTERVAL_1_FS 0x01 // one packet per uframe, each uF 1ms, so only 48khz
102 #define EP_INTERVAL_1_HS 0x02 // One packet per 2 uframe, each uF 125us, so 192khz
103
104
105 // USB Endpoint 2 descriptor
106 #define ENDPOINT_NB_2 ( UAC2_EP_AUDIO_OUT )
107 #define EP_ATTRIBUTES_2 0b00000101 // ISOCHRONOUS ASYNC
108 #define EP_OUT_LENGTH_2_HS 294 // 3 bytes * 49 samples * stereo
109 #define EP_OUT_LENGTH_2_FS 294
110 #define EP_SIZE_2_FS EP_OUT_LENGTH_2_FS
111 #define EP_SIZE_2_HS EP_OUT_LENGTH_2_HS
112 #define EP_INTERVAL_2_FS 0x01 // one packet per uframe
113 #define EP_INTERVAL_2_HS 0x02 // One packet per 2 uframe
114
115
116 // USB Endpoint 3 descriptor
117 #define ENDPOINT_NB_3 ( UAC2_EP_AUDIO_OUT_FB | MSK_EP_DIR ) // 0x83
118 #define EP_ATTRIBUTES_3 0b00010001 // ISOCHRONOUS FEEDBACK
119 #define EP_IN_LENGTH_3_FS 64 //
120 #define EP_IN_LENGTH_3_HS 64 //
121 #define EP_SIZE_3_FS EP_IN_LENGTH_3_FS
122 #define EP_SIZE_3_HS EP_IN_LENGTH_3_HS
123 #define EP_INTERVAL_3_FS 0x01
124 #define EP_INTERVAL_3_HS 0x04
125 #define EP_REFRESH_3_FS 0x05 // 16ms
126 #define EP_REFRESH_3_HS 0x08 // 2^(8-1) = 128 uframe = 16ms
127
128 // AC interface descriptor Audio specific
129 #define AUDIO_CLASS_REVISION_2 0x0200
130 #define MIC_CATEGORY AUDIO_FUNCTION_SUBCLASS_MICROPHONE
131 #define HEADSET_CATEGORY 0x04
132 #define MIC_LATENCY_CONTROL 0b00000000
133
134 // Clock Source descriptor
135 #define CSD_ID_1 0x04
136 #define CSD_ID_1_TYPE 0b00000001 // fixed freq internal clock
137 #define CSD_ID_1_CONTROL 0b00000111 // freq r/w, validity r
138 #define CSD_ID_2 0x05
139 #define CSD_ID_2_TYPE 0b00000001 // fixed freq internal clock
140 #define CSD_ID_2_CONTROL 0b00000111 // freq r/w, validity r
141
142 // Clock Selector descriptor
143 #define CSX_ID 0x06
144 #define CSX_INPUT_PINS 0x02
145 #define CSX_SOURCE_1 CSD_ID_1
146 #define CSX_SOURCE_2 CSD_ID_2
147 #define CSX_CONTROL 0b00000011 // clock selector is readable and writable
148
149
150 // Input Terminal descriptor
151 #define INPUT_TERMINAL_ID 0x01
152 #define INPUT_TERMINAL_TYPE 0x0201 // Terminal is microphone
153 #define INPUT_TERMINAL_ASSOCIATION 0x00 // No association
154 #define INPUT_TERMINAL_NB_CHANNELS 0x02 // Two channels for input terminal
155 #define INPUT_TERMINAL_CHANNEL_CONF 0x00000003 // Two channels at front left and front right positions
156 //#define INPUT_TERMINAL_CONTROLS 0x0040 // D7-6 Cluster control - readonly
157 #define INPUT_TERMINAL_CONTROLS 0x0000 // none
158 #define INPUT_TERMINAL_CH_NAME_ID 0x00 // No channel name
159 #define INPUT_TERMINAL_STRING_DESC 0x00 // No string descriptor
160
161 // Output Terminal descriptor
162 #define OUTPUT_TERMINAL_ID 0x03
163 #define OUTPUT_TERMINAL_TYPE 0x0101 // USB Streaming
164 #define OUTPUT_TERMINAL_ASSOCIATION 0x00 // No association
165 #define OUTPUT_TERMINAL_SOURCE_ID MIC_FEATURE_UNIT_ID
166 #define OUTPUT_TERMINAL_CONTROLS 0x0000 // no controls
167
168
169 //MIC Feature Unit descriptor
170 #define MIC_FEATURE_UNIT_ID 0x02
171 #define MIC_FEATURE_UNIT_SOURCE_ID INPUT_TERMINAL_ID
172 #define MIC_BMA_CONTROLS 0x00000003 // Mute readable and writable
173 #define MIC_BMA_CONTROLS_CH_1 0x00000003 //
174 #define MIC_BMA_CONTROLS_CH_2 0x00000003
175
176 // Speaker Input Terminal
177 #define SPK_INPUT_TERMINAL_ID 0x11
178 #define SPK_INPUT_TERMINAL_TYPE 0x0101 // USB Streaming
179 #define SPK_INPUT_TERMINAL_ASSOCIATION 0x00 // No association
180 #define SPK_INPUT_TERMINAL_NB_CHANNELS 0x02
181 #define SPK_INPUT_TERMINAL_CHANNEL_CONF 0x0003 // left front and right front
182 #define SPK_INPUT_TERMINAL_CH_NAME_ID 0x00 // No channel name
183
184 //SPK Feature Unit descriptor
185 #define SPK_FEATURE_UNIT_ID 0x12
186 #define SPK_FEATURE_UNIT_SOURCE_ID SPK_INPUT_TERMINAL_ID
187 #define SPK_BMA_CONTROLS 0x00000003 // Mute readable and writable
188 #define SPK_BMA_CONTROLS_CH_1 0x00000003 //
189 #define SPK_BMA_CONTROLS_CH_2 0x00000003
190
191 // SPK Output Terminal descriptor
192 #define SPK_OUTPUT_TERMINAL_ID 0x13
193 #define SPK_OUTPUT_TERMINAL_TYPE 0x0302 // Headphones
194 #define SPK_OUTPUT_TERMINAL_ASSOCIATION 0x00 // No association
195 #define SPK_OUTPUT_TERMINAL_SOURCE_ID SPK_FEATURE_UNIT_ID
196 #define SPK_OUTPUT_TERMINAL_CONTROLS 0x0000 // no controls
197
198 //Audio Streaming (AS) interface descriptor
199 #define STD_AS_INTERFACE_IN 0x02 // Index of Std AS Interface for Audio In
200 #define STD_AS_INTERFACE_OUT 0x03 // Index of Std AS Interface for Audio Out
201
202 #define DSC_INTERFACE_AS STD_AS_INTERFACE_IN
203 #define DSC_INTERFACE_AS_OUT STD_AS_INTERFACE_OUT
204
205
206 //Alternate O Audio Streaming (AS) interface descriptor
207 #define ALT0_AS_INTERFACE_INDEX 0x00 // Index of Std AS interface Alt0
208 #define ALT0_AS_NB_ENDPOINT 0x00 // Nb of endpoints for alt0 interface
209 #define ALT0_AS_INTERFACE_CLASS 0x01 // Audio class
210 #define ALT0_AS_INTERFACE_SUB_CLASS 0x02 // Audio streamn sub class
211 #define ALT0_AS_INTERFACE_PROTOCOL IP_VERSION_02_00
212
213
214 //Alternate 1 Audio Streaming (AS) interface descriptor
215 #define ALT1_AS_INTERFACE_INDEX 0x01 // Index of Std AS interface Alt1
216 #define ALT1_AS_NB_ENDPOINT 0x01 // Nb of endpoints for alt1 interface
217 #define ALT1_AS_INTERFACE_CLASS 0x01 // Audio class
218 #define ALT1_AS_INTERFACE_SUB_CLASS 0x02 // Audio streamn sub class
219 #define ALT1_AS_INTERFACE_PROTOCOL IP_VERSION_02_00
220
221
222 //Alternate 2 Audio Streaming (AS) interface descriptor
223 #define ALT2_AS_INTERFACE_INDEX 0x02 // Index of Std AS interface Alt2
224 #define ALT2_AS_NB_ENDPOINT 0x01 // Nb of endpoints for alt2 interface
225 #define ALT2_AS_INTERFACE_CLASS 0x01 // Audio class
226 #define ALT2_AS_INTERFACE_SUB_CLASS 0x02 // Audio streamn sub class
227 #define ALT2_AS_INTERFACE_PROTOCOL IP_VERSION_02_00
228
229
230 //Class Specific AS (general) Interface descriptor
231 #define AS_TERMINAL_LINK OUTPUT_TERMINAL_ID // Unit Id of the output terminal
232 #define AS_DELAY 0x01 // Interface delay
233 #define AS_FORMAT_TYPE 0x01 // PCM Format
234 #define AS_FORMATS 0x00000001 // PCM only
235 #define AS_CONTROLS 0b00000111 // active alt settings r/w, valid alt settings r
236 #define AS_NB_CHANNELS 0x02
237 #define AS_CHAN_CONFIG 0x00000003 // L+R front
238
239 // Format type for ALT1
240 #define FORMAT_TYPE_1 0x01 // Format TypeI
241 #define FORMAT_SUBSLOT_SIZE_1 0x03 // Number of bytes per subslot
242 #define FORMAT_BIT_RESOLUTION_1 0x18 // 24 bits per sample
243
244 //Audio endpoint specific descriptor field
245 #define AUDIO_EP_ATRIBUTES 0b00000000 // No sampling freq, no pitch, no pading
246 #define AUDIO_EP_CONTROLS 0b00000000
247 #define AUDIO_EP_DELAY_UNIT 0x00 // Unused
248 #define AUDIO_EP_LOCK_DELAY 0x0000 // Unused
249
250 //For playback
251 #define ALT1_AS_NB_ENDPOINT_OUT 0x02 // two EP, OUT and OUT_FB
252 #define AS_TERMINAL_LINK_OUT SPK_INPUT_TERMINAL_ID
253
255
256 typedef
257 #if (defined __ICCAVR32__)
258 #pragma pack(1)
259 #endif
260 struct
261 #if (defined __GNUC__)
262 __attribute__((__packed__))
263 #endif
264 {
265 S_usb_configuration_descriptor cfg;
266 S_usb_interface_descriptor ifc0;
267
269
270 S_usb_interface_association_descriptor iad1;
271 S_usb_interface_descriptor ifc1;
272 S_usb_ac_interface_descriptor_2 audioac;
273 S_usb_clock_source_descriptor audio_cs1;
274 S_usb_clock_source_descriptor audio_cs2;
275 S_usb_clock_selector_descriptor audio_csel;
276 // S_usb_clock_multiplier_descriptor audio_cmul;
277 S_usb_in_ter_descriptor_2 mic_in_ter;
278 S_usb_feature_unit_descriptor_2 mic_fea_unit;
279 S_usb_out_ter_descriptor_2 mic_out_ter;
280 S_usb_in_ter_descriptor_2 spk_in_ter;
281 S_usb_feature_unit_descriptor_2 spk_fea_unit;
282 S_usb_out_ter_descriptor_2 spk_out_ter;
283 S_usb_as_interface_descriptor mic_as_alt0;
284 S_usb_as_interface_descriptor mic_as_alt1;
285 S_usb_as_g_interface_descriptor_2 mic_g_as;
286 S_usb_format_type_2 mic_format_type;
287 S_usb_endpoint_audio_descriptor_2 ep1;
288 S_usb_endpoint_audio_specific_2 ep1_s;
289 S_usb_as_interface_descriptor spk_as_alt0;
290 S_usb_as_interface_descriptor spk_as_alt1;
291 S_usb_as_g_interface_descriptor_2 spk_g_as;
292 S_usb_format_type_2 spk_format_type;
293 S_usb_endpoint_audio_descriptor_2 ep2;
294 S_usb_endpoint_audio_specific_2 ep2_s;
295 S_usb_endpoint_audio_descriptor_2 ep3;
296 }
297 #if (defined __ICCAVR32__)
298 #pragma pack()
299 #endif
300 S_usb_user_configuration_descriptor;
301
302 extern const S_usb_device_descriptor uac2_dg8saq_usb_dev_desc;
303 extern const S_usb_device_descriptor uac2_audio_usb_dev_desc;
304 extern const S_usb_user_configuration_descriptor uac2_usb_conf_desc_fs;
305 extern const S_usb_user_configuration_descriptor uac2_usb_conf_desc_hs;
306 extern const S_usb_device_qualifier_descriptor uac2_usb_qualifier_desc;
307
308 #endif // _UAC2_USB_DESCRIPTORS_H_