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