Subversion Repositories NaviCtrl

Rev

Rev 41 | 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
{
101
  u32 timeout = 0;
102
  //SerialPutString(".vcpi.");
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
//  UART0_Config_Default();
113
  //SerialPutString("...");
114
  while (pInformation->Current_Configuration == 0 && (timeout++<600000)) NOP_Process();
115
   if(pInformation->Current_Configuration !=0) bDeviceState = CONFIGURED;
116
  //SerialPutString(".done.");
117
}
118
/*******************************************************************************
119
* Function Name  : Virtual_Com_Port_Reset
120
* Description    : Virtual_Com_Port Mouse reset routine
121
* Input          : None.
122
* Output         : None.
123
* Return         : None.
124
*******************************************************************************/
125
void Virtual_Com_Port_Reset(void)
126
{
127
  /* Set Virtual_Com_Port_DEVICE as not configured */
128
  pInformation->Current_Configuration = 0;
129
  pInformation->Current_Interface = 0;/*the default Interface*/
130
  SetBTABLE(BTABLE_ADDRESS);
131
 
132
  /* Initialize Endpoint 0 */
133
  SetEPType(ENDP0, EP_CONTROL);
134
  SetEPTxStatus(ENDP0, EP_TX_STALL);
135
  SetEPRxAddr(ENDP0, ENDP0_RXADDR);
136
  SetEPTxAddr(ENDP0, ENDP0_TXADDR);
137
  Clear_Status_Out(ENDP0);
138
  SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
139
  SetEPRxValid(ENDP0);
140
 
141
  /* Initialize Endpoint 1 */
142
  SetEPType(ENDP1, EP_BULK);
143
  SetEPTxAddr(ENDP1, ENDP1_TXADDR);
144
  SetEPTxStatus(ENDP1, EP_TX_NAK);
145
  SetEPRxStatus(ENDP1, EP_RX_DIS);
146
 
147
  /* Initialize Endpoint 2 */
148
  SetEPType(ENDP2, EP_INTERRUPT);
149
  SetEPTxAddr(ENDP2, ENDP2_TXADDR);
150
  SetEPRxStatus(ENDP2, EP_RX_DIS);
151
  SetEPTxStatus(ENDP2, EP_TX_NAK);
152
 
153
   /* Initialize Endpoint 3 */
154
  SetEPType(ENDP3, EP_BULK);
155
  SetEPRxAddr(ENDP3, ENDP3_RXADDR);
156
  SetEPRxCount(ENDP3, VIRTUAL_COM_PORT_DATA_SIZE);
157
  SetEPRxStatus(ENDP3, EP_RX_VALID);
158
  SetEPTxStatus(ENDP3, EP_TX_DIS);
159
 
160
  /* Set this device to response on default address */
161
  SetDeviceAddress(0);
162
}
163
/*******************************************************************************
164
* Function Name  : Virtual_Com_Port_Status_In
165
* Description    :
166
* Input          : None.
167
* Output         : None.
168
* Return         : None.
169
*******************************************************************************/
170
void Virtual_Com_Port_Status_In(void)
171
{
172
  if (Request == SET_LINE_CODING){
173
//    UART0_Config();
174
    Request = 0;
175
  }
176
}
177
/*******************************************************************************
178
* Function Name  : Virtual_Com_Port_Status_Out
179
* Description    :
180
* Input          : None.
181
* Output         : None.
182
* Return         : None.
183
*******************************************************************************/
184
void Virtual_Com_Port_Status_Out (void)
185
{
186
}
187
/*******************************************************************************
188
* Function Name  : Virtual_Com_Port_Data_Setup
189
* Description    : handle the data class specific requests
190
* Input          : Request Nb.
191
* Output         : None.
192
* Return         : USB_UNSUPPORT or USB_SUCCESS.
193
*******************************************************************************/
194
RESULT Virtual_Com_Port_Data_Setup(u8 RequestNo)
195
{
196
  u8    *(*CopyRoutine)(u16);
197
 
198
  CopyRoutine = NULL;
199
 
200
  if (RequestNo == GET_LINE_CODING) {
201
                if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT))
202
                        CopyRoutine = Virtual_Com_Port_GetLineCoding;
203
        }
204
        else if (RequestNo == SET_LINE_CODING) {
205
                if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT))
206
                        CopyRoutine = Virtual_Com_Port_SetLineCoding;
207
         Request = SET_LINE_CODING;
208
        }
209
 
210
  if (CopyRoutine == NULL) return USB_UNSUPPORT;
211
 
212
  pInformation->Ctrl_Info.CopyData = CopyRoutine;
213
  pInformation->Ctrl_Info.Usb_wOffset = 0;
214
  (*CopyRoutine)(0);
215
  return USB_SUCCESS;
216
}
217
/*******************************************************************************
218
* Function Name  : Virtual_Com_Port_NoData_Setup
219
* Description    : handle the no data class specific requests
220
* Input          : Request Nb.
221
* Output         : None.
222
* Return         : USB_UNSUPPORT or USB_SUCCESS.
223
*******************************************************************************/
224
RESULT Virtual_Com_Port_NoData_Setup(u8 RequestNo)
225
{
226
 
227
  if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT))
228
  {
229
    if (RequestNo == SET_COMM_FEATURE)  return USB_SUCCESS;
230
    else if (RequestNo == SET_CONTROL_LINE_STATE) return USB_SUCCESS;
231
  }
232
 
233
  return USB_UNSUPPORT;
234
}
235
/*******************************************************************************
236
* Function Name  : Virtual_Com_Port_GetDeviceDescriptor.
237
* Description    : Gets the device descriptor.
238
* Input          : Length
239
* Output         : None.
240
* Return         : The address of the device descriptor.
241
*******************************************************************************/
242
u8 *Virtual_Com_Port_GetDeviceDescriptor(u16 Length)
243
{
244
  return Standard_GetDescriptorData( Length, &Device_Descriptor );
245
}
246
/*******************************************************************************
247
* Function Name  : Virtual_Com_Port_GetConfigDescriptor.
248
* Description    : get the configuration descriptor.
249
* Input          : Length
250
* Output         : None.
251
* Return         : The address of the configuration descriptor.
252
*******************************************************************************/
253
u8 *Virtual_Com_Port_GetConfigDescriptor(u16 Length)
254
{
255
  return Standard_GetDescriptorData( Length, &Config_Descriptor );
256
}
257
/*******************************************************************************
258
* Function Name  : Virtual_Com_Port_GetStringDescriptor
259
* Description    : Gets the string descriptors according to the needed index
260
* Input          : Length
261
* Output         : None.
262
* Return         : The address of the string descriptors.
263
*******************************************************************************/
264
u8 *Virtual_Com_Port_GetStringDescriptor(u16 Length)
265
{
266
  u8 wValue0 = pInformation->USBwValue0;
267
  return Standard_GetDescriptorData( Length, &String_Descriptor[wValue0] );
268
}
269
/*******************************************************************************
270
* Function Name  : Virtual_Com_Port_Get_Interface_Setting.
271
* Description    : test the interface and the alternate setting according to the
272
*                  supported one.
273
* Input1         : u8: Interface : interface number.
274
* Input2         : u8: AlternateSetting : Alternate Setting number.
275
* Output         : None.
276
* Return         : The address of the string descriptors.
277
*******************************************************************************/
278
RESULT Virtual_Com_Port_Get_Interface_Setting(u8 Interface,u8 AlternateSetting)
279
{
280
  if(AlternateSetting >0) return USB_UNSUPPORT;
281
  else if(Interface > 1) return USB_UNSUPPORT;
282
  return USB_SUCCESS;
283
}
284
/*******************************************************************************
285
* Function Name  : Virtual_Com_Port_GetLineCoding.
286
* Description    : send the linecoding structure to the PC host.
287
* Input          : Length
288
* Output         : None.
289
* Return         : Inecoding structure base address.
290
*******************************************************************************/
291
u8 *Virtual_Com_Port_GetLineCoding(u16 Length)
292
{
293
  if(Length==0)
294
    {
295
      pInformation->Ctrl_Info.Usb_wLength = sizeof(linecoding);;
296
      return NULL;
297
    }
298
  return(u8 *)&linecoding;
299
}
300
/*******************************************************************************
301
* Function Name  : Virtual_Com_Port_SetLineCoding.
302
* Description    : Set the linecoding structure fields.
303
* Input          : Length
304
* Output         : None
305
* Return         : Linecoding structure base address.
306
*******************************************************************************/
307
u8 *Virtual_Com_Port_SetLineCoding(u16 Length)
308
{
309
  if(Length==0)
310
    {
311
      pInformation->Ctrl_Info.Usb_wLength = sizeof(linecoding);;
312
      return NULL;
313
    }
314
  return(u8 *)&linecoding;
315
}
316
 
317
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/
318
 
319