有一个基于 STM32F401CU 的开发板,来自 DevEBox,它支持 USB 主机,任务是将 HID 设备连接到它,在本例中是 Gunfighter 操纵杆。为了解决这个问题,我采用了一条简单的路径:CubeMX、USB_HOST 库,一切都在 HAL 上,如果使用鼠标和键盘,一切都会立即启动,并且通过回调USBH_HID_EventCallback
,您可以显示来自设备的数据。使用操纵杆并不容易,库报告不支持该设备,为了解决这个问题,我对库进行了一些更改,重点关注来自 USBlyzer 的数据:
- usbh_conf.h
/*---------- -----------*/
#define USBH_MAX_NUM_ENDPOINTS 1U
/*---------- -----------*/
#define USBH_MAX_NUM_INTERFACES 1U
- usbh_core.c
与创建和修改 IN 频道有关的所有内容都已在此处注释掉。
phost->gState = HOST_ENUMERATION;
phost->Control.pipe_out = USBH_AllocPipe(phost, 0x00U);
// phost->Control.pipe_in = USBH_AllocPipe(phost, 0x80U);
/* Open Control pipes */
// USBH_OpenPipe(phost, phost->Control.pipe_in, 0x80U,
// phost->device.address, phost->device.speed,
// USBH_EP_CONTROL, (uint16_t)phost->Control.pipe_size);
/* Open Control pipes */
USBH_OpenPipe(phost, phost->Control.pipe_out, 0x00U,
phost->device.address, phost->device.speed,
USBH_EP_CONTROL, (uint16_t)phost->Control.pipe_size);
- usbh_hid.h
添加了定义,以便将来该功能USBH_HID_InterfaceInit
可以识别快乐
/* Interface Descriptor field values for HID Boot Protocol */
#define HID_BOOT_CODE 0x01U
#define HID_NONE_BOOT_CODE 0x00U
#define HID_KEYBRD_BOOT_CODE 0x01U
#define HID_MOUSE_BOOT_CODE 0x02U
- usbh_hid.c
通过 SWO 提款有几个选项
else if (phost->device.CfgDesc.Itf_Desc[interface].bInterfaceProtocol == HID_NONE_BOOT_CODE)
{
USBH_UsrLog("Non boot device found!");
}
将协议切换为非引导
case HID_REQ_SET_PROTOCOL:
/* set protocol */
classReqStatus = USBH_HID_SetProtocol(phost, 1U);
if (classReqStatus == USBH_OK)
{
HID_Handle->ctl_state = HID_REQ_IDL
结果,我所做的一切工作的最后一个成功点是一个函数USBH_HID_GetHIDReportDescriptor
,描述符完成了,没有任何问题,但是问题开始了。说到USBH_HID_GetReport
, 位于USBH_HID_Process
, 我得到USBH_NOT_SUPPORTED
, 事实上,故事就此结束。然后代码循环旋转HID_POLL
,没有来自操纵杆的数据传给我。
从有趣的观察中,我可以注意到,如果您不对第二段进行更改,而是在函数中,USBH_HID_InterfaceInit
请执行以下操作:
for (num = 0U; num < max_ep; num++)
{
if (phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[num].bEndpointAddress & 0x80U)
{
HID_Handle->InEp = (phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[num].bEndpointAddress);
// HID_Handle->InPipe = USBH_AllocPipe(phost, HID_Handle->InEp);
HID_Handle->InPipe = 1;
/* Open pipe for IN endpoint */
USBH_OpenPipe(phost, HID_Handle->InPipe, HID_Handle->InEp, phost->device.address,
phost->device.speed, USB_EP_TYPE_INTR, HID_Handle->length);
USBH_LL_SetToggle(phost, HID_Handle->InPipe, 0U);
}
然后我得到报告本身而不是报告描述符,希望我不能比任何事情更聪明,我决定循环这个动作,只是不时地通过这个请求获取我需要的数据包,但是,之后第二张收据,一切都挂在了USBH_BUSY
我没有的状态和数据中。我将不胜感激有关此主题的任何想法和考虑,我还附上了来自 USBlyzer 的快乐数据:
Connection Status Device connected
Current Configuration 1
Speed Full (12 Mbit/s)
Device Address 6
Number Of Open Pipes 1
Device Descriptor VKB-Sim Space Gunfighter L
Offset Field Size Value Description
0 bLength 1 12h
1 bDescriptorType 1 01h Device
2 bcdUSB 2 0200h USB Spec 2.0
4 bDeviceClass 1 00h Class info in Ifc Descriptors
5 bDeviceSubClass 1 00h
6 bDeviceProtocol 1 00h
7 bMaxPacketSize0 1 08h 8 bytes
8 idVendor 2 231Dh
10 idProduct 2 0127h
12 bcdDevice 2 1997h 19.97
14 iManufacturer 1 01h ". Alex Oz 2012-2020"
15 iProduct 1 02h " VKB-Sim Space Gunfighter L "
16 iSerialNumber 1 00h
17 bNumConfigurations 1 01h
Configuration Descriptor 1 Bus Powered, 500 mA
Offset Field Size Value Description
0 bLength 1 09h
1 bDescriptorType 1 02h Configuration
2 wTotalLength 2 0022h
4 bNumInterfaces 1 01h
5 bConfigurationValue 1 01h
6 iConfiguration 1 00h
7 bmAttributes 1 80h Bus Powered
4..0: Reserved ...00000
5: Remote Wakeup ..0..... No
6: Self Powered .0...... No, Bus Powered
7: Reserved (set to one)
(bus-powered for 1.0) 1.......
8 bMaxPower 1 FAh 500 mA
Interface Descriptor 0/0 HID, 1 Endpoint
Offset Field Size Value Description
0 bLength 1 09h
1 bDescriptorType 1 04h Interface
2 bInterfaceNumber 1 00h
3 bAlternateSetting 1 00h
4 bNumEndpoints 1 01h
5 bInterfaceClass 1 03h HID
6 bInterfaceSubClass 1 00h
7 bInterfaceProtocol 1 00h
8 iInterface 1 00h
HID Descriptor
Offset Field Size Value Description
0 bLength 1 09h
1 bDescriptorType 1 21h HID
2 bcdHID 2 0111h 1.11
4 bCountryCode 1 00h
5 bNumDescriptors 1 01h
6 bDescriptorType 1 22h Report
7 wDescriptorLength 2 012Dh 301 bytes
Endpoint Descriptor 81 1 In, Interrupt, 1 ms
Offset Field Size Value Description
0 bLength 1 07h
1 bDescriptorType 1 05h Endpoint
2 bEndpointAddress 1 81h 1 In
3 bmAttributes 1 03h Interrupt
1..0: Transfer Type ......11 Interrupt
7..2: Reserved 000000..
4 wMaxPacketSize 2 0040h 64 bytes
6 bInterval 1 01h 1 ms
Interface 0 HID Report Descriptor Joystick
Item Tag (Value) Raw Data
Usage Page (Generic Desktop) 05 01
Usage (Joystick) 09 04
Collection (Application) A1 01
Usage Page (Generic Desktop) 05 01
Report ID (1) 85 01
Usage Page (Generic Desktop) 05 01
Usage (X) 09 30
Report Size (16) 75 10
Report Count (1) 95 01
Logical Minimum (0) 15 00
Logical Maximum (4095) 26 FF 0F
Physical Maximum (4095) 46 FF 0F
Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02
Usage Page (Generic Desktop) 05 01
Usage (Y) 09 31
Report Size (16) 75 10
Report Count (1) 95 01
Logical Minimum (0) 15 00
Logical Maximum (4095) 26 FF 0F
Physical Maximum (4095) 46 FF 0F
Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02
Usage Page (Generic Desktop) 05 01
Usage (Rx) 09 33
Report Size (16) 75 10
Report Count (1) 95 01
Logical Minimum (0) 15 00
Logical Maximum (2047) 26 FF 07
Physical Maximum (2047) 46 FF 07
Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02
Usage Page (Generic Desktop) 05 01
Usage (Ry) 09 34
Report Size (16) 75 10
Report Count (1) 95 01
Logical Minimum (0) 15 00
Logical Maximum (2047) 26 FF 07
Physical Maximum (2047) 46 FF 07
Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02
Usage Page (Generic Desktop) 05 01
Usage (Rz) 09 35
Report Size (16) 75 10
Report Count (1) 95 01
Logical Minimum (0) 15 00
Logical Maximum (2047) 26 FF 07
Physical Maximum (2047) 46 FF 07
Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02
Usage Page (Undefined) 05 00
Usage 09 00
Report Size (16) 75 10
Report Count (1) 95 01
Logical Minimum (0) 15 00
Logical Maximum (2047) 26 FF 07
Physical Maximum (2047) 46 FF 07
Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02
Usage Page (Generic Desktop) 05 01
Usage (Z) 09 32
Report Size (16) 75 10
Report Count (1) 95 01
Logical Minimum (0) 15 00
Logical Maximum (2047) 26 FF 07
Physical Maximum (2047) 46 FF 07
Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02
Usage Page (Undefined) 05 00
Usage 09 00
Report Size (16) 75 10
Report Count (1) 95 01
Logical Minimum (0) 15 00
Logical Maximum (2047) 26 FF 07
Physical Maximum (2047) 46 FF 07
Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02
Usage Page (Button) 05 09
Usage Minimum (Button 1) 19 01
Usage Maximum (Button 128) 2A 80 00
Logical Minimum (0) 15 00
Logical Maximum (1) 25 01
Report Size (1) 75 01
Report Count (128) 96 80 00
Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02
Usage Page (Generic Desktop) 05 01
Usage (Hat Switch) 09 39
Logical Minimum (0) 15 00
Logical Maximum (7) 26 07 00
Physical Minimum (0) 35 00
Physical Maximum (360) 46 68 01
Unit (Eng Rot: Degree) 65 14
Unit Exponent (1) 55 01
Report Size (4) 75 04
Report Count (1) 95 01
Input (Data,Var,Abs,NWrp,Lin,Pref,Null,Bit) 81 42
Usage (Undefined) 09 00
Unit (None) 65 00
Unit Exponent (0) 55 00
Report Size (4) 75 04
Report Count (3) 95 03
Input (Cnst,Ary,Abs) 81 01
Usage Page (Generic Desktop) 05 01
Usage (Undefined) 09 00
Report Size (16) 75 10
Report Count (1) 95 01
Input (Cnst,Ary,Abs) 81 01
Usage Page (Generic Desktop) 05 01
Usage (Undefined) 09 00
Report Size (16) 75 10
Report Count (1) 95 01
Input (Cnst,Ary,Abs) 81 01
Usage Page (Generic Desktop) 05 01
Usage (Undefined) 09 00
Report Size (16) 75 10
Report Count (1) 95 01
Input (Cnst,Ary,Abs) 81 01
Usage Page (Generic Desktop) 05 01
Usage (Undefined) 09 00
Report Size (8) 75 08
Report Count (23) 95 17
Input (Cnst,Ary,Abs) 81 01
Report ID (11) 85 0B
Usage Page (Generic Desktop) 05 01
Usage (Undefined) 09 00
Report Size (8) 75 08
Report Count (63) 95 3F
Input (Cnst,Ary,Abs) 81 01
Report ID (8) 85 08
Usage Page (Generic Desktop) 05 01
Usage (Undefined) 09 00
Report Size (8) 75 08
Report Count (63) 95 3F
Input (Cnst,Ary,Abs) 81 01
Logical Minimum (0) 15 00
Logical Maximum (255) 26 FF 00
Physical Maximum (255) 46 FF 00
Report ID (88) 85 58
Report Size (8) 75 08
Report Count (63) 95 3F
Usage (Undefined) 09 00
Output (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) 91 02
Report ID (89) 85 59
Report Size (8) 75 08
Report Count (128) 95 80
Usage (Undefined) 09 00
Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
End Collection C0
总的来说,问题更容易解决,不需要大量动作,实际上错误是我没有正确描述操纵杆的初始化,更准确地说,我一开始根本没有写并尝试使用现有的,来自鼠标。但是,由于报表维度的不同,发生的一切都发生了,设置所需维度的缓冲区挽救了局面。
这篇文章帮助我做出了决定。