/elec/audio-switcher

To get this branch, use:
bzr branch http://bzr.ed.am/elec/audio-switcher
1 by Tim Marston
initial commit
1
/*
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
2
3
  AUDIO SWITCHER
4
5
  Based on a serial device demonstration from the LUFA project
6
  (www.lufa-lib.org).  LUFA is Copyright (C) Dean Camera, 2012.
7
8
  Changes made to the serial device demonstration program are
9
  Copyright (C) Tim Marston, 2012.
10
11
  For more information:
12
    * see README, or
13
    * visit http://ed.am/
14
1 by Tim Marston
initial commit
15
*/
16
17
/*
18
  Copyright 2012  Dean Camera (dean [at] fourwalledcubicle [dot] com)
19
20
  Permission to use, copy, modify, distribute, and sell this
21
  software and its documentation for any purpose is hereby granted
22
  without fee, provided that the above copyright notice appear in
23
  all copies and that both that the copyright notice and this
24
  permission notice and warranty disclaimer appear in supporting
25
  documentation, and that the name of the author not be used in
26
  advertising or publicity pertaining to distribution of the
27
  software without specific, written prior permission.
28
29
  The author disclaim all warranties with regard to this
30
  software, including all implied warranties of merchantability
31
  and fitness.  In no event shall the author be liable for any
32
  special, indirect or consequential damages or any damages
33
  whatsoever resulting from loss of use, data or profits, whether
34
  in an action of contract, negligence or other tortious action,
35
  arising out of or in connection with the use or performance of
36
  this software.
37
*/
38
39
/** \file
40
 *
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
41
 *  USB Device Descriptors, for library use when in USB device mode.
42
 *  Descriptors are special computer-readable structures which the host
43
 *  requests upon device enumeration, to determine the device's capabilities
44
 *  and functions.
1 by Tim Marston
initial commit
45
 */
46
47
#include "Descriptors.h"
48
49
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
50
/** Device descriptor structure.  This descriptor, located in FLASH memory,
51
 *  describes the overall device characteristics, including the supported USB
52
 *  version, control endpoint size and the number of device configurations.
53
 *  The descriptor is read out by the USB host when the enumeration process
54
 *  begins.
1 by Tim Marston
initial commit
55
 */
56
const USB_Descriptor_Device_t PROGMEM DeviceDescriptor =
57
{
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
58
	.Header                 = {
59
		.Size = sizeof(USB_Descriptor_Device_t),
60
		.Type = DTYPE_Device
61
	},
1 by Tim Marston
initial commit
62
63
	.USBSpecification       = VERSION_BCD(01.10),
64
	.Class                  = CDC_CSCP_CDCClass,
65
	.SubClass               = CDC_CSCP_NoSpecificSubclass,
66
	.Protocol               = CDC_CSCP_NoSpecificProtocol,
67
68
	.Endpoint0Size          = FIXED_CONTROL_ENDPOINT_SIZE,
69
70
	.VendorID               = 0x03EB,
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
71
	.ProductID              = 0xba7f, // 0x2044,
1 by Tim Marston
initial commit
72
	.ReleaseNumber          = VERSION_BCD(00.01),
73
74
	.ManufacturerStrIndex   = 0x01,
75
	.ProductStrIndex        = 0x02,
76
	.SerialNumStrIndex      = USE_INTERNAL_SERIAL,
77
78
	.NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
79
};
80
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
81
/** Configuration descriptor structure. This descriptor, located in FLASH
82
 *  memory, describes the usage of the device in one of its supported
83
 *  configurations, including information about any device interfaces and
84
 *  endpoints.  The descriptor is read out by the USB host during the
85
 *  enumeration process when selecting a configuration so that the host may
86
 *  correctly communicate with the USB device.
1 by Tim Marston
initial commit
87
 */
88
const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
89
{
90
	.Config =
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
91
	{
92
		.Header                 = {
93
			.Size = sizeof(USB_Descriptor_Configuration_Header_t),
94
			.Type = DTYPE_Configuration,
1 by Tim Marston
initial commit
95
		},
96
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
97
		.TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),
98
		.TotalInterfaces        = 2,
99
100
		.ConfigurationNumber    = 1,
101
		.ConfigurationStrIndex  = NO_DESCRIPTOR,
102
103
		.ConfigAttributes       = (USB_CONFIG_ATTR_RESERVED |
104
								   USB_CONFIG_ATTR_SELFPOWERED),
105
106
		.MaxPowerConsumption    = USB_CONFIG_POWER_MA(100),
107
	},
108
1 by Tim Marston
initial commit
109
	.CDC_CCI_Interface =
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
110
	{
111
		.Header                 = {
112
			.Size = sizeof(USB_Descriptor_Interface_t),
113
			.Type = DTYPE_Interface,
1 by Tim Marston
initial commit
114
		},
115
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
116
		.InterfaceNumber        = 0,
117
		.AlternateSetting       = 0,
118
119
		.TotalEndpoints         = 1,
120
121
		.Class                  = CDC_CSCP_CDCClass,
122
		.SubClass               = CDC_CSCP_ACMSubclass,
123
		.Protocol               = CDC_CSCP_ATCommandProtocol,
124
125
		.InterfaceStrIndex      = NO_DESCRIPTOR,
126
	},
127
1 by Tim Marston
initial commit
128
	.CDC_Functional_Header =
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
129
	{
130
		.Header                 = {
131
			.Size = sizeof(USB_CDC_Descriptor_FunctionalHeader_t),
132
			.Type = DTYPE_CSInterface,
1 by Tim Marston
initial commit
133
		},
134
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
135
		.Subtype                = CDC_DSUBTYPE_CSInterface_Header,
136
137
		.CDCSpecification       = VERSION_BCD(01.10),
138
	},
139
1 by Tim Marston
initial commit
140
	.CDC_Functional_ACM =
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
141
	{
142
		.Header                 = {
143
			.Size = sizeof(USB_CDC_Descriptor_FunctionalACM_t),
144
			.Type = DTYPE_CSInterface,
1 by Tim Marston
initial commit
145
		},
146
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
147
		.Subtype                = CDC_DSUBTYPE_CSInterface_ACM,
148
149
		.Capabilities           = 0x06,
150
	},
151
1 by Tim Marston
initial commit
152
	.CDC_Functional_Union =
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
153
	{
154
		.Header                 = {
155
			.Size = sizeof(USB_CDC_Descriptor_FunctionalUnion_t),
156
			.Type = DTYPE_CSInterface,
1 by Tim Marston
initial commit
157
		},
158
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
159
		.Subtype                = CDC_DSUBTYPE_CSInterface_Union,
160
161
		.MasterInterfaceNumber  = 0,
162
		.SlaveInterfaceNumber   = 1,
163
	},
164
1 by Tim Marston
initial commit
165
	.CDC_NotificationEndpoint =
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
166
	{
167
		.Header                 = {
168
			.Size = sizeof(USB_Descriptor_Endpoint_t),
169
			.Type = DTYPE_Endpoint,
1 by Tim Marston
initial commit
170
		},
171
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
172
		.EndpointAddress        = CDC_NOTIFICATION_EPADDR,
173
		.Attributes             = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | 
174
								   ENDPOINT_USAGE_DATA),
175
		.EndpointSize           = CDC_NOTIFICATION_EPSIZE,
176
		.PollingIntervalMS      = 0xFF,
177
	},
178
1 by Tim Marston
initial commit
179
	.CDC_DCI_Interface =
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
180
	{
181
		.Header                 = {
182
			.Size = sizeof(USB_Descriptor_Interface_t),
183
			.Type = DTYPE_Interface,
1 by Tim Marston
initial commit
184
		},
185
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
186
		.InterfaceNumber        = 1,
187
		.AlternateSetting       = 0,
188
189
		.TotalEndpoints         = 2,
190
191
		.Class                  = CDC_CSCP_CDCDataClass,
192
		.SubClass               = CDC_CSCP_NoDataSubclass,
193
		.Protocol               = CDC_CSCP_NoDataProtocol,
194
195
		.InterfaceStrIndex      = NO_DESCRIPTOR,
196
	},
197
1 by Tim Marston
initial commit
198
	.CDC_DataOutEndpoint =
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
199
	{
200
		.Header                 = {
201
			.Size = sizeof(USB_Descriptor_Endpoint_t),
202
			.Type = DTYPE_Endpoint,
1 by Tim Marston
initial commit
203
		},
204
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
205
		.EndpointAddress        = CDC_RX_EPADDR,
206
		.Attributes             = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC |
207
								   ENDPOINT_USAGE_DATA),
208
		.EndpointSize           = CDC_TXRX_EPSIZE,
209
		.PollingIntervalMS      = 0x05,
210
	},
211
1 by Tim Marston
initial commit
212
	.CDC_DataInEndpoint =
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
213
	{
214
		.Header                 = {
215
			.Size = sizeof(USB_Descriptor_Endpoint_t),
216
			.Type = DTYPE_Endpoint,
217
		},
1 by Tim Marston
initial commit
218
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
219
		.EndpointAddress        = CDC_TX_EPADDR,
220
		.Attributes             = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC |
221
								   ENDPOINT_USAGE_DATA),
222
		.EndpointSize           = CDC_TXRX_EPSIZE,
223
		.PollingIntervalMS      = 0x05,
224
	}
1 by Tim Marston
initial commit
225
};
226
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
227
/** Language descriptor structure.  This descriptor, located in FLASH memory,
228
 *  is returned when the host requests the string descriptor with index 0 (the
229
 *  first index).  It is actually an array of 16-bit integers, which indicate
230
 *  via the language ID table available at USB.org what languages the device
231
 *  supports for its string descriptors.
1 by Tim Marston
initial commit
232
 */
233
const USB_Descriptor_String_t PROGMEM LanguageString =
234
{
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
235
	.Header                 = {
236
		.Size = USB_STRING_LEN(1),
237
		.Type = DTYPE_String,
238
	},
1 by Tim Marston
initial commit
239
240
	.UnicodeString          = {LANGUAGE_ID_ENG}
241
};
242
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
243
/** Manufacturer descriptor string.  This is a Unicode string containing the
244
 *  manufacturer's details in human readable form, and is read out upon request
245
 *  by the host when the appropriate string ID is requested, listed in the
246
 *  Device Descriptor.
1 by Tim Marston
initial commit
247
 */
248
const USB_Descriptor_String_t PROGMEM ManufacturerString =
249
{
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
250
	.Header                 = {
251
		.Size = USB_STRING_LEN(4),
252
		.Type = DTYPE_String,
253
	},
1 by Tim Marston
initial commit
254
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
255
	.UnicodeString          = L"edam"
1 by Tim Marston
initial commit
256
};
257
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
258
/** Product descriptor string.  This is a Unicode string containing the
259
 *  product's details in human readable form, and is read out upon request by
260
 *  the host when the appropriate string ID is requested, listed in the Device
1 by Tim Marston
initial commit
261
 *  Descriptor.
262
 */
263
const USB_Descriptor_String_t PROGMEM ProductString =
264
{
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
265
	.Header                 = {
266
		.Size = USB_STRING_LEN(14),
267
		.Type = DTYPE_String,
268
	},
1 by Tim Marston
initial commit
269
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
270
	.UnicodeString          = L"Audio Switcher"
1 by Tim Marston
initial commit
271
};
272
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
273
/** This function is called by the library when in device mode, and must be
274
 *  overridden (see library "USB Descriptors" documentation) by the application
275
 *  code so that the address and size of a requested descriptor can be given to
276
 *  the USB library.  When the device receives a Get Descriptor request on the
277
 *  control endpoint, this function is called so that the descriptor details
278
 *  can be passed back and the appropriate descriptor sent back to the USB
279
 *  host.
1 by Tim Marston
initial commit
280
 */
281
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
282
                                    const uint8_t wIndex,
283
                                    const void** const DescriptorAddress)
284
{
285
	const uint8_t  DescriptorType   = (wValue >> 8);
286
	const uint8_t  DescriptorNumber = (wValue & 0xFF);
287
288
	const void* Address = NULL;
289
	uint16_t    Size    = NO_DESCRIPTOR;
290
291
	switch (DescriptorType)
292
	{
6 by Tim Marston
cleaned up descriptors file and set manufacturer and product names
293
	case DTYPE_Device:
294
		Address = &DeviceDescriptor;
295
		Size    = sizeof(USB_Descriptor_Device_t);
296
		break;
297
	case DTYPE_Configuration:
298
		Address = &ConfigurationDescriptor;
299
		Size    = sizeof(USB_Descriptor_Configuration_t);
300
		break;
301
	case DTYPE_String:
302
		switch (DescriptorNumber)
303
		{
304
		case 0x00:
305
			Address = &LanguageString;
306
			Size    = pgm_read_byte(&LanguageString.Header.Size);
307
			break;
308
		case 0x01:
309
			Address = &ManufacturerString;
310
			Size    = pgm_read_byte(&ManufacturerString.Header.Size);
311
			break;
312
		case 0x02:
313
			Address = &ProductString;
314
			Size    = pgm_read_byte(&ProductString.Header.Size);
315
			break;
316
		}
317
		
318
		break;
1 by Tim Marston
initial commit
319
	}
320
321
	*DescriptorAddress = Address;
322
	return Size;
323
}
324