📄 usbsetup.c
字号:
break;
case ENDPOINT_RECIPIENT:
if ( descSetup.bValueL == 0 )
{
if ( ( descSetup.bIndexL & 0x7f ) == 0x00 )
{
StatusGet.Endpoint0 = 1;
}
if ( ( descSetup.bIndexL & 0x8f ) == 0x81 )
{
StatusGet.Endpoint1 = 1;
}
if ( ( descSetup.bIndexL & 0x8f ) == 0x03 )
{
StatusGet.Endpoint3 = 1;
}
}
break;
default:
break;
}
CLR_EP0_OUTPKTRDY_DATAEND();
ep0State = EP0_STATE_INIT;
break;
case SET_INTERFACE:
InterfaceGet.AlternateSetting = descSetup.bValueL;
CLR_EP0_OUTPKTRDY_DATAEND();
ep0State = EP0_STATE_INIT;
break;
case SYNCH_FRAME:
ep0State = EP0_STATE_INIT;
break;
//////////////////////////////////////////////////////////////
default:
DbgPrintf( "[UE:SETUP=%x]" , descSetup.bRequest );
CLR_EP0_OUTPKTRDY_DATAEND(); //Because of no data control transfers.
ep0State = EP0_STATE_INIT;
break;
}
}
switch ( ep0State )
{
case EP0_STATE_INIT:
break;
//=== GET_DESCRIPTOR:DEVICE ===
case EP0_STATE_GD_DEV_0:
DbgPrintf( "[GDD0]" );
WrPktEp0( ( U8 * ) &descDev + 0 , 8 ); //EP0_PKT_SIZE
SET_EP0_IN_PKT_RDY();
ep0State = EP0_STATE_GD_DEV_1;
break;
case EP0_STATE_GD_DEV_1:
DbgPrintf( "[GDD1]" );
WrPktEp0( ( U8 * ) &descDev + 0x8 , 8 );
SET_EP0_IN_PKT_RDY();
ep0State = EP0_STATE_GD_DEV_2;
break;
case EP0_STATE_GD_DEV_2:
DbgPrintf( "[GDD2]" );
WrPktEp0( ( U8 * ) &descDev + 0x10 , 2 ); //8+8+2=0x12
SET_EP0_INPKTRDY_DATAEND();
ep0State = EP0_STATE_INIT;
break;
//=== GET_DESCRIPTOR:CONFIGURATION+INTERFACE+ENDPOINT0+ENDPOINT1 ===
//Windows98 gets these 4 descriptors all together by issuing only a request.
//Windows2000 gets each descriptor seperately.
case EP0_STATE_GD_CFG_0:
DbgPrintf( "[GDC0]" );
WrPktEp0( ( U8 * ) &descConf + 0 , 8 ); //EP0_PKT_SIZE
SET_EP0_IN_PKT_RDY();
ep0State = EP0_STATE_GD_CFG_1;
break;
case EP0_STATE_GD_CFG_1:
DbgPrintf( "[GDC1]" );
WrPktEp0( ( U8 * ) &descConf + 8 , 1 );
WrPktEp0( ( U8 * ) &descIf + 0 , 7 );
SET_EP0_IN_PKT_RDY();
ep0State = EP0_STATE_GD_CFG_2;
break;
case EP0_STATE_GD_CFG_2:
DbgPrintf( "[GDC2]" );
WrPktEp0( ( U8 * ) &descIf + 7 , 2 );
WrPktEp0( ( U8 * ) &descEndpt0 + 0 , 6 );
SET_EP0_IN_PKT_RDY();
ep0State = EP0_STATE_GD_CFG_3;
break;
case EP0_STATE_GD_CFG_3:
DbgPrintf( "[GDC3]" );
WrPktEp0( ( U8 * ) &descEndpt0 + 6 , 1 );
WrPktEp0( ( U8 * ) &descEndpt1 + 0 , 7 );
SET_EP0_IN_PKT_RDY();
ep0State = EP0_STATE_GD_CFG_4;
break;
case EP0_STATE_GD_CFG_4:
DbgPrintf( "[GDC4]" );
//zero length data packit
SET_EP0_INPKTRDY_DATAEND();
ep0State = EP0_STATE_INIT;
break;
//=== GET_DESCRIPTOR:CONFIGURATION ONLY===
case EP0_STATE_GD_CFG_ONLY_0:
DbgPrintf( "[GDCO0]" );
WrPktEp0( ( U8 * ) &descConf + 0 , 8 ); //EP0_PKT_SIZE
SET_EP0_IN_PKT_RDY();
ep0State = EP0_STATE_GD_CFG_ONLY_1;
break;
case EP0_STATE_GD_CFG_ONLY_1:
DbgPrintf( "[GDCO1]" );
WrPktEp0( ( U8 * ) &descConf + 8 , 1 );
SET_EP0_INPKTRDY_DATAEND();
ep0State = EP0_STATE_INIT;
break;
//=== GET_DESCRIPTOR:INTERFACE ONLY===
case EP0_STATE_GD_IF_ONLY_0:
DbgPrintf( "[GDI0]" );
WrPktEp0( ( U8 * ) &descIf + 0 , 8 );
SET_EP0_IN_PKT_RDY();
ep0State = EP0_STATE_GD_IF_ONLY_1;
break;
case EP0_STATE_GD_IF_ONLY_1:
DbgPrintf( "[GDI1]" );
WrPktEp0( ( U8 * ) &descIf + 8 , 1 );
SET_EP0_INPKTRDY_DATAEND();
ep0State = EP0_STATE_INIT;
break;
//=== GET_DESCRIPTOR:ENDPOINT 0 ONLY===
case EP0_STATE_GD_EP0_ONLY_0:
DbgPrintf( "[GDE00]" );
WrPktEp0( ( U8 * ) &descEndpt0 + 0 , 7 );
SET_EP0_INPKTRDY_DATAEND();
ep0State = EP0_STATE_INIT;
break;
//=== GET_DESCRIPTOR:ENDPOINT 1 ONLY===
case EP0_STATE_GD_EP1_ONLY_0:
DbgPrintf( "[GDE10]" );
WrPktEp0( ( U8 * ) &descEndpt1 + 0 , 7 );
SET_EP0_INPKTRDY_DATAEND();
ep0State = EP0_STATE_INIT;
break;
////////////////////////////////////////////
case EP0_INTERFACE_GET:
WrPktEp0( ( U8 * ) &InterfaceGet + 0 , 1 );
SET_EP0_INPKTRDY_DATAEND();
ep0State = EP0_STATE_INIT;
break;
//=== GET_DESCRIPTOR:STRING ===
case EP0_STATE_GD_STR_I0:
DbgPrintf( "[GDS0_0]" );
WrPktEp0( ( U8 * ) descStr0 , 4 );
SET_EP0_INPKTRDY_DATAEND();
ep0State = EP0_STATE_INIT;
ep0SubState = 0;
break;
case EP0_STATE_GD_STR_I1:
DbgPrintf( "[GDS1_%d]" , ep0SubState );
if ( ( ep0SubState * EP0_PKT_SIZE + EP0_PKT_SIZE ) < sizeof( descStr1 ) )
{
WrPktEp0( ( U8 * ) descStr1 + ( ep0SubState * EP0_PKT_SIZE ) , EP0_PKT_SIZE );
SET_EP0_IN_PKT_RDY();
ep0State = EP0_STATE_GD_STR_I1;
ep0SubState++;
}
else
{
WrPktEp0( ( U8 * ) descStr1 + ( ep0SubState * EP0_PKT_SIZE ) ,
sizeof( descStr1 ) - ( ep0SubState * EP0_PKT_SIZE ) );
SET_EP0_INPKTRDY_DATAEND();
ep0State = EP0_STATE_INIT;
ep0SubState = 0;
}
break;
case EP0_STATE_GD_STR_I2:
DbgPrintf( "[GDS2_%d]" , ep0SubState );
if ( ( ep0SubState * EP0_PKT_SIZE + EP0_PKT_SIZE ) < sizeof( descStr2 ) )
{
WrPktEp0( ( U8 * ) descStr2 + ( ep0SubState * EP0_PKT_SIZE ) , EP0_PKT_SIZE );
SET_EP0_IN_PKT_RDY();
ep0State = EP0_STATE_GD_STR_I2;
ep0SubState++;
}
else
{
DbgPrintf( "[E]" );
WrPktEp0( ( U8 * ) descStr2 + ( ep0SubState * EP0_PKT_SIZE ) ,
sizeof( descStr2 ) - ( ep0SubState * EP0_PKT_SIZE ) );
SET_EP0_INPKTRDY_DATAEND();
ep0State = EP0_STATE_INIT;
ep0SubState = 0;
}
break;
case EP0_CONFIG_SET:
WrPktEp0( ( U8 * ) &ConfigSet + 0 , 1 );
SET_EP0_INPKTRDY_DATAEND();
ep0State = EP0_STATE_INIT;
break;
case EP0_GET_STATUS0:
WrPktEp0( ( U8 * ) &StatusGet + 0 , 1 );
SET_EP0_INPKTRDY_DATAEND();
ep0State = EP0_STATE_INIT;
break;
case EP0_GET_STATUS1:
WrPktEp0( ( U8 * ) &StatusGet + 1 , 1 );
SET_EP0_INPKTRDY_DATAEND();
ep0State = EP0_STATE_INIT;
break;
case EP0_GET_STATUS2:
WrPktEp0( ( U8 * ) &StatusGet + 2 , 1 );
SET_EP0_INPKTRDY_DATAEND();
ep0State = EP0_STATE_INIT;
break;
case EP0_GET_STATUS3:
WrPktEp0( ( U8 * ) &StatusGet + 3 , 1 );
SET_EP0_INPKTRDY_DATAEND();
ep0State = EP0_STATE_INIT;
break;
case EP0_GET_STATUS4:
WrPktEp0( ( U8 * ) &StatusGet + 4 , 1 );
SET_EP0_INPKTRDY_DATAEND();
ep0State = EP0_STATE_INIT;
break;
default:
DbgPrintf( "UE:G?D" );
break;
}
}
void PrintEp0Pkt( U8* pt )
{
int i;
DbgPrintf( "[RCV:" );
for ( i = 0; i < EP0_PKT_SIZE; i++ )
DbgPrintf( "%x," , pt[i] );
DbgPrintf( "]" );
}
void InitDescriptorTable( void )
{
//Standard device descriptor
descDev.bLength = 0x12; //EP0_DEV_DESC_SIZE=0x12 bytes
descDev.bDescriptorType = DEVICE_TYPE;
descDev.bcdUSBL = 0x10;
descDev.bcdUSBH = 0x01; //Ver 1.10
descDev.bDeviceClass = 0xFF; //0x0
descDev.bDeviceSubClass = 0x0;
descDev.bDeviceProtocol = 0x0;
descDev.bMaxPacketSize0 = 0x8;
descDev.idVendorL = 0x45;
descDev.idVendorH = 0x53;
descDev.idProductL = 0x34;
descDev.idProductH = 0x12;
descDev.bcdDeviceL = 0x00;
descDev.bcdDeviceH = 0x01;
descDev.iManufacturer = 0x1; //index of string descriptor
descDev.iProduct = 0x2; //index of string descriptor
descDev.iSerialNumber = 0x0;
descDev.bNumConfigurations = 0x1;
//Standard configuration descriptor
descConf.bLength = 0x9;
descConf.bDescriptorType = CONFIGURATION_TYPE;
descConf.wTotalLengthL = 0x20; //<cfg desc>+<if desc>+<endp0 desc>+<endp1 desc>
descConf.wTotalLengthH = 0;
descConf.bNumInterfaces = 1;
//dbg descConf.bConfigurationValue=2; //why 2? There's no reason.
descConf.bConfigurationValue = 1;
descConf.iConfiguration = 0;
descConf.bmAttributes = CONF_ATTR_DEFAULT | CONF_ATTR_SELFPOWERED; //bus powered only.
descConf.maxPower = 25; //draws 50mA current from the USB bus.
//Standard interface descriptor
descIf.bLength = 0x9;
descIf.bDescriptorType = INTERFACE_TYPE;
descIf.bInterfaceNumber = 0x0;
descIf.bAlternateSetting = 0x0; //?
descIf.bNumEndpoints = 2; //# of endpoints except EP0
descIf.bInterfaceClass = 0xff; //0x0 ?
descIf.bInterfaceSubClass = 0x0;
descIf.bInterfaceProtocol = 0x0;
descIf.iInterface = 0x0;
//Standard endpoint0 descriptor
descEndpt0.bLength = 0x7;
descEndpt0.bDescriptorType = ENDPOINT_TYPE;
descEndpt0.bEndpointAddress = 1 | EP_ADDR_IN; // 2400Xendpoint 1 is IN endpoint.
descEndpt0.bmAttributes = EP_ATTR_BULK;
descEndpt0.wMaxPacketSizeL = EP1_PKT_SIZE; //64
descEndpt0.wMaxPacketSizeH = 0x0;
descEndpt0.bInterval = 0x0; //not used
//Standard endpoint1 descriptor
descEndpt1.bLength = 0x7;
descEndpt1.bDescriptorType = ENDPOINT_TYPE;
descEndpt1.bEndpointAddress = 3 | EP_ADDR_OUT; // 2400X endpoint 3 is OUT endpoint.
descEndpt1.bmAttributes = EP_ATTR_BULK;
descEndpt1.wMaxPacketSizeL = EP3_PKT_SIZE; //64
descEndpt1.wMaxPacketSizeH = 0x0;
descEndpt1.bInterval = 0x0; //not used
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -