505ccd3c2b3a0d585c495148d55a194f13fd51cd
[pub/USBasp.git] / LUFA / Drivers / USB / HighLevel / StdRequestType.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2010.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2010 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 *
34 * This file contains structures and macros for the easy creation and parsing of standard USB control requests.
35 *
36 * \note This file should not be included directly. It is automatically included as needed by the USB driver
37 * dispatch header located in LUFA/Drivers/USB/USB.h.
38 */
39
40 /** \ingroup Group_USB
41 * @defgroup Group_StdRequest Standard USB Requests
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 /* Preprocessor Checks: */
53 #if !defined(__INCLUDE_FROM_USB_DRIVER)
54 #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
55 #endif
56
57 /* Public Interface - May be used in end-application: */
58 /* Macros: */
59 /** Mask for the request type parameter, to indicate the direction of the request data (Host to Device
60 * or Device to Host). The result of this mask should then be compared to the request direction masks.
61 *
62 * \see REQDIR_* macros for masks indicating the request data direction.
63 */
64 #define CONTROL_REQTYPE_DIRECTION 0x80
65
66 /** Mask for the request type parameter, to indicate the type of request (Device, Class or Vendor
67 * Specific). The result of this mask should then be compared to the request type masks.
68 *
69 * \see REQTYPE_* macros for masks indicating the request type.
70 */
71 #define CONTROL_REQTYPE_TYPE 0x60
72
73 /** Mask for the request type parameter, to indicate the recipient of the request (Standard, Class
74 * or Vendor Specific). The result of this mask should then be compared to the request recipient
75 * masks.
76 *
77 * \see REQREC_* macros for masks indicating the request recipient.
78 */
79 #define CONTROL_REQTYPE_RECIPIENT 0x1F
80
81 /** Request data direction mask, indicating that the request data will flow from host to device.
82 *
83 * \see \ref CONTROL_REQTYPE_DIRECTION macro.
84 */
85 #define REQDIR_HOSTTODEVICE (0 << 7)
86
87 /** Request data direction mask, indicating that the request data will flow from device to host.
88 *
89 * \see \ref CONTROL_REQTYPE_DIRECTION macro.
90 */
91 #define REQDIR_DEVICETOHOST (1 << 7)
92
93 /** Request type mask, indicating that the request is a standard request.
94 *
95 * \see \ref CONTROL_REQTYPE_TYPE macro.
96 */
97 #define REQTYPE_STANDARD (0 << 5)
98
99 /** Request type mask, indicating that the request is a class-specific request.
100 *
101 * \see \ref CONTROL_REQTYPE_TYPE macro.
102 */
103 #define REQTYPE_CLASS (1 << 5)
104
105 /** Request type mask, indicating that the request is a vendor specific request.
106 *
107 * \see \ref CONTROL_REQTYPE_TYPE macro.
108 */
109 #define REQTYPE_VENDOR (2 << 5)
110
111 /** Request recipient mask, indicating that the request is to be issued to the device as a whole.
112 *
113 * \see \ref CONTROL_REQTYPE_RECIPIENT macro.
114 */
115 #define REQREC_DEVICE (0 << 0)
116
117 /** Request recipient mask, indicating that the request is to be issued to an interface in the
118 * currently selected configuration.
119 *
120 * \see \ref CONTROL_REQTYPE_RECIPIENT macro.
121 */
122 #define REQREC_INTERFACE (1 << 0)
123
124 /** Request recipient mask, indicating that the request is to be issued to an endpoint in the
125 * currently selected configuration.
126 *
127 * \see \ref CONTROL_REQTYPE_RECIPIENT macro.
128 */
129 #define REQREC_ENDPOINT (2 << 0)
130
131 /** Request recipient mask, indicating that the request is to be issued to an unspecified element
132 * in the currently selected configuration.
133 *
134 * \see \ref CONTROL_REQTYPE_RECIPIENT macro.
135 */
136 #define REQREC_OTHER (3 << 0)
137
138 /** Feature indicator for Clear Feature or Set Feature commands. When used in a Clear Feature
139 * request this indicates that an endpoint (whose address is given elsewhere in the request
140 * should have its stall condition cleared. If used in a similar manner inside a Set Feature
141 * request, this stalls an endpoint.
142 */
143 #define FEATURE_ENDPOINT_HALT 0x00
144
145 /** Feature indicator for Clear Feature or Set Feature commands. When used in a Clear Feature
146 * request this indicates that the remote wakeup enabled device should not issue remote
147 * wakeup requests until further notice. If used in a similar manner inside a Set Feature
148 * request, this re-enabled the remote wakeup feature on the device.
149 */
150 #define FEATURE_REMOTE_WAKEUP 0x01
151
152 /* Type Defines: */
153 /** \brief Standard USB Control Request
154 *
155 * Type define for a standard USB control request.
156 *
157 * \see The USB 2.0 specification for more information on standard control requests.
158 */
159 typedef struct
160 {
161 uint8_t bmRequestType; /**< Type of the request. */
162 uint8_t bRequest; /**< Request command code. */
163 uint16_t wValue; /**< wValue parameter of the request. */
164 uint16_t wIndex; /**< wIndex parameter of the request. */
165 uint16_t wLength; /**< Length of the data to transfer in bytes. */
166 } USB_Request_Header_t;
167
168 /* Enums: */
169 /** Enumeration for the various standard request commands. These commands are applicable when the
170 * request type is \ref REQTYPE_STANDARD (with the exception of \ref REQ_GetDescriptor, which is always
171 * handled regardless of the request type value).
172 *
173 * \see Chapter 9 of the USB 2.0 Specification.
174 */
175 enum USB_Control_Request_t
176 {
177 REQ_GetStatus = 0, /**< Implemented in the library for device, endpoint and interface
178 * recipients. Passed to the user application for other recipients
179 * via the \ref EVENT_USB_Device_UnhandledControlRequest() event when received in
180 * device mode. */
181 REQ_ClearFeature = 1, /**< Implemented in the library for device, endpoint and interface
182 * recipients. Passed to the user application for other recipients
183 * via the \ref EVENT_USB_Device_UnhandledControlRequest() event when received in
184 * device mode. */
185 REQ_SetFeature = 3, /**< Implemented in the library for device, endpoint and interface
186 * recipients. Passed to the user application for other recipients
187 * via the \ref EVENT_USB_Device_UnhandledControlRequest() event when received in
188 * device mode. */
189 REQ_SetAddress = 5, /**< Implemented in the library for the device recipient. Passed
190 * to the user application for other recipients via the
191 * \ref EVENT_USB_Device_UnhandledControlRequest() event when received in
192 * device mode. */
193 REQ_GetDescriptor = 6, /**< Implemented in the library for all recipients and all request
194 * types. */
195 REQ_SetDescriptor = 7, /**< Not implemented in the library, passed to the user application
196 * via the \ref EVENT_USB_Device_UnhandledControlRequest() event when received in
197 * device mode. */
198 REQ_GetConfiguration = 8, /**< Implemented in the library for the device recipient. Passed
199 * to the user application for other recipients via the
200 * \ref EVENT_USB_Device_UnhandledControlRequest() event when received in
201 * device mode. */
202 REQ_SetConfiguration = 9, /**< Implemented in the library for the device recipient. Passed
203 * to the user application for other recipients via the
204 * \ref EVENT_USB_Device_UnhandledControlRequest() event when received in
205 * device mode. */
206 REQ_GetInterface = 10, /**< Not implemented in the library, passed to the user application
207 * via the \ref EVENT_USB_Device_UnhandledControlRequest() event when received in
208 * device mode. */
209 REQ_SetInterface = 11, /**< Not implemented in the library, passed to the user application
210 * via the \ref EVENT_USB_Device_UnhandledControlRequest() event when received in
211 * device mode. */
212 REQ_SynchFrame = 12, /**< Not implemented in the library, passed to the user application
213 * via the \ref EVENT_USB_Device_UnhandledControlRequest() event when received in
214 * device mode. */
215 };
216
217 /* Private Interface - For use in library only: */
218 #if !defined(__DOXYGEN__)
219 /* Macros: */
220 #define FEATURE_SELFPOWERED_ENABLED (1 << 0)
221 #define FEATURE_REMOTE_WAKEUP_ENABLED (1 << 1)
222 #endif
223
224 #endif
225
226 /** @} */