3      Copyright (C) Dean Camera, 2014. 
   5   dean [at] fourwalledcubicle [dot] com 
  10   Copyright 2014  Dean Camera (dean [at] fourwalledcubicle [dot] com) 
  11   Copyright 2010  Matthias Hullin (lufa [at] matthias [dot] hullin [dot] net) 
  13   Permission to use, copy, modify, distribute, and sell this 
  14   software and its documentation for any purpose is hereby granted 
  15   without fee, provided that the above copyright notice appear in 
  16   all copies and that both that the copyright notice and this 
  17   permission notice and warranty disclaimer appear in supporting 
  18   documentation, and that the name of the author not be used in 
  19   advertising or publicity pertaining to distribution of the 
  20   software without specific, written prior permission. 
  22   The author disclaims all warranties with regard to this 
  23   software, including all implied warranties of merchantability 
  24   and fitness.  In no event shall the author be liable for any 
  25   special, indirect or consequential damages or any damages 
  26   whatsoever resulting from loss of use, data or profits, whether 
  27   in an action of contract, negligence or other tortious action, 
  28   arising out of or in connection with the use or performance of 
  34  *  USB Device Descriptors, for library use when in USB device mode. Descriptors are special 
  35  *  computer-readable structures which the host requests upon device enumeration, to determine 
  36  *  the device's capabilities and functions. 
  39 #include "Descriptors.h" 
  42 /** HID class report descriptor. This is a special descriptor constructed with values from the 
  43  *  USBIF HID class specification to describe the reports and capabilities of the HID device. This 
  44  *  descriptor is parsed by the host and its contents used to determine what data (and in what encoding) 
  45  *  the device will send, and what it may be sent back from the host. Refer to the HID specification for 
  46  *  more details on HID report descriptors. 
  48 const USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport
[] = 
  50         /* Use the HID class driver's standard Keyboard report. 
  51          *   Max simultaneous keys: 6 
  53         HID_DESCRIPTOR_KEYBOARD(6) 
  56 /** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall 
  57  *  device characteristics, including the supported USB version, control endpoint size and the 
  58  *  number of device configurations. The descriptor is read out by the USB host when the enumeration 
  61 const USB_Descriptor_Device_t PROGMEM DeviceDescriptor 
= 
  63         .Header                 
= {.Size 
= sizeof(USB_Descriptor_Device_t
), .Type 
= DTYPE_Device
}, 
  65         .USBSpecification       
= VERSION_BCD(1,1,0), 
  66         .Class                  
= USB_CSCP_NoDeviceClass
, 
  67         .SubClass               
= USB_CSCP_NoDeviceSubclass
, 
  68         .Protocol               
= USB_CSCP_NoDeviceProtocol
, 
  70         .Endpoint0Size          
= FIXED_CONTROL_ENDPOINT_SIZE
, 
  74         .ReleaseNumber          
= VERSION_BCD(0,0,1), 
  76         .ManufacturerStrIndex   
= STRING_ID_Manufacturer
, 
  77         .ProductStrIndex        
= STRING_ID_Product
, 
  78         .SerialNumStrIndex      
= USE_INTERNAL_SERIAL
, 
  80         .NumberOfConfigurations 
= FIXED_NUM_CONFIGURATIONS
 
  83 /** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage 
  84  *  of the device in one of its supported configurations, including information about any device interfaces 
  85  *  and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting 
  86  *  a configuration so that the host may correctly communicate with the USB device. 
  88 const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor 
= 
  92                         .Header                 
= {.Size 
= sizeof(USB_Descriptor_Configuration_Header_t
), .Type 
= DTYPE_Configuration
}, 
  94                         .TotalConfigurationSize 
= sizeof(USB_Descriptor_Configuration_t
), 
  97                         .ConfigurationNumber    
= 1, 
  98                         .ConfigurationStrIndex  
= NO_DESCRIPTOR
, 
 100                         .ConfigAttributes       
= USB_CONFIG_ATTR_RESERVED
, 
 102                         .MaxPowerConsumption    
= USB_CONFIG_POWER_MA(100) 
 107                         .Header                 
= {.Size 
= sizeof(USB_Descriptor_Interface_t
), .Type 
= DTYPE_Interface
}, 
 109                         .InterfaceNumber        
= INTERFACE_ID_MassStorage
, 
 110                         .AlternateSetting       
= 0, 
 114                         .Class                  
= MS_CSCP_MassStorageClass
, 
 115                         .SubClass               
= MS_CSCP_SCSITransparentSubclass
, 
 116                         .Protocol               
= MS_CSCP_BulkOnlyTransportProtocol
, 
 118                         .InterfaceStrIndex      
= NO_DESCRIPTOR
 
 123                         .Header                 
= {.Size 
= sizeof(USB_Descriptor_Endpoint_t
), .Type 
= DTYPE_Endpoint
}, 
 125                         .EndpointAddress        
= MASS_STORAGE_IN_EPADDR
, 
 126                         .Attributes             
= (EP_TYPE_BULK 
| ENDPOINT_ATTR_NO_SYNC 
| ENDPOINT_USAGE_DATA
), 
 127                         .EndpointSize           
= MASS_STORAGE_IO_EPSIZE
, 
 128                         .PollingIntervalMS      
= 0x05 
 131         .MS_DataOutEndpoint 
= 
 133                         .Header                 
= {.Size 
= sizeof(USB_Descriptor_Endpoint_t
), .Type 
= DTYPE_Endpoint
}, 
 135                         .EndpointAddress        
= MASS_STORAGE_OUT_EPADDR
, 
 136                         .Attributes             
= (EP_TYPE_BULK 
| ENDPOINT_ATTR_NO_SYNC 
| ENDPOINT_USAGE_DATA
), 
 137                         .EndpointSize           
= MASS_STORAGE_IO_EPSIZE
, 
 138                         .PollingIntervalMS      
= 0x05 
 141         .HID_KeyboardInterface 
= 
 143                         .Header                 
= {.Size 
= sizeof(USB_Descriptor_Interface_t
), .Type 
= DTYPE_Interface
}, 
 145                         .InterfaceNumber        
= INTERFACE_ID_Keyboard
, 
 146                         .AlternateSetting       
= 0, 
 150                         .Class                  
= HID_CSCP_HIDClass
, 
 151                         .SubClass               
= HID_CSCP_BootSubclass
, 
 152                         .Protocol               
= HID_CSCP_KeyboardBootProtocol
, 
 154                         .InterfaceStrIndex      
= NO_DESCRIPTOR
 
 159                         .Header                 
= {.Size 
= sizeof(USB_HID_Descriptor_HID_t
), .Type 
= HID_DTYPE_HID
}, 
 161                         .HIDSpec                
= VERSION_BCD(1,1,1), 
 163                         .TotalReportDescriptors 
= 1, 
 164                         .HIDReportType          
= HID_DTYPE_Report
, 
 165                         .HIDReportLength        
= sizeof(KeyboardReport
) 
 168         .HID_ReportINEndpoint 
= 
 170                         .Header                 
= {.Size 
= sizeof(USB_Descriptor_Endpoint_t
), .Type 
= DTYPE_Endpoint
}, 
 172                         .EndpointAddress        
= KEYBOARD_EPADDR
, 
 173                         .Attributes             
= (EP_TYPE_INTERRUPT 
| ENDPOINT_ATTR_NO_SYNC 
| ENDPOINT_USAGE_DATA
), 
 174                         .EndpointSize           
= KEYBOARD_EPSIZE
, 
 175                         .PollingIntervalMS      
= 0x05 
 179 /** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests 
 180  *  the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate 
 181  *  via the language ID table available at USB.org what languages the device supports for its string descriptors. 
 183 const USB_Descriptor_String_t PROGMEM LanguageString 
= USB_STRING_DESCRIPTOR_ARRAY(LANGUAGE_ID_ENG
); 
 185 /** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable 
 186  *  form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device 
 189 const USB_Descriptor_String_t PROGMEM ManufacturerString 
= USB_STRING_DESCRIPTOR(L
"Dean Camera"); 
 191 /** Product descriptor string. This is a Unicode string containing the product's details in human readable form, 
 192  *  and is read out upon request by the host when the appropriate string ID is requested, listed in the Device 
 195 const USB_Descriptor_String_t PROGMEM ProductString 
= USB_STRING_DESCRIPTOR(L
"LUFA Mass Storage and Keyboard Demo"); 
 197 /** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors" 
 198  *  documentation) by the application code so that the address and size of a requested descriptor can be given 
 199  *  to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function 
 200  *  is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the 
 203 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue
, 
 204                                     const uint8_t wIndex
, 
 205                                     const void** const DescriptorAddress
) 
 207         const uint8_t  DescriptorType   
= (wValue 
>> 8); 
 208         const uint8_t  DescriptorNumber 
= (wValue 
& 0xFF); 
 210         const void* Address 
= NULL
; 
 211         uint16_t    Size    
= NO_DESCRIPTOR
; 
 213         switch (DescriptorType
) 
 216                         Address 
= &DeviceDescriptor
; 
 217                         Size    
= sizeof(USB_Descriptor_Device_t
); 
 219                 case DTYPE_Configuration
: 
 220                         Address 
= &ConfigurationDescriptor
; 
 221                         Size    
= sizeof(USB_Descriptor_Configuration_t
); 
 224                         switch (DescriptorNumber
) 
 226                                 case STRING_ID_Language
: 
 227                                         Address 
= &LanguageString
; 
 228                                         Size    
= pgm_read_byte(&LanguageString
.Header
.Size
); 
 230                                 case STRING_ID_Manufacturer
: 
 231                                         Address 
= &ManufacturerString
; 
 232                                         Size    
= pgm_read_byte(&ManufacturerString
.Header
.Size
); 
 234                                 case STRING_ID_Product
: 
 235                                         Address 
= &ProductString
; 
 236                                         Size    
= pgm_read_byte(&ProductString
.Header
.Size
); 
 242                         Address 
= &ConfigurationDescriptor
.HID_KeyboardHID
; 
 243                         Size    
= sizeof(USB_HID_Descriptor_HID_t
); 
 245                 case HID_DTYPE_Report
: 
 246                         Address 
= &KeyboardReport
; 
 247                         Size    
= sizeof(KeyboardReport
); 
 251         *DescriptorAddress 
= Address
;