Rev 111 | Rev 304 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 111 | Rev 275 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /******************** (C) COPYRIGHT 2006 STMicroelectronics ******************** |
1 | /******************** (C) COPYRIGHT 2008 STMicroelectronics ******************** |
2 | * File Name : usb_prop.c |
2 | * File Name : usb_prop.c |
3 | * Author : MCD Application Team |
3 | * Author : MCD Application Team |
4 | * Date First Issued : 10/01/2006 : V1.0 |
4 | * Date First Issued : 10/01/2008 : V1.0 |
5 | * Description : All processings related to Virtual Com Port Demo |
5 | * Description : All processings related to Virtual Com Port Demo |
6 | ******************************************************************************** |
6 | ******************************************************************************** |
7 | * History: |
7 | * History: |
8 | * 10/01/2006 : V1.0 |
8 | * 10/01/2008 : V1.0 |
9 | ******************************************************************************** |
9 | ******************************************************************************** |
10 | * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS |
10 | * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS |
11 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. |
11 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. |
12 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, |
12 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, |
13 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE |
13 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE |
14 | * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING |
14 | * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING |
15 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
15 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
16 | *******************************************************************************/ |
16 | *******************************************************************************/ |
Line 17... | Line 17... | ||
17 | 17 | ||
- | 18 | /* Includes ------------------------------------------------------------------*/ |
|
18 | /* Includes ------------------------------------------------------------------*/ |
19 | #include "usb.h" |
- | 20 | #include "usb_lib.h" |
|
- | 21 | #include "usb_conf.h" |
|
19 | #include "usb_lib.h" |
22 | #include "usb_prop.h" |
20 | #include "usb_desc.h" |
23 | #include "usb_desc.h" |
21 | #include "usb_pwr.h" |
- | |
- | 24 | #include "usb_pwr.h" |
|
22 | #include "usb_prop.h" |
25 | |
23 | /* Private typedef -----------------------------------------------------------*/ |
26 | /* Private typedef -----------------------------------------------------------*/ |
24 | /* Private define ------------------------------------------------------------*/ |
27 | /* Private define ------------------------------------------------------------*/ |
25 | /* Private macro -------------------------------------------------------------*/ |
28 | /* Private macro -------------------------------------------------------------*/ |
26 | /* Private variables ---------------------------------------------------------*/ |
29 | /* Private variables ---------------------------------------------------------*/ |
Line 96... | Line 99... | ||
96 | * Output : None. |
99 | * Output : None. |
97 | * Return : None. |
100 | * Return : None. |
98 | *******************************************************************************/ |
101 | *******************************************************************************/ |
99 | void Virtual_Com_Port_init(void) |
102 | void Virtual_Com_Port_init(void) |
100 | { |
103 | { |
101 | u32 timeout = 0; |
- | |
Line 102... | Line 104... | ||
102 | 104 | ||
103 | pInformation->Current_Configuration = 0; |
105 | pInformation->Current_Configuration = 0; |
104 | /* Connect the device */ |
106 | /* Connect the device */ |
105 | PowerOn(); |
107 | PowerOn(); |
106 | /* USB interrupts initialization */ |
108 | /* USB interrupts initialization */ |
107 | _SetISTR(0); /* clear pending interrupts */ |
109 | _SetISTR(0); /* clear pending interrupts */ |
108 | wInterrupt_Mask = IMR_MSK; |
110 | wInterrupt_Mask = IMR_MSK; |
109 | _SetCNTR(wInterrupt_Mask); /* set interrupts mask */ |
- | |
- | 111 | _SetCNTR(wInterrupt_Mask); /* set interrupts mask */ |
|
110 | pInformation->Current_Feature = Virtual_Com_Port_ConfigDescriptor[7]; |
112 | |
111 | /* Wait until device is configured */ |
- | |
- | 113 | //UART0_Config_Default(); |
|
112 | while (pInformation->Current_Configuration == 0 && (timeout++<600000)) NOP_Process(); |
114 | |
113 | if(pInformation->Current_Configuration !=0) bDeviceState = CONFIGURED; |
115 | bDeviceState = UNCONNECTED; |
114 | } |
116 | } |
115 | /******************************************************************************* |
117 | /******************************************************************************* |
116 | * Function Name : Virtual_Com_Port_Reset |
118 | * Function Name : Virtual_Com_Port_Reset |
117 | * Description : Virtual_Com_Port Mouse reset routine |
119 | * Description : Virtual_Com_Port Mouse reset routine |
Line 122... | Line 124... | ||
122 | void Virtual_Com_Port_Reset(void) |
124 | void Virtual_Com_Port_Reset(void) |
123 | { |
125 | { |
124 | /* Set Virtual_Com_Port_DEVICE as not configured */ |
126 | /* Set Virtual_Com_Port_DEVICE as not configured */ |
125 | pInformation->Current_Configuration = 0; |
127 | pInformation->Current_Configuration = 0; |
126 | pInformation->Current_Interface = 0;/*the default Interface*/ |
128 | pInformation->Current_Interface = 0;/*the default Interface*/ |
- | 129 | ||
- | 130 | /* Current Feature initialization */ |
|
- | 131 | pInformation->Current_Feature = Virtual_Com_Port_ConfigDescriptor[7]; |
|
- | 132 | ||
127 | SetBTABLE(BTABLE_ADDRESS); |
133 | SetBTABLE(BTABLE_ADDRESS); |
Line 128... | Line 134... | ||
128 | 134 | ||
129 | /* Initialize Endpoint 0 */ |
135 | /* Initialize Endpoint 0 */ |
130 | SetEPType(ENDP0, EP_CONTROL); |
136 | SetEPType(ENDP0, EP_CONTROL); |
Line 154... | Line 160... | ||
154 | SetEPRxStatus(ENDP3, EP_RX_VALID); |
160 | SetEPRxStatus(ENDP3, EP_RX_VALID); |
155 | SetEPTxStatus(ENDP3, EP_TX_DIS); |
161 | SetEPTxStatus(ENDP3, EP_TX_DIS); |
Line 156... | Line 162... | ||
156 | 162 | ||
157 | /* Set this device to response on default address */ |
163 | /* Set this device to response on default address */ |
- | 164 | SetDeviceAddress(0); |
|
- | 165 | bDeviceState = ATTACHED; |
|
- | 166 | } |
|
- | 167 | ||
- | 168 | /******************************************************************************* |
|
- | 169 | * Function Name : Virtual_Com_Port_SetConfiguration. |
|
- | 170 | * Description : Udpade the device state to configured. |
|
- | 171 | * Input : None. |
|
- | 172 | * Output : None. |
|
- | 173 | * Return : None. |
|
- | 174 | *******************************************************************************/ |
|
- | 175 | void Virtual_Com_Port_SetConfiguration(void) |
|
- | 176 | { |
|
- | 177 | DEVICE_INFO *pInfo = &Device_Info; |
|
- | 178 | ||
- | 179 | if (pInfo->Current_Configuration != 0) |
|
- | 180 | { |
|
- | 181 | /* Device configured */ |
|
- | 182 | bDeviceState = CONFIGURED; |
|
- | 183 | } |
|
- | 184 | } |
|
- | 185 | /******************************************************************************* |
|
- | 186 | * Function Name : Virtual_Com_Port_SetConfiguration. |
|
- | 187 | * Description : Udpade the device state to addressed. |
|
- | 188 | * Input : None. |
|
- | 189 | * Output : None. |
|
- | 190 | * Return : None. |
|
- | 191 | *******************************************************************************/ |
|
- | 192 | void Virtual_Com_Port_SetDeviceAddress (void) |
|
- | 193 | { |
|
158 | SetDeviceAddress(0); |
194 | bDeviceState = ADDRESSED; |
159 | } |
195 | } |
160 | /******************************************************************************* |
196 | /******************************************************************************* |
161 | * Function Name : Virtual_Com_Port_Status_In |
197 | * Function Name : Virtual_Com_Port_Status_In |
162 | * Description : |
198 | * Description : |
Line 166... | Line 202... | ||
166 | *******************************************************************************/ |
202 | *******************************************************************************/ |
167 | void Virtual_Com_Port_Status_In(void) |
203 | void Virtual_Com_Port_Status_In(void) |
168 | { |
204 | { |
169 | if (Request == SET_LINE_CODING) |
205 | if (Request == SET_LINE_CODING) |
170 | { |
206 | { |
- | 207 | //UART0_Config(); |
|
171 | Request = 0; |
208 | Request = 0; |
172 | } |
209 | } |
173 | } |
210 | } |
174 | /******************************************************************************* |
211 | /******************************************************************************* |
175 | * Function Name : Virtual_Com_Port_Status_Out |
212 | * Function Name : Virtual_Com_Port_Status_Out |
Line 177... | Line 214... | ||
177 | * Input : None. |
214 | * Input : None. |
178 | * Output : None. |
215 | * Output : None. |
179 | * Return : None. |
216 | * Return : None. |
180 | *******************************************************************************/ |
217 | *******************************************************************************/ |
181 | void Virtual_Com_Port_Status_Out (void) |
218 | void Virtual_Com_Port_Status_Out (void) |
182 | { |
- | |
183 | } |
219 | {} |
184 | /******************************************************************************* |
220 | /******************************************************************************* |
185 | * Function Name : Virtual_Com_Port_Data_Setup |
221 | * Function Name : Virtual_Com_Port_Data_Setup |
186 | * Description : handle the data class specific requests |
222 | * Description : handle the data class specific requests |
187 | * Input : Request Nb. |
223 | * Input : Request Nb. |
188 | * Output : None. |
224 | * Output : None. |
Line 194... | Line 230... | ||
194 | 230 | ||
Line 195... | Line 231... | ||
195 | CopyRoutine = NULL; |
231 | CopyRoutine = NULL; |
196 | 232 | ||
197 | if (RequestNo == GET_LINE_CODING) |
233 | if (RequestNo == GET_LINE_CODING) |
- | 234 | { |
|
198 | { |
235 | if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) |
199 | if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) CopyRoutine = Virtual_Com_Port_GetLineCoding; |
236 | CopyRoutine = Virtual_Com_Port_GetLineCoding; |
200 | } |
237 | } |
201 | else if (RequestNo == SET_LINE_CODING) |
238 | else if (RequestNo == SET_LINE_CODING) |
- | 239 | { |
|
202 | { |
240 | if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) |
203 | if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) CopyRoutine = Virtual_Com_Port_SetLineCoding; |
241 | CopyRoutine = Virtual_Com_Port_SetLineCoding; |
- | 242 | Request = SET_LINE_CODING; |
|
204 | Request = SET_LINE_CODING; |
243 | } |
Line 205... | Line 244... | ||
205 | } |
244 | |
206 | if (CopyRoutine == NULL) return USB_UNSUPPORT; |
245 | if (CopyRoutine == NULL) return USB_UNSUPPORT; |
207 | 246 | ||
Line 217... | Line 256... | ||
217 | * Output : None. |
256 | * Output : None. |
218 | * Return : USB_UNSUPPORT or USB_SUCCESS. |
257 | * Return : USB_UNSUPPORT or USB_SUCCESS. |
219 | *******************************************************************************/ |
258 | *******************************************************************************/ |
220 | RESULT Virtual_Com_Port_NoData_Setup(u8 RequestNo) |
259 | RESULT Virtual_Com_Port_NoData_Setup(u8 RequestNo) |
221 | { |
260 | { |
- | 261 | ||
222 | if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) |
262 | if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) |
223 | { |
263 | { |
224 | if (RequestNo == SET_COMM_FEATURE) return USB_SUCCESS; |
264 | if (RequestNo == SET_COMM_FEATURE) return USB_SUCCESS; |
225 | else if (RequestNo == SET_CONTROL_LINE_STATE) return USB_SUCCESS; |
265 | else if (RequestNo == SET_CONTROL_LINE_STATE) return USB_SUCCESS; |
226 | } |
266 | } |
- | 267 | ||
227 | return USB_UNSUPPORT; |
268 | return USB_UNSUPPORT; |
228 | } |
269 | } |
229 | /******************************************************************************* |
270 | /******************************************************************************* |
230 | * Function Name : Virtual_Com_Port_GetDeviceDescriptor. |
271 | * Function Name : Virtual_Com_Port_GetDeviceDescriptor. |
231 | * Description : Gets the device descriptor. |
272 | * Description : Gets the device descriptor. |
Line 256... | Line 297... | ||
256 | * Return : The address of the string descriptors. |
297 | * Return : The address of the string descriptors. |
257 | *******************************************************************************/ |
298 | *******************************************************************************/ |
258 | u8 *Virtual_Com_Port_GetStringDescriptor(u16 Length) |
299 | u8 *Virtual_Com_Port_GetStringDescriptor(u16 Length) |
259 | { |
300 | { |
260 | u8 wValue0 = pInformation->USBwValue0; |
301 | u8 wValue0 = pInformation->USBwValue0; |
- | 302 | ||
- | 303 | if (wValue0 > 5) |
|
- | 304 | { |
|
- | 305 | return NULL; |
|
- | 306 | } |
|
- | 307 | else |
|
- | 308 | { |
|
261 | return Standard_GetDescriptorData( Length, &String_Descriptor[wValue0] ); |
309 | return Standard_GetDescriptorData(Length, &String_Descriptor[wValue0]); |
262 | } |
310 | } |
- | 311 | } |
|
263 | /******************************************************************************* |
312 | /******************************************************************************* |
264 | * Function Name : Virtual_Com_Port_Get_Interface_Setting. |
313 | * Function Name : Virtual_Com_Port_Get_Interface_Setting. |
265 | * Description : test the interface and the alternate setting according to the |
314 | * Description : test the interface and the alternate setting according to the |
266 | * supported one. |
315 | * supported one. |
267 | * Input1 : u8: Interface : interface number. |
316 | * Input1 : u8: Interface : interface number. |
Line 269... | Line 318... | ||
269 | * Output : None. |
318 | * Output : None. |
270 | * Return : The address of the string descriptors. |
319 | * Return : The address of the string descriptors. |
271 | *******************************************************************************/ |
320 | *******************************************************************************/ |
272 | RESULT Virtual_Com_Port_Get_Interface_Setting(u8 Interface,u8 AlternateSetting) |
321 | RESULT Virtual_Com_Port_Get_Interface_Setting(u8 Interface, u8 AlternateSetting) |
273 | { |
322 | { |
- | 323 | if (AlternateSetting > 0) |
|
- | 324 | { |
|
274 | if(AlternateSetting >0) return USB_UNSUPPORT; |
325 | return USB_UNSUPPORT; |
- | 326 | } |
|
- | 327 | else if (Interface > 1) |
|
- | 328 | { |
|
275 | else if(Interface > 1) return USB_UNSUPPORT; |
329 | return USB_UNSUPPORT; |
- | 330 | } |
|
276 | return USB_SUCCESS; |
331 | return USB_SUCCESS; |
277 | } |
332 | } |
278 | /******************************************************************************* |
333 | /******************************************************************************* |
279 | * Function Name : Virtual_Com_Port_GetLineCoding. |
334 | * Function Name : Virtual_Com_Port_GetLineCoding. |
280 | * Description : send the linecoding structure to the PC host. |
335 | * Description : send the linecoding structure to the PC host. |
Line 284... | Line 339... | ||
284 | *******************************************************************************/ |
339 | *******************************************************************************/ |
285 | u8 *Virtual_Com_Port_GetLineCoding(u16 Length) |
340 | u8 *Virtual_Com_Port_GetLineCoding(u16 Length) |
286 | { |
341 | { |
287 | if(Length==0) |
342 | if (Length == 0) |
288 | { |
343 | { |
289 | pInformation->Ctrl_Info.Usb_wLength = sizeof(linecoding);; |
344 | pInformation->Ctrl_Info.Usb_wLength = sizeof(linecoding); |
290 | return NULL; |
345 | return NULL; |
291 | } |
346 | } |
292 | return(u8 *)&linecoding; |
347 | return(u8 *)&linecoding; |
293 | } |
348 | } |
294 | /******************************************************************************* |
349 | /******************************************************************************* |
Line 300... | Line 355... | ||
300 | *******************************************************************************/ |
355 | *******************************************************************************/ |
301 | u8 *Virtual_Com_Port_SetLineCoding(u16 Length) |
356 | u8 *Virtual_Com_Port_SetLineCoding(u16 Length) |
302 | { |
357 | { |
303 | if(Length==0) |
358 | if (Length == 0) |
304 | { |
359 | { |
305 | pInformation->Ctrl_Info.Usb_wLength = sizeof(linecoding);; |
360 | pInformation->Ctrl_Info.Usb_wLength = sizeof(linecoding); |
306 | return NULL; |
361 | return NULL; |
307 | } |
362 | } |
308 | return(u8 *)&linecoding; |
363 | return(u8 *)&linecoding; |
309 | } |
364 | } |
Line 310... | Line 365... | ||
310 | 365 |