signal11 / hidapi

A Simple library for communicating with USB and Bluetooth HID devices on Linux, Mac, and Windows.
http://www.signal11.us/oss/hidapi/
Other
2.45k stars 898 forks source link

Problem with STM32 HID #166

Closed modjo756 closed 10 years ago

modjo756 commented 10 years ago

Hi, i'm a newbie on stm32 and usb but i want to communicate with my stm32f3 discovery and my pc (with Qt). For this card (f3 discovery) i have an exemple with usb hid. Windows detect my card and i can moove the cursor with it. I downloaded hidapi and test "testgui.exe" it works for my keyboard and mouse but don't detect my stm32 ! I don't know why because windows recognise it and install hid driver. Do you have a solution to resolve it ? I also tested hidtest.cpp with Qt and it's the same problem (detect my mouse ... but not the stm32)

signal11 commented 10 years ago

Qt has nothing to do with HIDAPI.

Keyboards and mice aren't directly able to be manipulated with HIDAPI on windows. Try a joystick if you want to see something work.

HIDAPI is designed for communicating with HID devices which are vendor-defined (0xff) and have vendor-defined data in their reports.

modjo756 commented 10 years ago

Thank's for your answer. i just use qt with the dll to test if it's works (i know that qt has noting to do with HIDAPI. HIDAPi detect a 3dconnexion mouse (space pilot) and give data. My stm 32 have a vid and pid. See under the descriptor file of it

include "usb_lib.h"

include "usb_desc.h"

/\ @addtogroup STM32F3_Discovery_Peripheral_Examples

/\ @addtogroup USB_Example

/* Private typedef -----------------------------------------------------------/ / Private define ------------------------------------------------------------/ / Private macro -------------------------------------------------------------/ / Private variables ---------------------------------------------------------/ / Extern variables ----------------------------------------------------------/ / Private function prototypes -----------------------------------------------/ / Private functions ---------------------------------------------------------*/

/* USB Standard Device Descriptor _/ const uint8_t Joystick_DeviceDescriptor[JOYSTICK_SIZ_DEVICE_DESC] = { 0x12, /bLength / USB_DEVICE_DESCRIPTOR_TYPE, /bDescriptorType/ 0x00, /bcdUSB / 0x02, 0x00, /bDeviceClass/ 0x00, /bDeviceSubClass/ 0x00, /bDeviceProtocol/ 0x40, /bMaxPacketSize 64/ 0x83, /idVendor (0x0483)/ 0x04, 0x10, /idProduct = 0x5710/ 0x57, 0x00, /bcdDevice rel. 2.00/ 0x02, 1, /Index of string descriptor describing manufacturer / 2, /Index of string descriptor describing product/ 3, /Index of string descriptor describing the device serial number / 0x01 /bNumConfigurations/ } ; /_ Joystick_DeviceDescriptor */

For information libusb give me the pid and vid for it.

if i launch zadig.exe, it say that about stm32 driver : HidUsb (v6.1.7601.18199)

Why hidapi can't detect his ?

signal11 commented 10 years ago

hid is an interface level class. it takes more than having a vid and pid. plug it into a Linux box and check the log and lsusb for errors. hidapi will give you all the devices that windows will show it.

modjo756 commented 10 years ago

Hi, when i connect my card to ubuntu it works (the mouse cursor mouve) and when i write the commande lsusb -v that's the result under :
Bus 006 Device 002: ID 0483:5710 STMicroelectronics Joystick in FS Mode Couldn't open device, some information will be missing Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 2.00 bDeviceClass 0 (Defined at Interface level) bDeviceSubClass 0 bDeviceProtocol 0 bMaxPacketSize0 64 idVendor 0x0483 STMicroelectronics idProduct 0x5710 Joystick in FS Mode bcdDevice 2.00 iManufacturer 1 iProduct 2 iSerial 3 bNumConfigurations 1 Configuration Descriptor: bLength 9 bDescriptorType 2 wTotalLength 34 bNumInterfaces 1 bConfigurationValue 1 iConfiguration 0 bmAttributes 0xe0 Self Powered Remote Wakeup MaxPower 100mA Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 0 bAlternateSetting 0 bNumEndpoints 1 bInterfaceClass 3 Human Interface Device bInterfaceSubClass 1 Boot Interface Subclass bInterfaceProtocol 2 Mouse iInterface 0 HID Device Descriptor: bLength 9 bDescriptorType 33 bcdHID 1.00 bCountryCode 0 Not supported bNumDescriptors 1 bDescriptorType 34 Report wDescriptorLength 74 Report Descriptors: \ UNAVAILABLE ** Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0004 1x 4 bytes bInterval 32

signal11 commented 10 years ago

"check lsusb" doesn't mean send me the output without looking at it. Did you notice where the interface descriptor claims to be a mouse, and using the boot protocol? Please have a look at the hid specification for information on what to set those values to.

modjo756 commented 10 years ago

Hi, i found this :

define USB_DEVICE_DESCRIPTOR_TYPE 0x01

define USB_CONFIGURATION_DESCRIPTOR_TYPE 0x02

define USB_STRING_DESCRIPTOR_TYPE 0x03

define USB_INTERFACE_DESCRIPTOR_TYPE 0x04

define USB_ENDPOINT_DESCRIPTOR_TYPE 0x05

define HID_DESCRIPTOR_TYPE 0x21

define JOYSTICK_SIZ_HID_DESC 0x09

define JOYSTICK_OFF_HID_DESC 0x12

define JOYSTICK_SIZ_DEVICE_DESC 18

define JOYSTICK_SIZ_CONFIG_DESC 34

define JOYSTICK_SIZ_REPORT_DESC 74

define JOYSTICK_SIZ_STRING_LANGID 4

define JOYSTICK_SIZ_STRING_VENDOR 38

define JOYSTICK_SIZ_STRING_PRODUCT 30

define JOYSTICK_SIZ_STRING_SERIAL 26

define STANDARD_ENDPOINT_DESC_SIZE 0x09

and this :
/* USB Standard Device Descriptor _/ const uint8_t Joystick_DeviceDescriptor[JOYSTICK_SIZ_DEVICE_DESC] = { 0x12, /bLength / USB_DEVICE_DESCRIPTOR_TYPE, /bDescriptorType/ 0x00, /bcdUSB / 0x02, 0x00, /bDeviceClass/ 0x00, /bDeviceSubClass/ 0x00, /bDeviceProtocol/ 0x40, /bMaxPacketSize 64/ 0x83, /idVendor (0x0483)/ 0x04, 0x10, /idProduct = 0x5710/ 0x57, 0x00, /bcdDevice rel. 2.00/ 0x02, 1, /Index of string descriptor describing manufacturer / 2, /Index of string descriptor describing product/ 3, /Index of string descriptor describing the device serial number / 0x01 /bNumConfigurations/ } ; /_ Joystick_DeviceDescriptor */

/* USB Configuration Descriptor / / All Descriptors (Configuration, Interface, Endpoint, Class, Vendor _/ const uint8_t Joystick_ConfigDescriptor[JOYSTICK_SIZ_CONFIGDESC] = { 0x09, / bLength: Configuration Descriptor size _/ USB_CONFIGURATION_DESCRIPTORTYPE, / bDescriptorType: Configuration _/ JOYSTICK_SIZ_CONFIGDESC, / 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 / 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*/
0x01,         /*bNumEndpoints*/
0x03,         /*bInterfaceClass: HID*/
0x01,         /*bInterfaceSubClass : 1=BOOT, 0=no boot*/
0x02,         /*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*/
0x00,         /*bcdHID: HID Class Spec release number*/
0x01,
0x00,         /*bCountryCode: Hardware target country*/
0x01,         /*bNumDescriptors: Number of HID class descriptors to follow*/
0x22,         /*bDescriptorType*/
JOYSTICK_SIZ_REPORT_DESC,/*wItemLength: Total length of Report descriptor*/
0x00,
/******************** Descriptor of Joystick Mouse endpoint ********************/
/* 27 */
0x07,          /*bLength: Endpoint Descriptor size*/
USB_ENDPOINT_DESCRIPTOR_TYPE, /*bDescriptorType:*/

0x81,          /*bEndpointAddress: Endpoint Address (IN)*/
0x03,          /*bmAttributes: Interrupt endpoint*/
0x04,          /*wMaxPacketSize: 4 Byte max */
0x00,
0x20,          /*bInterval: Polling Interval (32 ms)*/
/* 34 */

} ; /* MOUSEConfigDescriptor / const uint8_t Joystick_ReportDescriptor[JOYSTICK_SIZ_REPORT_DESC] = { 0x05, /Usage Page(Generic Desktop)/ 0x01, 0x09, /Usage(Mouse)/ 0x02, 0xA1, /Collection(Logical)/ 0x01, 0x09, /Usage(Pointer)/ 0x01, / 8 / 0xA1, /Collection(Linked)/ 0x00, 0x05, /Usage Page(Buttons)/ 0x09, 0x19, /Usage Minimum(1)/ 0x01, 0x29, /Usage Maximum(3)/ 0x03, / 16 / 0x15, /Logical Minimum(0)/ 0x00, 0x25, /Logical Maximum(1)/ 0x01, 0x95, /Report Count(3)/ 0x03, 0x75, /Report Size(1)/ 0x01, / 24 / 0x81, /Input(Variable)/ 0x02, 0x95, /Report Count(1)/ 0x01, 0x75, /Report Size(5)/ 0x05, 0x81, /Input(Constant,Array)/ 0x01, / 32 / 0x05, /Usage Page(Generic Desktop)/ 0x01, 0x09, /Usage(X axis)/ 0x30, 0x09, /Usage(Y axis)/ 0x31, 0x09, /Usage(Wheel)/ 0x38, / 40 / 0x15, /Logical Minimum(-127)/ 0x81, 0x25, /Logical Maximum(127)/ 0x7F, 0x75, /Report Size(8)/ 0x08, 0x95, /Report Count(3)/ 0x03, / 48 / 0x81, /Input(Variable, Relative)/ 0x06, 0xC0, /End Collection/ 0x09, 0x3c, 0x05, 0xff, 0x09, / 56 / 0x01, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, / 64 / 0x02, 0xb1, 0x22, 0x75, 0x06, 0x95, 0x01, 0xb1, / 72 / 0x01, 0xc0 } ; /_ Joystick_ReportDescriptor */

/* USB String Descriptors (optional) _/ const uint8_t Joystick_StringLangID[JOYSTICK_SIZ_STRING_LANGID] = { JOYSTICK_SIZ_STRING_LANGID, USB_STRING_DESCRIPTORTYPE, 0x09, 0x04 } ; / LangID = 0x0409: U.S. English */

const uint8_t Joystick_StringVendor[JOYSTICK_SIZ_STRING_VENDOR] = { JOYSTICK_SIZ_STRINGVENDOR, /* Size of Vendor string / USB_STRING_DESCRIPTORTYPE, / bDescriptorType/ / Manufacturer: "STMicroelectronics" */ 'S', 0, 'T', 0, 'M', 0, 'i', 0, 'c', 0, 'r', 0, 'o', 0, 'e', 0, 'l', 0, 'e', 0, 'c', 0, 't', 0, 'r', 0, 'o', 0, 'n', 0, 'i', 0, 'c', 0, 's', 0 };

const uint8_t Joystick_StringProduct[JOYSTICK_SIZ_STRING_PRODUCT] = { JOYSTICK_SIZ_STRINGPRODUCT, /* bLength / USB_STRING_DESCRIPTORTYPE, / bDescriptorType _/ 'S', 0, 'T', 0, 'M', 0, '3', 0, '2', 0, ' ', 0, 'J', 0, 'o', 0, 'y', 0, 's', 0, 't', 0, 'i', 0, 'c', 0, 'k', 0 }; uint8_t Joystick_StringSerial[JOYSTICK_SIZ_STRING_SERIAL] = { JOYSTICK_SIZ_STRINGSERIAL, / bLength _/ USB_STRING_DESCRIPTORTYPE, / bDescriptorType */ 'S', 0, 'T', 0, 'M', 0, '3', 0, '2', 0, '1', 0, '0', 0 };

Let me know if you find anything ? :-)

signal11 commented 10 years ago

Yeah, I'll get right on that. I love combing through hundreds of lines unformatted code containing other people's problems.....

On top of that, I already told you what I found before. Your interface descriptor says MOUSE and BOOT. Please have a look at the HID specification for information on what to set those values to.

If you're really looking for someone to dig through your specific problems and do this project for your, I'd be happy to do it for a fee (consulting services) at an agreed upon rate, so long as this isn't a school project.

modjo756 commented 10 years ago

I apologize but i don't know how to comment the code on git hub ! It's not a project for work or school i just want to communicate with my card by usb (and understand how it works). Today i'm looking to find where is the specification of HID on stm. After that i will don't disturb you more longuer.

signal11 commented 10 years ago

I apologize but i don't know how to comment the code on git hub !

Click the text which says "Github Flavored Markdown" at the top of the box you're typing in.

i just want to communicate with my card by usb (and understand how it works).

Then you need to start by learning how USB works. See Jan Axelson's resources and book at www.lvr.com . Also see the specification documents (including HID) at USB.org.

After that i will don't disturb you more longuer.

It's ok if you ask questions, but learn how to ask the right questions the right way: http://www.catb.org/esr/faqs/smart-questions.html

signal11 commented 10 years ago

Since it's been a long time, I'm going to close this. If you have any additional questions on this topic. Please feel free to reopen.