1 (edited by anstmich 2012-03-13 22:34:56)

Topic: [SOLVED] libhid, chumby, and linking with "-lhid"

Hi all,

I am currently working on a project which requires that I access usb devices from the Chumby.  To do so, I am attempting to use libhid.  Compiling libusb-0.1 and libhid has not been an issue, however I am running into problems when I attempt to compile my own applications that use libusb.

Specifically, gcc/ld appear to have trouble finding the libhid headers and the libhid library files.  On my laptop, my code is easily compiled with:

gcc test_hid.c -o test_hid -lusb -lhid

Attempting to run the same command on my CHB results in in an "hid.h not found" error.  I am able to correct this problem by specifying the actual path of the include files:

gcc test_hid.c -o test_hid -I/mnt/storage/local/include -lusb -lhid

This fixes the first error, however a second error arises: -lhid is an unknown linking parameter.  In attempt to rectify this problem, I changed my compilation command to:

gcc test_hid.c -o test_hid -I/mnt/storage/local/include -L/mnt/storage/local/lib -lusb 

This eliminates the linker's complaints about "-lhid" however gcc still complains about not being able to find any of the libhid functions that I use in my code.  At this point I am about out of ideas.

Does anyone have any experience with libhid on the chumby that might be able to shed some light on the problem?

Also, on another note, I initially attempted to use libusb-1.0.  This compiled fine and I was even able to compile my code without a problem.  Unfortunately, I am unable to receive any data from my usb peripherals on my CHB using libusb 1.0 (the same code works fine on my other linux machines).   Any ideas why the CHB has trouble with this newer version of libusb?


Re: [SOLVED] libhid, chumby, and linking with "-lhid"

So I was being very silly.. I am able to compile my code, now, without a problem.  Unfortunately libhid is running into the same problems that I ran into with libusb:  I am able to connect to a device without a problem, however I am unable to receive data from the device.

With debugging output enabled in libhid, I get the following warning when I attempt to read from the device:

TRACE: hid_interrupt_read(): retrieving interrupt report from device 001/005[0] ...
USB error: error submitting URB: Invalid argument
WARNING: hid_interrupt_read(): failed to get interrupt read from device 001/005[0]: error submitting URB: Invalid argument

As far as I can tell, the problem has something to do with the way the kernel configures USB devices.  Has anyone ever encountered this problem on their chumby?  Any help is greatly appreciated.

3 (edited by anstmich 2012-03-13 22:42:04)

Re: [SOLVED] libhid, chumby, and linking with "-lhid"

I appear to have figured out  the problem..  It turns out to have been a problem with my original libusb-1.0 code (the problem that initially pushed me towards the older libusb-0.1/libhid combination).  Using libusb-1.0, after claiming the device interface via libusb_claim_interface() it is required that you set the libusb_set_interface_alt_setting:

In my case:

libusb_claim_interface (dev->device, 0); // dev->device is the libusb_device_handle for the device that I am accessing
libusb_set_interface_alt_setting (dev->device, 0,0); // added line of code

This line was not needed on any other computer that I have used.  It would seem that more "complete" linux distributions take care of certain tasks automatically in the background.

Re: [SOLVED] libhid, chumby, and linking with "-lhid"

Glad to hear you solved this.  Are you running the original kernel supplied with the CHB?

Re: [SOLVED] libhid, chumby, and linking with "-lhid"

Yup, I believe so.