3      Copyright (C) Dean Camera, 2012. 
   5   dean [at] fourwalledcubicle [dot] com 
  10   Copyright 2012  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 disclaim 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(02.00), 
  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(00.02), 
  60         .ManufacturerStrIndex   
= 0x01, 
  61         .ProductStrIndex        
= 0x02, 
  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
}, 
  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(01.00), 
 111                         .TotalLength              
= (sizeof(USB_Audio_Descriptor_Interface_AC_t
) + 
 112                                                      sizeof(USB_Audio_Descriptor_InputTerminal_t
) + 
 113                                                      sizeof(USB_Audio_Descriptor_OutputTerminal_t
)), 
 116                         .InterfaceNumber          
= 1, 
 119         .Audio_InputTerminal 
= 
 121                         .Header                   
= {.Size 
= sizeof(USB_Audio_Descriptor_InputTerminal_t
), .Type 
= DTYPE_CSInterface
}, 
 122                         .Subtype                  
= AUDIO_DSUBTYPE_CSInterface_InputTerminal
, 
 125                         .TerminalType             
= AUDIO_TERMINAL_IN_MIC
, 
 126                         .AssociatedOutputTerminal 
= 0x00, 
 131                         .ChannelStrIndex          
= NO_DESCRIPTOR
, 
 132                         .TerminalStrIndex         
= NO_DESCRIPTOR
 
 135         .Audio_OutputTerminal 
= 
 137                         .Header                   
= {.Size 
= sizeof(USB_Audio_Descriptor_OutputTerminal_t
), .Type 
= DTYPE_CSInterface
}, 
 138                         .Subtype                  
= AUDIO_DSUBTYPE_CSInterface_OutputTerminal
, 
 141                         .TerminalType             
= AUDIO_TERMINAL_STREAMING
, 
 142                         .AssociatedInputTerminal  
= 0x00, 
 146                         .TerminalStrIndex         
= NO_DESCRIPTOR
 
 149         .Audio_StreamInterface_Alt0 
= 
 151                         .Header                   
= {.Size 
= sizeof(USB_Descriptor_Interface_t
), .Type 
= DTYPE_Interface
}, 
 153                         .InterfaceNumber          
= 1, 
 154                         .AlternateSetting         
= 0, 
 158                         .Class                    
= AUDIO_CSCP_AudioClass
, 
 159                         .SubClass                 
= AUDIO_CSCP_AudioStreamingSubclass
, 
 160                         .Protocol                 
= AUDIO_CSCP_StreamingProtocol
, 
 162                         .InterfaceStrIndex        
= NO_DESCRIPTOR
 
 165         .Audio_StreamInterface_Alt1 
= 
 167                         .Header                   
= {.Size 
= sizeof(USB_Descriptor_Interface_t
), .Type 
= DTYPE_Interface
}, 
 169                         .InterfaceNumber          
= 1, 
 170                         .AlternateSetting         
= 1, 
 174                         .Class                    
= AUDIO_CSCP_AudioClass
, 
 175                         .SubClass                 
= AUDIO_CSCP_AudioStreamingSubclass
, 
 176                         .Protocol                 
= AUDIO_CSCP_StreamingProtocol
, 
 178                         .InterfaceStrIndex        
= NO_DESCRIPTOR
 
 181         .Audio_StreamInterface_SPC 
= 
 183                         .Header                   
= {.Size 
= sizeof(USB_Audio_Descriptor_Interface_AS_t
), .Type 
= DTYPE_CSInterface
}, 
 184                         .Subtype                  
= AUDIO_DSUBTYPE_CSInterface_General
, 
 186                         .TerminalLink             
= 0x02, 
 189                         .AudioFormat              
= 0x0001 
 194                         .Header                   
= {.Size 
= sizeof(USB_Audio_Descriptor_Format_t
) + 
 195                                                              sizeof(ConfigurationDescriptor
.Audio_AudioFormatSampleRates
), 
 196                                                      .Type 
= DTYPE_CSInterface
}, 
 197                         .Subtype                  
= AUDIO_DSUBTYPE_CSInterface_FormatType
, 
 202                         .SubFrameSize             
= 0x02, 
 205                         .TotalDiscreteSampleRates 
= (sizeof(ConfigurationDescriptor
.Audio_AudioFormatSampleRates
) / sizeof(USB_Audio_SampleFreq_t
)) 
 208         .Audio_AudioFormatSampleRates 
= 
 210                         AUDIO_SAMPLE_FREQ(8000), 
 211                         AUDIO_SAMPLE_FREQ(11025), 
 212                         AUDIO_SAMPLE_FREQ(22050), 
 213                         AUDIO_SAMPLE_FREQ(44100), 
 214                         AUDIO_SAMPLE_FREQ(48000), 
 217         .Audio_StreamEndpoint 
= 
 221                                         .Header              
= {.Size 
= sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t
), .Type 
= DTYPE_Endpoint
}, 
 223                                         .EndpointAddress     
= AUDIO_STREAM_EPADDR
, 
 224                                         .Attributes          
= (EP_TYPE_ISOCHRONOUS 
| ENDPOINT_ATTR_SYNC 
| ENDPOINT_USAGE_DATA
), 
 225                                         .EndpointSize        
= AUDIO_STREAM_EPSIZE
, 
 226                                         .PollingIntervalMS   
= 0x01 
 230                         .SyncEndpointNumber       
= 0 
 233         .Audio_StreamEndpoint_SPC 
= 
 235                         .Header                   
= {.Size 
= sizeof(USB_Audio_Descriptor_StreamEndpoint_Spc_t
), .Type 
= DTYPE_CSEndpoint
}, 
 236                         .Subtype                  
= AUDIO_DSUBTYPE_CSEndpoint_General
, 
 238                         .Attributes               
= (AUDIO_EP_ACCEPTS_SMALL_PACKETS 
| AUDIO_EP_SAMPLE_FREQ_CONTROL
), 
 240                         .LockDelayUnits           
= 0x00, 
 245 /** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests 
 246  *  the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate 
 247  *  via the language ID table available at USB.org what languages the device supports for its string descriptors. 
 249 const USB_Descriptor_String_t PROGMEM LanguageString 
= 
 251         .Header                 
= {.Size 
= USB_STRING_LEN(1), .Type 
= DTYPE_String
}, 
 253         .UnicodeString          
= {LANGUAGE_ID_ENG
} 
 256 /** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable 
 257  *  form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device 
 260 const USB_Descriptor_String_t PROGMEM ManufacturerString 
= 
 262         .Header                 
= {.Size 
= USB_STRING_LEN(11), .Type 
= DTYPE_String
}, 
 264         .UnicodeString          
= L
"Dean Camera" 
 267 /** Product descriptor string. This is a Unicode string containing the product's details in human readable form, 
 268  *  and is read out upon request by the host when the appropriate string ID is requested, listed in the Device 
 271 const USB_Descriptor_String_t PROGMEM ProductString 
= 
 273         .Header                 
= {.Size 
= USB_STRING_LEN(18), .Type 
= DTYPE_String
}, 
 275         .UnicodeString          
= L
"LUFA Audio In Demo" 
 278 /** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors" 
 279  *  documentation) by the application code so that the address and size of a requested descriptor can be given 
 280  *  to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function 
 281  *  is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the 
 284 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue
, 
 285                                     const uint8_t wIndex
, 
 286                                     const void** const DescriptorAddress
) 
 288         const uint8_t  DescriptorType   
= (wValue 
>> 8); 
 289         const uint8_t  DescriptorNumber 
= (wValue 
& 0xFF); 
 291         const void* Address 
= NULL
; 
 292         uint16_t    Size    
= NO_DESCRIPTOR
; 
 294         switch (DescriptorType
) 
 297                         Address 
= &DeviceDescriptor
; 
 298                         Size    
= sizeof(USB_Descriptor_Device_t
); 
 300                 case DTYPE_Configuration
: 
 301                         Address 
= &ConfigurationDescriptor
; 
 302                         Size    
= sizeof(USB_Descriptor_Configuration_t
); 
 305                         switch (DescriptorNumber
) 
 308                                         Address 
= &LanguageString
; 
 309                                         Size    
= pgm_read_byte(&LanguageString
.Header
.Size
); 
 312                                         Address 
= &ManufacturerString
; 
 313                                         Size    
= pgm_read_byte(&ManufacturerString
.Header
.Size
); 
 316                                         Address 
= &ProductString
; 
 317                                         Size    
= pgm_read_byte(&ProductString
.Header
.Size
); 
 324         *DescriptorAddress 
= Address
;