usbdebug.c
来自「基于USB2.0芯片 ISP1581 的扫描仪固件源码,USB驱动模块」· C语言 代码 · 共 1,209 行 · 第 1/5 页
C
1,209 行
}
Descriptor_Ptr = &Int_In_Descriptor[0]; //set pointer to interface descriptor
count = *Descriptor_Ptr; //read in descriptor length
while(count != 0)
{
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
count--;
Descriptor_Ptr++;
}
Descriptor_Ptr = &Int_Out_Descriptor[0]; //set pointer to interface descriptor
count = *Descriptor_Ptr; //read in descriptor length
while(count != 0)
{
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
count--;
Descriptor_Ptr++;
}
Descriptor_Ptr = &Bulk_In_Descriptor[0]; //set pointer to interface descriptor
count = *Descriptor_Ptr; //read in descriptor length
while(count != 0)
{
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
count--;
Descriptor_Ptr++;
}
Descriptor_Ptr = &Bulk_Out_Descriptor[0]; //set pointer to interface descriptor
count = *Descriptor_Ptr; //read in descriptor length
while(count != 0)
{
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr;
count--;
Descriptor_Ptr++;
}
}
D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.VENDP = 1; //validate FIFO
//check for status stage
while(!USB_Int_Flag.BITS.EP0TX)
{
if(USB_Int_Flag.BITS.SUSP ||
USB_Int_Flag.BITS.RESET)
return;
}
USB_Int_Flag.BITS.EP0TX = 0;
D14_Cntrl_Reg.D14_ENDPT_INDEX = 0;
D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.STATUS = 1;
//end of status stage
while(!USB_Int_Flag.BITS.EP0RX)
{
if(USB_Int_Flag.BITS.SUSP ||
USB_Int_Flag.BITS.RESET)
return;
}
USB_Int_Flag.BITS.EP0RX = 0;
}
break;
case 8 :
break;
default :
D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.STALL = 1;
while(!USB_Int_Flag.BITS.EP0SETUP)
{
if(USB_Int_Flag.BITS.SUSP ||
USB_Int_Flag.BITS.RESET)
return;
}
USB_Int_Flag.BITS.EP0TX = 0;
break;
}
break;
case Set_Address :
USB_Int_Flag.BITS.EP0RX = 0;
switch(USB_Device.BITS.State)
{
default :
case USB_Default :
if(USB_Device_Request.wValue > 0)
USB_Device.BITS.State = USB_Addressed;
D14_Cntrl_Reg.D14_ADDRESS.BITS.DEVADDR = (USB_Device_Request.wValue >> 8);
D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
D14_Cntrl_Reg.D14_CONTROL_FUNCTION.VALUE = 2;
//end of status stage
while(!USB_Int_Flag.BITS.EP0TX)
{
if(USB_Int_Flag.BITS.SUSP ||
USB_Int_Flag.BITS.RESET)
return;
}
USB_Int_Flag.BITS.EP0TX = 0;
break;
case USB_Configured :
case USB_Addressed :
if(USB_Device_Request.wValue == 0)
USB_Device.BITS.State = USB_Default;
D14_Cntrl_Reg.D14_ADDRESS.BITS.DEVADDR = (USB_Device_Request.wValue >> 8);
D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
D14_Cntrl_Reg.D14_CONTROL_FUNCTION.VALUE = 2;
//end of status stage
while(!USB_Int_Flag.BITS.EP0TX)
{
if(USB_Int_Flag.BITS.SUSP ||
USB_Int_Flag.BITS.RESET)
return;
}
USB_Int_Flag.BITS.EP0TX = 0;
break;
}
break;
case Set_Config :
USB_Int_Flag.BITS.EP0RX = 0;
switch(USB_Device.BITS.State)
{
case USB_Default :
default :
break;
case USB_Addressed :
if(USB_Device_Request.wValue == 0)
{
Device_Config_Value = 0;
D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.STATUS = 1;
//end of status stage
while(!USB_Int_Flag.BITS.EP0TX)
{
if(USB_Int_Flag.BITS.SUSP ||
USB_Int_Flag.BITS.RESET)
return;
}
USB_Int_Flag.BITS.EP0TX = 0;
break;
}
if(USB_Device_Request.wValue == 0x0100 ||
USB_Device_Request.wValue == 0x0200)
{
Device_Config_Value = (UC) (USB_Device_Request.wValue >> 8);
USB_Device.BITS.State = USB_Configured;
D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.STATUS = 1;
//end of status stage
while(!USB_Int_Flag.BITS.EP0TX)
{
if(USB_Int_Flag.BITS.SUSP ||
USB_Int_Flag.BITS.RESET)
return;
}
USB_Int_Flag.BITS.EP0TX = 0;
break;
}
D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.STALL = 1;
while(!USB_Int_Flag.BITS.EP0SETUP)
{
if(USB_Int_Flag.BITS.SUSP ||
USB_Int_Flag.BITS.RESET)
return;
}
USB_Int_Flag.BITS.EP0TX = 0;
break;
case USB_Configured :
if(USB_Device_Request.wValue == 0)
{
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?