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