Moved all source to the trunk directory.
[pub/lufa.git] / Bootloaders / DFU / Descriptors.h
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 /** \file
32 *
33 * Header file for Descriptors.c.
34 */
35
36 #ifndef _DESCRIPTORS_H_
37 #define _DESCRIPTORS_H_
38
39 /* Includes: */
40 #include <LUFA/Drivers/USB/USB.h>
41
42 /* Macros: */
43 /** Descriptor type value for a DFU class functional descriptor. */
44 #define DTYPE_DFUFunctional 0x21
45
46 /** DFU attribute mask, indicating that the DFU device will detach and re-attach when a DFU_DETACH
47 * command is issued, rather than the host issing a USB Reset.
48 */
49 #define ATTR_WILL_DETATCH (1 << 3)
50
51 /** DFU attribute mask, indicating that the DFU device can communicate during the manefestation phase
52 * (memory programming phase).
53 */
54 #define ATTR_MANEFESTATION_TOLLERANT (1 << 2)
55
56 /** DFU attribute mask, indicating that the DFU device can accept DFU_UPLOAD requests to send data from
57 * the device to the host.
58 */
59 #define ATTR_CAN_UPLOAD (1 << 1)
60
61 /** DFU attribute mask, indicating that the DFU device can accept DFU_DNLOAD requests to send data from
62 * the host to the device.
63 */
64 #define ATTR_CAN_DOWNLOAD (1 << 0)
65
66 #if defined(__AVR_AT90USB1286__)
67 #define PRODUCT_ID_CODE 0x2FFB
68
69 #define SIGNATURE_BYTE_1 0x1E
70 #define SIGNATURE_BYTE_2 0x97
71 #define SIGNATURE_BYTE_3 0x82
72 #elif defined(__AVR_AT90USB1287__)
73 #define PRODUCT_ID_CODE 0x2FFB
74
75 #define SIGNATURE_BYTE_1 0x1E
76 #define SIGNATURE_BYTE_2 0x97
77 #define SIGNATURE_BYTE_3 0x82
78 #elif defined(__AVR_AT90USB646__)
79 #define PRODUCT_ID_CODE 0x2FF9
80
81 #define SIGNATURE_BYTE_1 0x1E
82 #define SIGNATURE_BYTE_2 0x96
83 #define SIGNATURE_BYTE_3 0x82
84 #elif defined(__AVR_AT90USB647__)
85 #define PRODUCT_ID_CODE 0x2FF9
86
87 #define SIGNATURE_BYTE_1 0x1E
88 #define SIGNATURE_BYTE_2 0x96
89 #define SIGNATURE_BYTE_3 0x82
90 #elif defined(__AVR_AT90USB162__)
91 #define PRODUCT_ID_CODE 0x2FFA
92
93 #define SIGNATURE_BYTE_1 0x1E
94 #define SIGNATURE_BYTE_2 0x94
95 #define SIGNATURE_BYTE_3 0x82
96 #elif defined(__AVR_AT90USB82__)
97 #define PRODUCT_ID_CODE 0x2FF7
98
99 #define SIGNATURE_BYTE_1 0x1E
100 #define SIGNATURE_BYTE_2 0x94
101 #define SIGNATURE_BYTE_3 0x82
102 #elif defined(__AVR_ATmega32U6__)
103 #define PRODUCT_ID_CODE 0x2FFB
104
105 #define SIGNATURE_BYTE_1 0x1E
106 #define SIGNATURE_BYTE_2 0x95
107 #define SIGNATURE_BYTE_3 0x88
108 #elif defined(__AVR_ATmega32U4__)
109 #define PRODUCT_ID_CODE 0x2FF4
110
111 #define SIGNATURE_BYTE_1 0x1E
112 #define SIGNATURE_BYTE_2 0x95
113 #define SIGNATURE_BYTE_3 0x87
114 #elif defined(__AVR_ATmega16U4__)
115 #define PRODUCT_ID_CODE 0x2FF3
116
117 #define SIGNATURE_BYTE_1 0x1E
118 #define SIGNATURE_BYTE_2 0x94
119 #define SIGNATURE_BYTE_3 0x88
120 #else
121 #error The selected AVR part is not currently supported by this bootloader.
122 #endif
123
124 #if !defined(PRODUCT_ID_CODE)
125 #error Current AVR model is not supported by this bootloader.
126 #endif
127
128 /* Type Defines: */
129 /** Type define for a DFU class function descriptor. This descriptor gives DFU class information
130 * to the host when read, indicating the DFU device's capabilities.
131 */
132 typedef struct
133 {
134 USB_Descriptor_Header_t Header; /**< Standard descriptor header structure */
135
136 uint8_t Attributes; /**< DFU device attributes, a mask comprising of the
137 * ATTR_* macros listed in this source file
138 */
139 uint16_t DetatchTimeout; /**< Timeout in milliseconds between a USB_DETACH
140 * command being issued and the device detaching
141 * from the USB bus
142 */
143 uint16_t TransferSize; /**< Maximum number of bytes the DFU device can accept
144 * from the host in a transaction
145 */
146 uint16_t DFUSpecification; /**< BCD packed DFU specification number this DFU
147 * device complies with
148 */
149 } USB_DFU_Functional_Descriptor_t;
150
151 /** Type define for the device configuration descriptor structure. This must be defined in the
152 * application code, as the configuration descriptor contains several sub-descriptors which
153 * vary between devices, and which describe the device's usage to the host.
154 */
155 typedef struct
156 {
157 USB_Descriptor_Configuration_Header_t Config;
158 USB_Descriptor_Interface_t DFUInterface;
159 USB_DFU_Functional_Descriptor_t DFUFunctional;
160 } USB_Descriptor_Configuration_t;
161
162 /* Function Prototypes: */
163 uint16_t USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex, void** const DescriptorAddress)
164 ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3);
165
166 #endif