sanguino/firmwares/arduino-usbdfu/Descriptors.c

Fri, 17 Nov 2017 10:13:31 +0100

author
mdd
date
Fri, 17 Nov 2017 10:13:31 +0100
changeset 3
770b218a4931
parent 2
b373b0288715
permissions
-rw-r--r--

proper configuration, homing and planner optimization

2
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
1 /*
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
2 LUFA Library
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
3 Copyright (C) Dean Camera, 2010.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
4
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
5 dean [at] fourwalledcubicle [dot] com
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
6 www.fourwalledcubicle.com
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
7 */
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
8
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
9 /*
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
10 Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
11
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
12 Permission to use, copy, modify, distribute, and sell this
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
13 software and its documentation for any purpose is hereby granted
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
14 without fee, provided that the above copyright notice appear in
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
15 all copies and that both that the copyright notice and this
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
16 permission notice and warranty disclaimer appear in supporting
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
17 documentation, and that the name of the author not be used in
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
18 advertising or publicity pertaining to distribution of the
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
19 software without specific, written prior permission.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
20
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
21 The author disclaim all warranties with regard to this
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
22 software, including all implied warranties of merchantability
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
23 and fitness. In no event shall the author be liable for any
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
24 special, indirect or consequential damages or any damages
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
25 whatsoever resulting from loss of use, data or profits, whether
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
26 in an action of contract, negligence or other tortious action,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
27 arising out of or in connection with the use or performance of
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
28 this software.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
29 */
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
30
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
31 /** \file
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
32 *
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
33 * USB Device Descriptors, for library use when in USB device mode. Descriptors are special
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
34 * computer-readable structures which the host requests upon device enumeration, to determine
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
35 * the device's capabilities and functions.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
36 */
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
37
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
38 #include "Descriptors.h"
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
39
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
40 /** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
41 * device characteristics, including the supported USB version, control endpoint size and the
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
42 * number of device configurations. The descriptor is read out by the USB host when the enumeration
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
43 * process begins.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
44 */
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
45 USB_Descriptor_Device_t DeviceDescriptor =
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
46 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
47 .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
48
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
49 .USBSpecification = VERSION_BCD(01.10),
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
50 .Class = 0x00,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
51 .SubClass = 0x00,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
52 .Protocol = 0x00,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
53
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
54 .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
55
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
56 .VendorID = 0x03EB, // Atmel
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
57 .ProductID = PRODUCT_ID_CODE, // MCU-dependent
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
58 .ReleaseNumber = 0x0000,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
59
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
60 .ManufacturerStrIndex = NO_DESCRIPTOR,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
61 .ProductStrIndex = 0x01,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
62 .SerialNumStrIndex = NO_DESCRIPTOR,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
63
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
64 .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
65 };
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
66
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
67 /** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
68 * of the device in one of its supported configurations, including information about any device interfaces
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
69 * and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
70 * a configuration so that the host may correctly communicate with the USB device.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
71 */
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
72 USB_Descriptor_Configuration_t ConfigurationDescriptor =
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
73 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
74 .Config =
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
75 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
76 .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
77
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
78 .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
79 .TotalInterfaces = 1,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
80
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
81 .ConfigurationNumber = 1,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
82 .ConfigurationStrIndex = NO_DESCRIPTOR,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
83
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
84 .ConfigAttributes = USB_CONFIG_ATTR_BUSPOWERED,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
85
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
86 .MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
87 },
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
88
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
89 .DFU_Interface =
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
90 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
91 .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
92
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
93 .InterfaceNumber = 0,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
94 .AlternateSetting = 0,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
95
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
96 .TotalEndpoints = 0,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
97
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
98 .Class = 0xFE,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
99 .SubClass = 0x01,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
100 .Protocol = 0x02,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
101
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
102 .InterfaceStrIndex = NO_DESCRIPTOR
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
103 },
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
104
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
105 .DFU_Functional =
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
106 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
107 .Header = {.Size = sizeof(USB_DFU_Functional_Descriptor_t), .Type = DTYPE_DFUFunctional},
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
108
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
109 .Attributes = (ATTR_CAN_UPLOAD | ATTR_CAN_DOWNLOAD),
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
110
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
111 .DetachTimeout = 0x0000,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
112 .TransferSize = 0x0c00,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
113
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
114 .DFUSpecification = VERSION_BCD(01.01)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
115 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
116 };
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
117
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
118 /** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
119 * the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
120 * via the language ID table available at USB.org what languages the device supports for its string descriptors.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
121 */
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
122 USB_Descriptor_String_t LanguageString =
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
123 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
124 .Header = {.Size = USB_STRING_LEN(1), .Type = DTYPE_String},
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
125
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
126 .UnicodeString = {LANGUAGE_ID_ENG}
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
127 };
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
128
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
129 /** Product descriptor string. This is a Unicode string containing the product's details in human readable form,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
130 * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
131 * Descriptor.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
132 */
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
133 USB_Descriptor_String_t ProductString =
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
134 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
135 #if (ARDUINO_MODEL_PID == ARDUINO_UNO_PID)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
136 .Header = {.Size = USB_STRING_LEN(15), .Type = DTYPE_String},
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
137
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
138 .UnicodeString = L"Arduino Uno DFU"
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
139 #elif (ARDUINO_MODEL_PID == ARDUINO_MEGA2560_PID)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
140 .Header = {.Size = USB_STRING_LEN(21), .Type = DTYPE_String},
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
141
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
142 .UnicodeString = L"Arduino Mega 2560 DFU"
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
143 #endif
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
144 };
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
145
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
146 /** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
147 * documentation) by the application code so that the address and size of a requested descriptor can be given
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
148 * to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
149 * is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
150 * USB host.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
151 */
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
152 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
153 const uint8_t wIndex,
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
154 void** const DescriptorAddress)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
155 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
156 const uint8_t DescriptorType = (wValue >> 8);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
157 const uint8_t DescriptorNumber = (wValue & 0xFF);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
158
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
159 void* Address = NULL;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
160 uint16_t Size = NO_DESCRIPTOR;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
161
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
162 switch (DescriptorType)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
163 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
164 case DTYPE_Device:
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
165 Address = &DeviceDescriptor;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
166 Size = sizeof(USB_Descriptor_Device_t);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
167 break;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
168 case DTYPE_Configuration:
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
169 Address = &ConfigurationDescriptor;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
170 Size = sizeof(USB_Descriptor_Configuration_t);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
171 break;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
172 case DTYPE_String:
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
173 if (!(DescriptorNumber))
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
174 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
175 Address = &LanguageString;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
176 Size = LanguageString.Header.Size;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
177 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
178 else
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
179 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
180 Address = &ProductString;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
181 Size = ProductString.Header.Size;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
182 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
183
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
184 break;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
185 }
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
186
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
187 *DescriptorAddress = Address;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
188 return Size;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
189 }

mercurial