]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/protocol/lufa/LUFA-git/LUFA/Drivers/USB/Core/HostStandardReq.h
Merge commit '60b30c036397cb5627fa374bb930794b225daa29' as 'lib/lufa'
[qmk_firmware.git] / tmk_core / protocol / lufa / LUFA-git / LUFA / Drivers / USB / Core / HostStandardReq.h
1 /*
2              LUFA Library
3      Copyright (C) Dean Camera, 2014.
4
5   dean [at] fourwalledcubicle [dot] com
6            www.lufa-lib.org
7 */
8
9 /*
10   Copyright 2014  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 disclaims 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 host standard request management.
33  *
34  *  This file contains the function prototypes necessary for the issuing of outgoing standard control requests
35  *  when the library is in USB host mode.
36  *
37  *  \note This file should not be included directly. It is automatically included as needed by the USB driver
38  *        dispatch header located in LUFA/Drivers/USB/USB.h.
39  */
40
41 #ifndef __HOSTSTDREQ_H__
42 #define __HOSTSTDREQ_H__
43
44         /* Includes: */
45                 #include "../../../Common/Common.h"
46                 #include "USBMode.h"
47                 #include "StdRequestType.h"
48                 #include "USBController.h"
49
50         /* Enable C linkage for C++ Compilers: */
51                 #if defined(__cplusplus)
52                         extern "C" {
53                 #endif
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                         #if !defined(USB_HOST_TIMEOUT_MS) || defined(__DOXYGEN__)
63                                 /** Constant for the maximum software timeout period of sent USB control transactions to an attached
64                                  *  device. If a device fails to respond to a sent control request within this period, the
65                                  *  library will return a timeout error code.
66                                  *
67                                  *  This value may be overridden in the user project makefile as the value of the
68                                  *  \ref USB_HOST_TIMEOUT_MS token, and passed to the compiler using the -D switch.
69                                  */
70                                 #define USB_HOST_TIMEOUT_MS                1000
71                         #endif
72
73                 /* Enums: */
74                         /** Enum for the \ref USB_Host_SendControlRequest() return code, indicating the reason for the error
75                          *  if the transfer of the request is unsuccessful.
76                          *
77                          *  \ingroup Group_PipeControlReq
78                          */
79                         enum USB_Host_SendControlErrorCodes_t
80                         {
81                                 HOST_SENDCONTROL_Successful         = 0, /**< No error occurred in the request transfer. */
82                                 HOST_SENDCONTROL_DeviceDisconnected = 1, /**< The attached device was disconnected during the
83                                                                         *     request transfer.
84                                                                         */
85                                 HOST_SENDCONTROL_PipeError          = 2, /**< An error occurred in the pipe while sending the request. */
86                                 HOST_SENDCONTROL_SetupStalled       = 3, /**< The attached device stalled the request, usually
87                                                                           *   indicating that the request is unsupported on the device.
88                                                                           */
89                                 HOST_SENDCONTROL_SoftwareTimeOut    = 4, /**< The request or data transfer timed out. */
90                         };
91
92                 /* Global Variables: */
93                         /** Indicates the currently set configuration number of the attached device. This indicates the currently
94                          *  selected configuration value if one has been set successfully, or 0 if no configuration has been selected.
95                          *
96                          *  To set a device configuration, call the \ref USB_Host_SetDeviceConfiguration() function.
97                          *
98                          *  \attention This variable should be treated as read-only in the user application, and never manually
99                          *             changed in value.
100                          *
101                          *  \ingroup Group_Host
102                          */
103                         extern uint8_t USB_Host_ConfigurationNumber;
104
105                 /* Function Prototypes: */
106                         /** Sends the request stored in the \ref USB_ControlRequest global structure to the attached device,
107                          *  and transfers the data stored in the buffer to the device, or from the device to the buffer
108                          *  as requested. The transfer is made on the currently selected pipe.
109                          *
110                          *  \ingroup Group_PipeControlReq
111                          *
112                          *  \param[in] BufferPtr  Pointer to the start of the data buffer if the request has a data stage, or
113                          *                        \c NULL if the request transfers no data to or from the device.
114                          *
115                          *  \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result.
116                          */
117                         uint8_t USB_Host_SendControlRequest(void* const BufferPtr);
118
119                         /** Sends a SET CONFIGURATION standard request to the attached device, with the given configuration index.
120                          *
121                          *  This routine will automatically update the \ref USB_HostState and \ref USB_Host_ConfigurationNumber
122                          *  state variables according to the given function parameters and the result of the request.
123                          *
124                          *  \note After this routine returns, the control pipe will be selected.
125                          *
126                          *  \ingroup Group_PipeControlReq
127                          *
128                          *  \param[in] ConfigNumber  Configuration index to send to the device.
129                          *
130                          *  \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result.
131                          */
132                         uint8_t USB_Host_SetDeviceConfiguration(const uint8_t ConfigNumber);
133
134                         /** Sends a GET CONFIGURATION standard request to the attached device, to retrieve the currently selected
135                          *  device configuration index.
136                          *
137                          *  \note After this routine returns, the control pipe will be selected.
138                          *
139                          *  \ingroup Group_PipeControlReq
140                          *
141                          *  \param[out] ConfigNumber  Pointer to a location where the retrieved configuration index should be stored.
142                          *
143                          *  \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result.
144                          */
145                         uint8_t USB_Host_GetDeviceConfiguration(uint8_t* const ConfigNumber) ATTR_NON_NULL_PTR_ARG(1);
146
147                         /** Sends a GET DESCRIPTOR standard request to the attached device, requesting the  descriptor of the
148                          *  specified type and index.
149                          *
150                          *  \note After this routine returns, the control pipe will be selected.
151                          *
152                          *  \ingroup Group_PipeControlReq
153                          *
154                          *  \param[in]  Type          Type of descriptor to retrieve, a value from the \ref USB_DescriptorTypes_t enum.
155                          *  \param[in]  Index         Index of the descriptor to retrieve.
156                          *  \param[out] Buffer        Pointer to the destination buffer where the retrieved string descriptor is to be stored.
157                          *  \param[in]  BufferLength  Maximum size of the string descriptor which can be stored into the buffer.
158                          *
159                          *  \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result.
160                          */
161                         uint8_t USB_Host_GetDescriptor(const uint8_t Type,
162                                                        const uint8_t Index,
163                                                        void* const Buffer,
164                                                        const uint8_t BufferLength) ATTR_NON_NULL_PTR_ARG(3);
165
166                         /** Retrieves the current feature status of the attached device, via a GET STATUS standard request. The
167                          *  retrieved feature status can then be examined by masking the retrieved value with the various
168                          *  \c FEATURE_* masks for bus/self power information and remote wakeup support.
169                          *
170                          *  \note After this routine returns, the control pipe will be selected.
171                          *
172                          *  \ingroup Group_PipeControlReq
173                          *
174                          *  \param[out]  FeatureStatus  Location where the retrieved feature status should be stored.
175                          *
176                          *  \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result.
177                          */
178                         uint8_t USB_Host_GetDeviceStatus(uint8_t* const FeatureStatus) ATTR_NON_NULL_PTR_ARG(1);
179
180                         /** Clears a stall condition on the given pipe, via a CLEAR FEATURE standard request to the attached device.
181                          *
182                          *  \note After this routine returns, the control pipe will be selected.
183                          *
184                          *  \ingroup Group_PipeControlReq
185                          *
186                          *  \param[in] EndpointAddress  Address of the endpoint to clear, including the endpoint's direction.
187                          *
188                          *  \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result.
189                          */
190                         uint8_t USB_Host_ClearEndpointStall(const uint8_t EndpointAddress);
191
192                         /** Selects a given alternative setting for the specified interface, via a SET INTERFACE standard request to
193                          *  the attached device.
194                          *
195                          *  \note After this routine returns, the control pipe will be selected.
196                          *
197                          *  \ingroup Group_PipeControlReq
198                          *
199                          *  \param[in] InterfaceIndex  Index of the interface whose alternative setting is to be altered.
200                          *  \param[in] AltSetting      Index of the interface's alternative setting which is to be selected.
201                          *
202                          *  \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result.
203                          */
204                         uint8_t USB_Host_SetInterfaceAltSetting(const uint8_t InterfaceIndex,
205                                                                 const uint8_t AltSetting);
206
207
208                         /** Retrieves the current alternative setting for the specified interface, via a GET INTERFACE standard request to
209                          *  the attached device.
210                          *
211                          *  \note After this routine returns, the control pipe will be selected.
212                          *
213                          *  \ingroup Group_PipeControlReq
214                          *
215                          *  \param[in]  InterfaceIndex  Index of the interface whose alternative setting is to be altered.
216                          *  \param[out] AltSetting      Pointer to a location where the retrieved alternative setting value should be stored.
217                          *
218                          *  \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result.
219                          */
220                         uint8_t USB_Host_GetInterfaceAltSetting(const uint8_t InterfaceIndex,
221                                                                 uint8_t* const AltSetting) ATTR_NON_NULL_PTR_ARG(2);
222
223                 /* Inline Functions: */
224                         /** Sends a GET DESCRIPTOR standard request to the attached device, requesting the device descriptor.
225                          *  This can be used to easily retrieve information about the device such as its VID, PID and power
226                          *  requirements. This is a convenience wrapper for \ref USB_Host_GetDescriptor().
227                          *
228                          *  \note After this routine returns, the control pipe will be selected.
229                          *
230                          *  \ingroup Group_PipeControlReq
231                          *
232                          *  \param[out] DeviceDescriptorPtr  Pointer to the destination device descriptor structure where
233                          *                                   the read data is to be stored.
234                          *
235                          *  \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result.
236                          */
237                         static inline uint8_t USB_Host_GetDeviceDescriptor(USB_Descriptor_Device_t* const DeviceDescriptorPtr) ATTR_NON_NULL_PTR_ARG(1);
238                         static inline uint8_t USB_Host_GetDeviceDescriptor(USB_Descriptor_Device_t* const DeviceDescriptorPtr)
239                         {
240                                 return USB_Host_GetDescriptor(DTYPE_Device, 0, DeviceDescriptorPtr, sizeof(USB_Descriptor_Device_t));
241                         }
242
243                         /** Sends a GET DESCRIPTOR standard request to the attached device, requesting the string descriptor
244                          *  of the specified index. This can be used to easily retrieve string descriptors from the device by
245                          *  index, after the index is obtained from the Device or Configuration descriptors. This is a convenience
246                          *  wrapper for \ref USB_Host_GetDescriptor().
247                          *
248                          *  \note After this routine returns, the control pipe will be selected.
249                          *
250                          *  \ingroup Group_PipeControlReq
251                          *
252                          *  \param[in]  Index        Index of the string descriptor to retrieve.
253                          *  \param[out] Buffer       Pointer to the destination buffer where the retrieved string descriptor is
254                          *                           to be stored.
255                          *  \param[in] BufferLength  Maximum size of the string descriptor which can be stored into the buffer.
256                          *
257                          *  \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result.
258                          */
259                         static inline uint8_t USB_Host_GetDeviceStringDescriptor(const uint8_t Index,
260                                                                                  void* const Buffer,
261                                                                                  const uint8_t BufferLength) ATTR_NON_NULL_PTR_ARG(2);
262                         static inline uint8_t USB_Host_GetDeviceStringDescriptor(const uint8_t Index,
263                                                                                  void* const Buffer,
264                                                                                  const uint8_t BufferLength)
265                         {
266                                 return USB_Host_GetDescriptor(DTYPE_String, Index,  Buffer, BufferLength);
267                         }
268
269         /* Private Interface - For use in library only: */
270         #if !defined(__DOXYGEN__)
271                 /* Enums: */
272                         enum USB_WaitForTypes_t
273                         {
274                                 USB_HOST_WAITFOR_SetupSent,
275                                 USB_HOST_WAITFOR_InReceived,
276                                 USB_HOST_WAITFOR_OutReady,
277                         };
278
279                 /* Function Prototypes: */
280                         #if defined(__INCLUDE_FROM_HOSTSTDREQ_C)
281                                 static uint8_t USB_Host_SendControlRequest_PRV(void* const BufferPtr);
282                                 static uint8_t USB_Host_WaitForIOS(const uint8_t WaitType);
283                         #endif
284         #endif
285
286         /* Disable C linkage for C++ Compilers: */
287                 #if defined(__cplusplus)
288                         }
289                 #endif
290
291 #endif
292