Page 1 of 1

Custom HID class device

Posted: Tue Feb 21, 2012 8:55 pm
by xiangrui
I am playing with the wonderful V-USB. With an atmega8 and a breadboard, I successfully made HIDkeys, hid-data and AVR-Doper work. What I like to build is a simple USB device which controls 2 or more TTL output. I also have some experience with AVR, so this should be easy. My difficulty is to figure out a way for driver-free device across major computer systems. According to V-USB wiki, it seems that Custom HID class device is what I need. One of examples of the class is the AVR-Doper. With the included usbasp-mega8-12mhz.hex, my device can be recognized as HID device on Windows and Linux machine. But I can't open it within Matlab by PsychHID from Psychtoolbox. This is the same for HIDkeys and hid-data. I understand that HIDkeys is like a keyboard, so it is occupied by the system, but why does it fail to open for hid-data and AVR-Doper? I don't have any HID device to test PsychHID, but it is available to multi-OS, and is used by many users. The source code for PsychHID is at http://code.google.com/p/psychtoolbox-3/source/browse/trunk/PsychSourceGL/Source/Common/PsychHID/PsychHIDOpenUSBDevice.c

Does anyone have experience with this, or could anyone point me some hint? Thanks.

-Xiangrui

Re: Custom HID class device

Posted: Sat Mar 10, 2012 11:01 pm
by xiangrui
I got help from the Psychtoolbox developer. And I understand I don't have to open the device, but can use HID report to control and query a device. Here is the reply.
"PsychHID on both Linux and Windows uses libusb-1.0 for low-level usb control transfers." For report related stuff, "it uses HIDAPI which itself uses libusb-1.0 on Linux and direct Windows calls on Windows." The V-USB "does the same, except that it uses the outdated libusb-0.1 instead of libusb-1.0 on Linux."

I tried the feature report with hid-data example in V-USB. It works under Linux with PsychHID, but with some unspecified error. Under Windows (XP and 7), PsychHID fails to send data to or receive data from the hid-data device, but apparently PsychHID connects to the device. The error message is "Data error (cyclic redundancy check)". I noted that the V-USB API doesn't check CRC at 12MHz, but I think this is irrelevant to above CRC error since they are at device side and host side respectively.

The hidtools.exe from V-USB works fine for both data write and read.

According to the suggestion from the Psychtoolbox developer, I downloaded the HIDAPI test tool from https://github.com/signal11/hidapi, and ran its testgui under Windows. When I connect to hid device from the testgui, it shows it is connected, but gives error message "hid_read() returned error" continuously. If I try to send or get report, it gives me the CRC error message. I also changed the firmware to different examples, including hid-data, bootloaderHID, and mine (descriptor from ARV-Doper), and the error message is the same.

I noticed that V-USB recommends libusb or libusb-win32. This is different from what PsychHID uses. But does this make difference? What could be the reason for the CRC error?

Thanks.
-Xiangrui

xiangrui wrote:I am playing with the wonderful V-USB. With an atmega8 and a breadboard, I successfully made HIDkeys, hid-data and AVR-Doper work. What I like to build is a simple USB device which controls 2 or more TTL output. I also have some experience with AVR, so this should be easy. My difficulty is to figure out a way for driver-free device across major computer systems. According to V-USB wiki, it seems that Custom HID class device is what I need. One of examples of the class is the AVR-Doper. With the included usbasp-mega8-12mhz.hex, my device can be recognized as HID device on Windows and Linux machine. But I can't open it within Matlab by PsychHID from Psychtoolbox. This is the same for HIDkeys and hid-data. I understand that HIDkeys is like a keyboard, so it is occupied by the system, but why does it fail to open for hid-data and AVR-Doper? I don't have any HID device to test PsychHID, but it is available to multi-OS, and is used by many users. The source code for PsychHID is at http://code.google.com/p/psychtoolbox-3/source/browse/trunk/PsychSourceGL/Source/Common/PsychHID/PsychHIDOpenUSBDevice.c

Does anyone have experience with this, or could anyone point me some hint? Thanks.

-Xiangrui

Re: Custom HID class device

Posted: Mon Mar 19, 2012 11:55 pm
by xiangrui
The CRC error is due to the data size is wrong. With correct data size, the HID feature Get/Set works fine, although the HIDAPI testgui still gives continuous "hid_read() returned error" when it connects to the device.

Re: Custom HID class device

Posted: Sat Apr 21, 2012 8:24 pm
by xiangrui
In the readme file under hid-custom-rq example folder,
"Please note that you should install the filter version of libusb-win32 to take full advantage or [of?] this mode. The device driver version only has access to devices which have been registered for it with a *.inf file. The filter version has access to all devices."

But from libusb website, the filter version seems to be recommended only to developers. This means, for a custom USB device to work under Windows, one has to include a INF file for driver installation.

Here is an update about my progress. Since I need to send/receive only couple of bytes, my current solution is to simply use HID class.