f6d16c8412bd55c5deffb9508a1e522d95248d1d
[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.fourwalledcubicle.com
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(02.00),
38 Class: 0x00,
39 SubClass: 0x00,
40 Protocol: 0x00,
41
42 Endpoint0Size: 8,
43
44 VendorID: 0x03EB,
45 ProductID: 0x2040,
46 ReleaseNumber: 0x0001,
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, const uint8_t wIndex, void** const DescriptorAddress)
158 {
159 const uint8_t DescriptorType = (wValue >> 8);
160 const uint8_t DescriptorNumber = (wValue & 0xFF);
161
162 void* Address = NULL;
163 uint16_t Size = NO_DESCRIPTOR;
164
165 switch (DescriptorType)
166 {
167 case DTYPE_Device:
168 Address = (void*)&DeviceDescriptor;
169 Size = sizeof(USB_Descriptor_Device_t);
170 break;
171 case DTYPE_Configuration:
172 Address = (void*)&ConfigurationDescriptor;
173 Size = sizeof(USB_Descriptor_Configuration_t);
174 break;
175 case DTYPE_String:
176 switch (DescriptorNumber)
177 {
178 case 0x00:
179 Address = (void*)&LanguageString;
180 Size = pgm_read_byte(&LanguageString.Header.Size);
181 break;
182 case 0x01:
183 Address = (void*)&ManufacturerString;
184 Size = pgm_read_byte(&ManufacturerString.Header.Size);
185 break;
186 case 0x02:
187 Address = (void*)&ProductString;
188 Size = pgm_read_byte(&ProductString.Header.Size);
189 break;
190 case 0x03:
191 Address = (void*)&SerialNumberString;
192 Size = pgm_read_byte(&SerialNumberString.Header.Size);
193 break;
194 case 0xEE:
195 /* A Microsoft-proprietary extention. String address 0xEE is used by Windows for
196 "OS Descriptors", which in this case allows us to indicate that our device is
197 Sideshow compatible regardless of VID/PID values. */
198 Address = (void*)&OSDescriptorString;
199 Size = pgm_read_byte(&OSDescriptorString.Header.Size);
200 break;
201 }
202
203 break;
204 }
205
206 *DescriptorAddress = Address;
207 return Size;
208 }
209
210 bool USB_GetOSFeatureDescriptor(const uint16_t wValue, const uint8_t wIndex,
211 void** const DescriptorAddress, uint16_t* const DescriptorSize)
212 {
213 void* Address = NULL;
214 uint16_t Size = 0;
215
216 /* Check if a device level OS feature descriptor is being requested */
217 if (wValue == 0x0000)
218 {
219 /* Only the Extended Device Compatibility descriptor is supported */
220 if (wIndex == EXTENDED_COMPAT_ID_DESCRIPTOR)
221 {
222 Address = (void*)&DevCompatIDs;
223 Size = sizeof(USB_OSCompatibleIDDescriptor_t);
224 }
225 }
226
227 if (Address != NULL)
228 {
229 *DescriptorAddress = Address;
230 *DescriptorSize = Size;
231
232 return true;
233 }
234
235 return false;
236 }