Merge pull request #10531 from b14ckyy/master
[inav.git] / lib / main / STM32_USB-FS-Device_Driver / inc / usb_core.h
blobbf303f79e64474a7c22accdff027ba36207adcab
1 /**
2 ******************************************************************************
3 * @file usb_core.h
4 * @author MCD Application Team
5 * @version V4.0.0
6 * @date 28-August-2012
7 * @brief Standard protocol processing functions prototypes
8 ******************************************************************************
9 * @attention
11 * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
13 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
14 * You may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at:
17 * http://www.st.com/software_license_agreement_liberty_v2
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
25 ******************************************************************************
29 /* Define to prevent recursive inclusion -------------------------------------*/
30 #ifndef __USB_CORE_H
31 #define __USB_CORE_H
33 /* Includes ------------------------------------------------------------------*/
34 /* Exported types ------------------------------------------------------------*/
35 typedef enum _CONTROL_STATE
37 WAIT_SETUP, /* 0 */
38 SETTING_UP, /* 1 */
39 IN_DATA, /* 2 */
40 OUT_DATA, /* 3 */
41 LAST_IN_DATA, /* 4 */
42 LAST_OUT_DATA, /* 5 */
43 WAIT_STATUS_IN, /* 7 */
44 WAIT_STATUS_OUT, /* 8 */
45 STALLED, /* 9 */
46 PAUSE /* 10 */
47 } CONTROL_STATE; /* The state machine states of a control pipe */
49 typedef struct OneDescriptor
51 uint8_t *Descriptor;
52 uint16_t Descriptor_Size;
54 ONE_DESCRIPTOR, *PONE_DESCRIPTOR;
55 /* All the request process routines return a value of this type
56 If the return value is not SUCCESS or NOT_READY,
57 the software will STALL the correspond endpoint */
58 typedef enum _RESULT
60 USB_SUCCESS = 0, /* Process successfully */
61 USB_ERROR,
62 USB_UNSUPPORT,
63 USB_NOT_READY /* The process has not been finished, endpoint will be
64 NAK to further request */
65 } RESULT;
68 /*-*-*-*-*-*-*-*-*-*-* Definitions for endpoint level -*-*-*-*-*-*-*-*-*-*-*-*/
69 typedef struct _ENDPOINT_INFO
71 /* When send data out of the device,
72 CopyData() is used to get data buffer 'Length' bytes data
73 if Length is 0,
74 CopyData() returns the total length of the data
75 if the request is not supported, returns 0
76 (NEW Feature )
77 if CopyData() returns -1, the calling routine should not proceed
78 further and will resume the SETUP process by the class device
79 if Length is not 0,
80 CopyData() returns a pointer to indicate the data location
81 Usb_wLength is the data remain to be sent,
82 Usb_wOffset is the Offset of original data
83 When receive data from the host,
84 CopyData() is used to get user data buffer which is capable
85 of Length bytes data to copy data from the endpoint buffer.
86 if Length is 0,
87 CopyData() returns the available data length,
88 if Length is not 0,
89 CopyData() returns user buffer address
90 Usb_rLength is the data remain to be received,
91 Usb_rPointer is the Offset of data buffer
93 uint16_t Usb_wLength;
94 uint16_t Usb_wOffset;
95 uint16_t PacketSize;
96 uint8_t *(*CopyData)(uint16_t Length);
97 }ENDPOINT_INFO;
99 /*-*-*-*-*-*-*-*-*-*-*-* Definitions for device level -*-*-*-*-*-*-*-*-*-*-*-*/
101 typedef struct _DEVICE
103 uint8_t Total_Endpoint; /* Number of endpoints that are used */
104 uint8_t Total_Configuration;/* Number of configuration available */
106 DEVICE;
108 typedef union
110 uint16_t w;
111 struct BW
113 uint8_t bb1;
114 uint8_t bb0;
117 } uint16_t_uint8_t;
119 typedef struct _DEVICE_INFO
121 uint8_t USBbmRequestType; /* bmRequestType */
122 uint8_t USBbRequest; /* bRequest */
123 uint16_t_uint8_t USBwValues; /* wValue */
124 uint16_t_uint8_t USBwIndexs; /* wIndex */
125 uint16_t_uint8_t USBwLengths; /* wLength */
127 uint8_t ControlState; /* of type CONTROL_STATE */
128 uint8_t Current_Feature;
129 uint8_t Current_Configuration; /* Selected configuration */
130 uint8_t Current_Interface; /* Selected interface of current configuration */
131 uint8_t Current_AlternateSetting;/* Selected Alternate Setting of current
132 interface*/
134 ENDPOINT_INFO Ctrl_Info;
135 }DEVICE_INFO;
137 typedef struct _DEVICE_PROP
139 void (*Init)(void); /* Initialize the device */
140 void (*Reset)(void); /* Reset routine of this device */
142 /* Device dependent process after the status stage */
143 void (*Process_Status_IN)(void);
144 void (*Process_Status_OUT)(void);
146 /* Procedure of process on setup stage of a class specified request with data stage */
147 /* All class specified requests with data stage are processed in Class_Data_Setup
148 Class_Data_Setup()
149 responses to check all special requests and fills ENDPOINT_INFO
150 according to the request
151 If IN tokens are expected, then wLength & wOffset will be filled
152 with the total transferring bytes and the starting position
153 If OUT tokens are expected, then rLength & rOffset will be filled
154 with the total expected bytes and the starting position in the buffer
156 If the request is valid, Class_Data_Setup returns SUCCESS, else UNSUPPORT
158 CAUTION:
159 Since GET_CONFIGURATION & GET_INTERFACE are highly related to
160 the individual classes, they will be checked and processed here.
162 RESULT (*Class_Data_Setup)(uint8_t RequestNo);
164 /* Procedure of process on setup stage of a class specified request without data stage */
165 /* All class specified requests without data stage are processed in Class_NoData_Setup
166 Class_NoData_Setup
167 responses to check all special requests and perform the request
169 CAUTION:
170 Since SET_CONFIGURATION & SET_INTERFACE are highly related to
171 the individual classes, they will be checked and processed here.
173 RESULT (*Class_NoData_Setup)(uint8_t RequestNo);
175 /*Class_Get_Interface_Setting
176 This function is used by the file usb_core.c to test if the selected Interface
177 and Alternate Setting (uint8_t Interface, uint8_t AlternateSetting) are supported by
178 the application.
179 This function is writing by user. It should return "SUCCESS" if the Interface
180 and Alternate Setting are supported by the application or "UNSUPPORT" if they
181 are not supported. */
183 RESULT (*Class_Get_Interface_Setting)(uint8_t Interface, uint8_t AlternateSetting);
185 uint8_t* (*GetDeviceDescriptor)(uint16_t Length);
186 uint8_t* (*GetConfigDescriptor)(uint16_t Length);
187 uint8_t* (*GetStringDescriptor)(uint16_t Length);
189 /* This field is not used in current library version. It is kept only for
190 compatibility with previous versions */
191 void* RxEP_buffer;
193 uint8_t MaxPacketSize;
195 }DEVICE_PROP;
197 typedef struct _USER_STANDARD_REQUESTS
199 void (*User_GetConfiguration)(void); /* Get Configuration */
200 void (*User_SetConfiguration)(void); /* Set Configuration */
201 void (*User_GetInterface)(void); /* Get Interface */
202 void (*User_SetInterface)(void); /* Set Interface */
203 void (*User_GetStatus)(void); /* Get Status */
204 void (*User_ClearFeature)(void); /* Clear Feature */
205 void (*User_SetEndPointFeature)(void); /* Set Endpoint Feature */
206 void (*User_SetDeviceFeature)(void); /* Set Device Feature */
207 void (*User_SetDeviceAddress)(void); /* Set Device Address */
209 USER_STANDARD_REQUESTS;
211 /* Exported constants --------------------------------------------------------*/
212 #define Type_Recipient (pInformation->USBbmRequestType & (REQUEST_TYPE | RECIPIENT))
214 #define Usb_rLength Usb_wLength
215 #define Usb_rOffset Usb_wOffset
217 #define USBwValue USBwValues.w
218 #define USBwValue0 USBwValues.bw.bb0
219 #define USBwValue1 USBwValues.bw.bb1
220 #define USBwIndex USBwIndexs.w
221 #define USBwIndex0 USBwIndexs.bw.bb0
222 #define USBwIndex1 USBwIndexs.bw.bb1
223 #define USBwLength USBwLengths.w
224 #define USBwLength0 USBwLengths.bw.bb0
225 #define USBwLength1 USBwLengths.bw.bb1
227 /* Exported macro ------------------------------------------------------------*/
228 /* Exported functions ------------------------------------------------------- */
229 uint8_t Setup0_Process(void);
230 uint8_t Post0_Process(void);
231 uint8_t Out0_Process(void);
232 uint8_t In0_Process(void);
234 RESULT Standard_SetEndPointFeature(void);
235 RESULT Standard_SetDeviceFeature(void);
237 uint8_t *Standard_GetConfiguration(uint16_t Length);
238 RESULT Standard_SetConfiguration(void);
239 uint8_t *Standard_GetInterface(uint16_t Length);
240 RESULT Standard_SetInterface(void);
241 uint8_t *Standard_GetDescriptorData(uint16_t Length, PONE_DESCRIPTOR pDesc);
243 uint8_t *Standard_GetStatus(uint16_t Length);
244 RESULT Standard_ClearFeature(void);
245 void SetDeviceAddress(uint8_t);
246 void NOP_Process(void);
248 extern DEVICE_PROP Device_Property;
249 extern USER_STANDARD_REQUESTS User_Standard_Requests;
250 extern DEVICE Device_Table;
251 extern DEVICE_INFO Device_Info;
253 /* cells saving status during interrupt servicing */
254 extern __IO uint16_t SaveRState;
255 extern __IO uint16_t SaveTState;
257 #endif /* __USB_CORE_H */
259 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/