3      Copyright (C) Dean Camera, 2018. 
   5   dean [at] fourwalledcubicle [dot] com 
  10   Copyright 2018  Dean Camera (dean [at] fourwalledcubicle [dot] com) 
  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. 
  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 
  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. 
  38 #include "Descriptors.h" 
  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 
  45 const USB_Descriptor_Device_t PROGMEM DeviceDescriptor 
= 
  47         .Header                 
= {.Size 
= sizeof(USB_Descriptor_Device_t
), .Type 
= DTYPE_Device
}, 
  49         .USBSpecification       
= VERSION_BCD(1,1,0), 
  50         .Class                  
= USB_CSCP_NoDeviceClass
, 
  51         .SubClass               
= USB_CSCP_NoDeviceSubclass
, 
  52         .Protocol               
= USB_CSCP_NoDeviceProtocol
, 
  54         .Endpoint0Size          
= FIXED_CONTROL_ENDPOINT_SIZE
, 
  58         .ReleaseNumber          
= VERSION_BCD(0,0,2), 
  60         .ManufacturerStrIndex   
= STRING_ID_Manufacturer
, 
  61         .ProductStrIndex        
= STRING_ID_Product
, 
  62         .SerialNumStrIndex      
= NO_DESCRIPTOR
, 
  64         .NumberOfConfigurations 
= FIXED_NUM_CONFIGURATIONS
 
  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. 
  72 const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor 
= 
  76                         .Header                   
= {.Size 
= sizeof(USB_Descriptor_Configuration_Header_t
), .Type 
= DTYPE_Configuration
}, 
  78                         .TotalConfigurationSize   
= sizeof(USB_Descriptor_Configuration_t
), 
  81                         .ConfigurationNumber      
= 1, 
  82                         .ConfigurationStrIndex    
= NO_DESCRIPTOR
, 
  84                         .ConfigAttributes         
= (USB_CONFIG_ATTR_RESERVED 
| USB_CONFIG_ATTR_SELFPOWERED
), 
  86                         .MaxPowerConsumption      
= USB_CONFIG_POWER_MA(100) 
  89         .Audio_ControlInterface 
= 
  91                         .Header                   
= {.Size 
= sizeof(USB_Descriptor_Interface_t
), .Type 
= DTYPE_Interface
}, 
  93                         .InterfaceNumber          
= INTERFACE_ID_AudioControl
, 
  94                         .AlternateSetting         
= 0, 
  98                         .Class                    
= AUDIO_CSCP_AudioClass
, 
  99                         .SubClass                 
= AUDIO_CSCP_ControlSubclass
, 
 100                         .Protocol                 
= AUDIO_CSCP_ControlProtocol
, 
 102                         .InterfaceStrIndex        
= NO_DESCRIPTOR
 
 105         .Audio_ControlInterface_SPC 
= 
 107                         .Header                   
= {.Size 
= sizeof(USB_Audio_Descriptor_Interface_AC_t
), .Type 
= DTYPE_CSInterface
}, 
 108                         .Subtype                  
= AUDIO_DSUBTYPE_CSInterface_Header
, 
 110                         .ACSpecification          
= VERSION_BCD(1,0,0), 
 111                         .TotalLength              
= sizeof(USB_Audio_Descriptor_Interface_AC_t
), 
 114                         .InterfaceNumber          
= INTERFACE_ID_AudioStream
, 
 117         .Audio_StreamInterface 
= 
 119                         .Header                   
= {.Size 
= sizeof(USB_Descriptor_Interface_t
), .Type 
= DTYPE_Interface
}, 
 121                         .InterfaceNumber          
= INTERFACE_ID_AudioStream
, 
 122                         .AlternateSetting         
= 0, 
 126                         .Class                    
= AUDIO_CSCP_AudioClass
, 
 127                         .SubClass                 
= AUDIO_CSCP_MIDIStreamingSubclass
, 
 128                         .Protocol                 
= AUDIO_CSCP_StreamingProtocol
, 
 130                         .InterfaceStrIndex        
= NO_DESCRIPTOR
 
 133         .Audio_StreamInterface_SPC 
= 
 135                         .Header                   
= {.Size 
= sizeof(USB_MIDI_Descriptor_AudioInterface_AS_t
), .Type 
= DTYPE_CSInterface
}, 
 136                         .Subtype                  
= AUDIO_DSUBTYPE_CSInterface_General
, 
 138                         .AudioSpecification       
= VERSION_BCD(1,0,0), 
 140                         .TotalLength              
= (sizeof(USB_Descriptor_Configuration_t
) - 
 141                                                      offsetof(USB_Descriptor_Configuration_t
, Audio_StreamInterface_SPC
)) 
 146                         .Header                   
= {.Size 
= sizeof(USB_MIDI_Descriptor_InputJack_t
), .Type 
= DTYPE_CSInterface
}, 
 147                         .Subtype                  
= AUDIO_DSUBTYPE_CSInterface_InputTerminal
, 
 149                         .JackType                 
= MIDI_JACKTYPE_Embedded
, 
 152                         .JackStrIndex             
= NO_DESCRIPTOR
 
 157                         .Header                   
= {.Size 
= sizeof(USB_MIDI_Descriptor_InputJack_t
), .Type 
= DTYPE_CSInterface
}, 
 158                         .Subtype                  
= AUDIO_DSUBTYPE_CSInterface_InputTerminal
, 
 160                         .JackType                 
= MIDI_JACKTYPE_Embedded
, 
 163                         .JackStrIndex             
= NO_DESCRIPTOR
 
 168                         .Header                   
= {.Size 
= sizeof(USB_MIDI_Descriptor_InputJack_t
), .Type 
= DTYPE_CSInterface
}, 
 169                         .Subtype                  
= AUDIO_DSUBTYPE_CSInterface_InputTerminal
, 
 171                         .JackType                 
= MIDI_JACKTYPE_External
, 
 174                         .JackStrIndex             
= NO_DESCRIPTOR
 
 179                         .Header                   
= {.Size 
= sizeof(USB_MIDI_Descriptor_InputJack_t
), .Type 
= DTYPE_CSInterface
}, 
 180                         .Subtype                  
= AUDIO_DSUBTYPE_CSInterface_InputTerminal
, 
 182                         .JackType                 
= MIDI_JACKTYPE_External
, 
 185                         .JackStrIndex             
= NO_DESCRIPTOR
 
 190                         .Header                   
= {.Size 
= sizeof(USB_MIDI_Descriptor_OutputJack_t
), .Type 
= DTYPE_CSInterface
}, 
 191                         .Subtype                  
= AUDIO_DSUBTYPE_CSInterface_OutputTerminal
, 
 193                         .JackType                 
= MIDI_JACKTYPE_Embedded
, 
 197                         .SourceJackID             
= {0x03}, 
 198                         .SourcePinID              
= {0x01}, 
 200                         .JackStrIndex             
= NO_DESCRIPTOR
 
 203         .MIDI_Out_Jack_Emb2 
= 
 205                         .Header                   
= {.Size 
= sizeof(USB_MIDI_Descriptor_OutputJack_t
), .Type 
= DTYPE_CSInterface
}, 
 206                         .Subtype                  
= AUDIO_DSUBTYPE_CSInterface_OutputTerminal
, 
 208                         .JackType                 
= MIDI_JACKTYPE_Embedded
, 
 212                         .SourceJackID             
= {0x04}, 
 213                         .SourcePinID              
= {0x01}, 
 215                         .JackStrIndex             
= NO_DESCRIPTOR
 
 220                         .Header                   
= {.Size 
= sizeof(USB_MIDI_Descriptor_OutputJack_t
), .Type 
= DTYPE_CSInterface
}, 
 221                         .Subtype                  
= AUDIO_DSUBTYPE_CSInterface_OutputTerminal
, 
 223                         .JackType                 
= MIDI_JACKTYPE_External
, 
 227                         .SourceJackID             
= {0x01}, 
 228                         .SourcePinID              
= {0x01}, 
 230                         .JackStrIndex             
= NO_DESCRIPTOR
 
 233         .MIDI_Out_Jack_Ext2 
= 
 235                         .Header                   
= {.Size 
= sizeof(USB_MIDI_Descriptor_OutputJack_t
), .Type 
= DTYPE_CSInterface
}, 
 236                         .Subtype                  
= AUDIO_DSUBTYPE_CSInterface_OutputTerminal
, 
 238                         .JackType                 
= MIDI_JACKTYPE_External
, 
 242                         .SourceJackID             
= {0x02}, 
 243                         .SourcePinID              
= {0x01}, 
 245                         .JackStrIndex             
= NO_DESCRIPTOR
 
 248         .MIDI_In_Jack_Endpoint 
= 
 252                                         .Header              
= {.Size 
= sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t
), .Type 
= DTYPE_Endpoint
}, 
 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 
 261                         .SyncEndpointNumber       
= 0 
 264         .MIDI_In_Jack_Endpoint_SPC 
= 
 266                         .Header                   
= {.Size 
= sizeof(USB_MIDI_Descriptor_DualJack_Endpoint_t
), .Type 
= DTYPE_CSEndpoint
}, 
 267                         .Subtype                  
= AUDIO_DSUBTYPE_CSEndpoint_General
, 
 269                         .TotalEmbeddedJacks       
= 0x02, 
 270                         .AssociatedJackID         
= {0x01, 0x02} 
 273         .MIDI_Out_Jack_Endpoint 
= 
 277                                         .Header              
= {.Size 
= sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t
), .Type 
= DTYPE_Endpoint
}, 
 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 
 286                         .SyncEndpointNumber       
= 0 
 289         .MIDI_Out_Jack_Endpoint_SPC 
= 
 291                         .Header                   
= {.Size 
= sizeof(USB_MIDI_Descriptor_DualJack_Endpoint_t
), .Type 
= DTYPE_CSEndpoint
}, 
 292                         .Subtype                  
= AUDIO_DSUBTYPE_CSEndpoint_General
, 
 294                         .TotalEmbeddedJacks       
= 0x02, 
 295                         .AssociatedJackID         
= {0x05, 0x06} 
 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. 
 303 const USB_Descriptor_String_t PROGMEM LanguageString 
= USB_STRING_DESCRIPTOR_ARRAY(LANGUAGE_ID_ENG
); 
 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 
 309 const USB_Descriptor_String_t PROGMEM ManufacturerString 
= USB_STRING_DESCRIPTOR(L
"Dean Camera"); 
 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 
 315 const USB_Descriptor_String_t PROGMEM ProductString 
= USB_STRING_DESCRIPTOR(L
"LUFA Dual MIDI Demo"); 
 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 
 323 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue
, 
 324                                     const uint16_t wIndex
, 
 325                                     const void** const DescriptorAddress
) 
 327         const uint8_t  DescriptorType   
= (wValue 
>> 8); 
 328         const uint8_t  DescriptorNumber 
= (wValue 
& 0xFF); 
 330         const void* Address 
= NULL
; 
 331         uint16_t    Size    
= NO_DESCRIPTOR
; 
 333         switch (DescriptorType
) 
 336                         Address 
= &DeviceDescriptor
; 
 337                         Size    
= sizeof(USB_Descriptor_Device_t
); 
 339                 case DTYPE_Configuration
: 
 340                         Address 
= &ConfigurationDescriptor
; 
 341                         Size    
= sizeof(USB_Descriptor_Configuration_t
); 
 344                         switch (DescriptorNumber
) 
 346                                 case STRING_ID_Language
: 
 347                                         Address 
= &LanguageString
; 
 348                                         Size    
= pgm_read_byte(&LanguageString
.Header
.Size
); 
 350                                 case STRING_ID_Manufacturer
: 
 351                                         Address 
= &ManufacturerString
; 
 352                                         Size    
= pgm_read_byte(&ManufacturerString
.Header
.Size
); 
 354                                 case STRING_ID_Product
: 
 355                                         Address 
= &ProductString
; 
 356                                         Size    
= pgm_read_byte(&ProductString
.Header
.Size
); 
 363         *DescriptorAddress 
= Address
;