USB HID 通信求助

2019-07-20 17:05发布

[mw_shl_code=c,true]int main(void) { uint8_t buf[16] = {1,2,3,4}; Demo_Exec(); while(1) { Delay(10); USBD_HID_ReceiveReport( &USB_OTG_dev, HID_OUT_EP, buf, 4); Delay(10); //buf[0]++; USBD_HID_SendReport (&USB_OTG_dev, buf, 4); //DCD_EP_Tx (&USB_OTG_dev, HID_OUT_EP, buf, 4); } } __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, /*bNumEndpoints*/ //????????2 0x03, /*bInterfaceClass: HID*/ 0x00, /*bInterfaceSubClass : 1=BOOT, 0=no boot*/ 0x00, /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*/ 0, /*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:*/ //0x82 ????2 IN MODE ??????FIFO?è???????? HID_IN_EP, /*bEndpointAddress: Endpoint Address (IN)*/ 0x03, /*bmAttributes: Interrupt endpoint*/ HID_IN_PACKET, /*wMaxPacketSize: 4 Byte max */ 0x00, 0x0A, /*bInterval: Polling Interval (10 ms)*/ /* 34 */ 0x07, /*bLength: Endpoint Descriptor size*/ USB_ENDPOINT_DESCRIPTOR_TYPE, /*bDescriptorType:*/ //0x01 ????1 OUT ???????? HID_OUT_EP, /*bEndpointAddress: Endpoint Address (IN)*/ 0x03, /*bmAttributes: Interrupt endpoint*/ HID_IN_PACKET, /*wMaxPacketSize: 4 Byte max */ 0x00, 0x0A, /*bInterval: Polling Interval (10 ms)*/ /* 34 */ } ; /** * @brief USBD_HID_Init ?ò?????? * Initialize the HID interface * @param pdev: device instance * @param cfgidx: Configuration index * @retval status */ static uint8_t USBD_HID_Init (void *pdev, uint8_t cfgidx) { /* Open EP IN */ DCD_EP_Open(pdev, HID_IN_EP, HID_IN_PACKET, USB_OTG_EP_INT); /* Open EP OUT */ DCD_EP_Open(pdev, HID_OUT_EP, HID_OUT_PACKET, USB_OTG_EP_INT); return USBD_OK; } /** * @brief USBD_HID_SendReport * Send HID Report * @param pdev: device instance * @param buff: pointer to report * @retval status */ uint8_t USBD_HID_SendReport (USB_OTG_CORE_HANDLE *pdev, uint8_t *report, uint16_t len) { if (pdev->dev.device_status == USB_OTG_CONFIGURED ) { DCD_EP_Tx (pdev, HID_IN_EP, report, len); } return USBD_OK; } //?????????????? 2015/6/24 uint8_t USBD_HID_ReceiveReport( USB_OTG_CORE_HANDLE *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t buf_len) { if (pdev->dev.device_status == USB_OTG_CONFIGURED ) { DCD_EP_PrepareRx(pdev, HID_OUT_EP, pbuf, buf_len); } return USBD_OK; } /****************** USB OTG FS CONFIGURATION **********************************/ #ifdef USB_OTG_FS_CORE #define RX_FIFO_FS_SIZE 128 #define TX0_FIFO_FS_SIZE 64 #define RX1_FIFO_FS_SIZE 64 #define TX1_FIFO_FS_SIZE 0 #define TX2_FIFO_FS_SIZE 64 #define RX2_FIFO_FS_SIZE 0 #define TX3_FIFO_FS_SIZE 0 /** @defgroup USB_HID_Class_Layer_Parameter * @{ */ #define HID_IN_EP 0x82 #define HID_OUT_EP 0x01 #define HID_IN_PACKET 64 #define HID_OUT_PACKET 64 以上是我配置的USB HID模式的程序,在官方上修改的鼠标例程,然后要实现的功能是双向通信,已经参考改了好多次,能够枚举不能收发数据,会的还请帮忙指导下呀! [/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。