257 lines
15 KiB
C++
257 lines
15 KiB
C++
|
|
|||
|
/********************************** (C) COPYRIGHT *******************************
|
|||
|
* File Name : USBHostHUB_KM.C
|
|||
|
* Author : WCH
|
|||
|
* Version : V1.0
|
|||
|
* Date : 2017/01/20
|
|||
|
* Description :
|
|||
|
USB host example for CH554, start USB device under DP/DM and HP/HM port
|
|||
|
USB<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD><EFBFBD>USB<EFBFBD>˿<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><EFBFBD>豸,ͬʱ֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><EFBFBD>USB<EFBFBD>豸,֧<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ⲿHUB,
|
|||
|
<EFBFBD><EFBFBD><EFBFBD>Բ<EFBFBD><EFBFBD><EFBFBD>USB<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>HUB,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>HID<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>U<EFBFBD>̣<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ο<EFBFBD>U_DISK<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
֧<EFBFBD>ּ<EFBFBD><EFBFBD><EFBFBD>USB<EFBFBD><EFBFBD>ӡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>д<EFBFBD><EFBFBD><EFBFBD>USB<EFBFBD><EFBFBD>ӡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*******************************************************************************/
|
|||
|
|
|||
|
#include "..\..\Public\CH554.H"
|
|||
|
#include "..\..\Public\Debug.H"
|
|||
|
#include "..\USB_LIB\USBHOST.H"
|
|||
|
#include <stdio.h>
|
|||
|
#include <string.h>
|
|||
|
|
|||
|
#pragma NOAREGS
|
|||
|
|
|||
|
/*<2A><>ȡ<EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
|||
|
UINT8C SetupGetDevDescr[] = { USB_REQ_TYP_IN, USB_GET_DESCRIPTOR, 0x00, USB_DESCR_TYP_DEVICE, 0x00, 0x00, sizeof( USB_DEV_DESCR ), 0x00 };
|
|||
|
|
|||
|
/*<2A><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
|||
|
UINT8C SetupGetCfgDescr[] = { USB_REQ_TYP_IN, USB_GET_DESCRIPTOR, 0x00, USB_DESCR_TYP_CONFIG, 0x00, 0x00, 0x04, 0x00 };
|
|||
|
|
|||
|
/*<2A><><EFBFBD><EFBFBD>USB<53><42>ַ*/
|
|||
|
UINT8C SetupSetUsbAddr[] = { USB_REQ_TYP_OUT, USB_SET_ADDRESS, USB_DEVICE_ADDR, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|||
|
|
|||
|
/*<2A><><EFBFBD><EFBFBD>USB<53><42><EFBFBD><EFBFBD>*/
|
|||
|
UINT8C SetupSetUsbConfig[] = { USB_REQ_TYP_OUT, USB_SET_CONFIGURATION, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|||
|
|
|||
|
/*<2A><><EFBFBD><EFBFBD>USB<53>ӿ<EFBFBD><D3BF><EFBFBD><EFBFBD><EFBFBD>*/
|
|||
|
UINT8C SetupSetUsbInterface[] = { USB_REQ_RECIP_INTERF, USB_SET_INTERFACE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|||
|
|
|||
|
/*<2A><><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>STALL*/
|
|||
|
UINT8C SetupClrEndpStall[] = { USB_REQ_TYP_OUT | USB_REQ_RECIP_ENDP, USB_CLEAR_FEATURE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|||
|
|
|||
|
/*<2A><>ȡHUB<55><42><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
|||
|
UINT8C SetupGetHubDescr[] = { HUB_GET_HUB_DESCRIPTOR, HUB_GET_DESCRIPTOR, 0x00, USB_DESCR_TYP_HUB, 0x00, 0x00, sizeof( USB_HUB_DESCR ), 0x00 };
|
|||
|
|
|||
|
/*<2A><>ȡHID<49>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
|||
|
UINT8C SetupGetHIDDevReport[] = { 0x81, USB_GET_DESCRIPTOR, 0x00, USB_DESCR_TYP_REPORT, 0x00, 0x00, 0x41, 0x00 };
|
|||
|
|
|||
|
/*<2A><>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
|||
|
UINT8C XPrinterReport[] = { 0xA1, 0, 0x00, 0, 0x00, 0x00, 0xF1, 0x03 };
|
|||
|
|
|||
|
UINT8X UsbDevEndp0Size; //* USB<53>豸<EFBFBD>Ķ˵<C4B6>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߴ<EFBFBD> */
|
|||
|
UINT8X RxBuffer[ MAX_PACKET_SIZE ] _at_ 0x0000 ; // IN, must even address
|
|||
|
UINT8X TxBuffer[ MAX_PACKET_SIZE ] _at_ 0x0040 ; // OUT, must even address
|
|||
|
|
|||
|
UINT8 Set_Port = 0;
|
|||
|
|
|||
|
_RootHubDev xdata ThisUsbDev; //ROOT<4F><54>
|
|||
|
_DevOnHubPort xdata DevOnHubPort[HUB_MAX_PORTS]; // <20>ٶ<EFBFBD>:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD>ⲿHUB,ÿ<><C3BF><EFBFBD>ⲿHUB<55><42><EFBFBD><EFBFBD><EFBFBD><EFBFBD>HUB_MAX_PORTS<54><53><EFBFBD>˿<EFBFBD>(<28><><EFBFBD>˲<EFBFBD><CBB2><EFBFBD>)
|
|||
|
|
|||
|
bit RootHubId; // <20><>ǰ<EFBFBD><C7B0><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD>root-hub<75>˿ں<CBBF>:0=HUB0,1=HUB1
|
|||
|
bit FoundNewDev;
|
|||
|
|
|||
|
main( )
|
|||
|
{
|
|||
|
UINT8 i, s, len, endp;
|
|||
|
UINT16 loc;
|
|||
|
CfgFsys( );
|
|||
|
mDelaymS(5); //<2F><EFBFBD><DEB8><EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD>ȴ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ȶ<EFBFBD>
|
|||
|
mInitSTDIO( ); //Ϊ<><CEAA><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
|
|||
|
printf( "Start @ChipID=%02X\n", (UINT16)CHIP_ID );
|
|||
|
InitUSB_Host( );
|
|||
|
FoundNewDev = 0;
|
|||
|
printf( "Wait Device In\n" );
|
|||
|
while ( 1 )
|
|||
|
{
|
|||
|
s = ERR_SUCCESS;
|
|||
|
if ( UIF_DETECT ){ // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>USB<53><42><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
UIF_DETECT = 0; // <20><><EFBFBD>жϱ<D0B6>־
|
|||
|
s = AnalyzeRootHub( ); // <20><><EFBFBD><EFBFBD>ROOT-HUB״̬
|
|||
|
if ( s == ERR_USB_CONNECT ) FoundNewDev = 1;
|
|||
|
}
|
|||
|
if ( FoundNewDev ){ // <20><><EFBFBD>µ<EFBFBD>USB<53>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
|||
|
FoundNewDev = 0;
|
|||
|
mDelaymS( 200 ); // <20><><EFBFBD><EFBFBD>USB<53>豸<EFBFBD>ղ<EFBFBD><D5B2><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD>ȶ<EFBFBD>,<2C>ʵȴ<CAB5>USB<53>豸<EFBFBD><E8B1B8><EFBFBD>ٺ<EFBFBD><D9BA><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ζ<EFBFBD><CEB6><EFBFBD>
|
|||
|
s = EnumAllRootDevice( ); // ö<><C3B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ROOT-HUB<55>˿ڵ<CBBF>USB<53>豸
|
|||
|
if ( s != ERR_SUCCESS ){
|
|||
|
printf( "EnumAllRootDev err = %02X\n", (UINT16)s );
|
|||
|
}
|
|||
|
}
|
|||
|
if ( RI == 0 ) continue;
|
|||
|
i = getkey( );
|
|||
|
printf( "%c", (UINT8)i );
|
|||
|
if ( i == 'E'){ // ÿ<><C3BF>һ<EFBFBD><D2BB>ʱ<EFBFBD><CAB1>,ͨ<><CDA8><EFBFBD><EFBFBD>100mS<6D><53>1000mS,<2C><><EFBFBD>ⲿHUB<55>Ķ˿ڽ<CBBF><DABD><EFBFBD>һ<EFBFBD><D2BB>ö<EFBFBD><C3B6>,<2C><>Ƭ<EFBFBD><C6AC><EFBFBD>п<EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
s = EnumAllHubPort( ); // ö<><C3B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ROOT-HUB<55>˿<EFBFBD><CBBF><EFBFBD><EFBFBD>ⲿHUB<55><42><EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD>USB<53>豸
|
|||
|
if ( s != ERR_SUCCESS ){ // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>HUB<55>Ͽ<EFBFBD><CFBF><EFBFBD>
|
|||
|
printf( "EnumAllHubPort err = %02X\n", (UINT16)s );
|
|||
|
}
|
|||
|
}
|
|||
|
switch( i ){ // ģ<><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><>ijUSB<53>豸<EFBFBD><E8B1B8><EFBFBD>в<EFBFBD><D0B2><EFBFBD>
|
|||
|
case 'M': // <20>ö<EFBFBD>ʱģ<CAB1><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
loc = SearchTypeDevice( DEV_TYPE_MOUSE ); // <20><>ROOT-HUB<55>Լ<EFBFBD><D4BC>ⲿHUB<55><42><EFBFBD>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><CDB5>豸<EFBFBD><E8B1B8><EFBFBD>ڵĶ˿ں<CBBF>
|
|||
|
if ( loc != 0xFFFF ){ // <20>ҵ<EFBFBD><D2B5><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>MOUSE<53><45><EFBFBD>δ<EFBFBD><CEB4><EFBFBD>?
|
|||
|
printf( "Query Mouse @%04X\n", loc );
|
|||
|
i = (UINT8)( loc >> 8 );
|
|||
|
len = (UINT8)loc;
|
|||
|
SelectHubPort( len ); // ѡ<><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ROOT-HUB<55>˿<EFBFBD>,<2C><><EFBFBD>õ<EFBFBD>ǰUSB<53>ٶ<EFBFBD><D9B6>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8>USB<53><42>ַ
|
|||
|
endp = len ? DevOnHubPort[len-1].GpVar : ThisUsbDev.GpVar; // <20>ж϶˵<CFB6><CBB5>ĵ<EFBFBD>ַ,λ7<CEBB><37><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD>־λ
|
|||
|
if ( endp & USB_ENDP_ADDR_MASK ){ // <20>˵<EFBFBD><CBB5><EFBFBD>Ч
|
|||
|
s = USBHostTransact( USB_PID_IN << 4 | endp & 0x7F, endp & 0x80 ? bUH_R_TOG | bUH_T_TOG : 0, 0 );// CH554<35><34><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>,NAK<41><4B><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
if ( s == ERR_SUCCESS ){
|
|||
|
endp ^= 0x80; // ͬ<><CDAC><EFBFBD><EFBFBD>־<EFBFBD><D6BE>ת
|
|||
|
if ( len ) DevOnHubPort[len-1].GpVar = endp; // <20><><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD>־λ
|
|||
|
else ThisUsbDev.GpVar = endp;
|
|||
|
len = USB_RX_LEN; // <20><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
|
|||
|
if ( len ) {
|
|||
|
printf("Mouse data: ");
|
|||
|
for ( i = 0; i < len; i ++ ){
|
|||
|
printf("x%02X ",(UINT16)(RxBuffer[i]) );
|
|||
|
}
|
|||
|
printf("\n");
|
|||
|
}
|
|||
|
}
|
|||
|
else if ( s != ( USB_PID_NAK | ERR_USB_TRANSFER ) ) {
|
|||
|
printf("Mouse error %02x\n",(UINT16)s); // <20><><EFBFBD><EFBFBD><EFBFBD>ǶϿ<C7B6><CFBF><EFBFBD>
|
|||
|
}
|
|||
|
}
|
|||
|
else {
|
|||
|
printf("Mouse no interrupt endpoint\n");
|
|||
|
}
|
|||
|
SetUsbSpeed( 1 ); // Ĭ<><C4AC>Ϊȫ<CEAA><C8AB>
|
|||
|
}
|
|||
|
break;
|
|||
|
case 'K': // <20>ö<EFBFBD>ʱģ<CAB1><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
loc = SearchTypeDevice( DEV_TYPE_KEYBOARD ); // <20><>ROOT-HUB<55>Լ<EFBFBD><D4BC>ⲿHUB<55><42><EFBFBD>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><CDB5>豸<EFBFBD><E8B1B8><EFBFBD>ڵĶ˿ں<CBBF>
|
|||
|
if ( loc != 0xFFFF ){ // <20>ҵ<EFBFBD><D2B5><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>KeyBoard<72><64><EFBFBD>δ<EFBFBD><CEB4><EFBFBD>?
|
|||
|
printf( "Query Keyboard @%04X\n", loc );
|
|||
|
i = (UINT8)( loc >> 8 );
|
|||
|
len = (UINT8)loc;
|
|||
|
SelectHubPort( len ); // ѡ<><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ROOT-HUB<55>˿<EFBFBD>,<2C><><EFBFBD>õ<EFBFBD>ǰUSB<53>ٶ<EFBFBD><D9B6>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8>USB<53><42>ַ
|
|||
|
endp = len ? DevOnHubPort[len-1].GpVar : ThisUsbDev.GpVar; // <20>ж϶˵<CFB6><CBB5>ĵ<EFBFBD>ַ,λ7<CEBB><37><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD>־λ
|
|||
|
printf("%02X ",endp);
|
|||
|
if ( endp & USB_ENDP_ADDR_MASK ){ // <20>˵<EFBFBD><CBB5><EFBFBD>Ч
|
|||
|
s = USBHostTransact( USB_PID_IN << 4 | endp & 0x7F, endp & 0x80 ? bUH_R_TOG | bUH_T_TOG : 0, 0 );// CH554<35><34><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>,NAK<41><4B><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
if ( s == ERR_SUCCESS ){
|
|||
|
endp ^= 0x80; // ͬ<><CDAC><EFBFBD><EFBFBD>־<EFBFBD><D6BE>ת
|
|||
|
if ( len ) DevOnHubPort[len-1].GpVar = endp; // <20><><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD>־λ
|
|||
|
else ThisUsbDev.GpVar = endp;
|
|||
|
len = USB_RX_LEN; // <20><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
|
|||
|
if ( len ){
|
|||
|
SETorOFFNumLock(RxBuffer);
|
|||
|
printf("keyboard data: ");
|
|||
|
for ( i = 0; i < len; i ++ ){
|
|||
|
printf("x%02X ",(UINT16)(RxBuffer[i]) );
|
|||
|
}
|
|||
|
printf("\n");
|
|||
|
}
|
|||
|
}
|
|||
|
else if ( s != ( USB_PID_NAK | ERR_USB_TRANSFER ) ){
|
|||
|
printf("keyboard error %02x\n",(UINT16)s); // <20><><EFBFBD><EFBFBD><EFBFBD>ǶϿ<C7B6><CFBF><EFBFBD>
|
|||
|
}
|
|||
|
}
|
|||
|
else{
|
|||
|
printf("keyboard no interrupt endpoint\n");
|
|||
|
}
|
|||
|
SetUsbSpeed( 1 ); // Ĭ<><C4AC>Ϊȫ<CEAA><C8AB>
|
|||
|
}
|
|||
|
break;
|
|||
|
case 'H': //<2F><><EFBFBD><EFBFBD>HUB
|
|||
|
loc = SearchTypeDevice( DEV_TYPE_KEYBOARD ); // <20><>ROOT-HUB<55>Լ<EFBFBD><D4BC>ⲿHUB<55><42><EFBFBD>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><CDB5>豸<EFBFBD><E8B1B8><EFBFBD>ڵĶ˿ں<CBBF>
|
|||
|
if ( loc != 0xFFFF ){ // <20>ҵ<EFBFBD><D2B5><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>KeyBoard<72><64><EFBFBD>δ<EFBFBD><CEB4><EFBFBD>?
|
|||
|
printf( "Query Keyboard @%04X\n", loc );
|
|||
|
i = (UINT8)( loc >> 8 );
|
|||
|
len = (UINT8)loc;
|
|||
|
SelectHubPort( len ); // ѡ<><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ROOT-HUB<55>˿<EFBFBD>,<2C><><EFBFBD>õ<EFBFBD>ǰUSB<53>ٶ<EFBFBD><D9B6>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8>USB<53><42>ַ
|
|||
|
endp = len ? DevOnHubPort[len-1].GpVar : ThisUsbDev.GpVar; // <20>ж϶˵<CFB6><CBB5>ĵ<EFBFBD>ַ,λ7<CEBB><37><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD>־λ
|
|||
|
printf("%02X ",endp);
|
|||
|
if ( endp & USB_ENDP_ADDR_MASK ){ // <20>˵<EFBFBD><CBB5><EFBFBD>Ч
|
|||
|
s = USBHostTransact( USB_PID_IN << 4 | endp & 0x7F, endp & 0x80 ? bUH_R_TOG | bUH_T_TOG : 0, 0 );// CH554<35><34><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>,NAK<41><4B><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
if ( s == ERR_SUCCESS ){
|
|||
|
endp ^= 0x80; // ͬ<><CDAC><EFBFBD><EFBFBD>־<EFBFBD><D6BE>ת
|
|||
|
if ( len ) DevOnHubPort[len-1].GpVar = endp; // <20><><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD>־λ
|
|||
|
else ThisUsbDev.GpVar = endp;
|
|||
|
len = USB_RX_LEN; // <20><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
|
|||
|
if ( len ) {
|
|||
|
//SETorOFFNumLock(RxBuffer);
|
|||
|
printf("keyboard data: ");
|
|||
|
for ( i = 0; i < len; i ++ ){
|
|||
|
printf("x%02X ",(UINT16)(RxBuffer[i]) );
|
|||
|
}
|
|||
|
printf("\n");
|
|||
|
}
|
|||
|
}
|
|||
|
else if ( s != ( USB_PID_NAK | ERR_USB_TRANSFER ) ){
|
|||
|
printf("keyboard error %02x\n",(UINT16)s); // <20><><EFBFBD><EFBFBD><EFBFBD>ǶϿ<C7B6><CFBF><EFBFBD>
|
|||
|
}
|
|||
|
}
|
|||
|
else printf("keyboard no interrupt endpoint\n");
|
|||
|
}
|
|||
|
for(i=0; i<2; i++) {
|
|||
|
if((ThisUsbDev.DeviceStatus == ROOT_DEV_SUCCESS)&&(ThisUsbDev.DeviceType == USB_DEV_CLASS_HUB)){
|
|||
|
SelectHubPort( 0 ); // ѡ<><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ROOT-HUB<55>˿<EFBFBD>,<2C><><EFBFBD>õ<EFBFBD>ǰUSB<53>ٶ<EFBFBD><D9B6>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8>USB<53><42>ַ
|
|||
|
endp = ThisUsbDev.GpVar1; // <20>ж϶˵<CFB6><CBB5>ĵ<EFBFBD>ַ,λ7<CEBB><37><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD>־λ
|
|||
|
if ( endp & USB_ENDP_ADDR_MASK ){ // <20>˵<EFBFBD><CBB5><EFBFBD>Ч
|
|||
|
s = USBHostTransact( USB_PID_IN << 4 | endp & 0x7F, endp & 0x80 ? bUH_R_TOG | bUH_T_TOG : 0, 0 );// CH554<35><34><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>,NAK<41><4B><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
if ( s == ERR_SUCCESS ) {
|
|||
|
endp ^= 0x80; // ͬ<><CDAC><EFBFBD><EFBFBD>־<EFBFBD><D6BE>ת
|
|||
|
ThisUsbDev.GpVar1 = endp; // <20><><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD>־λ
|
|||
|
len = USB_RX_LEN; // <20><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
|
|||
|
if ( len ){
|
|||
|
EnumHubPort();
|
|||
|
for ( i = 0; i < len; i ++ ){
|
|||
|
printf("x%02X ",(UINT16)(RxBuffer[i]) );
|
|||
|
}
|
|||
|
printf("\n");
|
|||
|
}
|
|||
|
}
|
|||
|
else if ( s != ( USB_PID_NAK | ERR_USB_TRANSFER ) ) {
|
|||
|
printf("HUB error %02x\n",(UINT16)s); // <20><><EFBFBD><EFBFBD><EFBFBD>ǶϿ<C7B6><CFBF><EFBFBD>
|
|||
|
}
|
|||
|
}
|
|||
|
else printf("HUB %02d no interrupt endpoint\n",i);
|
|||
|
}
|
|||
|
else printf("ROOTHUB %02d not HUB\n",i);
|
|||
|
}
|
|||
|
break;
|
|||
|
case 'P': //<2F><><EFBFBD><EFBFBD>USB<53><42>ӡ<EFBFBD><D3A1>
|
|||
|
if(TIN0 == 0){ //P10Ϊ<30>ͣ<EFBFBD><CDA3><EFBFBD>ʼ<EFBFBD><CABC>ӡ
|
|||
|
memset(TxBuffer,0,sizeof(TxBuffer));
|
|||
|
TxBuffer[0]=0x1B;TxBuffer[1]=0x40;TxBuffer[2]=0x1D;TxBuffer[3]=0x55;TxBuffer[4]=0x42;TxBuffer[5]=0x02;TxBuffer[6]=0x18;TxBuffer[7]=0x1D;
|
|||
|
TxBuffer[8]=0x76;TxBuffer[9]=0x30;TxBuffer[10]=0x00;TxBuffer[11]=0x30;TxBuffer[12]=0x00;TxBuffer[13]=0x18;
|
|||
|
loc = SearchTypeDevice( USB_DEV_CLASS_PRINTER ); // <20><>ROOT-HUB<55>Լ<EFBFBD><D4BC>ⲿHUB<55><42><EFBFBD>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><CDB5>豸<EFBFBD><E8B1B8><EFBFBD>ڵĶ˿ں<CBBF>
|
|||
|
if ( loc != 0xFFFF ){ // <20>ҵ<EFBFBD><D2B5><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD>?
|
|||
|
printf( "Query Printer @%04X\n", loc );
|
|||
|
i = (UINT8)( loc >> 8 );
|
|||
|
len = (UINT8)loc;
|
|||
|
SelectHubPort( len ); // ѡ<><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ROOT-HUB<55>˿<EFBFBD>,<2C><><EFBFBD>õ<EFBFBD>ǰUSB<53>ٶ<EFBFBD><D9B6>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8>USB<53><42>ַ
|
|||
|
endp = len ? DevOnHubPort[len-1].GpVar : ThisUsbDev.GpVar; // <20>˵<EFBFBD><CBB5>ĵ<EFBFBD>ַ,λ7<CEBB><37><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD>־λ
|
|||
|
printf("%02X ",endp);
|
|||
|
if ( endp & USB_ENDP_ADDR_MASK ){ // <20>˵<EFBFBD><CBB5><EFBFBD>Ч
|
|||
|
UH_TX_LEN = 64; // Ĭ<><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݹ<EFBFBD>״̬<D7B4><EFBFBD>ΪIN
|
|||
|
s = USBHostTransact( USB_PID_OUT << 4 | endp & 0x7F, endp & 0x80 ? bUH_R_TOG | bUH_T_TOG : 0, 0xffff );// CH554<35><34><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>,NAK<41><4B><EFBFBD><EFBFBD>
|
|||
|
if ( s == ERR_SUCCESS ){
|
|||
|
endp ^= 0x80; // ͬ<><CDAC><EFBFBD><EFBFBD>־<EFBFBD><D6BE>ת
|
|||
|
memset(TxBuffer,0,sizeof(TxBuffer));
|
|||
|
UH_TX_LEN = 64; // Ĭ<><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݹ<EFBFBD>״̬<D7B4><EFBFBD>ΪIN
|
|||
|
s = USBHostTransact( USB_PID_OUT << 4 | endp & 0x7F, endp & 0x80 ? bUH_R_TOG | bUH_T_TOG : 0, 0xffff );// CH554<35><34><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>,NAK<41><4B><EFBFBD><EFBFBD>
|
|||
|
}
|
|||
|
else if ( s != ( USB_PID_NAK | ERR_USB_TRANSFER ) ) printf("Printer error %02x\n",(UINT16)s); // <20><><EFBFBD><EFBFBD><EFBFBD>ǶϿ<C7B6><CFBF><EFBFBD>
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
break;
|
|||
|
default:
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|