83f59afc62dda7261dd026e48c164b3bd13fd270
[pub/USBasp.git] / LUFA / Drivers / USB / Core / StdRequestType.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2011.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2011 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 /** \file
32 * \brief USB control endpoint request definitions.
33 * \copydetails Group_StdRequest
34 *
35 * \note This file should not be included directly. It is automatically included as needed by the USB driver
36 * dispatch header located in LUFA/Drivers/USB/USB.h.
37 */
38
39 /** \ingroup Group_USB
40 * \defgroup Group_StdRequest Standard USB Requests
41 * \brief USB control endpoint request definitions.
42 *
43 * This module contains definitions for the various control request parameters, so that the request
44 * details (such as data direction, request recipient, etc.) can be extracted via masking.
45 *
46 * @{
47 */
48
49 #ifndef __STDREQTYPE_H__
50 #define __STDREQTYPE_H__
51
52 /* Includes: */
53 #include "../../../Common/Common.h"
54 #include "USBMode.h"
55
56 /* Preprocessor Checks: */
57 #if !defined(__INCLUDE_FROM_USB_DRIVER)
58 #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
59 #endif
60
61 /* Public Interface - May be used in end-application: */
62 /* Macros: */
63 /** Mask for the request type parameter, to indicate the direction of the request data (Host to Device
64 * or Device to Host). The result of this mask should then be compared to the request direction masks.
65 *
66 * \see REQDIR_* macros for masks indicating the request data direction.
67 */
68 #define CONTROL_REQTYPE_DIRECTION 0x80
69
70 /** Mask for the request type parameter, to indicate the type of request (Device, Class or Vendor
71 * Specific). The result of this mask should then be compared to the request type masks.
72 *
73 * \see REQTYPE_* macros for masks indicating the request type.
74 */
75 #define CONTROL_REQTYPE_TYPE 0x60
76
77 /** Mask for the request type parameter, to indicate the recipient of the request (Device, Interface
78 * Endpoint or Other). The result of this mask should then be compared to the request recipient
79 * masks.
80 *
81 * \see REQREC_* macros for masks indicating the request recipient.
82 */
83 #define CONTROL_REQTYPE_RECIPIENT 0x1F
84
85 /** \name Control Request Data Direction Masks */
86 //@{
87 /** Request data direction mask, indicating that the request data will flow from host to device.
88 *
89 * \see \ref CONTROL_REQTYPE_DIRECTION macro.
90 */
91 #define REQDIR_HOSTTODEVICE (0 << 7)
92
93 /** Request data direction mask, indicating that the request data will flow from device to host.
94 *
95 * \see \ref CONTROL_REQTYPE_DIRECTION macro.
96 */
97 #define REQDIR_DEVICETOHOST (1 << 7)
98 //@}
99
100 /** \name Control Request Type Masks */
101 //@{
102 /** Request type mask, indicating that the request is a standard request.
103 *
104 * \see \ref CONTROL_REQTYPE_TYPE macro.
105 */
106 #define REQTYPE_STANDARD (0 << 5)
107
108 /** Request type mask, indicating that the request is a class-specific request.
109 *
110 * \see \ref CONTROL_REQTYPE_TYPE macro.
111 */
112 #define REQTYPE_CLASS (1 << 5)
113
114 /** Request type mask, indicating that the request is a vendor specific request.
115 *
116 * \see \ref CONTROL_REQTYPE_TYPE macro.
117 */
118 #define REQTYPE_VENDOR (2 << 5)
119 //@}
120
121 /** \name Control Request Recipient Masks */
122 //@{
123 /** Request recipient mask, indicating that the request is to be issued to the device as a whole.
124 *
125 * \see \ref CONTROL_REQTYPE_RECIPIENT macro.
126 */
127 #define REQREC_DEVICE (0 << 0)
128
129 /** Request recipient mask, indicating that the request is to be issued to an interface in the
130 * currently selected configuration.
131 *
132 * \see \ref CONTROL_REQTYPE_RECIPIENT macro.
133 */
134 #define REQREC_INTERFACE (1 << 0)
135
136 /** Request recipient mask, indicating that the request is to be issued to an endpoint in the
137 * currently selected configuration.
138 *
139 * \see \ref CONTROL_REQTYPE_RECIPIENT macro.
140 */
141 #define REQREC_ENDPOINT (2 << 0)
142
143 /** Request recipient mask, indicating that the request is to be issued to an unspecified element
144 * in the currently selected configuration.
145 *
146 * \see \ref CONTROL_REQTYPE_RECIPIENT macro.
147 */
148 #define REQREC_OTHER (3 << 0)
149 //@}
150
151 /* Type Defines: */
152 /** \brief Standard USB Control Request
153 *
154 * Type define for a standard USB control request.
155 *
156 * \see The USB 2.0 specification for more information on standard control requests.
157 */
158 typedef struct
159 {
160 uint8_t bmRequestType; /**< Type of the request. */
161 uint8_t bRequest; /**< Request command code. */
162 uint16_t wValue; /**< wValue parameter of the request. */
163 uint16_t wIndex; /**< wIndex parameter of the request. */
164 uint16_t wLength; /**< Length of the data to transfer in bytes. */
165 } USB_Request_Header_t;
166
167 /* Enums: */
168 /** Enumeration for the various standard request commands. These commands are applicable when the
169 * request type is \ref REQTYPE_STANDARD (with the exception of \ref REQ_GetDescriptor, which is always
170 * handled regardless of the request type value).
171 *
172 * \see Chapter 9 of the USB 2.0 Specification.
173 */
174 enum USB_Control_Request_t
175 {
176 REQ_GetStatus = 0, /**< Implemented in the library for device, endpoint and interface
177 * recipients. Passed to the user application for other recipients
178 * via the \ref EVENT_USB_Device_ControlRequest() event when received in
179 * device mode. */
180 REQ_ClearFeature = 1, /**< Implemented in the library for device, endpoint and interface
181 * recipients. Passed to the user application for other recipients
182 * via the \ref EVENT_USB_Device_ControlRequest() event when received in
183 * device mode. */
184 REQ_SetFeature = 3, /**< Implemented in the library for device, endpoint and interface
185 * recipients. Passed to the user application for other recipients
186 * via the \ref EVENT_USB_Device_ControlRequest() event when received in
187 * device mode. */
188 REQ_SetAddress = 5, /**< Implemented in the library for the device recipient. Passed
189 * to the user application for other recipients via the
190 * \ref EVENT_USB_Device_ControlRequest() event when received in
191 * device mode. */
192 REQ_GetDescriptor = 6, /**< Implemented in the library for device and interface recipients. Passed to the
193 * user application for other recipients via the
194 * \ref EVENT_USB_Device_ControlRequest() event when received in
195 * device mode. */
196 REQ_SetDescriptor = 7, /**< Not implemented in the library, passed to the user application
197 * via the \ref EVENT_USB_Device_ControlRequest() event when received in
198 * device mode. */
199 REQ_GetConfiguration = 8, /**< Implemented in the library for the device recipient. Passed
200 * to the user application for other recipients via the
201 * \ref EVENT_USB_Device_ControlRequest() event when received in
202 * device mode. */
203 REQ_SetConfiguration = 9, /**< Implemented in the library for the device recipient. Passed
204 * to the user application for other recipients via the
205 * \ref EVENT_USB_Device_ControlRequest() event when received in
206 * device mode. */
207 REQ_GetInterface = 10, /**< Not implemented in the library, passed to the user application
208 * via the \ref EVENT_USB_Device_ControlRequest() event when received in
209 * device mode. */
210 REQ_SetInterface = 11, /**< Not implemented in the library, passed to the user application
211 * via the \ref EVENT_USB_Device_ControlRequest() event when received in
212 * device mode. */
213 REQ_SynchFrame = 12, /**< Not implemented in the library, passed to the user application
214 * via the \ref EVENT_USB_Device_ControlRequest() event when received in
215 * device mode. */
216 };
217
218 /** Feature Selector values for Set Feature and Clear Feature standard control requests directed to the device, interface
219 * and endpoint recipients.
220 */
221 enum USB_Feature_Selectors_t
222 {
223 FEATURE_SEL_EndpointHalt = 0x00, /**< Feature selector for Clear Feature or Set Feature commands. When
224 * used in a Set Feature or Clear Feature request this indicates that an
225 * endpoint (whose address is given elsewhere in the request should have
226 * its stall condition changed.
227 */
228 FEATURE_SEL_DeviceRemoteWakeup = 0x01, /**< Feature selector for Device level Remote Wakeup enable set or clear.
229 * This feature can be controlled by the host on devices which indicate
230 * remote wakeup support in their descriptors to selectively disable or
231 * enable remote wakeup.
232 */
233 FEATURE_SEL_TestMode = 0x02, /**< Feature selector for Test Mode features, used to test the USB controller
234 * to check for incorrect operation.
235 */
236 };
237
238 /* Private Interface - For use in library only: */
239 #if !defined(__DOXYGEN__)
240 /* Macros: */
241 #define FEATURE_SELFPOWERED_ENABLED (1 << 0)
242 #define FEATURE_REMOTE_WAKEUP_ENABLED (1 << 1)
243 #endif
244
245 #endif
246
247 /** @} */
248