]> git.friedersdorff.com Git - max/tmk_keyboard.git/blob - tmk_core/protocol/lufa/LUFA-git/Demos/Device/ClassDriver/DualMIDI/Descriptors.c
Merge commit '5a0132f1c1c9a14fd2941f0a5e29bbf5e31da20c' into master-core-pull
[max/tmk_keyboard.git] / tmk_core / protocol / lufa / LUFA-git / Demos / Device / ClassDriver / DualMIDI / Descriptors.c
1 /*
2              LUFA Library
3      Copyright (C) Dean Camera, 2014.
4
5   dean [at] fourwalledcubicle [dot] com
6            www.lufa-lib.org
7 */
8
9 /*
10   Copyright 2014  Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12   Permission to use, copy, modify, distribute, and sell this
13   software and its documentation for any purpose is hereby granted
14   without fee, provided that the above copyright notice appear in
15   all copies and that both that the copyright notice and this
16   permission notice and warranty disclaimer appear in supporting
17   documentation, and that the name of the author not be used in
18   advertising or publicity pertaining to distribution of the
19   software without specific, written prior permission.
20
21   The author disclaims all warranties with regard to this
22   software, including all implied warranties of merchantability
23   and fitness.  In no event shall the author be liable for any
24   special, indirect or consequential damages or any damages
25   whatsoever resulting from loss of use, data or profits, whether
26   in an action of contract, negligence or other tortious action,
27   arising out of or in connection with the use or performance of
28   this software.
29 */
30
31 /** \file
32  *
33  *  USB Device Descriptors, for library use when in USB device mode. Descriptors are special
34  *  computer-readable structures which the host requests upon device enumeration, to determine
35  *  the device's capabilities and functions.
36  */
37
38 #include "Descriptors.h"
39
40 /** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall
41  *  device characteristics, including the supported USB version, control endpoint size and the
42  *  number of device configurations. The descriptor is read out by the USB host when the enumeration
43  *  process begins.
44  */
45 const USB_Descriptor_Device_t PROGMEM DeviceDescriptor =
46 {
47         .Header                 = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
48
49         .USBSpecification       = VERSION_BCD(1,1,0),
50         .Class                  = USB_CSCP_NoDeviceClass,
51         .SubClass               = USB_CSCP_NoDeviceSubclass,
52         .Protocol               = USB_CSCP_NoDeviceProtocol,
53
54         .Endpoint0Size          = FIXED_CONTROL_ENDPOINT_SIZE,
55
56         .VendorID               = 0x03EB,
57         .ProductID              = 0x206D,
58         .ReleaseNumber          = VERSION_BCD(0,0,2),
59
60         .ManufacturerStrIndex   = STRING_ID_Manufacturer,
61         .ProductStrIndex        = STRING_ID_Product,
62         .SerialNumStrIndex      = NO_DESCRIPTOR,
63
64         .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
65 };
66
67 /** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage
68  *  of the device in one of its supported configurations, including information about any device interfaces
69  *  and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting
70  *  a configuration so that the host may correctly communicate with the USB device.
71  */
72 const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
73 {
74         .Config =
75                 {
76                         .Header                   = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
77
78                         .TotalConfigurationSize   = sizeof(USB_Descriptor_Configuration_t),
79                         .TotalInterfaces          = 2,
80
81                         .ConfigurationNumber      = 1,
82                         .ConfigurationStrIndex    = NO_DESCRIPTOR,
83
84                         .ConfigAttributes         = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_SELFPOWERED),
85
86                         .MaxPowerConsumption      = USB_CONFIG_POWER_MA(100)
87                 },
88
89         .Audio_ControlInterface =
90                 {
91                         .Header                   = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
92
93                         .InterfaceNumber          = INTERFACE_ID_AudioControl,
94                         .AlternateSetting         = 0,
95
96                         .TotalEndpoints           = 0,
97
98                         .Class                    = AUDIO_CSCP_AudioClass,
99                         .SubClass                 = AUDIO_CSCP_ControlSubclass,
100                         .Protocol                 = AUDIO_CSCP_ControlProtocol,
101
102                         .InterfaceStrIndex        = NO_DESCRIPTOR
103                 },
104
105         .Audio_ControlInterface_SPC =
106                 {
107                         .Header                   = {.Size = sizeof(USB_Audio_Descriptor_Interface_AC_t), .Type = DTYPE_CSInterface},
108                         .Subtype                  = AUDIO_DSUBTYPE_CSInterface_Header,
109
110                         .ACSpecification          = VERSION_BCD(1,0,0),
111                         .TotalLength              = sizeof(USB_Audio_Descriptor_Interface_AC_t),
112
113                         .InCollection             = 1,
114                         .InterfaceNumber          = INTERFACE_ID_AudioStream,
115                 },
116
117         .Audio_StreamInterface =
118                 {
119                         .Header                   = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
120
121                         .InterfaceNumber          = INTERFACE_ID_AudioStream,
122                         .AlternateSetting         = 0,
123
124                         .TotalEndpoints           = 2,
125
126                         .Class                    = AUDIO_CSCP_AudioClass,
127                         .SubClass                 = AUDIO_CSCP_MIDIStreamingSubclass,
128                         .Protocol                 = AUDIO_CSCP_StreamingProtocol,
129
130                         .InterfaceStrIndex        = NO_DESCRIPTOR
131                 },
132
133         .Audio_StreamInterface_SPC =
134                 {
135                         .Header                   = {.Size = sizeof(USB_MIDI_Descriptor_AudioInterface_AS_t), .Type = DTYPE_CSInterface},
136                         .Subtype                  = AUDIO_DSUBTYPE_CSInterface_General,
137
138                         .AudioSpecification       = VERSION_BCD(1,0,0),
139
140                         .TotalLength              = (sizeof(USB_Descriptor_Configuration_t) -
141                                                      offsetof(USB_Descriptor_Configuration_t, Audio_StreamInterface_SPC))
142                 },
143
144         .MIDI_In_Jack_Emb =
145                 {
146                         .Header                   = {.Size = sizeof(USB_MIDI_Descriptor_InputJack_t), .Type = DTYPE_CSInterface},
147                         .Subtype                  = AUDIO_DSUBTYPE_CSInterface_InputTerminal,
148
149                         .JackType                 = MIDI_JACKTYPE_Embedded,
150                         .JackID                   = 0x01,
151
152                         .JackStrIndex             = NO_DESCRIPTOR
153                 },
154
155         .MIDI_In_Jack_Emb2 =
156                 {
157                         .Header                   = {.Size = sizeof(USB_MIDI_Descriptor_InputJack_t), .Type = DTYPE_CSInterface},
158                         .Subtype                  = AUDIO_DSUBTYPE_CSInterface_InputTerminal,
159
160                         .JackType                 = MIDI_JACKTYPE_Embedded,
161                         .JackID                   = 0x02,
162
163                         .JackStrIndex             = NO_DESCRIPTOR
164                 },
165
166         .MIDI_In_Jack_Ext =
167                 {
168                         .Header                   = {.Size = sizeof(USB_MIDI_Descriptor_InputJack_t), .Type = DTYPE_CSInterface},
169                         .Subtype                  = AUDIO_DSUBTYPE_CSInterface_InputTerminal,
170
171                         .JackType                 = MIDI_JACKTYPE_External,
172                         .JackID                   = 0x03,
173
174                         .JackStrIndex             = NO_DESCRIPTOR
175                 },
176
177         .MIDI_In_Jack_Ext2 =
178                 {
179                         .Header                   = {.Size = sizeof(USB_MIDI_Descriptor_InputJack_t), .Type = DTYPE_CSInterface},
180                         .Subtype                  = AUDIO_DSUBTYPE_CSInterface_InputTerminal,
181
182                         .JackType                 = MIDI_JACKTYPE_External,
183                         .JackID                   = 0x04,
184
185                         .JackStrIndex             = NO_DESCRIPTOR
186                 },
187
188         .MIDI_Out_Jack_Emb =
189                 {
190                         .Header                   = {.Size = sizeof(USB_MIDI_Descriptor_OutputJack_t), .Type = DTYPE_CSInterface},
191                         .Subtype                  = AUDIO_DSUBTYPE_CSInterface_OutputTerminal,
192
193                         .JackType                 = MIDI_JACKTYPE_Embedded,
194                         .JackID                   = 0x05,
195
196                         .NumberOfPins             = 1,
197                         .SourceJackID             = {0x03},
198                         .SourcePinID              = {0x01},
199
200                         .JackStrIndex             = NO_DESCRIPTOR
201                 },
202
203         .MIDI_Out_Jack_Emb2 =
204                 {
205                         .Header                   = {.Size = sizeof(USB_MIDI_Descriptor_OutputJack_t), .Type = DTYPE_CSInterface},
206                         .Subtype                  = AUDIO_DSUBTYPE_CSInterface_OutputTerminal,
207
208                         .JackType                 = MIDI_JACKTYPE_Embedded,
209                         .JackID                   = 0x06,
210
211                         .NumberOfPins             = 1,
212                         .SourceJackID             = {0x04},
213                         .SourcePinID              = {0x01},
214
215                         .JackStrIndex             = NO_DESCRIPTOR
216                 },
217
218         .MIDI_Out_Jack_Ext =
219                 {
220                         .Header                   = {.Size = sizeof(USB_MIDI_Descriptor_OutputJack_t), .Type = DTYPE_CSInterface},
221                         .Subtype                  = AUDIO_DSUBTYPE_CSInterface_OutputTerminal,
222
223                         .JackType                 = MIDI_JACKTYPE_External,
224                         .JackID                   = 0x07,
225
226                         .NumberOfPins             = 1,
227                         .SourceJackID             = {0x01},
228                         .SourcePinID              = {0x01},
229
230                         .JackStrIndex             = NO_DESCRIPTOR
231                 },
232
233         .MIDI_Out_Jack_Ext2 =
234                 {
235                         .Header                   = {.Size = sizeof(USB_MIDI_Descriptor_OutputJack_t), .Type = DTYPE_CSInterface},
236                         .Subtype                  = AUDIO_DSUBTYPE_CSInterface_OutputTerminal,
237
238                         .JackType                 = MIDI_JACKTYPE_External,
239                         .JackID                   = 0x08,
240
241                         .NumberOfPins             = 1,
242                         .SourceJackID             = {0x02},
243                         .SourcePinID              = {0x01},
244
245                         .JackStrIndex             = NO_DESCRIPTOR
246                 },
247
248         .MIDI_In_Jack_Endpoint =
249                 {
250                         .Endpoint =
251                                 {
252                                         .Header              = {.Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t), .Type = DTYPE_Endpoint},
253
254                                         .EndpointAddress     = MIDI_STREAM_OUT_EPADDR,
255                                         .Attributes          = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
256                                         .EndpointSize        = MIDI_STREAM_EPSIZE,
257                                         .PollingIntervalMS   = 0x05
258                                 },
259
260                         .Refresh                  = 0,
261                         .SyncEndpointNumber       = 0
262                 },
263
264         .MIDI_In_Jack_Endpoint_SPC =
265                 {
266                         .Header                   = {.Size = sizeof(USB_MIDI_Descriptor_DualJack_Endpoint_t), .Type = DTYPE_CSEndpoint},
267                         .Subtype                  = AUDIO_DSUBTYPE_CSEndpoint_General,
268
269                         .TotalEmbeddedJacks       = 0x02,
270                         .AssociatedJackID         = {0x01, 0x02}
271                 },
272
273         .MIDI_Out_Jack_Endpoint =
274                 {
275                         .Endpoint =
276                                 {
277                                         .Header              = {.Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t), .Type = DTYPE_Endpoint},
278
279                                         .EndpointAddress     = MIDI_STREAM_IN_EPADDR,
280                                         .Attributes          = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
281                                         .EndpointSize        = MIDI_STREAM_EPSIZE,
282                                         .PollingIntervalMS   = 0x05
283                                 },
284
285                         .Refresh                  = 0,
286                         .SyncEndpointNumber       = 0
287                 },
288
289         .MIDI_Out_Jack_Endpoint_SPC =
290                 {
291                         .Header                   = {.Size = sizeof(USB_MIDI_Descriptor_DualJack_Endpoint_t), .Type = DTYPE_CSEndpoint},
292                         .Subtype                  = AUDIO_DSUBTYPE_CSEndpoint_General,
293
294                         .TotalEmbeddedJacks       = 0x02,
295                         .AssociatedJackID         = {0x05, 0x06}
296                 }
297 };
298
299 /** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests
300  *  the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate
301  *  via the language ID table available at USB.org what languages the device supports for its string descriptors.
302  */
303 const USB_Descriptor_String_t PROGMEM LanguageString = USB_STRING_DESCRIPTOR_ARRAY(LANGUAGE_ID_ENG);
304
305 /** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable
306  *  form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
307  *  Descriptor.
308  */
309 const USB_Descriptor_String_t PROGMEM ManufacturerString = USB_STRING_DESCRIPTOR(L"Dean Camera");
310
311 /** Product descriptor string. This is a Unicode string containing the product's details in human readable form,
312  *  and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
313  *  Descriptor.
314  */
315 const USB_Descriptor_String_t PROGMEM ProductString = USB_STRING_DESCRIPTOR(L"LUFA Dual MIDI Demo");
316
317 /** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"
318  *  documentation) by the application code so that the address and size of a requested descriptor can be given
319  *  to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function
320  *  is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the
321  *  USB host.
322  */
323 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
324                                     const uint8_t wIndex,
325                                     const void** const DescriptorAddress)
326 {
327         const uint8_t  DescriptorType   = (wValue >> 8);
328         const uint8_t  DescriptorNumber = (wValue & 0xFF);
329
330         const void* Address = NULL;
331         uint16_t    Size    = NO_DESCRIPTOR;
332
333         switch (DescriptorType)
334         {
335                 case DTYPE_Device:
336                         Address = &DeviceDescriptor;
337                         Size    = sizeof(USB_Descriptor_Device_t);
338                         break;
339                 case DTYPE_Configuration:
340                         Address = &ConfigurationDescriptor;
341                         Size    = sizeof(USB_Descriptor_Configuration_t);
342                         break;
343                 case DTYPE_String:
344                         switch (DescriptorNumber)
345                         {
346                                 case STRING_ID_Language:
347                                         Address = &LanguageString;
348                                         Size    = pgm_read_byte(&LanguageString.Header.Size);
349                                         break;
350                                 case STRING_ID_Manufacturer:
351                                         Address = &ManufacturerString;
352                                         Size    = pgm_read_byte(&ManufacturerString.Header.Size);
353                                         break;
354                                 case STRING_ID_Product:
355                                         Address = &ProductString;
356                                         Size    = pgm_read_byte(&ProductString.Header.Size);
357                                         break;
358                         }
359
360                         break;
361         }
362
363         *DescriptorAddress = Address;
364         return Size;
365 }
366