/*設(shè)備描述符*/ UINT8C?DevDesc[18]?=?{0x12,0x01,0x10,0x01,0x00,0x00,0x00,THIS_ENDP0_SIZE, ??????????????????????0x31,0x51,0x07,0x20,0x00,0x00,0x00,0x00, ??????????????????????0x00,0x01 ?????????????????????}; UINT8C?CfgDesc[41]?= { ????0x09,0x02,0x29,0x00,0x01,0x01,0x04,0xA0,0x23,???????????????//配置描述符 ????0x09,0x04,0x00,0x00,0x02,0x03,0x00,0x00,0x05,???????????????//接口描述符 ????0x09,0x21,0x00,0x01,0x00,0x01,0x22,0x22,0x00,???????????????//HID類描述符 ????0x07,0x05,0x82,0x03,ENDP2_IN_SIZE,0x00,0x01,??????????????//端點描述符 ????0x07,0x05,0x02,0x03,ENDP2_OUT_SIZE,0x00,0x01,??????????????//端點描述符?? }; /*字符串描述符?略*/? /*HID類報表描述符*/ UINT8C?HIDRepDesc[?]?= { ????0x06,?0x00,0xff, ????0x09,?0x01, ????0xa1,?0x01,???????????????????????????????????????????????????//集合開始 ????0x09,?0x02,???????????????????????????????????????????????????//Usage?Page??用法 ????0x15,?0x00,???????????????????????????????????????????????????//Logical??Minimun ????0x26,?0x00,0xff,??????????????????????????????????????????????//Logical??Maximun ????0x75,?0x08,???????????????????????????????????????????????????//Report?Size ????0x95,?THIS_ENDP0_SIZE,????????????????????????????????????????//Report?Counet ????0x81,?0x06,???????????????????????????????????????????????????//Input ????0x09,?0x02,???????????????????????????????????????????????????//Usage?Page??用法 ????0x15,?0x00,???????????????????????????????????????????????????//Logical??Minimun ????0x26,?0x00,0xff,??????????????????????????????????????????????//Logical??Maximun ????0x75,?0x08,???????????????????????????????????????????????????//Report?Size ????0x95,?THIS_ENDP0_SIZE,????????????????????????????????????????//Report?Counet ????0x91,?0x06,???????????????????????????????????????????????????//Output ????0xC0 }; //?建議gamepad UINT8C?HIDRepDesc2[]?=?{ ????0x05,?0x01,????????????????????//?USAGE_PAGE?(Generic?Desktop) ????0x09,?0x05,????????????????????//?USAGE?(Game?Pad) ????0xa1,?0x01,????????????????????//?COLLECTION?(Application) ????0xa1,?0x00,????????????????????//???COLLECTION?(Physical) ????//?ReportID?-?8?bits ????0x85,?0x01,????????????????????//?????REPORT_ID?(1) ????//?X?&?Y?-?2x8?=?16?bits ????0x05,?0x01,????????????????????//?????USAGE_PAGE?(Generic?Desktop) ????0x09,?0x30,????????????????????//?????USAGE?(X) ????0x09,?0x31,????????????????????//?????USAGE?(Y) ????0x15,?0x81,????????????????????//?????LOGICAL_MINIMUM?(-127) ????0x25,?0x7f,????????????????????//?????LOGICAL_MAXIMUM?(127) ????0x75,?0x08,????????????????????//?????REPORT_SIZE?(8) ????0x95,?0x02,????????????????????//?????REPORT_COUNT?(2) ????0x81,?0x02,????????????????????//?????INPUT?(Data,Var,Abs) ????//?Buttons?-?8?bits ????0x05,?0x09,????????????????????//?????USAGE_PAGE?(Button) ????0x19,?0x01,????????????????????//?????USAGE_MINIMUM?(Button?1) ????0x29,?0x08,????????????????????//?????USAGE_MAXIMUM?(Button?8) ????0x15,?0x00,????????????????????//?????LOGICAL_MINIMUM?(0) ????0x25,?0x01,????????????????????//?????LOGICAL_MAXIMUM?(1) ????0x75,?0x08,????????????????????//?????REPORT_SIZE?(8) ????0x95,?0x01,????????????????????//?????REPORT_COUNT?(1) ????0x81,?0x02,????????????????????//?????INPUT?(Data,Var,Abs) ????0xc0,??????????????????????????//?????END_COLLECTION ????0xc0???????????????????????????//?END_COLLECTION }; void?Enp2BlukIn(?) { ????memcpy(?Ep2Buffer+MAX_PACKET_SIZE_2,?UserEp2Buf,?USE_EP2_BUF_LEN);????????//加載上傳數(shù)據(jù) ????if(?Ready?) ????{ ????????UEP2_T_LEN?=?THIS_ENDP0_SIZE;??????????????????????????????????????????????//上傳最大包長度 ????????UEP2_CTRL?=?UEP2_CTRL?&?~?MASK_UEP_T_RES?|?UEP_T_RES_ACK;??????????????????//有數(shù)據(jù)時上傳數(shù)據(jù)并應(yīng)答ACK ????????Endp2Busy?=?1;?????????????????????????????????????????????????????????? ????} } main() { ????UINT8?i,?ch; ????CfgFsys();?//?CH559時鐘選擇配置 ????mDelaymS(5);?//?修改主頻等待內(nèi)部晶振穩(wěn)定,必加 ????mInitSTDIO();?//?串口0初始化 ????Port1Cfg(1,?6); ????for?(i?=?0;?i?<?ENDP2_IN_SIZE;?i++)?//?準(zhǔn)備演示數(shù)據(jù) ????{ ????????UserEp2Buf[i]?=?i; ????} ????USBDeviceInit();?//?USB設(shè)備模式初始化 ????EA?=?1;?//?允許單片機(jī)中斷 ????UEP1_T_LEN?=?0;?//?預(yù)使用發(fā)送長度一定要清空 ????UEP2_T_LEN?=?0;?//?預(yù)使用發(fā)送長度一定要清空 ????Ready?=?0; ????ch?=?0; ????LED_PIN?=?0; ????while?(1)?{ ????????if?(Ready?&&?(Ep2InKey?==?0))?{ ????????????while?(Endp2Busy)?{?} ????????????UserEp2Buf[0]?=?1; ????????????++ch; ????????????UserEp2Buf[1]?=?ch; ????????????UserEp2Buf[2]?=?ch; ????????????UserEp2Buf[3]?=?ch; ????????????UserEp2Buf[4]?=?ch; ????????????Enp2IntIn(); ????????} ????????LED_PIN?=?!Ep2InKey; ????????mDelaymS(100);?//?模擬單片機(jī)做其它事 ????} }
請教各位大佬,上面代碼中HIDRepDesc是官網(wǎng)默認(rèn)帶的,可以發(fā)送數(shù)據(jù),并通過HidRawDataWatcher看到發(fā)送了什么數(shù)據(jù);
改為HIDRepDesc2,這個我自定義的gamepad后,Enp2BlukIn發(fā)送的數(shù)據(jù)HidRawDataWatcher就看不到了。
好像只要指定了report id就無法發(fā)送數(shù)據(jù)了,我在main中已經(jīng)指定了UserEp2Buf的第一個字節(jié)是1了。