STM32F10,L1 en F3 USB Full Speed Device bibliotheek  1.0
ST Microelectronics USB Full Speed Device bibliotheek documentatie
 All Data Structures Files
usb_core.h
Go to the documentation of this file.
1 
29 /* Define to prevent recursive inclusion -------------------------------------*/
30 #ifndef __USB_CORE_H
31 #define __USB_CORE_H
32 
33 /* Includes ------------------------------------------------------------------*/
34 /* Exported types ------------------------------------------------------------*/
35 typedef enum _CONTROL_STATE
36 {
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 */
48 
49 typedef struct OneDescriptor
50 {
51  uint8_t *Descriptor;
52  uint16_t Descriptor_Size;
53 }
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
59 {
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;
66 
67 
68 /*-*-*-*-*-*-*-*-*-*-* Definitions for endpoint level -*-*-*-*-*-*-*-*-*-*-*-*/
69 typedef struct _ENDPOINT_INFO
70 {
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
92  */
93  uint16_t Usb_wLength;
94  uint16_t Usb_wOffset;
95  uint16_t PacketSize;
96  uint8_t *(*CopyData)(uint16_t Length);
98 
99 /*-*-*-*-*-*-*-*-*-*-*-* Definitions for device level -*-*-*-*-*-*-*-*-*-*-*-*/
100 
101 typedef struct _DEVICE
102 {
103  uint8_t Total_Endpoint; /* Number of endpoints that are used */
104  uint8_t Total_Configuration;/* Number of configuration available */
105 }
106 DEVICE;
107 
108 typedef union
109 {
110  uint16_t w;
111  struct BW
112  {
113  uint8_t bb1;
114  uint8_t bb0;
115  }
116  bw;
118 
119 typedef struct _DEVICE_INFO
120 {
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 */
126 
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*/
133 
134  ENDPOINT_INFO Ctrl_Info;
135 }DEVICE_INFO;
136 
137 typedef struct _DEVICE_PROP
138 {
139  void (*Init)(void); /* Initialize the device */
140  void (*Reset)(void); /* Reset routine of this device */
141 
142  /* Device dependent process after the status stage */
143  void (*Process_Status_IN)(void);
144  void (*Process_Status_OUT)(void);
145 
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
155 
156  If the request is valid, Class_Data_Setup returns SUCCESS, else UNSUPPORT
157 
158  CAUTION:
159  Since GET_CONFIGURATION & GET_INTERFACE are highly related to
160  the individual classes, they will be checked and processed here.
161  */
162  RESULT (*Class_Data_Setup)(uint8_t RequestNo);
163 
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
168 
169  CAUTION:
170  Since SET_CONFIGURATION & SET_INTERFACE are highly related to
171  the individual classes, they will be checked and processed here.
172  */
173  RESULT (*Class_NoData_Setup)(uint8_t RequestNo);
174 
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. */
182 
183  RESULT (*Class_Get_Interface_Setting)(uint8_t Interface, uint8_t AlternateSetting);
184 
185  uint8_t* (*GetDeviceDescriptor)(uint16_t Length);
186  uint8_t* (*GetConfigDescriptor)(uint16_t Length);
187  uint8_t* (*GetStringDescriptor)(uint16_t Length);
188 
189  /* This field is not used in current library version. It is kept only for
190  compatibility with previous versions */
191  void* RxEP_buffer;
192 
193  uint8_t MaxPacketSize;
194 
195 }DEVICE_PROP;
196 
198 {
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 */
208 }
210 
211 /* Exported constants --------------------------------------------------------*/
212 #define Type_Recipient (pInformation->USBbmRequestType & (REQUEST_TYPE | RECIPIENT))
213 
214 #define Usb_rLength Usb_wLength
215 #define Usb_rOffset Usb_wOffset
216 
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
226 
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);
233 
234 RESULT Standard_SetEndPointFeature(void);
235 RESULT Standard_SetDeviceFeature(void);
236 
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);
242 
243 uint8_t *Standard_GetStatus(uint16_t Length);
244 RESULT Standard_ClearFeature(void);
245 void SetDeviceAddress(uint8_t);
246 void NOP_Process(void);
247 
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;
252 
253 /* cells saving status during interrupt servicing */
254 extern __IO uint16_t SaveRState;
255 extern __IO uint16_t SaveTState;
256 
257 #endif /* __USB_CORE_H */
258 
259 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/