647e0b4f965e82e7e4d8a13948bb9c41799bca6b
[pub/USBasp.git] / Demos / Device / Incomplete / Sideshow / Descriptors.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2009.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
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.
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 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 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 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 /* 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. */
199
200 Address = (void*)&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 bool USB_GetOSFeatureDescriptor(const uint16_t wValue, const uint8_t wIndex,
213 void** const DescriptorAddress, uint16_t* const DescriptorSize)
214 {
215 void* Address = NULL;
216 uint16_t Size = 0;
217
218 /* Check if a device level OS feature descriptor is being requested */
219 if (wValue == 0x0000)
220 {
221 /* Only the Extended Device Compatibility descriptor is supported */
222 if (wIndex == EXTENDED_COMPAT_ID_DESCRIPTOR)
223 {
224 Address = (void*)&DevCompatIDs;
225 Size = sizeof(USB_OSCompatibleIDDescriptor_t);
226 }
227 }
228
229 if (Address != NULL)
230 {
231 *DescriptorAddress = Address;
232 *DescriptorSize = Size;
233
234 return true;
235 }
236
237 return false;
238 }