3 Copyright (C) Dean Camera, 2013.
5 dean [at] fourwalledcubicle [dot] com
10 Copyright 2013 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"
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 const USB_Descriptor_Device_t PROGMEM DeviceDescriptor
=
48 .Header
= {.Size
= sizeof(USB_Descriptor_Device_t
), .Type
= DTYPE_Device
},
50 .USBSpecification
= VERSION_BCD(01.10),
51 .Class
= USB_CSCP_NoDeviceClass
,
52 .SubClass
= USB_CSCP_NoDeviceSubclass
,
53 .Protocol
= USB_CSCP_NoDeviceProtocol
,
55 .Endpoint0Size
= FIXED_CONTROL_ENDPOINT_SIZE
,
59 .ReleaseNumber
= VERSION_BCD(00.01),
61 .ManufacturerStrIndex
= STRING_ID_Manufacturer
,
62 .ProductStrIndex
= STRING_ID_Product
,
63 .SerialNumStrIndex
= USE_INTERNAL_SERIAL
,
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 const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor
=
77 .Header
= {.Size
= sizeof(USB_Descriptor_Configuration_Header_t
), .Type
= DTYPE_Configuration
},
79 .TotalConfigurationSize
= sizeof(USB_Descriptor_Configuration_t
),
82 .ConfigurationNumber
= 1,
83 .ConfigurationStrIndex
= NO_DESCRIPTOR
,
85 .ConfigAttributes
= USB_CONFIG_ATTR_RESERVED
,
87 .MaxPowerConsumption
= USB_CONFIG_POWER_MA(100)
92 .Header
= {.Size
= sizeof(USB_Descriptor_Interface_t
), .Type
= DTYPE_Interface
},
94 .InterfaceNumber
= INTERFACE_ID_MassStorage
,
95 .AlternateSetting
= 0,
99 .Class
= MS_CSCP_MassStorageClass
,
100 .SubClass
= MS_CSCP_SCSITransparentSubclass
,
101 .Protocol
= MS_CSCP_BulkOnlyTransportProtocol
,
103 .InterfaceStrIndex
= NO_DESCRIPTOR
108 .Header
= {.Size
= sizeof(USB_Descriptor_Endpoint_t
), .Type
= DTYPE_Endpoint
},
110 .EndpointAddress
= MASS_STORAGE_IN_EPADDR
,
111 .Attributes
= (EP_TYPE_BULK
| ENDPOINT_ATTR_NO_SYNC
| ENDPOINT_USAGE_DATA
),
112 .EndpointSize
= MASS_STORAGE_IO_EPSIZE
,
113 .PollingIntervalMS
= 0x05
116 .MS_DataOutEndpoint
=
118 .Header
= {.Size
= sizeof(USB_Descriptor_Endpoint_t
), .Type
= DTYPE_Endpoint
},
120 .EndpointAddress
= MASS_STORAGE_OUT_EPADDR
,
121 .Attributes
= (EP_TYPE_BULK
| ENDPOINT_ATTR_NO_SYNC
| ENDPOINT_USAGE_DATA
),
122 .EndpointSize
= MASS_STORAGE_IO_EPSIZE
,
123 .PollingIntervalMS
= 0x05
127 /** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests
128 * the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate
129 * via the language ID table available at USB.org what languages the device supports for its string descriptors.
131 const USB_Descriptor_String_t PROGMEM LanguageString
=
133 .Header
= {.Size
= USB_STRING_LEN(1), .Type
= DTYPE_String
},
135 .UnicodeString
= {LANGUAGE_ID_ENG
}
138 /** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable
139 * form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
142 const USB_Descriptor_String_t PROGMEM ManufacturerString
=
144 .Header
= {.Size
= USB_STRING_LEN(11), .Type
= DTYPE_String
},
146 .UnicodeString
= L
"Dean Camera"
149 /** Product descriptor string. This is a Unicode string containing the product's details in human readable form,
150 * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
153 const USB_Descriptor_String_t PROGMEM ProductString
=
155 .Header
= {.Size
= USB_STRING_LEN(22), .Type
= DTYPE_String
},
157 .UnicodeString
= L
"LUFA Mass Storage Demo"
160 /** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"
161 * documentation) by the application code so that the address and size of a requested descriptor can be given
162 * to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function
163 * is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the
166 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue
,
167 const uint8_t wIndex
,
168 const void** const DescriptorAddress
)
170 const uint8_t DescriptorType
= (wValue
>> 8);
171 const uint8_t DescriptorNumber
= (wValue
& 0xFF);
173 const void* Address
= NULL
;
174 uint16_t Size
= NO_DESCRIPTOR
;
176 switch (DescriptorType
)
179 Address
= &DeviceDescriptor
;
180 Size
= sizeof(USB_Descriptor_Device_t
);
182 case DTYPE_Configuration
:
183 Address
= &ConfigurationDescriptor
;
184 Size
= sizeof(USB_Descriptor_Configuration_t
);
187 switch (DescriptorNumber
)
189 case STRING_ID_Language
:
190 Address
= &LanguageString
;
191 Size
= pgm_read_byte(&LanguageString
.Header
.Size
);
193 case STRING_ID_Manufacturer
:
194 Address
= &ManufacturerString
;
195 Size
= pgm_read_byte(&ManufacturerString
.Header
.Size
);
197 case STRING_ID_Product
:
198 Address
= &ProductString
;
199 Size
= pgm_read_byte(&ProductString
.Header
.Size
);
206 *DescriptorAddress
= Address
;