📄 host20_ap_hid.c
字号:
/////////////////////////////////////////////////////////////////////////////////// File name: OTGHost_AP_HID.C// Version: 1.0// Date: 2004/1/07//// Author: Bruce// Email: // Phone: (03) 578-7888// Company: Faraday Tech. Corp.//// ** Support: <1>.Mouse// <2>.Keyboard //// **Description: // Group-1:Main Function// <1>.OTGH_HID_Main//// Step1:HOST20_AP.C will enumerate the Device => if bInterfaceClass = HID class then call "OTGH_HID_Main"// Step2:OTGH_HID_Main => HID_Enumerate <1>.Setup 0x21,0x0A,0x00,0x00, 0x00,0x00,0x00,0x00 // <2>.GetDescriptor HID Report 0x81,0x06,0x00,0x22,0x00,0x00,0x74,0x00// <3>.Get String => Print string descriptor// Step3:If bInterfaceProtocol = 1 =>Keyboard call OTGH_HID_Keyboard// = 2 =>Mouse Call OTGH_HID_Mouse//// <2>.OTGH_HID_Keyboard//////// <3>.OTGH_HID_Mouse// Step1:Start to issue Interrupr-In 4 bytes // Step2:Analysis the "Interrupr-In 4 bytes"// Step3:Goto step1//// /////////////////////////////////////////////////////////////////////////////////#include <stdlib.h>#include <stdarg.h>#include <stdio.h>#include <string.h>#include "chipset.h" #include "flib.h" #include "Lib_Host20.h" #include "Host20_AP.H"#include "Host20_AP_HID.H"//====================================================================// * Function Name: OTGH_HID_Main // * Description: // <1>.If bInterfaceProtocol = 1 =>Keyboard call OTGH_HID_Keyboard// = 2 =>Mouse Call OTGH_HID_Mouse// * Input: none// * OutPut: none//====================================================================void OTGH_HID_Main(UINT8 bControlListNum){ // <1>.If bInterfaceProtocol = 1 =>Keyboard call OTGH_HID_Keyboard // = 2 =>Mouse Call OTGH_HID_Mouse if (psDevice_AP->saCD[0].sInterface[0].bInterfaceProtocol == 1) OTGH_HID_Keyboard(); else if (psDevice_AP->saCD[0].sInterface[0].bInterfaceProtocol == 2) OTGH_HID_Mouse(bControlListNum); else { printf(">>> Non Support HID Device...\n"); while(1); } }//====================================================================// * Function Name: OTGH_HID_Keyboard // * Description: // * Input: none// * OutPut: none//====================================================================void OTGH_HID_Keyboard(void){UINT8 *pbBuffer4K_1;// UINT8 bCMD[8];//UINT8 bTemp[0xFF];Host20_BufferPointerArray_Structure aTemp; //<1>.Set Interface-0 Idle to 0 => 0x21,0x0A,0x00,0x00, 0x00,0x00,0x00,0x00 //<2>.Set Interface-1 Idle to 0 => 0x21,0x0A,0x00,0x00, 0x01,0x00,0x00,0x00 //<3>.SetReport to => 0x21,0x09,0x00,0x02, 0x00,0x00,0x01,0x00 pbBuffer4K_1=flib_Host20_GetStructure(Host20_MEM_TYPE_4K_BUFFER); aTemp.BufferPointerArray[0]=pbBuffer4K_1; aTemp.BufferPointerArray[1]=0; aTemp.BufferPointerArray[2]=0; aTemp.BufferPointerArray[3]=0; aTemp.BufferPointerArray[4]=0; flib_Host20_Interrupt_Init(psDevice_AP->saCD[0].sInterface[0].sED[0].bED_Interval,0,1); while(psDevice_AP->bConnectStatus>0) { flib_Host20_Issue_Interrupt(0,8,&(aTemp.BufferPointerArray[0]),0,OTGH_Dir_IN); printf(">>> Keyboard Data:0x%x 0x%x 0x%x 0x%x / 0x%x 0x%x 0x%x 0x%x \n" ,*pbBuffer4K_1,*(pbBuffer4K_1+1),*(pbBuffer4K_1+2),*(pbBuffer4K_1+3) ,*(pbBuffer4K_1+4),*(pbBuffer4K_1+5),*(pbBuffer4K_1+6),*(pbBuffer4K_1+7)); } //<7>.free memory flib_Host20_ReleaseStructure(Host20_MEM_TYPE_4K_BUFFER,pbBuffer4K_1); //<8>.Disable Periodic flib_Host20_Periodic_Setting(HOST20_Disable);}//====================================================================// * Function Name: OTGH_HID_Mouse // * Description: // <1>.Init Interrupt EndPoint // <2>.Start to issue Interrupr-In 4 bytes // <3>.Analysis the "Interrupr-In 4 bytes"// <4>.Goto step1// * Input: none// * OutPut: none//====================================================================void OTGH_HID_Mouse(UINT8 bControlListNum){UINT8 *pbBuffer4K_1; UINT8 bCMD[8];//UINT8 bTemp[0xFF];Host20_BufferPointerArray_Structure aTemp; // <1>.Set Idle to 0 => 0x21,0x0A,0x00,0x00, 0x00,0x00,0x00,0x00 pbBuffer4K_1=flib_Host20_GetStructure(Host20_MEM_TYPE_4K_BUFFER); aTemp.BufferPointerArray[0]=pbBuffer4K_1; aTemp.BufferPointerArray[1]=0; aTemp.BufferPointerArray[2]=0; aTemp.BufferPointerArray[3]=0; aTemp.BufferPointerArray[4]=0; flib_Host20_Control_Command_Request(&bCMD,0x21,HOST20_HID_SetIdle,0,0,0); flib_Host20_Issue_Control_Turbo(bControlListNum,&bCMD,0x01,&(aTemp.BufferPointerArray[0]),0);//bEdNum,*pbCmd,hwDataSize,*pbData) printf(">>> Set Idle to 0 finish...\n"); // <2>.GetDescriptor HID Report Descriptor => 0x81,0x06,0x00,0x22,0x00,0x00,0xFF,0x00 flib_Host20_Control_Command_Request(&bCMD,0x81,HOST20_CONTROL_GetDescriptor,0x2200,0,0xFF); flib_Host20_Issue_Control_Turbo(bControlListNum,&bCMD,0xFF,&(aTemp.BufferPointerArray[0]),0);//bEdNum,*pbCmd,hwDataSize,*pbData) printf(">>> GetDescriptor HID Report Descriptor finish...\n"); //<3>.Allocate memory //<4>.Init Interrupt EndPoint flib_Host20_Interrupt_Init(psDevice_AP->saCD[0].sInterface[0].sED[0].bED_Interval,0,1); while(psDevice_AP->bConnectStatus>0) { //<5>.Start to issue Interrupr-In 4 bytes flib_Host20_Issue_Interrupt(0,4,&(aTemp.BufferPointerArray[0]),0,OTGH_Dir_IN); //<6>.Analysis the "Interrupr-In 4 bytes" //<Byte-1>.Button-1 down => 0x04 //<Byte-2>.X(Left=>0xFF Right=>0x01) //<Byte-3>.Y(UP=>0xFF Down=>0x01) //<Byte-4>.Wheel(Up=>0xFF Down=>0x01) printf(">>> Mouse Data:0x%x 0x%x 0x%x 0x%x \n",*pbBuffer4K_1 ,*(pbBuffer4K_1+1),*(pbBuffer4K_1+2),*(pbBuffer4K_1+3)); }// while(psDevice_AP->bConnectStatus>0) //<7>.free memory flib_Host20_ReleaseStructure(Host20_MEM_TYPE_4K_BUFFER,pbBuffer4K_1); //<8>.Disable Periodic flib_Host20_Periodic_Setting(HOST20_Disable);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -