00001 /* ---------------------------------------------------------------------------- */ 00002 /* Atmel Microcontroller Software Support */ 00003 /* SAM Software Package License */ 00004 /* ---------------------------------------------------------------------------- */ 00005 /* Copyright (c) 2015, Atmel Corporation */ 00006 /* */ 00007 /* All rights reserved. */ 00008 /* */ 00009 /* Redistribution and use in source and binary forms, with or without */ 00010 /* modification, are permitted provided that the following condition is met: */ 00011 /* */ 00012 /* - Redistributions of source code must retain the above copyright notice, */ 00013 /* this list of conditions and the disclaimer below. */ 00014 /* */ 00015 /* Atmel's name may not be used to endorse or promote products derived from */ 00016 /* this software without specific prior written permission. */ 00017 /* */ 00018 /* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR */ 00019 /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */ 00020 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE */ 00021 /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, */ 00022 /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 00023 /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */ 00024 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */ 00025 /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */ 00026 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */ 00027 /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 00028 /* ---------------------------------------------------------------------------- */ 00029 00030 /** \file 00031 * \section Purpose 00032 * 00033 * Definitions and methods for USB request structures described by the 00034 * USB specification. 00035 * 00036 * \section Usage 00037 * 00038 */ 00039 00040 #ifndef _USBREQUESTS_H_ 00041 #define _USBREQUESTS_H_ 00042 /** \addtogroup usb_general 00043 * @{ 00044 * \addtogroup usb_request USB Requests 00045 * @{ 00046 */ 00047 00048 /*--------------------------------------------------------------------------- 00049 * Headers 00050 *---------------------------------------------------------------------------*/ 00051 00052 /* These headers were introduced in C99 by working group 00053 * ISO/IEC JTC1/SC22/WG14. 00054 */ 00055 #include <stdint.h> 00056 00057 /*--------------------------------------------------------------------------- 00058 * Definitions 00059 *---------------------------------------------------------------------------*/ 00060 00061 /*----------- Generic Request ------------*/ 00062 00063 /** \addtogroup usb_request_define USB Generic Request definitions 00064 * @{ 00065 * This section lists the codes of USB generic request. 00066 * 00067 * - \ref usb_request_code USB Request codes 00068 * - \ref USBGenericRequest_GETSTATUS 00069 * - \ref USBGenericRequest_CLEARFEATURE 00070 * - \ref USBGenericRequest_SETFEATURE 00071 * - \ref USBGenericRequest_SETADDRESS 00072 * - \ref USBGenericRequest_GETDESCRIPTOR 00073 * - \ref USBGenericRequest_SETDESCRIPTOR 00074 * - \ref USBGenericRequest_GETCONFIGURATION 00075 * - \ref USBGenericRequest_SETCONFIGURATION 00076 * - \ref USBGenericRequest_GETINTERFACE 00077 * - \ref USBGenericRequest_SETINTERFACE 00078 * - \ref USBGenericRequest_SYNCHFRAME 00079 * 00080 * - \ref usb_request_recipient USB Request Recipients 00081 * - \ref USBGenericRequest_DEVICE 00082 * - \ref USBGenericRequest_INTERFACE 00083 * - \ref USBGenericRequest_ENDPOINT 00084 * - \ref USBGenericRequest_OTHER 00085 * 00086 * - \ref usb_request_type USB Request Types 00087 * - \ref USBGenericRequest_STANDARD 00088 * - \ref USBGenericRequest_CLASS 00089 * - \ref USBGenericRequest_VENDOR 00090 * 00091 * - \ref usb_request_dir USB Request Directions 00092 * - \ref USBGenericRequest_IN 00093 * - \ref USBGenericRequest_OUT 00094 */ 00095 00096 /** \addtogroup usb_request_code USB Request codes 00097 * @{ 00098 * This section lists the USB generic request codes. 00099 * - \ref USBGenericRequest_GETSTATUS 00100 * - \ref USBGenericRequest_CLEARFEATURE 00101 * - \ref USBGenericRequest_SETFEATURE 00102 * - \ref USBGenericRequest_SETADDRESS 00103 * - \ref USBGenericRequest_GETDESCRIPTOR 00104 * - \ref USBGenericRequest_SETDESCRIPTOR 00105 * - \ref USBGenericRequest_GETCONFIGURATION 00106 * - \ref USBGenericRequest_SETCONFIGURATION 00107 * - \ref USBGenericRequest_GETINTERFACE 00108 * - \ref USBGenericRequest_SETINTERFACE 00109 * - \ref USBGenericRequest_SYNCHFRAME 00110 */ 00111 /** GET_STATUS request code. */ 00112 #define USBGenericRequest_GETSTATUS 0 00113 /** CLEAR_FEATURE request code. */ 00114 #define USBGenericRequest_CLEARFEATURE 1 00115 /** SET_FEATURE request code. */ 00116 #define USBGenericRequest_SETFEATURE 3 00117 /** SET_ADDRESS request code. */ 00118 #define USBGenericRequest_SETADDRESS 5 00119 /** GET_DESCRIPTOR request code. */ 00120 #define USBGenericRequest_GETDESCRIPTOR 6 00121 /** SET_DESCRIPTOR request code. */ 00122 #define USBGenericRequest_SETDESCRIPTOR 7 00123 /** GET_CONFIGURATION request code. */ 00124 #define USBGenericRequest_GETCONFIGURATION 8 00125 /** SET_CONFIGURATION request code. */ 00126 #define USBGenericRequest_SETCONFIGURATION 9 00127 /** GET_INTERFACE request code. */ 00128 #define USBGenericRequest_GETINTERFACE 10 00129 /** SET_INTERFACE request code. */ 00130 #define USBGenericRequest_SETINTERFACE 11 00131 /** SYNCH_FRAME request code. */ 00132 #define USBGenericRequest_SYNCHFRAME 12 00133 /** @}*/ 00134 00135 /** \addtogroup usb_request_recipient USB Request Recipients 00136 * @{ 00137 * This section lists codes of USB request recipients. 00138 * - \ref USBGenericRequest_DEVICE 00139 * - \ref USBGenericRequest_INTERFACE 00140 * - \ref USBGenericRequest_ENDPOINT 00141 * - \ref USBGenericRequest_OTHER 00142 */ 00143 /** Recipient is the whole device. */ 00144 #define USBGenericRequest_DEVICE 0 00145 /** Recipient is an interface. */ 00146 #define USBGenericRequest_INTERFACE 1 00147 /** Recipient is an endpoint. */ 00148 #define USBGenericRequest_ENDPOINT 2 00149 /** Recipient is another entity. */ 00150 #define USBGenericRequest_OTHER 3 00151 /** @}*/ 00152 00153 /** \addtogroup usb_request_type USB Request Types 00154 * @{ 00155 * This section lists codes of USB request types. 00156 * - \ref USBGenericRequest_STANDARD 00157 * - \ref USBGenericRequest_CLASS 00158 * - \ref USBGenericRequest_VENDOR 00159 */ 00160 /** Request is standard. */ 00161 #define USBGenericRequest_STANDARD 0 00162 /** Request is class-specific. */ 00163 #define USBGenericRequest_CLASS 1 00164 /** Request is vendor-specific. */ 00165 #define USBGenericRequest_VENDOR 2 00166 /** @}*/ 00167 00168 /** \addtogroup usb_request_dir USB Request Directions 00169 * @{ 00170 * This section lists codes of USB request directions. 00171 * - \ref USBGenericRequest_IN 00172 * - \ref USBGenericRequest_OUT 00173 */ 00174 /** Transfer occurs from device to the host. */ 00175 #define USBGenericRequest_OUT 0 00176 /** Transfer occurs from the host to the device. */ 00177 #define USBGenericRequest_IN 1 00178 /** @}*/ 00179 /** @}*/ 00180 00181 00182 /*----------- Feature Request ------------*/ 00183 00184 /** \addtogroup usb_feature_def USB Feature Request Definitions 00185 * @{ 00186 * This section lists codes of USB Feature Request 00187 * 00188 * - \ref usb_feature_sel USB Feature selectors 00189 * - \ref USBFeatureRequest_ENDPOINTHALT 00190 * - \ref USBFeatureRequest_DEVICEREMOTEWAKEUP 00191 * - \ref USBFeatureRequest_TESTMODE 00192 * 00193 * - \ref usb_test_sel USB Test mode selectors 00194 * - \ref USBFeatureRequest_TESTJ 00195 * - \ref USBFeatureRequest_TESTK 00196 * - \ref USBFeatureRequest_TESTSE0NAK 00197 * - \ref USBFeatureRequest_TESTPACKET 00198 * - \ref USBFeatureRequest_TESTFORCEENABLE 00199 * - \ref USBFeatureRequest_TESTSENDZLP 00200 */ 00201 00202 /** \addtogroup usb_feature_sel USB Feature selectors 00203 * @{ 00204 * This section lists codes of USB feature selectors. 00205 * - \ref USBFeatureRequest_ENDPOINTHALT 00206 * - \ref USBFeatureRequest_DEVICEREMOTEWAKEUP 00207 * - \ref USBFeatureRequest_TESTMODE 00208 */ 00209 /** Halt feature of an endpoint. */ 00210 #define USBFeatureRequest_ENDPOINTHALT 0 00211 /** Remote wake-up feature of the device. */ 00212 #define USBFeatureRequest_DEVICEREMOTEWAKEUP 1 00213 /** Test mode of the device. */ 00214 #define USBFeatureRequest_TESTMODE 2 00215 /** OTG set feature */ 00216 #define USBFeatureRequest_OTG 0x0B 00217 /** OTG b_hnp_enable */ 00218 #define USBFeatureRequest_OTG_B_HNP_ENABLE 3 00219 /** OTG a_hnp_support */ 00220 #define USBFeatureRequest_OTG_A_HNP_SUPPORT 4 00221 /** OTG a_alt_hnp_support */ 00222 #define USBFeatureRequest_OTG_A_ALT_HNP_SUPPORT 5 00223 /** @}*/ 00224 00225 /** \addtogroup usb_test_sel USB Test mode selectors 00226 * @{ 00227 * This section lists codes of USB high speed test mode selectors. 00228 * - \ref USBFeatureRequest_TESTJ 00229 * - \ref USBFeatureRequest_TESTK 00230 * - \ref USBFeatureRequest_TESTSE0NAK 00231 * - \ref USBFeatureRequest_TESTPACKET 00232 * - \ref USBFeatureRequest_TESTFORCEENABLE 00233 * - \ref USBFeatureRequest_TESTSENDZLP 00234 */ 00235 00236 /** Tests the high-output drive level on the D+ line. */ 00237 #define USBFeatureRequest_TESTJ 1 00238 /** Tests the high-output drive level on the D- line. */ 00239 #define USBFeatureRequest_TESTK 2 00240 /** Tests the output impedance, low-level output voltage and loading 00241 characteristics. */ 00242 #define USBFeatureRequest_TESTSE0NAK 3 00243 /** Tests rise and fall times, eye patterns and jitter. */ 00244 #define USBFeatureRequest_TESTPACKET 4 00245 /** Tests the hub disconnect detection. */ 00246 #define USBFeatureRequest_TESTFORCEENABLE 5 00247 /** Send a ZLP in Test Mode. */ 00248 #define USBFeatureRequest_TESTSENDZLP 6 00249 /** @}*/ 00250 /** @}*/ 00251 00252 /*--------------------------------------------------------------------------- 00253 * Types 00254 *---------------------------------------------------------------------------*/ 00255 typedef uint8_t USBHS_Add_t; 00256 typedef uint8_t USBHS_Ep_t; 00257 /* 00258 * Function types 00259 */ 00260 00261 /* 00262 * Descriptor structs types 00263 */ 00264 #pragma pack(1) 00265 #if defined ( __CC_ARM ) /* Keil ¦̀Vision 4 */ 00266 #elif defined ( __ICCARM__ ) /* IAR Ewarm 5.41+ */ 00267 #define __attribute__(...) 00268 #elif defined ( __GNUC__ ) /* GCC CS3 2009q3-68 */ 00269 #endif 00270 00271 /** 00272 * Generic USB SETUP request sent over Control endpoints. 00273 */ 00274 typedef struct { 00275 00276 /** Type of request 00277 * \sa usb_request_recipient "USB Request Recipients" 00278 * \sa usb_request_type "USB Request Types" 00279 * \sa usb_request_dir "USB Request Directions" */ 00280 uint8_t bmRequestType:8; 00281 /** Request code 00282 * \sa usb_request_code "USB Request Codes" */ 00283 uint8_t bRequest:8; 00284 /** Request-specific value parameter. */ 00285 uint16_t wValue:16; 00286 /** Request-specific index parameter. */ 00287 uint16_t wIndex:16; 00288 /** Expected length (in bytes) of the data phase. */ 00289 uint16_t wLength:16; 00290 00291 } USBGenericRequest; 00292 00293 #pragma pack() 00294 00295 /*--------------------------------------------------------------------------- 00296 * Exported Functions 00297 *---------------------------------------------------------------------------*/ 00298 00299 extern uint8_t USBGenericRequest_GetType( 00300 const USBGenericRequest *request); 00301 00302 extern uint8_t USBGenericRequest_GetRequest( 00303 const USBGenericRequest *request); 00304 00305 extern uint16_t USBGenericRequest_GetValue( 00306 const USBGenericRequest *request); 00307 00308 extern uint16_t USBGenericRequest_GetIndex( 00309 const USBGenericRequest *request); 00310 00311 extern uint16_t USBGenericRequest_GetLength( 00312 const USBGenericRequest *request); 00313 00314 extern uint8_t USBGenericRequest_GetEndpointNumber( 00315 const USBGenericRequest *request); 00316 00317 extern uint8_t USBGenericRequest_GetRecipient( 00318 const USBGenericRequest *request); 00319 00320 extern uint8_t USBGenericRequest_GetDirection( 00321 const USBGenericRequest *request); 00322 00323 00324 extern uint8_t USBGetDescriptorRequest_GetDescriptorType( 00325 const USBGenericRequest *request); 00326 00327 extern uint8_t USBGetDescriptorRequest_GetDescriptorIndex( 00328 const USBGenericRequest *request); 00329 00330 00331 extern uint8_t USBSetAddressRequest_GetAddress( 00332 const USBGenericRequest *request); 00333 00334 00335 extern uint8_t USBSetConfigurationRequest_GetConfiguration( 00336 const USBGenericRequest *request); 00337 00338 00339 extern uint8_t USBInterfaceRequest_GetInterface( 00340 const USBGenericRequest *request); 00341 00342 extern uint8_t USBInterfaceRequest_GetAlternateSetting( 00343 const USBGenericRequest *request); 00344 00345 00346 extern uint8_t USBFeatureRequest_GetFeatureSelector( 00347 const USBGenericRequest *request); 00348 00349 extern uint8_t USBFeatureRequest_GetTestSelector( 00350 const USBGenericRequest *request); 00351 00352 /** @}*/ 00353 /**@}*/ 00354 #endif /* #ifndef _USBREQUESTS_H_ */ 00355