control servo 0 with axis 0
[protos/xbee-avr.git] / Descriptors.c
1 /*\r
2              LUFA Library\r
3      Copyright (C) Dean Camera, 2011.\r
4 \r
5   dean [at] fourwalledcubicle [dot] com\r
6            www.lufa-lib.org\r
7 */\r
8 \r
9 /*\r
10   Copyright 2011  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
11 \r
12   Permission to use, copy, modify, distribute, and sell this\r
13   software and its documentation for any purpose is hereby granted\r
14   without fee, provided that the above copyright notice appear in\r
15   all copies and that both that the copyright notice and this\r
16   permission notice and warranty disclaimer appear in supporting\r
17   documentation, and that the name of the author not be used in\r
18   advertising or publicity pertaining to distribution of the\r
19   software without specific, written prior permission.\r
20 \r
21   The author disclaim all warranties with regard to this\r
22   software, including all implied warranties of merchantability\r
23   and fitness.  In no event shall the author be liable for any\r
24   special, indirect or consequential damages or any damages\r
25   whatsoever resulting from loss of use, data or profits, whether\r
26   in an action of contract, negligence or other tortious action,\r
27   arising out of or in connection with the use or performance of\r
28   this software.\r
29 */\r
30 \r
31 /** \file\r
32  *\r
33  *  USB Device Descriptors, for library use when in USB device mode. Descriptors are special\r
34  *  computer-readable structures which the host requests upon device enumeration, to determine\r
35  *  the device's capabilities and functions.\r
36  */\r
37 \r
38 #include "Descriptors.h"\r
39 \r
40 /* On some devices, there is a factory set internal serial number which can be automatically sent to the host as\r
41  * the device's serial number when the Device Descriptor's .SerialNumStrIndex entry is set to USE_INTERNAL_SERIAL.\r
42  * This allows the host to track a device across insertions on different ports, allowing them to retain allocated\r
43  * resources like COM port numbers and drivers. On demos using this feature, give a warning on unsupported devices\r
44  * so that the user can supply their own serial number descriptor instead or remove the USE_INTERNAL_SERIAL value\r
45  * from the Device Descriptor (forcing the host to generate a serial number for each device from the VID, PID and\r
46  * port location).\r
47  */\r
48 #if (USE_INTERNAL_SERIAL == NO_DESCRIPTOR)\r
49         #warning USE_INTERNAL_SERIAL is not available on this AVR - please manually construct a device serial descriptor.\r
50 #endif\r
51 \r
52 /** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall\r
53  *  device characteristics, including the supported USB version, control endpoint size and the\r
54  *  number of device configurations. The descriptor is read out by the USB host when the enumeration\r
55  *  process begins.\r
56  */\r
57 const USB_Descriptor_Device_t PROGMEM DeviceDescriptor =\r
58 {\r
59         .Header                 = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},\r
60 \r
61         .USBSpecification       = VERSION_BCD(01.10),\r
62         .Class                  = USB_CSCP_IADDeviceClass,\r
63         .SubClass               = USB_CSCP_IADDeviceSubclass,\r
64         .Protocol               = USB_CSCP_IADDeviceProtocol,\r
65 \r
66         .Endpoint0Size          = FIXED_CONTROL_ENDPOINT_SIZE,\r
67 \r
68         .VendorID               = 0x03EB,\r
69         .ProductID              = 0x204E,\r
70         .ReleaseNumber          = VERSION_BCD(00.01),\r
71 \r
72         .ManufacturerStrIndex   = 0x01,\r
73         .ProductStrIndex        = 0x02,\r
74         .SerialNumStrIndex      = USE_INTERNAL_SERIAL,\r
75 \r
76         .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS\r
77 };\r
78 \r
79 /** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage\r
80  *  of the device in one of its supported configurations, including information about any device interfaces\r
81  *  and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting\r
82  *  a configuration so that the host may correctly communicate with the USB device.\r
83  */\r
84 const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =\r
85 {\r
86         .Config =\r
87                 {\r
88                         .Header                 = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},\r
89 \r
90                         .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),\r
91                         .TotalInterfaces        = 4,\r
92 \r
93                         .ConfigurationNumber    = 1,\r
94                         .ConfigurationStrIndex  = NO_DESCRIPTOR,\r
95 \r
96                         .ConfigAttributes       = (USB_CONFIG_ATTR_BUSPOWERED | USB_CONFIG_ATTR_SELFPOWERED),\r
97 \r
98                         .MaxPowerConsumption    = USB_CONFIG_POWER_MA(100)\r
99                 },\r
100 \r
101         .CDC1_IAD =\r
102                 {\r
103                         .Header                 = {.Size = sizeof(USB_Descriptor_Interface_Association_t), .Type = DTYPE_InterfaceAssociation},\r
104 \r
105                         .FirstInterfaceIndex    = 0,\r
106                         .TotalInterfaces        = 2,\r
107 \r
108                         .Class                  = CDC_CSCP_CDCClass,\r
109                         .SubClass               = CDC_CSCP_ACMSubclass,\r
110                         .Protocol               = CDC_CSCP_ATCommandProtocol,\r
111 \r
112                         .IADStrIndex            = NO_DESCRIPTOR\r
113                 },\r
114 \r
115         .CDC1_CCI_Interface =\r
116                 {\r
117                         .Header                 = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},\r
118 \r
119                         .InterfaceNumber        = 0,\r
120                         .AlternateSetting       = 0,\r
121 \r
122                         .TotalEndpoints         = 1,\r
123 \r
124                         .Class                  = CDC_CSCP_CDCClass,\r
125                         .SubClass               = CDC_CSCP_ACMSubclass,\r
126                         .Protocol               = CDC_CSCP_ATCommandProtocol,\r
127 \r
128                         .InterfaceStrIndex      = NO_DESCRIPTOR\r
129                 },\r
130 \r
131         .CDC1_Functional_Header =\r
132                 {\r
133                         .Header                 = {.Size = sizeof(USB_CDC_Descriptor_FunctionalHeader_t), .Type = DTYPE_CSInterface},\r
134                         .Subtype                = CDC_DSUBTYPE_CSInterface_Header,\r
135 \r
136                         .CDCSpecification       = VERSION_BCD(01.10),\r
137                 },\r
138 \r
139         .CDC1_Functional_ACM =\r
140                 {\r
141                         .Header                 = {.Size = sizeof(USB_CDC_Descriptor_FunctionalACM_t), .Type = DTYPE_CSInterface},\r
142                         .Subtype                = CDC_DSUBTYPE_CSInterface_ACM,\r
143 \r
144                         .Capabilities           = 0x06,\r
145                 },\r
146 \r
147         .CDC1_Functional_Union =\r
148                 {\r
149                         .Header                 = {.Size = sizeof(USB_CDC_Descriptor_FunctionalUnion_t), .Type = DTYPE_CSInterface},\r
150                         .Subtype                = CDC_DSUBTYPE_CSInterface_Union,\r
151 \r
152                         .MasterInterfaceNumber  = 0,\r
153                         .SlaveInterfaceNumber   = 1,\r
154                 },\r
155 \r
156         .CDC1_ManagementEndpoint =\r
157                 {\r
158                         .Header                 = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},\r
159 \r
160                         .EndpointAddress        = (ENDPOINT_DIR_IN | CDC1_NOTIFICATION_EPNUM),\r
161                         .Attributes             = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),\r
162                         .EndpointSize           = CDC_NOTIFICATION_EPSIZE,\r
163                         .PollingIntervalMS      = 0xFF\r
164                 },\r
165 \r
166         .CDC1_DCI_Interface =\r
167                 {\r
168                         .Header                 = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},\r
169 \r
170                         .InterfaceNumber        = 1,\r
171                         .AlternateSetting       = 0,\r
172 \r
173                         .TotalEndpoints         = 2,\r
174 \r
175                         .Class                  = CDC_CSCP_CDCDataClass,\r
176                         .SubClass               = CDC_CSCP_NoDataSubclass,\r
177                         .Protocol               = CDC_CSCP_NoDataProtocol,\r
178 \r
179                         .InterfaceStrIndex      = NO_DESCRIPTOR\r
180                 },\r
181 \r
182         .CDC1_DataOutEndpoint =\r
183                 {\r
184                         .Header                 = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},\r
185 \r
186                         .EndpointAddress        = (ENDPOINT_DIR_OUT | CDC1_RX_EPNUM),\r
187                         .Attributes             = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),\r
188                         .EndpointSize           = CDC_TXRX_EPSIZE,\r
189                         .PollingIntervalMS      = 0x01\r
190                 },\r
191 \r
192         .CDC1_DataInEndpoint =\r
193                 {\r
194                         .Header                 = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},\r
195 \r
196                         .EndpointAddress        = (ENDPOINT_DIR_IN | CDC1_TX_EPNUM),\r
197                         .Attributes             = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),\r
198                         .EndpointSize           = CDC_TXRX_EPSIZE,\r
199                         .PollingIntervalMS      = 0x01\r
200                 },\r
201 \r
202         .CDC2_IAD =\r
203                 {\r
204                         .Header                 = {.Size = sizeof(USB_Descriptor_Interface_Association_t), .Type = DTYPE_InterfaceAssociation},\r
205 \r
206                         .FirstInterfaceIndex    = 2,\r
207                         .TotalInterfaces        = 2,\r
208 \r
209                         .Class                  = CDC_CSCP_CDCClass,\r
210                         .SubClass               = CDC_CSCP_ACMSubclass,\r
211                         .Protocol               = CDC_CSCP_ATCommandProtocol,\r
212 \r
213                         .IADStrIndex            = NO_DESCRIPTOR\r
214                 },\r
215 \r
216         .CDC2_CCI_Interface =\r
217                 {\r
218                         .Header                 = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},\r
219 \r
220                         .InterfaceNumber        = 2,\r
221                         .AlternateSetting       = 0,\r
222 \r
223                         .TotalEndpoints         = 1,\r
224 \r
225                         .Class                  = CDC_CSCP_CDCClass,\r
226                         .SubClass               = CDC_CSCP_ACMSubclass,\r
227                         .Protocol               = CDC_CSCP_ATCommandProtocol,\r
228 \r
229                         .InterfaceStrIndex      = NO_DESCRIPTOR\r
230                 },\r
231 \r
232         .CDC2_Functional_Header =\r
233                 {\r
234                         .Header                 = {.Size = sizeof(USB_CDC_Descriptor_FunctionalHeader_t), .Type = DTYPE_CSInterface},\r
235                         .Subtype                = CDC_DSUBTYPE_CSInterface_Header,\r
236 \r
237                         .CDCSpecification       = VERSION_BCD(01.10),\r
238                 },\r
239 \r
240         .CDC2_Functional_ACM =\r
241                 {\r
242                         .Header                 = {.Size = sizeof(USB_CDC_Descriptor_FunctionalACM_t), .Type = DTYPE_CSInterface},\r
243                         .Subtype                = CDC_DSUBTYPE_CSInterface_ACM,\r
244 \r
245                         .Capabilities           = 0x06,\r
246                 },\r
247 \r
248         .CDC2_Functional_Union =\r
249                 {\r
250                         .Header                 = {.Size = sizeof(USB_CDC_Descriptor_FunctionalUnion_t), .Type = DTYPE_CSInterface},\r
251                         .Subtype                = CDC_DSUBTYPE_CSInterface_Union,\r
252 \r
253                         .MasterInterfaceNumber  = 2,\r
254                         .SlaveInterfaceNumber   = 3,\r
255                 },\r
256 \r
257         .CDC2_ManagementEndpoint =\r
258                 {\r
259                         .Header                 = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},\r
260 \r
261                         .EndpointAddress        = (ENDPOINT_DIR_IN | CDC2_NOTIFICATION_EPNUM),\r
262                         .Attributes             = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),\r
263                         .EndpointSize           = CDC_NOTIFICATION_EPSIZE,\r
264                         .PollingIntervalMS      = 0xFF\r
265                 },\r
266 \r
267         .CDC2_DCI_Interface =\r
268                 {\r
269                         .Header                 = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},\r
270 \r
271                         .InterfaceNumber        = 3,\r
272                         .AlternateSetting       = 0,\r
273 \r
274                         .TotalEndpoints         = 2,\r
275 \r
276                         .Class                  = CDC_CSCP_CDCDataClass,\r
277                         .SubClass               = CDC_CSCP_NoDataSubclass,\r
278                         .Protocol               = CDC_CSCP_NoDataProtocol,\r
279 \r
280                         .InterfaceStrIndex      = NO_DESCRIPTOR\r
281                 },\r
282 \r
283         .CDC2_DataOutEndpoint =\r
284                 {\r
285                         .Header                 = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},\r
286 \r
287                         .EndpointAddress        = (ENDPOINT_DIR_OUT | CDC2_RX_EPNUM),\r
288                         .Attributes             = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),\r
289                         .EndpointSize           = CDC_TXRX_EPSIZE,\r
290                         .PollingIntervalMS      = 0x01\r
291                 },\r
292 \r
293         .CDC2_DataInEndpoint =\r
294                 {\r
295                         .Header                 = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},\r
296 \r
297                         .EndpointAddress        = (ENDPOINT_DIR_IN | CDC2_TX_EPNUM),\r
298                         .Attributes             = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),\r
299                         .EndpointSize           = CDC_TXRX_EPSIZE,\r
300                         .PollingIntervalMS      = 0x01\r
301                 }\r
302 };\r
303 \r
304 /** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests\r
305  *  the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate\r
306  *  via the language ID table available at USB.org what languages the device supports for its string descriptors.\r
307  */\r
308 const USB_Descriptor_String_t PROGMEM LanguageString =\r
309 {\r
310         .Header                 = {.Size = USB_STRING_LEN(1), .Type = DTYPE_String},\r
311 \r
312         .UnicodeString          = {LANGUAGE_ID_ENG}\r
313 };\r
314 \r
315 /** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable\r
316  *  form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device\r
317  *  Descriptor.\r
318  */\r
319 const USB_Descriptor_String_t PROGMEM ManufacturerString =\r
320 {\r
321         .Header                 = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String},\r
322 \r
323         .UnicodeString          = L"Dean Camera"\r
324 };\r
325 \r
326 /** Product descriptor string. This is a Unicode string containing the product's details in human readable form,\r
327  *  and is read out upon request by the host when the appropriate string ID is requested, listed in the Device\r
328  *  Descriptor.\r
329  */\r
330 const USB_Descriptor_String_t PROGMEM ProductString =\r
331 {\r
332         .Header                 = {.Size = USB_STRING_LEN(13), .Type = DTYPE_String},\r
333 \r
334         .UnicodeString          = L"LUFA Dual CDC Demo"\r
335 };\r
336 \r
337 /** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"\r
338  *  documentation) by the application code so that the address and size of a requested descriptor can be given\r
339  *  to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function\r
340  *  is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the\r
341  *  USB host.\r
342  */\r
343 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,\r
344                                     const uint8_t wIndex,\r
345                                     const void** const DescriptorAddress)\r
346 {\r
347         const uint8_t  DescriptorType   = (wValue >> 8);\r
348         const uint8_t  DescriptorNumber = (wValue & 0xFF);\r
349 \r
350         const void* Address = NULL;\r
351         uint16_t    Size    = NO_DESCRIPTOR;\r
352 \r
353         switch (DescriptorType)\r
354         {\r
355                 case DTYPE_Device:\r
356                         Address = &DeviceDescriptor;\r
357                         Size    = sizeof(USB_Descriptor_Device_t);\r
358                         break;\r
359                 case DTYPE_Configuration:\r
360                         Address = &ConfigurationDescriptor;\r
361                         Size    = sizeof(USB_Descriptor_Configuration_t);\r
362                         break;\r
363                 case DTYPE_String:\r
364                         switch (DescriptorNumber)\r
365                         {\r
366                                 case 0x00:\r
367                                         Address = &LanguageString;\r
368                                         Size    = pgm_read_byte(&LanguageString.Header.Size);\r
369                                         break;\r
370                                 case 0x01:\r
371                                         Address = &ManufacturerString;\r
372                                         Size    = pgm_read_byte(&ManufacturerString.Header.Size);\r
373                                         break;\r
374                                 case 0x02:\r
375                                         Address = &ProductString;\r
376                                         Size    = pgm_read_byte(&ProductString.Header.Size);\r
377                                         break;\r
378                         }\r
379 \r
380                         break;\r
381         }\r
382 \r
383         *DescriptorAddress = Address;\r
384         return Size;\r
385 }\r
386 \r