OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 7209|回复: 4

USB HID 通信求助

[复制链接]

2

主题

9

帖子

0

精华

新手上路

积分
38
金钱
38
注册时间
2015-6-18
在线时间
0 小时
发表于 2015-6-24 14:17:42 | 显示全部楼层 |阅读模式
5金钱
[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]

正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

2

主题

9

帖子

0

精华

新手上路

积分
38
金钱
38
注册时间
2015-6-18
在线时间
0 小时
 楼主| 发表于 2015-6-24 14:19:50 | 显示全部楼层
主要改动了Usbd_hid_core文件,配置了两个端点。时钟收发不到数据,大神们帮忙看下哪里需要改动。
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165540
金钱
165540
注册时间
2010-12-1
在线时间
2117 小时
发表于 2015-6-24 22:54:46 | 显示全部楼层
帮顶。。。。
我是开源电子网www.openedv.com站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺http://openedv.taobao.com
正点原子官方微信公众平台,点击这里关注“正点原子”
回复

使用道具 举报

14

主题

1592

帖子

0

精华

资深版主

Rank: 8Rank: 8

积分
2622
金钱
2622
注册时间
2014-7-17
在线时间
350 小时
发表于 2015-6-24 23:18:04 | 显示全部楼层
帮顶。。。。
回复

使用道具 举报

1

主题

4

帖子

0

精华

初级会员

Rank: 2

积分
81
金钱
81
注册时间
2011-12-4
在线时间
11 小时
发表于 2017-2-6 15:32:45 | 显示全部楼层
USBD_LL_Init尝试修改下这个函数调用里的端点的发送和接收fifo的设置
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-19 22:01

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表