Rev 41 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ingob | 1 | /******************** (C) COPYRIGHT 2006 STMicroelectronics ******************** |
2 | * File Name : usb_prop.c |
||
3 | * Author : MCD Application Team |
||
4 | * Date First Issued : 10/01/2006 : V1.0 |
||
5 | * Description : All processings related to Virtual Com Port Demo |
||
6 | ******************************************************************************** |
||
7 | * History: |
||
8 | * 10/01/2006 : V1.0 |
||
9 | ******************************************************************************** |
||
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. |
||
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 |
||
14 | * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING |
||
15 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
||
16 | *******************************************************************************/ |
||
17 | |||
18 | /* Includes ------------------------------------------------------------------*/ |
||
19 | #include "main.h" |
||
20 | /* Private typedef -----------------------------------------------------------*/ |
||
21 | /* Private define ------------------------------------------------------------*/ |
||
22 | /* Private macro -------------------------------------------------------------*/ |
||
23 | /* Private variables ---------------------------------------------------------*/ |
||
24 | u32 Request = 0; |
||
25 | |||
26 | LINE_CODING linecoding = |
||
27 | { |
||
28 | 57600, /* baud rate*/ |
||
29 | 0x00, /* stop bits-1*/ |
||
30 | 0x00, /* parity - none*/ |
||
31 | 0x08 /* no. of bits 8*/ |
||
32 | }; |
||
33 | /* -------------------------------------------------------------------------- */ |
||
34 | /* Structures initializations */ |
||
35 | /* -------------------------------------------------------------------------- */ |
||
36 | |||
37 | DEVICE Device_Table = { |
||
38 | EP_NUM, |
||
39 | 1 |
||
40 | }; |
||
41 | |||
42 | DEVICE_PROP Device_Property = { |
||
43 | Virtual_Com_Port_init, |
||
44 | Virtual_Com_Port_Reset, |
||
45 | Virtual_Com_Port_Status_In, |
||
46 | Virtual_Com_Port_Status_Out, |
||
47 | Virtual_Com_Port_Data_Setup, |
||
48 | Virtual_Com_Port_NoData_Setup, |
||
49 | Virtual_Com_Port_Get_Interface_Setting, |
||
50 | Virtual_Com_Port_GetDeviceDescriptor, |
||
51 | Virtual_Com_Port_GetConfigDescriptor, |
||
52 | Virtual_Com_Port_GetStringDescriptor, |
||
53 | 0, |
||
54 | 0x40 /*MAX PACKET SIZE*/ |
||
55 | }; |
||
56 | USER_STANDARD_REQUESTS User_Standard_Requests = { |
||
57 | Virtual_Com_Port_GetConfiguration, |
||
58 | Virtual_Com_Port_SetConfiguration, |
||
59 | Virtual_Com_Port_GetInterface, |
||
60 | Virtual_Com_Port_SetInterface, |
||
61 | Virtual_Com_Port_GetStatus, |
||
62 | Virtual_Com_Port_ClearFeature, |
||
63 | Virtual_Com_Port_SetEndPointFeature, |
||
64 | Virtual_Com_Port_SetDeviceFeature, |
||
65 | Virtual_Com_Port_SetDeviceAddress |
||
66 | }; |
||
67 | |||
68 | ONE_DESCRIPTOR Device_Descriptor = { |
||
69 | (u8*)Virtual_Com_Port_DeviceDescriptor, |
||
70 | VIRTUAL_COM_PORT_SIZ_DEVICE_DESC |
||
71 | }; |
||
72 | |||
73 | ONE_DESCRIPTOR Config_Descriptor = { |
||
74 | (u8*)Virtual_Com_Port_ConfigDescriptor, |
||
75 | VIRTUAL_COM_PORT_SIZ_CONFIG_DESC |
||
76 | }; |
||
77 | |||
78 | ONE_DESCRIPTOR String_Descriptor[5] = { |
||
79 | {(u8*)Virtual_Com_Port_StringLangID, VIRTUAL_COM_PORT_SIZ_STRING_LANGID}, |
||
80 | {(u8*)Virtual_Com_Port_StringVendor, VIRTUAL_COM_PORT_SIZ_STRING_VENDOR}, |
||
81 | {(u8*)Virtual_Com_Port_StringProduct, VIRTUAL_COM_PORT_SIZ_STRING_PRODUCT}, |
||
82 | {(u8*)Virtual_Com_Port_StringSerial, VIRTUAL_COM_PORT_SIZ_STRING_SERIAL} |
||
83 | |||
84 | }; |
||
85 | /* Extern variables ----------------------------------------------------------*/ |
||
86 | /* Private function prototypes -----------------------------------------------*/ |
||
87 | /* Extern function prototypes ------------------------------------------------*/ |
||
88 | /* Private functions ---------------------------------------------------------*/ |
||
89 | /******************************************************************************* |
||
90 | * Function Name : Virtual_Com_Port_init |
||
91 | * Description : Virtual_Com_Port Mouse init routine |
||
92 | * Input : None. |
||
93 | * Output : None. |
||
94 | * Return : None. |
||
95 | *******************************************************************************/ |
||
96 | void Virtual_Com_Port_init(void) |
||
97 | { |
||
98 | u32 timeout = 0; |
||
99 | //SerialPutString(".vcpi."); |
||
100 | pInformation->Current_Configuration = 0; |
||
101 | /* Connect the device */ |
||
102 | PowerOn(); |
||
103 | /* USB interrupts initialization */ |
||
104 | _SetISTR(0); /* clear pending interrupts */ |
||
105 | wInterrupt_Mask = IMR_MSK; |
||
106 | _SetCNTR(wInterrupt_Mask); /* set interrupts mask */ |
||
107 | pInformation->Current_Feature = Virtual_Com_Port_ConfigDescriptor[7]; |
||
108 | /* Wait until device is configured */ |
||
109 | // UART0_Config_Default(); |
||
110 | //SerialPutString("..."); |
||
111 | while (pInformation->Current_Configuration == 0 && (timeout++<600000)) NOP_Process(); |
||
112 | if(pInformation->Current_Configuration !=0) bDeviceState = CONFIGURED; |
||
113 | //SerialPutString(".done."); |
||
114 | } |
||
115 | /******************************************************************************* |
||
116 | * Function Name : Virtual_Com_Port_Reset |
||
117 | * Description : Virtual_Com_Port Mouse reset routine |
||
118 | * Input : None. |
||
119 | * Output : None. |
||
120 | * Return : None. |
||
121 | *******************************************************************************/ |
||
122 | void Virtual_Com_Port_Reset(void) |
||
123 | { |
||
124 | /* Set Virtual_Com_Port_DEVICE as not configured */ |
||
125 | pInformation->Current_Configuration = 0; |
||
126 | pInformation->Current_Interface = 0;/*the default Interface*/ |
||
127 | SetBTABLE(BTABLE_ADDRESS); |
||
128 | |||
129 | /* Initialize Endpoint 0 */ |
||
130 | SetEPType(ENDP0, EP_CONTROL); |
||
131 | SetEPTxStatus(ENDP0, EP_TX_STALL); |
||
132 | SetEPRxAddr(ENDP0, ENDP0_RXADDR); |
||
133 | SetEPTxAddr(ENDP0, ENDP0_TXADDR); |
||
134 | Clear_Status_Out(ENDP0); |
||
135 | SetEPRxCount(ENDP0, Device_Property.MaxPacketSize); |
||
136 | SetEPRxValid(ENDP0); |
||
137 | |||
138 | /* Initialize Endpoint 1 */ |
||
139 | SetEPType(ENDP1, EP_BULK); |
||
140 | SetEPTxAddr(ENDP1, ENDP1_TXADDR); |
||
141 | SetEPTxStatus(ENDP1, EP_TX_NAK); |
||
142 | SetEPRxStatus(ENDP1, EP_RX_DIS); |
||
143 | |||
144 | /* Initialize Endpoint 2 */ |
||
145 | SetEPType(ENDP2, EP_INTERRUPT); |
||
146 | SetEPTxAddr(ENDP2, ENDP2_TXADDR); |
||
147 | SetEPRxStatus(ENDP2, EP_RX_DIS); |
||
148 | SetEPTxStatus(ENDP2, EP_TX_NAK); |
||
149 | |||
150 | /* Initialize Endpoint 3 */ |
||
151 | SetEPType(ENDP3, EP_BULK); |
||
152 | SetEPRxAddr(ENDP3, ENDP3_RXADDR); |
||
153 | SetEPRxCount(ENDP3, VIRTUAL_COM_PORT_DATA_SIZE); |
||
154 | SetEPRxStatus(ENDP3, EP_RX_VALID); |
||
155 | SetEPTxStatus(ENDP3, EP_TX_DIS); |
||
156 | |||
157 | /* Set this device to response on default address */ |
||
158 | SetDeviceAddress(0); |
||
159 | } |
||
160 | /******************************************************************************* |
||
161 | * Function Name : Virtual_Com_Port_Status_In |
||
162 | * Description : |
||
163 | * Input : None. |
||
164 | * Output : None. |
||
165 | * Return : None. |
||
166 | *******************************************************************************/ |
||
167 | void Virtual_Com_Port_Status_In(void) |
||
168 | { |
||
169 | if (Request == SET_LINE_CODING){ |
||
170 | // UART0_Config(); |
||
171 | Request = 0; |
||
172 | } |
||
173 | } |
||
174 | /******************************************************************************* |
||
175 | * Function Name : Virtual_Com_Port_Status_Out |
||
176 | * Description : |
||
177 | * Input : None. |
||
178 | * Output : None. |
||
179 | * Return : None. |
||
180 | *******************************************************************************/ |
||
181 | void Virtual_Com_Port_Status_Out (void) |
||
182 | { |
||
183 | } |
||
184 | /******************************************************************************* |
||
185 | * Function Name : Virtual_Com_Port_Data_Setup |
||
186 | * Description : handle the data class specific requests |
||
187 | * Input : Request Nb. |
||
188 | * Output : None. |
||
189 | * Return : USB_UNSUPPORT or USB_SUCCESS. |
||
190 | *******************************************************************************/ |
||
191 | RESULT Virtual_Com_Port_Data_Setup(u8 RequestNo) |
||
192 | { |
||
193 | u8 *(*CopyRoutine)(u16); |
||
194 | |||
195 | CopyRoutine = NULL; |
||
196 | |||
197 | if (RequestNo == GET_LINE_CODING) { |
||
198 | if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) |
||
199 | CopyRoutine = Virtual_Com_Port_GetLineCoding; |
||
200 | } |
||
201 | else if (RequestNo == SET_LINE_CODING) { |
||
202 | if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) |
||
203 | CopyRoutine = Virtual_Com_Port_SetLineCoding; |
||
204 | Request = SET_LINE_CODING; |
||
205 | } |
||
206 | |||
207 | if (CopyRoutine == NULL) return USB_UNSUPPORT; |
||
208 | |||
209 | pInformation->Ctrl_Info.CopyData = CopyRoutine; |
||
210 | pInformation->Ctrl_Info.Usb_wOffset = 0; |
||
211 | (*CopyRoutine)(0); |
||
212 | return USB_SUCCESS; |
||
213 | } |
||
214 | /******************************************************************************* |
||
215 | * Function Name : Virtual_Com_Port_NoData_Setup |
||
216 | * Description : handle the no data class specific requests |
||
217 | * Input : Request Nb. |
||
218 | * Output : None. |
||
219 | * Return : USB_UNSUPPORT or USB_SUCCESS. |
||
220 | *******************************************************************************/ |
||
221 | RESULT Virtual_Com_Port_NoData_Setup(u8 RequestNo) |
||
222 | { |
||
223 | |||
224 | if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) |
||
225 | { |
||
226 | if (RequestNo == SET_COMM_FEATURE) return USB_SUCCESS; |
||
227 | else if (RequestNo == SET_CONTROL_LINE_STATE) return USB_SUCCESS; |
||
228 | } |
||
229 | |||
230 | return USB_UNSUPPORT; |
||
231 | } |
||
232 | /******************************************************************************* |
||
233 | * Function Name : Virtual_Com_Port_GetDeviceDescriptor. |
||
234 | * Description : Gets the device descriptor. |
||
235 | * Input : Length |
||
236 | * Output : None. |
||
237 | * Return : The address of the device descriptor. |
||
238 | *******************************************************************************/ |
||
239 | u8 *Virtual_Com_Port_GetDeviceDescriptor(u16 Length) |
||
240 | { |
||
241 | return Standard_GetDescriptorData( Length, &Device_Descriptor ); |
||
242 | } |
||
243 | /******************************************************************************* |
||
244 | * Function Name : Virtual_Com_Port_GetConfigDescriptor. |
||
245 | * Description : get the configuration descriptor. |
||
246 | * Input : Length |
||
247 | * Output : None. |
||
248 | * Return : The address of the configuration descriptor. |
||
249 | *******************************************************************************/ |
||
250 | u8 *Virtual_Com_Port_GetConfigDescriptor(u16 Length) |
||
251 | { |
||
252 | return Standard_GetDescriptorData( Length, &Config_Descriptor ); |
||
253 | } |
||
254 | /******************************************************************************* |
||
255 | * Function Name : Virtual_Com_Port_GetStringDescriptor |
||
256 | * Description : Gets the string descriptors according to the needed index |
||
257 | * Input : Length |
||
258 | * Output : None. |
||
259 | * Return : The address of the string descriptors. |
||
260 | *******************************************************************************/ |
||
261 | u8 *Virtual_Com_Port_GetStringDescriptor(u16 Length) |
||
262 | { |
||
263 | u8 wValue0 = pInformation->USBwValue0; |
||
264 | return Standard_GetDescriptorData( Length, &String_Descriptor[wValue0] ); |
||
265 | } |
||
266 | /******************************************************************************* |
||
267 | * Function Name : Virtual_Com_Port_Get_Interface_Setting. |
||
268 | * Description : test the interface and the alternate setting according to the |
||
269 | * supported one. |
||
270 | * Input1 : u8: Interface : interface number. |
||
271 | * Input2 : u8: AlternateSetting : Alternate Setting number. |
||
272 | * Output : None. |
||
273 | * Return : The address of the string descriptors. |
||
274 | *******************************************************************************/ |
||
275 | RESULT Virtual_Com_Port_Get_Interface_Setting(u8 Interface,u8 AlternateSetting) |
||
276 | { |
||
277 | if(AlternateSetting >0) return USB_UNSUPPORT; |
||
278 | else if(Interface > 1) return USB_UNSUPPORT; |
||
279 | return USB_SUCCESS; |
||
280 | } |
||
281 | /******************************************************************************* |
||
282 | * Function Name : Virtual_Com_Port_GetLineCoding. |
||
283 | * Description : send the linecoding structure to the PC host. |
||
284 | * Input : Length |
||
285 | * Output : None. |
||
286 | * Return : Inecoding structure base address. |
||
287 | *******************************************************************************/ |
||
288 | u8 *Virtual_Com_Port_GetLineCoding(u16 Length) |
||
289 | { |
||
290 | if(Length==0) |
||
291 | { |
||
292 | pInformation->Ctrl_Info.Usb_wLength = sizeof(linecoding);; |
||
293 | return NULL; |
||
294 | } |
||
295 | return(u8 *)&linecoding; |
||
296 | } |
||
297 | /******************************************************************************* |
||
298 | * Function Name : Virtual_Com_Port_SetLineCoding. |
||
299 | * Description : Set the linecoding structure fields. |
||
300 | * Input : Length |
||
301 | * Output : None |
||
302 | * Return : Linecoding structure base address. |
||
303 | *******************************************************************************/ |
||
304 | u8 *Virtual_Com_Port_SetLineCoding(u16 Length) |
||
305 | { |
||
306 | if(Length==0) |
||
307 | { |
||
308 | pInformation->Ctrl_Info.Usb_wLength = sizeof(linecoding);; |
||
309 | return NULL; |
||
310 | } |
||
311 | return(u8 *)&linecoding; |
||
312 | } |
||
313 | |||
314 | /******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/ |
||
315 | |||
316 |