3      Copyright (C) Dean Camera, 2010. 
   5   dean [at] fourwalledcubicle [dot] com 
   6       www.fourwalledcubicle.com 
  10   Copyright 2010  OBinou (obconseil [at] gmail [dot] com) 
  11   Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com) 
  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 disclaim 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" 
  41 /** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall 
  42  *  device characteristics, including the supported USB version, control endpoint size and the 
  43  *  number of device configurations. The descriptor is read out by the USB host when the enumeration 
  46 USB_Descriptor_Device_t PROGMEM RelayBoard_DeviceDescriptor 
= 
  48         .Header                 
= {.Size 
= sizeof(USB_Descriptor_Device_t
), .Type 
= DTYPE_Device
}, 
  50         .USBSpecification       
= VERSION_BCD(01.10), 
  55         .Endpoint0Size          
= FIXED_CONTROL_ENDPOINT_SIZE
, 
  59         .ReleaseNumber          
= VERSION_BCD(02.00), 
  61         .ManufacturerStrIndex   
= 0x01, 
  62         .ProductStrIndex        
= 0x02, 
  63         .SerialNumStrIndex      
= 0x03, 
  65         .NumberOfConfigurations 
= FIXED_NUM_CONFIGURATIONS
 
  68 /** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage 
  69  *  of the device in one of its supported configurations, including information about any device interfaces 
  70  *  and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting 
  71  *  a configuration so that the host may correctly communicate with the USB device. 
  73 RelayBoard_USB_Descriptor_Configuration_t PROGMEM RelayBoard_ConfigurationDescriptor 
= 
  77                         .Header                 
= {.Size 
= sizeof(USB_Descriptor_Configuration_Header_t
), .Type 
= DTYPE_Configuration
}, 
  79                         .TotalConfigurationSize 
= sizeof(RelayBoard_USB_Descriptor_Configuration_t
), 
  82                         .ConfigurationNumber    
= 1, 
  83                         .ConfigurationStrIndex  
= NO_DESCRIPTOR
, 
  85                         .ConfigAttributes       
= USB_CONFIG_ATTR_BUSPOWERED
, 
  87                         .MaxPowerConsumption    
= USB_CONFIG_POWER_MA(500) 
  90         .RelayBoardInterface 
= 
  92                         .Header                 
= {.Size 
= sizeof(USB_Descriptor_Interface_t
), .Type 
= DTYPE_Interface
}, 
  95                         .AlternateSetting       
= 0, 
 103                         .InterfaceStrIndex      
= NO_DESCRIPTOR
 
 107 /** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests 
 108  *  the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate 
 109  *  via the language ID table available at USB.org what languages the device supports for its string descriptors. 
 111 USB_Descriptor_String_t PROGMEM RelayBoard_LanguageString 
= 
 113         .Header                 
= {.Size 
= USB_STRING_LEN(1), .Type 
= DTYPE_String
}, 
 115         .UnicodeString          
= {LANGUAGE_ID_ENG
} 
 118 /** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable 
 119  *  form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device 
 122 USB_Descriptor_String_t PROGMEM RelayBoard_ManufacturerString 
= 
 124         .Header                 
= {.Size 
= USB_STRING_LEN(5), .Type 
= DTYPE_String
}, 
 126         .UnicodeString          
= L
"SISPM" 
 129 /** Product descriptor string. This is a Unicode string containing the product's details in human readable form, 
 130  *  and is read out upon request by the host when the appropriate string ID is requested, listed in the Device 
 133 USB_Descriptor_String_t PROGMEM RelayBoard_ProductString 
= 
 135         .Header                 
= {.Size 
= USB_STRING_LEN(10), .Type 
= DTYPE_String
}, 
 137         .UnicodeString          
= L
"RelayBoard" 
 140 /** Serial number string. This is a Unicode string containing the device's unique serial number, expressed as a 
 141  *  series of uppercase hexadecimal digits. 
 143 USB_Descriptor_String_t PROGMEM RelayBoard_SerialString 
= 
 145         .Header                 
= {.Size 
= USB_STRING_LEN(5), .Type 
= DTYPE_String
}, 
 147         .UnicodeString          
= L
"00001" 
 150 /** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors" 
 151  *  documentation) by the application code so that the address and size of a requested descriptor can be given 
 152  *  to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function 
 153  *  is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the 
 156 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue
, const uint8_t wIndex
, void** const DescriptorAddress
) 
 158         const uint8_t  DescriptorType   
= (wValue 
>> 8); 
 159         const uint8_t  DescriptorNumber 
= (wValue 
& 0xFF); 
 161         void*    Address 
= NULL
; 
 162         uint16_t Size    
= NO_DESCRIPTOR
; 
 164         switch (DescriptorType
) 
 167                         Address 
= (void*)&RelayBoard_DeviceDescriptor
; 
 168                         Size    
= sizeof(USB_Descriptor_Device_t
); 
 170                 case DTYPE_Configuration
: 
 171                         Address 
= (void*)&RelayBoard_ConfigurationDescriptor
; 
 172                         Size    
= sizeof(RelayBoard_USB_Descriptor_Configuration_t
); 
 175                         switch (DescriptorNumber
) 
 178                                         Address 
= (void*)&RelayBoard_LanguageString
; 
 179                                         Size    
= pgm_read_byte(&RelayBoard_LanguageString
.Header
.Size
); 
 182                                         Address 
= (void*)&RelayBoard_ManufacturerString
; 
 183                                         Size    
= pgm_read_byte(&RelayBoard_ManufacturerString
.Header
.Size
); 
 186                                         Address 
= (void*)&RelayBoard_ProductString
; 
 187                                         Size    
= pgm_read_byte(&RelayBoard_ProductString
.Header
.Size
); 
 190                                         Address 
= (void*)&RelayBoard_SerialString
; 
 191                                         Size    
= pgm_read_byte(&RelayBoard_SerialString
.Header
.Size
); 
 198         *DescriptorAddress 
= Address
;