完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我正在研究一种能够使用CDC和HID类与主机交谈的设备。单片机是PIC18F70J50。我还没有实现它作为一个复合设备(为此,我需要使用IAD描述符,据我的理解去)。我基本上已经采取了一个工作的CDC项目,并修改它,以便结合一个HID接口。从我在USBlyzer可以看到,HID鼠标是公认的。正确的,但不是CDC设备。然而,嗅探与HID鼠标的通信揭示了很多交易错误:我使用的是来自微芯片的CDC项目,并应用了必要的修改,所以我可能犯了一些错误。是否有完整的CDC + HID样本项目在那里,我可以作为参考?描述符:
以上来自于百度翻译 以下为原文 I'm working on a device capable of talking to the host using the CDC and the HID classes. The MCU is a PIC18F87J50. I'm not implementing it yet as a composite device (for this purpose I'd need to use IAD descriptors, as far as my understanding goes). I have basically taken a working CDC project and have modified it so as to incorporate an HID interface. From what I can see in USBlyzer, the HID mouse is recognized correctly, but not the CDC device. However, sniffing the communications with the HID mouse reveals a lot of transaction errors: I'm using a sample CDC project from Microchip and have applied the needed modifications, so it's possible I've made some mistakes. Are there full CDC+HID samples projects out there that I can use as reference? The descriptors: rom USB_DEV_DSC device_dsc= { sizeof(USB_DEV_DSC), // Size of this descriptor in bytes DSC_DEV, // DEVICE descriptor type 0x0200, // USB Spec Release Number in BCD format 0x00, // Class Code 0x00, // Subclass code 0x00, // Protocol code EP0_BUFF_SIZE, // Max packet size for EP0, see u***cfg.h 0x04D8, // Vendor ID PROD_ID, // Product ID: CDC RS-232 Emulation Demo 0x0001, // Device release number in BCD format 0x01, // Manufacturer string index 0x02, // Product string index 0x00, // Device serial number string index 0x01 // Number of possible configurations }; CFG01= { //Configuration Descriptor sizeof(USB_CFG_DSC), // Size of this descriptor in bytes DSC_CFG, // CONFIGURATION descriptor type sizeof(cfg01), // Total length of data for this cfg 3, // Number of interfaces in this cfg 1, // Index value of this configuration 0, // Configuration string index _DEFAULT | _SELF, // Attributes, see u***defs_std_dsc.h 50, // Max power consumption (2X mA) //Interface Descriptor sizeof(USB_INTF_DSC), // Size of this descriptor in bytes DSC_INTF, // INTERFACE descriptor type CDC_COMM_INTF_ID, // Interface Number 0, // Alternate Setting Number 1, // Number of endpoints in this intf COMM_INTF, // Class code ABSTRACT_CONTROL_MODEL, // Subclass code V25TER, // Protocol code 0, // Interface string index //CDC Class-Specific Descriptors sizeof(USB_CDC_HEADER_FN_DSC), //HEADER FUNCTIONAL DSC CS_INTERFACE, //MUST BE CS_INTERFACE DSC_FN_HEADER, 0x0110, sizeof(USB_CDC_ACM_FN_DSC), //ABSTRACT CONTROL MANAGEMENT FUNCTIONAL DSC CS_INTERFACE, DSC_FN_ACM, //DSC SUBTYPE : ABSTRACT CONTROL MANAGEMENT 0x02, sizeof(USB_CDC_UNION_FN_DSC), //UNION FUNCTIONAL DSC CS_INTERFACE, //MUST BE! DSC_FN_UNION, //SUBTYPE = UNION CDC_COMM_INTF_ID, //MASTER INTERFACE = 0 CDC_DATA_INTF_ID, //SLAVE INTERFACE = 1 sizeof(USB_CDC_CALL_MGT_FN_DSC), CS_INTERFACE, DSC_FN_CALL_MGT, 0x00, CDC_DATA_INTF_ID, //Endpoint Descriptor sizeof(USB_EP_DSC), DSC_EP, _EP01_IN, _INT, CDC_INT_EP_SIZE, 0x02, // *************************************************************************** // ******************* C D C *************************** // *************************************************************************** //Interface Descriptor sizeof(USB_INTF_DSC), // Size of this descriptor in bytes DSC_INTF, // INTERFACE descriptor type CDC_DATA_INTF_ID, // Interface Number 0, // Alternate Setting Number 2, // Number of endpoints in this intf DATA_INTF, // Class code 0, // Subclass code NO_PROTOCOL, // Protocol code 0, // Interface string index //Endpoint Descriptors sizeof(USB_EP_DSC), DSC_EP, _EP02_OUT, _BULK, CDC_BULK_OUT_EP_SIZE, 0x00, sizeof(USB_EP_DSC), DSC_EP, _EP02_IN, _BULK, CDC_BULK_IN_EP_SIZE, 0x00, // **************************************************************************** // ******************* H I D **************************** // **************************************************************************** //Interface Descriptor sizeof(USB_INTF_DSC), // Size of this descriptor in bytes DSC_INTF, // INTERFACE descriptor type HID_INTF_ID, // Interface Number 0, // Alternate Setting Number 1, // Number of endpoints in this intf HID_INTF, // Class code BOOT_INTF_SUBCLASS, // Subclass code HID_PROTOCOL_MOUSE, // Protocol code 0, // Interface string index //HID Class-Specific Descriptor sizeof(USB_HID_DSC), // Size of this descriptor in bytes DSC_HID, // HID descriptor type 0x0111, // HID Spec Release Number in BCD format 0x00, // Country Code (0x00 for Not supported) HID_NUM_OF_DSC, // Number of class descriptors, see u***cfg.h DSC_RPT, // Report descriptor type sizeof(hid_rpt01), // Size of the report descriptor //Endpoint Descriptor sizeof(USB_EP_DSC), DSC_EP, _EP03_IN, _INT, HID_INT_IN_EP_SIZE, 0x0A }; |
|
相关推荐
1个回答
|
|
自从上一篇文章以来,我已经取得了一些进展。现在,复合设备已经被OS正确识别。串行设备和主机工作100%之间的通信。然而,主机无法接收来自鼠标设备的数据:会发生什么?UBCFG.H中的定义:新的描述符:
以上来自于百度翻译 以下为原文 I've made some progress since the last post. The composite device is now correctly recognized by OS. Communications between the serial device and the host work 100%. However, the host isn't being able to receive the data from the mouse device: What could be happening? Definitions in u***cfg.h: /* CDC */ #define CDC_COMM_INTF_ID 0x00 /* USING IFACE 0 */ #define CDC_COMM_UEP UEP1 /* USING USB ENDPOINT 2 CONTROL REGISTER (THERE'S ONE PER ENDPOINT!)*/ #define CDC_INT_BD_IN ep1Bi /* ENDPOINT IN-BUFFER DESCRIPTOR 2 */ #define CDC_INT_EP_SIZE 8 /* BUFFER SIZE OF 8 BYTES */ #define CDC_DATA_INTF_ID 0x01 /* USING INTERFACE 1 */ #define CDC_DATA_UEP UEP2 /* USB ENDPOINT 3 CONTROL REG */ #define CDC_BULK_BD_OUT ep2Bo /* ENDPOINT 3 OUT-BUFFER DESCRIPTOR */ #define CDC_BULK_OUT_EP_SIZE 64 /* 64 BYTES */ #define CDC_BULK_BD_IN ep2Bi /* ENDPOINT 3 IN-BUFFER DESCRIPTOR */ #define CDC_BULK_IN_EP_SIZE 64 /* 64 BYTES TOO! */ /* HID */ #define HID_INTF_ID 0x02 #define HID_UEP UEP3 #define HID_BD_OUT ep3Bo #define HID_INT_OUT_EP_SIZE 3 #define HID_BD_IN ep3Bi #define HID_INT_IN_EP_SIZE 3 #define HID_NUM_OF_DSC 1 #define HID_RPT01_SIZE 50 The new descriptors: /* Device Descriptor */ rom USB_DEV_DSC device_dsc= { sizeof(USB_DEV_DSC), // Size of this descriptor in bytes DSC_DEV, // DEVICE descriptor type 0x0200, // USB Spec Release Number in BCD format CLASS_CODE, // Class Code SUBCLASS_CODE, // Subclass code PROT_CODE, // Protocol code EP0_BUFF_SIZE, // Max packet size for EP0, see u***cfg.h VENDOR_ID, // Vendor ID PROD_ID, // Product ID: CDC RS-232 Emulation Demo 0x0002, // Device release number in BCD format 0x01, // Manufacturer string index 0x02, // Product string index 0x00, // Device serial number string index 0x01 // Number of possible configurations }; CFG01= { //Configuration Descriptor sizeof(USB_CFG_DSC), // Size of this descriptor in bytes DSC_CFG, // CONFIGURATION descriptor type sizeof(cfg01), // Total length of data for this cfg 3, // Number of interfaces in this cfg 1, // Index value of this configuration 0, // Configuration string index _DEFAULT|_SELF, // Attributes, see u***defs_std_dsc.h 50, // Max power consumption (2X mA) // **************************************************************************** // ******************* I A D **************************** // **************************************************************************** // Interface Association Descriptor 0x08, // Size of this descriptor in bytes 0x0B, // Interface association descriptor type CDC_COMM_INTF_ID, // First associated interface 2, // Number of contiguous associated interfaces COMM_INTF, // bInterfaceClass of the first interface ABSTRACT_CONTROL_MODEL, // bInterfaceSubClass of the first interface V25TER, // bInterfaceProtocol of the first interface 0x00, // Interface string index // *************************************************************************** // ******************* C D C *************************** // ****************************** CONTROL ************************************ //Interface Descriptor sizeof(USB_INTF_DSC), // Size of this descriptor in bytes DSC_INTF, // INTERFACE descriptor type CDC_COMM_INTF_ID, // Interface Number 0, // Alternate Setting Number 1, // Number of endpoints in this intf COMM_INTF, // Class code ABSTRACT_CONTROL_MODEL, // Subclass code V25TER, // Protocol code 0, // Interface string index //CDC Class-Specific Descriptors sizeof(USB_CDC_HEADER_FN_DSC), //HEADER FUNCTIONAL DSC CS_INTERFACE, //MUST BE CS_INTERFACE DSC_FN_HEADER, 0x0110, sizeof(USB_CDC_ACM_FN_DSC), //ABSTRACT CONTROL MANAGEMENT FUNCTIONAL DSC CS_INTERFACE, DSC_FN_ACM, //DSC SUBTYPE : ABSTRACT CONTROL MANAGEMENT 0x02, sizeof(USB_CDC_UNION_FN_DSC), //UNION FUNCTIONAL DSC CS_INTERFACE, //MUST BE! DSC_FN_UNION, //SUBTYPE = UNION CDC_COMM_INTF_ID, //MASTER INTERFACE = 0 CDC_DATA_INTF_ID, //SLAVE INTERFACE = 1 sizeof(USB_CDC_CALL_MGT_FN_DSC), CS_INTERFACE, DSC_FN_CALL_MGT, 0x00, CDC_DATA_INTF_ID, //Endpoint Descriptor sizeof(USB_EP_DSC), DSC_EP, _EP01_IN, _INT, CDC_INT_EP_SIZE, 0x02, // *************************************************************************** // ******************* C D C *************************** // ****************************** DATA *************************************** //Interface Descriptor sizeof(USB_INTF_DSC), // Size of this descriptor in bytes DSC_INTF, // INTERFACE descriptor type CDC_DATA_INTF_ID, // Interface Number 0, // Alternate Setting Number 2, // Number of endpoints in this intf DATA_INTF, // Class code 0, // Subclass code NO_PROTOCOL, // Protocol code 0, // Interface string index //Endpoint Descriptors sizeof(USB_EP_DSC), DSC_EP, _EP02_OUT, _BULK, CDC_BULK_OUT_EP_SIZE, 0x00, sizeof(USB_EP_DSC), DSC_EP, _EP02_IN, _BULK, CDC_BULK_IN_EP_SIZE, 0x00, // **************************************************************************** // ******************* H I D **************************** // **************************************************************************** //Interface Descriptor sizeof(USB_INTF_DSC), // Size of this descriptor in bytes DSC_INTF, // INTERFACE descriptor type HID_INTF_ID, // Interface Number 0, // Alternate Setting Number 1, // Number of endpoints in this intf HID_INTF, // Class code BOOT_INTF_SUBCLASS, // Subclass code HID_PROTOCOL_MOUSE, // Protocol code 0, // Interface string index //HID Class-Specific Descriptor sizeof(USB_HID_DSC), // Size of this descriptor in bytes DSC_HID, // HID descriptor type 0x0111, // HID Spec Release Number in BCD format 0x00, // Country Code (0x00 for Not supported) HID_NUM_OF_DSC, // Number of class descriptors, see u***cfg.h DSC_RPT, // Report descriptor type sizeof(hid_rpt01), // Size of the report descriptor //Endpoint Descriptor sizeof(USB_EP_DSC), DSC_EP, _EP03_IN, _INT, HID_INT_IN_EP_SIZE, 0x0A }; |
|
|
|
只有小组成员才能发言,加入小组>>
5234 浏览 9 评论
2026 浏览 8 评论
1950 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3201 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2253 浏览 5 评论
771浏览 1评论
659浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
588浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
670浏览 0评论
571浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-20 20:33 , Processed in 1.384409 second(s), Total 78, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号