USB鼠标程序改成HID自定义设备

2019-07-20 15:46发布

    请问谁做过HID自定义设备?我想把STM32F407的鼠标例程改为能收发数据的自定义HID设备,现在枚举已经成功, 能一次性发送64个字节,但是收不到数据。我只修改了usbd_hid_core.c文件里的描述符,并增加了一个USBD_HID_Data回调函数用于处理接收到的数据。
程序如下,请问谁知道怎么解决啊?????

USBD_Class_cb_TypeDef  USBD_HID_cb =  { USBD_HID_Init, USBD_HID_DeInit, USBD_HID_Setup, NULL, /*EP0_TxSent*/   NULL, /*EP0_RxReady*/ USBD_HID_DataIn, /*DataIn*/ USBD_HID_DataOut, /*xcs DataOut*/*********** 增加的回调函数用于处理接收到的数据 NULL, /*SOF */ NULL, NULL,       USBD_HID_GetCfgDesc, #ifdef USB_OTG_HS_CORE   USBD_HID_GetCfgDesc, /* use same config as per FS */ #endif   };
 /* USB HID device Configuration Descriptor */ __ALIGN_BEGIN static uint8_t USBD_HID_CfgDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_END = {   0x09, /* bLength: Configuration Descriptor size */   USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */   USB_HID_CONFIG_DESC_SIZ,   /* wTotalLength: Bytes returned */   0x00,   0x01,         /*bNumInterfaces: 1 interface*/   0x01,         /*bConfigurationValue: Configuration value*/   0x00,         /*iConfiguration: Index of string descriptor describing the configuration*/   0xE0,         /*bmAttributes: bus powered and Support Remote Wake-up */   0x32,         /*MaxPower 100 mA: this current is used for detecting Vbus*/      /************** Descriptor of Joystick Mouse interface ****************/   /* 09 */   0x09,         /*bLength: Interface Descriptor size*/   USB_INTERFACE_DESCRIPTOR_TYPE,/*bDescriptorType: Interface descriptor type*/   0x00,         /*bInterfaceNumber: Number of Interface*/   0x00,         /*bAlternateSetting: Alternate setting*/   0x02,//xcs 0x01,         /*bNumEndpoints*/   0x03,         /*bInterfaceClass: HID*/   0x00,//xcs 0x01,         /*bInterfaceSubClass : 1=BOOT, 0=no boot*/   0x00,//xcs 0x02,         /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*/   0x00,         /*iInterface: Index of string descriptor*/   /******************** Descriptor of Joystick Mouse HID ********************/   /* 18 */   0x09,         /*bLength: HID Descriptor size*/   HID_DESCRIPTOR_TYPE, /*bDescriptorType: HID*/   0x11,         /*bcdHID: HID Class Spec release number?汾*/   0x01,   0x00,         /*bCountryCode: Hardware target country*/   0x01,         /*bNumDescriptors: Number of HID class descriptors to follow*/   0x22,         /*bDescriptorType*/   HID_MOUSE_REPORT_DESC_SIZE,/*wItemLength: Total length of Report descriptor*/   0x00,   /******************** Descriptor of Mouse endpoint ********************/   /* 27 */   0x07,          /*bLength: Endpoint Descriptor size*/   USB_ENDPOINT_DESCRIPTOR_TYPE, /*bDescriptorType:*/      HID_IN_EP,     /*bEndpointAddress: Endpoint Address (IN)*/   0x03,          /*bmAttributes: Interrupt endpoint*/   HID_IN_PACKET, /*wMaxPacketSize*/   0x00,   0x0A,          /*bInterval: Polling Interval (10 ms)*/   /* 34 */      //xcs************************************************   0x07,          /*bLength: Endpoint Descriptor size*/   USB_ENDPOINT_DESCRIPTOR_TYPE, /*bDescriptorType:*/      HID_OUT_EP,     /*bEndpointAddress: Endpoint Address (IN)*/   0x03,          /*bmAttributes: Interrupt endpoint*/   HID_IN_PACKET, /*wMaxPacketSize*/   0x00,   0x0A,          /*bInterval: Polling Interval (10 ms)*/   /* 41 */ } ;
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED   #if defined ( __ICCARM__ ) /*!< IAR Compiler */     #pragma data_alignment=4      #endif /* USB HID device Configuration Descriptor */ __ALIGN_BEGIN static uint8_t USBD_HID_Desc[USB_HID_DESC_SIZ] __ALIGN_END= {   /* 18 */   0x09,         /*bLength: HID Descriptor size*/   HID_DESCRIPTOR_TYPE, /*bDescriptorType: HID*/   0x11,         /*bcdHID: HID Class Spec release number*/   0x01,   0x00,         /*bCountryCode: Hardware target country*/   0x01,         /*bNumDescriptors: Number of HID class descriptors to follow*/   0x22,         /*bDescriptorType*/   HID_MOUSE_REPORT_DESC_SIZE,/*wItemLength: Total length of Report descriptor*/   0x00, }; #endif 

#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED   #if defined ( __ICCARM__ ) /*!< IAR Compiler */     #pragma data_alignment=4      #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */   __ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE] __ALIGN_END = //xcs { 0x05,0x8C,              //USAGE_PAGE (Vendor Defined Page 1) 0x09,0x01,              //USAGE (Vendor Usage 1) 0xA1,0x01,              //COLLECTION (Application)
0x09,0x03,              //(Vendor Usage 1) 0x15,0x00,              //LOGICAL_MINIMUM (0) 0x26,0xFF,0x00,     //LOGICAL_MAXIMUM (255) 0x75,0x08,              //REPORT_SIZE (8) 0x95,0x40,              //REPORT_COUNT (64) 0x81,0x02,              //INPUT (Data,Var,Abs)
0x09,0x04,              //(Vendor Usage 1) 0x15,0x00,              //LOGICAL_MINIMUM (0) 0x26,0xFF,0x00,     //LOGICAL_MAXIMUM (255) 0x75,0x08,              //REPORT_SIZE (8) 0x95,0x40,              //REPORT_COUNT (64) 0x91,0x02,              //OUTPUT (Data,Var,Abs)
0xC0                /*     END_COLLECTION */ }
 static uint8_t  USBD_HID_DataIn (void  *pdev,                                uint8_t epnum) {      /* Ensure that the FIFO is empty before a new transfer, this condition could    be caused by  a new transfer before the end of the previous transfer */   DCD_EP_Flush(pdev, HID_IN_EP);   return USBD_OK; }

static uint8_t USBD_HID_DataOut( void *pdev, uint8_t epnum) { return USBD_OK; }
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
34条回答
haoyu729
1楼-- · 2019-07-20 20:23
 精彩回答 2  元偷偷看……
正点原子
2楼-- · 2019-07-20 22:03
 精彩回答 2  元偷偷看……
zhhj
3楼-- · 2019-07-21 01:29
回复【3楼】正点原子:
---------------------------------
你有改好的吗?给大伙参考参考
正点原子
4楼-- · 2019-07-21 02:00
回复【4楼】zhhj:
---------------------------------
没有。
真的好多巧合
5楼-- · 2019-07-21 03:44
楼主,如果要改成游戏手柄,需要修改那些描述符?
为爱停留
6楼-- · 2019-07-21 04:18
 精彩回答 2  元偷偷看……

一周热门 更多>