3      Copyright (C) Dean Camera, 2011. 
   5   dean [at] fourwalledcubicle [dot] com 
  10   Copyright 2011  Dean Camera (dean [at] fourwalledcubicle [dot] com) 
  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. 
  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 
  32  *  \brief USB host standard request management. 
  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. 
  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. 
  41 #ifndef __HOSTSTDREQ_H__ 
  42 #define __HOSTSTDREQ_H__ 
  45                 #include "../../../Common/Common.h" 
  47                 #include "StdRequestType.h" 
  48                 #include "USBController.h" 
  50         /* Enable C linkage for C++ Compilers: */ 
  51                 #if defined(__cplusplus) 
  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. 
  60         /* Public Interface - May be used in end-application: */ 
  62                         /** Enum for the \ref USB_Host_SendControlRequest() return code, indicating the reason for the error 
  63                          *  if the transfer of the request is unsuccessful. 
  65                          *  \ingroup Group_PipeControlReq 
  67                         enum USB_Host_SendControlErrorCodes_t
 
  69                                 HOST_SENDCONTROL_Successful         
= 0, /**< No error occurred in the request transfer. */ 
  70                                 HOST_SENDCONTROL_DeviceDisconnected 
= 1, /**< The attached device was disconnected during the 
  73                                 HOST_SENDCONTROL_PipeError          
= 2, /**< An error occurred in the pipe while sending the request. */ 
  74                                 HOST_SENDCONTROL_SetupStalled       
= 3, /**< The attached device stalled the request, usually 
  75                                                                         *   indicating that the request is unsupported on the device. 
  77                                 HOST_SENDCONTROL_SoftwareTimeOut    
= 4, /**< The request or data transfer timed out. */ 
  80                 /* Global Variables: */ 
  81                         /** Indicates the currently set configuration number of the attached device. This indicates the currently 
  82                          *  selected configuration value if one has been set sucessfully, or 0 if no configuration has been selected. 
  84                          *  To set a device configuration, call the \ref USB_Host_SetDeviceConfiguration() function. 
  86                          *  \note This variable should be treated as read-only in the user application, and never manually 
  91                         extern uint8_t USB_Host_ConfigurationNumber
; 
  93                 /* Function Prototypes: */ 
  94                         /** Sends the request stored in the \ref USB_ControlRequest global structure to the attached device, 
  95                          *  and transfers the data stored in the buffer to the device, or from the device to the buffer 
  96                          *  as requested. The transfer is made on the currently selected pipe. 
  98                          *  \ingroup Group_PipeControlReq 
 100                          *  \param[in] BufferPtr  Pointer to the start of the data buffer if the request has a data stage, or 
 101                          *                        \c NULL if the request transfers no data to or from the device. 
 103                          *  \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result. 
 105                         uint8_t USB_Host_SendControlRequest(void* const BufferPtr
); 
 107                         /** Sends a SET CONFIGURATION standard request to the attached device, with the given configuration index. 
 109                          *  This routine will automatically update the \ref USB_HostState and \ref USB_Host_ConfigurationNumber 
 110                          *  state variables according to the given function parameters and the result of the request. 
 112                          *  \note After this routine returns, the control pipe will be selected. 
 114                          *  \ingroup Group_PipeControlReq 
 116                          *  \param[in] ConfigNumber  Configuration index to send to the device. 
 118                          *  \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result. 
 120                         uint8_t USB_Host_SetDeviceConfiguration(const uint8_t ConfigNumber
); 
 122                         /** Sends a GET DESCRIPTOR standard request to the attached device, requesting the device descriptor. 
 123                          *  This can be used to easily retrieve information about the device such as its VID, PID and power 
 126                          *  \note After this routine returns, the control pipe will be selected. 
 128                          *  \ingroup Group_PipeControlReq 
 130                          *  \param[out] DeviceDescriptorPtr  Pointer to the destination device descriptor structure where 
 131                          *                                   the read data is to be stored. 
 133                          *  \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result. 
 135                         uint8_t USB_Host_GetDeviceDescriptor(void* const DeviceDescriptorPtr
) ATTR_NON_NULL_PTR_ARG(1); 
 137                         /** Sends a GET DESCRIPTOR standard request to the attached device, requesting the string descriptor 
 138                          *  of the specified index. This can be used to easily retrieve string descriptors from the device by 
 139                          *  index, after the index is obtained from the Device or Configuration descriptors. 
 141                          *  \note After this routine returns, the control pipe will be selected. 
 143                          *  \ingroup Group_PipeControlReq 
 145                          *  \param[in]  Index        Index of the string index to retrieve. 
 146                          *  \param[out] Buffer       Pointer to the destination buffer where the retrieved string descriptor is 
 148                          *  \param[in] BufferLength  Maximum size of the string descriptor which can be stored into the buffer. 
 150                          *  \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result. 
 152                         uint8_t USB_Host_GetDeviceStringDescriptor(const uint8_t Index
, 
 154                                                                    const uint8_t BufferLength
) ATTR_NON_NULL_PTR_ARG(2); 
 156                         /** Retrieves the current feature status of the attached device, via a GET STATUS standard request. The 
 157                          *  retrieved feature status can then be examined by masking the retrieved value with the various 
 158                          *  FEATURE_* masks for bus/self power information and remote wakeup support. 
 160                          *  \note After this routine returns, the control pipe will be selected. 
 162                          *  \ingroup Group_PipeControlReq 
 164                          *  \param[out]  FeatureStatus  Location where the retrieved feature status should be stored. 
 166                          *  \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result. 
 168                         uint8_t USB_Host_GetDeviceStatus(uint8_t* const FeatureStatus
) ATTR_NON_NULL_PTR_ARG(1); 
 170                         /** Clears a stall condition on the given pipe, via a CLEAR FEATURE standard request to the attached device. 
 172                          *  \note After this routine returns, the control pipe will be selected. 
 174                          *  \ingroup Group_PipeControlReq 
 176                          *  \param[in] EndpointAddress  Address of the endpoint to clear, including the endpoint's direction. 
 178                          *  \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result. 
 180                         uint8_t USB_Host_ClearPipeStall(const uint8_t EndpointAddress
); 
 182                         /** Selects a given alternative setting for the specified interface, via a SET INTERFACE standard request to 
 183                          *  the attached device. 
 185                          *  \note After this routine returns, the control pipe will be selected. 
 187                          *  \ingroup Group_PipeControlReq 
 189                          *  \param[in] InterfaceIndex  Index of the interface whose alternative setting is to be altered. 
 190                          *  \param[in] AltSetting      Index of the interface's alternative setting which is to be selected. 
 192                          *  \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result. 
 194                         uint8_t USB_Host_SetInterfaceAltSetting(const uint8_t InterfaceIndex
, 
 195                                                                                                         const uint8_t AltSetting
); 
 197         /* Private Interface - For use in library only: */ 
 198         #if !defined(__DOXYGEN__) 
 200                         enum USB_WaitForTypes_t
 
 202                                 USB_HOST_WAITFOR_SetupSent
, 
 203                                 USB_HOST_WAITFOR_InReceived
, 
 204                                 USB_HOST_WAITFOR_OutReady
, 
 207                 /* Function Prototypes: */ 
 208                         #if defined(__INCLUDE_FROM_HOSTSTDREQ_C) 
 209                                 static uint8_t USB_Host_WaitForIOS(const uint8_t WaitType
); 
 213         /* Disable C linkage for C++ Compilers: */ 
 214                 #if defined(__cplusplus)