Init374Host();// 初始化USB主機(jī)
?
?while(1)
?{
??SetHostLeisure();//設(shè)定USB主機(jī)空閑
??while(1)
??{
???if (Query374Interrupt()) HostDetectInterrupt();? // 如果有USB主機(jī)中斷則處理
???if (Query374DeviceIn()) break;?????????????????? // 有USB設(shè)備
??? OSTimeDly(5); //100ms
??}
??
??OSTimeDly(14); //延時(shí)14*20ms = 280ms????? // 由于USB設(shè)備剛插入尚未穩(wěn)定,故等待USB設(shè)備數(shù)百毫秒,消除插拔抖動(dòng)
??if(Query374Interrupt()) HostDetectInterrupt(); // 如果有USB主機(jī)中斷則處理
???
??HostSetReset();// USB總線復(fù)位
??
??for(i=0;i<100;i++ )// 等待USB設(shè)備復(fù)位后重新連接
??? {
???if(Query374DeviceIn())? break; // 有USB設(shè)備
???delay_us(1000);
??}
??
??if(Query374Interrupt()) HostDetectInterrupt( ); // 如果有USB主機(jī)中斷則處理
??
??if(Query374DeviceIn())// 有USB設(shè)備
??? {?
???if(Query374DevFullSpeed())
????? {
????HostSetFullSpeed();// 檢測(cè)到全速USB設(shè)備
????printf( "Start Full-Speed Device\r\n" );
???}
???else
????? {
????HostSetLowSpeed();// 檢測(cè)到低速USB設(shè)備
?????printf( "Start Low-Speed Device\r\n" );
???}
??}
??else
??? {
???continue;// 設(shè)備已經(jīng)斷開,繼續(xù)等待
??}
??OSTimeDly(3); //延時(shí)3*20ms = 60ms
??
??close_bit_flag=0;//設(shè)備是否拔出
??
//1、獲取設(shè)備描述符??
??s = GetDeviceDescr(DeviceDescribe_buf); // 獲取設(shè)備描述符
??if(s != USB_INT_SUCCESS )
??? {
???printf("GetDeviceDescr Error\r\n");
???goto WaitDeviceOut;// 終止操作,等待USB設(shè)備拔出
??}
??
??printf("DeviceDescr:");
??for(i=0;i <((PUSB_SETUP_REQ)SetupGetDevDescr ) -> wLengthL;i++ )
??? printf("%02X ",DeviceDescribe_buf[i]);//輸出描述符
??printf( "\r\n" );
=======================================
串口輸出信息:
鍵盤1:
Start Low-Speed Device
GetDeviceDescr Error
Wait Device Out
鍵盤2:
Start Low-Speed Device
DeviceDescr:12 01 10 01 00 00 00 08 D5 05 89 06 03 01 00 01 00 01
SetUsbAddress:0X02 Success
GetConfigDescr:
09 02 3B 00 02 01 00 A0 32 09 04 00 00 01 03 01 01 00 09 21 10 01 00 01 22 41 00 07 05 81 03 08 00 0A 09 04 01 00 01 03 00 00 00 09 21 10 01 00 01 22 32 00 07 05 82 03 05 00 0A
hid_des_leng=41
endp_in_addr=01
endp_out_addr=00
GetConfigDescr Success
SetUsbConfig success