typedef struct _DEVICE_PROP
{
void(*Init)(void); /* Initialize thedevice */
void(*Reset)(void); /* Reset routine ofthis device */
void(*Process_Status_IN)(void);
void(*Process_Status_OUT)(void);
RESULT (*Class_Data_Setup)(u8 RequestNo);
RESULT (*Class_NoData_Setup)(u8 RequestNo);
RESULT (*Class_Get_Interface_Setting)(u8 Interface, u8 AlternateSetting);
u8* (*GetDeviceDescriptor)(u16 Length);
u8*(*GetConfigDescriptor)(u16 Length);
u8*(*GetStringDescriptor)(u16 Length);
u8* RxEP_buffer;
u8MaxPacketSize;
}DEVICE_PROP;
DEVICE_PROP *pProperty;
pProperty = &Device_Property;
DEVICE_PROP Device_Property =
{
Joystick_init, //鼠标初始化
Joystick_Reset, //鼠标复位
Joystick_Status_In,
Joystick_Status_Out,
Joystick_Data_Setup,
Joystick_NoData_Setup,
Joystick_Get_Interface_Setting,
Joystick_GetDeviceDescriptor,
Joystick_GetConfigDescriptor,
Joystick_GetStringDescriptor,
0,
0x40 /*MAX PACKET SIZE*/
};
typedef struct _USER_STANDARD_REQUESTS
{
void(*User_GetConfiguration)(void); /*Get Configuration */
void(*User_SetConfiguration)(void); /*Set Configuration */
void(*User_GetInterface)(void); /*Get Interface */
void(*User_SetInterface)(void); /*Set Interface */
void(*User_GetStatus)(void); /*Get Status */
void(*User_ClearFeature)(void); /*Clear Feature */
void(*User_SetEndPointFeature)(void); /*Set Endpoint Feature */
void(*User_SetDeviceFeature)(void); /*Set Device Feature */
void(*User_SetDeviceAddress)(void); /*Set Device Address */
}
USER_STANDARD_REQUESTS;
USER_STANDARD_REQUESTS *pUser_Standard_Requests;
pUser_Standard_Requests =&User_Standard_Requests;
USER_STANDARD_REQUESTSUser_Standard_Requests =
{
Joystick_GetConfiguration,
Joystick_SetConfiguration,
Joystick_GetInterface,
Joystick_SetInterface,
Joystick_GetStatus,
Joystick_ClearFeature,
Joystick_SetEndPointFeature,
Joystick_SetDeviceFeature,
Joystick_SetDeviceAddress
};
{
u8USBbmRequestType; /* bmRequestType*/
u8USBbRequest; /* bRequest */
u16_u8 USBwValues; /*wValue */
u16_u8 USBwIndexs; /* wIndex */
u16_u8 USBwLengths; /*wLength */
u8ControlState; /* of typeCONTROL_STATE */
u8Current_Feature;
u8Current_Configuration; /* Selectedconfiguration 当前配置*/
u8Current_Interface; /* Selectedinterface of current configuration 当前接口*/
u8Current_AlternateSetting;/* Selected Alternate Setting of current
interface*/
ENDPOINT_INFO Ctrl_Info;
}DEVICE_INFO;
DEVICE_INFO *pInformation;
pInformation = &Device_Info;
DEVICE_INFO Device_Info;
pInformation->ControlState = 2; //
函数1
void USB_Init(void)
{
pInformation = &Device_Info;
pInformation->ControlState = 2;
pProperty = &Device_Property;
pUser_Standard_Requests = &User_Standard_Requests;
pProperty->Init(); //下步进入此函数
}
用于初始化几个结构体
函数2
void Joystick_init(void)
{
pInformation->Current_Configuration = 0;
PowerOn();
_SetISTR(0); /*clear pending interrupts */
wInterrupt_Mask =IMR_MSK; //将中断使能的值赋给wInterrupt_Mask