Rev 110 | Rev 238 | Go to most recent revision | Details | Compare with Previous | 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 ------------------------------------------------------------------*/ |
||
41 | ingob | 19 | #include "usb_lib.h" |
20 | #include "usb_desc.h" |
||
21 | #include "usb_pwr.h" |
||
22 | #include "usb_prop.h" |
||
1 | ingob | 23 | /* Private typedef -----------------------------------------------------------*/ |
24 | /* Private define ------------------------------------------------------------*/ |
||
25 | /* Private macro -------------------------------------------------------------*/ |
||
26 | /* Private variables ---------------------------------------------------------*/ |
||
27 | u32 Request = 0; |
||
28 | |||
29 | LINE_CODING linecoding = |
||
30 | { |
||
31 | 57600, /* baud rate*/ |
||
32 | 0x00, /* stop bits-1*/ |
||
33 | 0x00, /* parity - none*/ |
||
34 | 0x08 /* no. of bits 8*/ |
||
35 | }; |
||
36 | /* -------------------------------------------------------------------------- */ |
||
37 | /* Structures initializations */ |
||
38 | /* -------------------------------------------------------------------------- */ |
||
39 | |||
40 | DEVICE Device_Table = { |
||
41 | EP_NUM, |
||
42 | 1 |
||
43 | }; |
||
44 | |||
45 | DEVICE_PROP Device_Property = { |
||
46 | Virtual_Com_Port_init, |
||
47 | Virtual_Com_Port_Reset, |
||
48 | Virtual_Com_Port_Status_In, |
||
49 | Virtual_Com_Port_Status_Out, |
||
50 | Virtual_Com_Port_Data_Setup, |
||
51 | Virtual_Com_Port_NoData_Setup, |
||
52 | Virtual_Com_Port_Get_Interface_Setting, |
||
53 | Virtual_Com_Port_GetDeviceDescriptor, |
||
54 | Virtual_Com_Port_GetConfigDescriptor, |
||
55 | Virtual_Com_Port_GetStringDescriptor, |
||
56 | 0, |
||
57 | 0x40 /*MAX PACKET SIZE*/ |
||
58 | }; |
||
59 | USER_STANDARD_REQUESTS User_Standard_Requests = { |
||
60 | Virtual_Com_Port_GetConfiguration, |
||
61 | Virtual_Com_Port_SetConfiguration, |
||
62 | Virtual_Com_Port_GetInterface, |
||
63 | Virtual_Com_Port_SetInterface, |
||
64 | Virtual_Com_Port_GetStatus, |
||
65 | Virtual_Com_Port_ClearFeature, |
||
66 | Virtual_Com_Port_SetEndPointFeature, |
||
67 | Virtual_Com_Port_SetDeviceFeature, |
||
68 | Virtual_Com_Port_SetDeviceAddress |
||
69 | }; |
||
70 | |||
71 | ONE_DESCRIPTOR Device_Descriptor = { |
||
72 | (u8*)Virtual_Com_Port_DeviceDescriptor, |
||
73 | VIRTUAL_COM_PORT_SIZ_DEVICE_DESC |
||
74 | }; |
||
75 | |||
76 | ONE_DESCRIPTOR Config_Descriptor = { |
||
77 | (u8*)Virtual_Com_Port_ConfigDescriptor, |
||
78 | VIRTUAL_COM_PORT_SIZ_CONFIG_DESC |
||
79 | }; |
||
80 | |||
81 | ONE_DESCRIPTOR String_Descriptor[5] = { |
||
82 | {(u8*)Virtual_Com_Port_StringLangID, VIRTUAL_COM_PORT_SIZ_STRING_LANGID}, |
||
83 | {(u8*)Virtual_Com_Port_StringVendor, VIRTUAL_COM_PORT_SIZ_STRING_VENDOR}, |
||
84 | {(u8*)Virtual_Com_Port_StringProduct, VIRTUAL_COM_PORT_SIZ_STRING_PRODUCT}, |
||
85 | {(u8*)Virtual_Com_Port_StringSerial, VIRTUAL_COM_PORT_SIZ_STRING_SERIAL} |
||
86 | |||
87 | }; |
||
88 | /* Extern variables ----------------------------------------------------------*/ |
||
89 | /* Private function prototypes -----------------------------------------------*/ |
||
90 | /* Extern function prototypes ------------------------------------------------*/ |
||
91 | /* Private functions ---------------------------------------------------------*/ |
||
92 | /******************************************************************************* |
||
93 | * Function Name : Virtual_Com_Port_init |
||
94 | * Description : Virtual_Com_Port Mouse init routine |
||
95 | * Input : None. |
||
96 | * Output : None. |
||
97 | * Return : None. |
||
98 | *******************************************************************************/ |
||
99 | void Virtual_Com_Port_init(void) |
||
100 | { |
||
111 | killagreg | 101 | u32 timeout = 0; |
102 | |||
103 | pInformation->Current_Configuration = 0; |
||
104 | /* Connect the device */ |
||
105 | PowerOn(); |
||
106 | /* USB interrupts initialization */ |
||
107 | _SetISTR(0); /* clear pending interrupts */ |
||
108 | wInterrupt_Mask = IMR_MSK; |
||
109 | _SetCNTR(wInterrupt_Mask); /* set interrupts mask */ |
||
110 | pInformation->Current_Feature = Virtual_Com_Port_ConfigDescriptor[7]; |
||
111 | /* Wait until device is configured */ |
||
112 | while (pInformation->Current_Configuration == 0 && (timeout++<600000)) NOP_Process(); |
||
113 | if(pInformation->Current_Configuration !=0) bDeviceState = CONFIGURED; |
||
1 | ingob | 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 | { |
||
111 | killagreg | 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); |
||
1 | ingob | 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 | { |
||
111 | killagreg | 169 | if (Request == SET_LINE_CODING) |
170 | { |
||
171 | Request = 0; |
||
172 | } |
||
1 | ingob | 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 | { |
||
111 | killagreg | 193 | u8 *(*CopyRoutine)(u16); |
1 | ingob | 194 | |
111 | killagreg | 195 | CopyRoutine = NULL; |
196 | |||
197 | if (RequestNo == GET_LINE_CODING) |
||
198 | { |
||
199 | if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) CopyRoutine = Virtual_Com_Port_GetLineCoding; |
||
1 | ingob | 200 | } |
111 | killagreg | 201 | else if (RequestNo == SET_LINE_CODING) |
202 | { |
||
203 | if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) CopyRoutine = Virtual_Com_Port_SetLineCoding; |
||
204 | Request = SET_LINE_CODING; |
||
205 | } |
||
206 | if (CopyRoutine == NULL) return USB_UNSUPPORT; |
||
1 | ingob | 207 | |
111 | killagreg | 208 | pInformation->Ctrl_Info.CopyData = CopyRoutine; |
209 | pInformation->Ctrl_Info.Usb_wOffset = 0; |
||
210 | (*CopyRoutine)(0); |
||
211 | return USB_SUCCESS; |
||
1 | ingob | 212 | } |
213 | /******************************************************************************* |
||
214 | * Function Name : Virtual_Com_Port_NoData_Setup |
||
215 | * Description : handle the no data class specific requests |
||
216 | * Input : Request Nb. |
||
217 | * Output : None. |
||
218 | * Return : USB_UNSUPPORT or USB_SUCCESS. |
||
219 | *******************************************************************************/ |
||
220 | RESULT Virtual_Com_Port_NoData_Setup(u8 RequestNo) |
||
221 | { |
||
111 | killagreg | 222 | if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) |
223 | { |
||
224 | if (RequestNo == SET_COMM_FEATURE) return USB_SUCCESS; |
||
225 | else if (RequestNo == SET_CONTROL_LINE_STATE) return USB_SUCCESS; |
||
226 | } |
||
227 | return USB_UNSUPPORT; |
||
1 | ingob | 228 | } |
229 | /******************************************************************************* |
||
230 | * Function Name : Virtual_Com_Port_GetDeviceDescriptor. |
||
231 | * Description : Gets the device descriptor. |
||
232 | * Input : Length |
||
233 | * Output : None. |
||
234 | * Return : The address of the device descriptor. |
||
235 | *******************************************************************************/ |
||
236 | u8 *Virtual_Com_Port_GetDeviceDescriptor(u16 Length) |
||
237 | { |
||
111 | killagreg | 238 | return Standard_GetDescriptorData( Length, &Device_Descriptor ); |
1 | ingob | 239 | } |
240 | /******************************************************************************* |
||
241 | * Function Name : Virtual_Com_Port_GetConfigDescriptor. |
||
242 | * Description : get the configuration descriptor. |
||
243 | * Input : Length |
||
244 | * Output : None. |
||
245 | * Return : The address of the configuration descriptor. |
||
246 | *******************************************************************************/ |
||
247 | u8 *Virtual_Com_Port_GetConfigDescriptor(u16 Length) |
||
248 | { |
||
111 | killagreg | 249 | return Standard_GetDescriptorData( Length, &Config_Descriptor ); |
1 | ingob | 250 | } |
251 | /******************************************************************************* |
||
252 | * Function Name : Virtual_Com_Port_GetStringDescriptor |
||
253 | * Description : Gets the string descriptors according to the needed index |
||
254 | * Input : Length |
||
255 | * Output : None. |
||
256 | * Return : The address of the string descriptors. |
||
257 | *******************************************************************************/ |
||
258 | u8 *Virtual_Com_Port_GetStringDescriptor(u16 Length) |
||
259 | { |
||
111 | killagreg | 260 | u8 wValue0 = pInformation->USBwValue0; |
261 | return Standard_GetDescriptorData( Length, &String_Descriptor[wValue0] ); |
||
1 | ingob | 262 | } |
263 | /******************************************************************************* |
||
264 | * Function Name : Virtual_Com_Port_Get_Interface_Setting. |
||
265 | * Description : test the interface and the alternate setting according to the |
||
266 | * supported one. |
||
267 | * Input1 : u8: Interface : interface number. |
||
268 | * Input2 : u8: AlternateSetting : Alternate Setting number. |
||
269 | * Output : None. |
||
270 | * Return : The address of the string descriptors. |
||
271 | *******************************************************************************/ |
||
272 | RESULT Virtual_Com_Port_Get_Interface_Setting(u8 Interface,u8 AlternateSetting) |
||
273 | { |
||
111 | killagreg | 274 | if(AlternateSetting >0) return USB_UNSUPPORT; |
275 | else if(Interface > 1) return USB_UNSUPPORT; |
||
276 | return USB_SUCCESS; |
||
1 | ingob | 277 | } |
278 | /******************************************************************************* |
||
279 | * Function Name : Virtual_Com_Port_GetLineCoding. |
||
280 | * Description : send the linecoding structure to the PC host. |
||
281 | * Input : Length |
||
282 | * Output : None. |
||
283 | * Return : Inecoding structure base address. |
||
284 | *******************************************************************************/ |
||
285 | u8 *Virtual_Com_Port_GetLineCoding(u16 Length) |
||
286 | { |
||
111 | killagreg | 287 | if(Length==0) |
1 | ingob | 288 | { |
111 | killagreg | 289 | pInformation->Ctrl_Info.Usb_wLength = sizeof(linecoding);; |
290 | return NULL; |
||
1 | ingob | 291 | } |
111 | killagreg | 292 | return(u8 *)&linecoding; |
1 | ingob | 293 | } |
294 | /******************************************************************************* |
||
295 | * Function Name : Virtual_Com_Port_SetLineCoding. |
||
296 | * Description : Set the linecoding structure fields. |
||
297 | * Input : Length |
||
298 | * Output : None |
||
299 | * Return : Linecoding structure base address. |
||
300 | *******************************************************************************/ |
||
301 | u8 *Virtual_Com_Port_SetLineCoding(u16 Length) |
||
302 | { |
||
111 | killagreg | 303 | if(Length==0) |
1 | ingob | 304 | { |
111 | killagreg | 305 | pInformation->Ctrl_Info.Usb_wLength = sizeof(linecoding);; |
306 | return NULL; |
||
1 | ingob | 307 | } |
111 | killagreg | 308 | return(u8 *)&linecoding; |
1 | ingob | 309 | } |
310 | |||
311 | /******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/ |
||
312 | |||
313 |