Changed over www.fourwalledcubicle.com links to the new www.lufa-lib.org redirect...
[pub/USBasp.git] / Demos / Device / Incomplete / Sideshow / Descriptors.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2010.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
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.
20
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
28 this software.
29 */
30
31 #include "Descriptors.h"
32
33 USB_Descriptor_Device_t PROGMEM DeviceDescriptor =
34 {
35 Header: {Size: sizeof(USB_Descriptor_Device_t), Type: DTYPE_Device},
36
37 USBSpecification: VERSION_BCD(01.10),
38 Class: 0x00,
39 SubClass: 0x00,
40 Protocol: 0x00,
41
42 Endpoint0Size: 8,
43
44 VendorID: 0x03EB,
45 ProductID: 0x2040,
46 ReleaseNumber: VERSION_BCD(00.01),
47
48 ManufacturerStrIndex: 0x01,
49 ProductStrIndex: 0x02,
50 SerialNumStrIndex: 0x03,
51
52 NumberOfConfigurations: 1
53 };
54
55 USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
56 {
57 .Config =
58 {
59 Header: {Size: sizeof(USB_Descriptor_Configuration_Header_t), Type: DTYPE_Configuration},
60
61 TotalConfigurationSize: sizeof(USB_Descriptor_Configuration_t),
62 TotalInterfaces: 1,
63
64 ConfigurationNumber: 1,
65 ConfigurationStrIndex: NO_DESCRIPTOR,
66
67 ConfigAttributes: (USB_CONFIG_ATTR_BUSPOWERED | USB_CONFIG_ATTR_SELFPOWERED),
68
69 MaxPowerConsumption: USB_CONFIG_POWER_MA(100)
70 },
71
72 .SSHOW_Interface =
73 {
74 Header: {Size: sizeof(USB_Descriptor_Interface_t), Type: DTYPE_Interface},
75
76 InterfaceNumber: 0,
77 AlternateSetting: 0,
78
79 TotalEndpoints: 2,
80
81 Class: 0xFF,
82 SubClass: 0x00,
83 Protocol: 0x00,
84
85 InterfaceStrIndex: NO_DESCRIPTOR
86 },
87
88 .SSHOW_DataInEndpoint =
89 {
90 Header: {Size: sizeof(USB_Descriptor_Endpoint_t), Type: DTYPE_Endpoint},
91
92 EndpointAddress: (ENDPOINT_DESCRIPTOR_DIR_IN | SIDESHOW_IN_EPNUM),
93 Attributes: EP_TYPE_BULK,
94 EndpointSize: SIDESHOW_IO_EPSIZE,
95 PollingIntervalMS: 0x00
96 },
97
98 .SSHOW_DataOutEndpoint =
99 {
100 Header: {Size: sizeof(USB_Descriptor_Endpoint_t), Type: DTYPE_Endpoint},
101
102 EndpointAddress: (ENDPOINT_DESCRIPTOR_DIR_OUT | SIDESHOW_OUT_EPNUM),
103 Attributes: EP_TYPE_BULK,
104 EndpointSize: SIDESHOW_IO_EPSIZE,
105 PollingIntervalMS: 0x00
106 }
107 };
108
109 USB_Descriptor_String_t PROGMEM LanguageString =
110 {
111 Header: {Size: USB_STRING_LEN(1), Type: DTYPE_String},
112
113 UnicodeString: {LANGUAGE_ID_ENG}
114 };
115
116 USB_Descriptor_String_t PROGMEM ManufacturerString =
117 {
118 Header: {Size: USB_STRING_LEN(11), Type: DTYPE_String},
119
120 UnicodeString: L"Dean Camera"
121 };
122
123 USB_Descriptor_String_t PROGMEM ProductString =
124 {
125 Header: {Size: USB_STRING_LEN(22), Type: DTYPE_String},
126
127 UnicodeString: L"LUFA Sideshow Demo"
128 };
129
130 USB_Descriptor_String_t PROGMEM SerialNumberString =
131 {
132 Header: {Size: USB_STRING_LEN(12), Type: DTYPE_String},
133
134 UnicodeString: L"000000000000"
135 };
136
137 USB_OSDescriptor_t PROGMEM OSDescriptorString =
138 {
139 Header: {Size: sizeof(USB_OSDescriptor_t), Type: DTYPE_String},
140
141 Signature: L"MSFT100",
142 VendorCode: REQ_GetOSFeatureDescriptor
143 };
144
145 USB_OSCompatibleIDDescriptor_t PROGMEM DevCompatIDs =
146 {
147 TotalLength: sizeof(USB_OSCompatibleIDDescriptor_t),
148 Version: 0x0100,
149 Index: EXTENDED_COMPAT_ID_DESCRIPTOR,
150 TotalSections: 1,
151
152 SideshowCompatID: {FirstInterfaceNumber: 0x00,
153 CompatibleID: "SIDESHW",
154 SubCompatibleID: "UNIV1"}
155 };
156
157 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
158 const uint8_t wIndex,
159 const void** const DescriptorAddress)
160 {
161 const uint8_t DescriptorType = (wValue >> 8);
162 const uint8_t DescriptorNumber = (wValue & 0xFF);
163
164 const void* Address = NULL;
165 uint16_t Size = NO_DESCRIPTOR;
166
167 switch (DescriptorType)
168 {
169 case DTYPE_Device:
170 Address = &DeviceDescriptor;
171 Size = sizeof(USB_Descriptor_Device_t);
172 break;
173 case DTYPE_Configuration:
174 Address = &ConfigurationDescriptor;
175 Size = sizeof(USB_Descriptor_Configuration_t);
176 break;
177 case DTYPE_String:
178 switch (DescriptorNumber)
179 {
180 case 0x00:
181 Address = &LanguageString;
182 Size = pgm_read_byte(&LanguageString.Header.Size);
183 break;
184 case 0x01:
185 Address = &ManufacturerString;
186 Size = pgm_read_byte(&ManufacturerString.Header.Size);
187 break;
188 case 0x02:
189 Address = &ProductString;
190 Size = pgm_read_byte(&ProductString.Header.Size);
191 break;
192 case 0x03:
193 Address = &SerialNumberString;
194 Size = pgm_read_byte(&SerialNumberString.Header.Size);
195 break;
196 case 0xEE:
197 /* A Microsoft-proprietary extension. String address 0xEE is used by Windows for
198 "OS Descriptors", which in this case allows us to indicate that our device is
199 Sideshow compatible regardless of VID/PID values. */
200 Address = &OSDescriptorString;
201 Size = pgm_read_byte(&OSDescriptorString.Header.Size);
202 break;
203 }
204
205 break;
206 }
207
208 *DescriptorAddress = Address;
209 return Size;
210 }
211
212 uint16_t USB_GetOSFeatureDescriptor(const uint16_t wValue,
213 const uint8_t wIndex,
214 const void** const DescriptorAddress)
215 {
216 const void* Address = NULL;
217 uint16_t Size = NO_DESCRIPTOR;
218
219 /* Check if a device level OS feature descriptor is being requested */
220 if (wValue == 0x0000)
221 {
222 /* Only the Extended Device Compatibility descriptor is supported */
223 if (wIndex == EXTENDED_COMPAT_ID_DESCRIPTOR)
224 {
225 Address = &DevCompatIDs;
226 Size = sizeof(USB_OSCompatibleIDDescriptor_t);
227 }
228 }
229
230 *DescriptorAddress = Address;
231 return Size;
232 }
233