请问谁做过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;
}
---------------------------------
不好意思哦,最近忙的没有看帖子。程序方面估计其他地方也要微调,可能地方有点多,我不太好细说,我现在换高速模式了,上行速度已经可以达到12M字节每秒了,满足你的要求了。如果不行,你把程序发给我我给你看看
---------------------------------
我现在在使用vcp官方代码修改,现在还没到调速度,刚把USB接收程序搞好,发送还没搞好,官方封装的那个发送函数不行,发不出数。我想问一下之前的FS模式最大上行能到多少?我们现在不想用HS,成本考虑。
--------------------------------
我用的是高速模式,所以够的,不用外扩SRAM,但是高速模式的话要外扩另一个片子,因为手上有一块STM32F407IGT6的板子已经外扩了3300的片子了
你好,可否帮忙看看我的代码,我需要将F407的游戏操作杆例程的修改为可以使用HID与主机进行数据的接收与发送的!但是我不会啊,老板催命似得催,急死个人啦!非常感谢~~
一周热门 更多>