3      Copyright (C) Dean Camera, 2009. 
   5   dean [at] fourwalledcubicle [dot] com 
   6       www.fourwalledcubicle.com 
  10   Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com) 
  12   Permission to use, copy, modify, and distribute this software 
  13   and its documentation for any purpose and without fee is hereby 
  14   granted, provided that the above copyright notice appear in all 
  15   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 
  31 #include "Descriptors.h" 
  33 USB_Descriptor_Device_t PROGMEM DeviceDescriptor 
= 
  35         Header
:                 {Size
: sizeof(USB_Descriptor_Device_t
), Type
: DTYPE_Device
}, 
  37         USBSpecification
:       VERSION_BCD(02.00), 
  46         ReleaseNumber
:          0x0000, 
  48         ManufacturerStrIndex
:   0x01, 
  49         ProductStrIndex
:        0x02, 
  50         SerialNumStrIndex
:      0x03, 
  52         NumberOfConfigurations
: 1 
  55 USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor 
= 
  59                         Header
:                 {Size
: sizeof(USB_Descriptor_Configuration_Header_t
), Type
: DTYPE_Configuration
}, 
  61                         TotalConfigurationSize
: sizeof(USB_Descriptor_Configuration_t
), 
  64                         ConfigurationNumber
:    1, 
  65                         ConfigurationStrIndex
:  NO_DESCRIPTOR
, 
  67                         ConfigAttributes
:       (USB_CONFIG_ATTR_BUSPOWERED 
| USB_CONFIG_ATTR_SELFPOWERED
), 
  69                         MaxPowerConsumption
:    USB_CONFIG_POWER_MA(100) 
  74                         Header
:                 {Size
: sizeof(USB_Descriptor_Interface_t
), Type
: DTYPE_Interface
}, 
  85                         InterfaceStrIndex
:      NO_DESCRIPTOR
 
  90                         Header
:                 {Size
: sizeof(USB_Descriptor_Endpoint_t
), Type
: DTYPE_Endpoint
}, 
  92                         EndpointAddress
:        (ENDPOINT_DESCRIPTOR_DIR_IN 
| SIDESHOW_IN_EPNUM
), 
  93                         Attributes
:             EP_TYPE_BULK
, 
  94                         EndpointSize
:           SIDESHOW_IO_EPSIZE
, 
  95                         PollingIntervalMS
:      0x00 
 100                         Header
:                 {Size
: sizeof(USB_Descriptor_Endpoint_t
), Type
: DTYPE_Endpoint
}, 
 102                         EndpointAddress
:        (ENDPOINT_DESCRIPTOR_DIR_OUT 
| SIDESHOW_OUT_EPNUM
), 
 103                         Attributes
:             EP_TYPE_BULK
, 
 104                         EndpointSize
:           SIDESHOW_IO_EPSIZE
, 
 105                         PollingIntervalMS
:      0x00 
 109 USB_Descriptor_String_t PROGMEM LanguageString 
= 
 111         Header
:                 {Size
: USB_STRING_LEN(1), Type
: DTYPE_String
}, 
 113         UnicodeString
:          {LANGUAGE_ID_ENG
} 
 116 USB_Descriptor_String_t PROGMEM ManufacturerString 
= 
 118         Header
:                 {Size
: USB_STRING_LEN(11), Type
: DTYPE_String
}, 
 120         UnicodeString
:          L
"Dean Camera" 
 123 USB_Descriptor_String_t PROGMEM ProductString 
= 
 125         Header
:                 {Size
: USB_STRING_LEN(22), Type
: DTYPE_String
}, 
 127         UnicodeString
:          L
"LUFA Sideshow Demo" 
 130 USB_Descriptor_String_t PROGMEM SerialNumberString 
= 
 132         Header
:                 {Size
: USB_STRING_LEN(12), Type
: DTYPE_String
}, 
 134         UnicodeString
:          L
"000000000000" 
 137 USB_OSDescriptor_t PROGMEM OSDescriptorString 
= 
 139         Header
:                 {Size
: sizeof(USB_OSDescriptor_t
), Type
: DTYPE_String
}, 
 141         Signature
:              L
"MSFT100", 
 142         VendorCode
:             REQ_GetOSFeatureDescriptor
 
 145 USB_OSCompatibleIDDescriptor_t PROGMEM DevCompatIDs 
= 
 147         TotalLength
:            sizeof(USB_OSCompatibleIDDescriptor_t
), 
 149         Index
:                  EXTENDED_COMPAT_ID_DESCRIPTOR
, 
 152         SideshowCompatID
:       {FirstInterfaceNumber
: 0x00, 
 153                                  CompatibleID
: "SIDESHW", 
 154                                  SubCompatibleID
: "UNIV1"} 
 157 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue
, const uint8_t wIndex
, void** const DescriptorAddress
) 
 159         const uint8_t  DescriptorType   
= (wValue 
>> 8); 
 160         const uint8_t  DescriptorNumber 
= (wValue 
& 0xFF); 
 162         void*    Address 
= NULL
; 
 163         uint16_t Size    
= NO_DESCRIPTOR
; 
 165         switch (DescriptorType
) 
 168                         Address 
= (void*)&DeviceDescriptor
; 
 169                         Size    
= sizeof(USB_Descriptor_Device_t
); 
 171                 case DTYPE_Configuration
: 
 172                         Address 
= (void*)&ConfigurationDescriptor
; 
 173                         Size    
= sizeof(USB_Descriptor_Configuration_t
); 
 176                         switch (DescriptorNumber
) 
 179                                         Address 
= (void*)&LanguageString
; 
 180                                         Size    
= pgm_read_byte(&LanguageString
.Header
.Size
); 
 183                                         Address 
= (void*)&ManufacturerString
; 
 184                                         Size    
= pgm_read_byte(&ManufacturerString
.Header
.Size
); 
 187                                         Address 
= (void*)&ProductString
; 
 188                                         Size    
= pgm_read_byte(&ProductString
.Header
.Size
); 
 191                                         Address 
= (void*)&SerialNumberString
; 
 192                                         Size    
= pgm_read_byte(&SerialNumberString
.Header
.Size
); 
 195                                         /* Great, another Microsoft-proprietary extention. String address 0xEE is used 
 196                                            by Windows for "OS Descriptors", which in this case allows us to indicate that 
 197                                            our device is Sideshow compatible. Most people would be happy using the normal 
 198                                            0xFF 0x?? 0x?? Class/Subclass/Protocol values like the USBIF intended. */ 
 200                                         Address 
= (void*)&OSDescriptorString
; 
 201                                         Size    
= pgm_read_byte(&OSDescriptorString
.Header
.Size
); 
 208         *DescriptorAddress 
= Address
;            
 212 bool USB_GetOSFeatureDescriptor(const uint16_t wValue
, const uint8_t wIndex
, 
 213                                 void** const DescriptorAddress
, uint16_t* const DescriptorSize
) 
 215         void*    Address 
= NULL
; 
 218         /* Check if a device level OS feature descriptor is being requested */ 
 219         if (wValue 
== 0x0000) 
 221                 /* Only the Extended Device Compatibility descriptor is supported */ 
 222                 if (wIndex 
== EXTENDED_COMPAT_ID_DESCRIPTOR
) 
 224                         Address 
= (void*)&DevCompatIDs
; 
 225                         Size    
= sizeof(USB_OSCompatibleIDDescriptor_t
); 
 231                 *DescriptorAddress 
= Address
; 
 232                 *DescriptorSize    
= Size
;