Discussion:
[libhid-discuss] problems reading data
Tim Nicholson
2010-01-08 11:16:19 UTC
Permalink
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/libhid-discuss/attachments/20100108/7c9416ce/attachment.htm>
Charles Lepple
2010-01-08 12:10:31 UTC
Permalink
I am trying to write an interface in C so I can communicate with a
PIC chip via USB using libhid, but I do not understand how to use
the path information I am seeing to send and receive massages.
Your device's HID report descriptor does not specify any report IDs,
so the paths don't matter.

However, there is a chance that the device is only expecting you to
read and write to the interrupt endpoints (not the control endpoint).
Is the source code for this device available online?
Tim Nicholson
2010-01-08 12:29:22 UTC
Permalink
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/libhid-discuss/attachments/20100108/e305090c/attachment.htm>
Charles Lepple
2010-01-08 13:14:17 UTC
Permalink
Post by Charles Lepple
I am trying to write an interface in C so I can communicate with a
PIC chip via USB using libhid, but I do not understand how to use
the path information I am seeing to send and receive massages.
Your device's HID report descriptor does not specify any report
IDs, so the paths don't matter.
However, there is a chance that the device is only expecting you to
read and write to the interrupt endpoints (not the control
endpoint). Is the source code for this device available online?
Charles,
Thanks so much for replying so quickly.
The code is part of the Microchip USB framework which can be
downloaded from the microchip website. It is the generic HID example
code for the low pin count development board which uses the
PIC18F14K50.
Is there anything I can post that will help? I could email you the
source I used to compile the .hex if you wouldn't mind taking a look?
I could take a look after work. For the benefit of others searching
the list in the future, can you post a direct link to the page on
Microchip's site?

If you have made any significant changes to the source code, that
would be useful to know - but if you are just reading and writing the
64-byte buffers being sent in and out, then the exact data probably
doesn't matter. That also means that libhid is probably overkill for
what you are doing. There are a few key libusb functions which you
might be interested in, and you can save yourself some trouble by just
incorporating that into your code.

libhid is really for devices like uninterruptible power supplies,
which provide a "tree" of values (hence the "path" for specifying a
value of interest). In the case of an UPS, you would want to poll a
few key values to determine whether to shut down the system, and the
rest are just statistics which are harvested less frequently.

Also, if your target application is more like a specialized mouse or
keyboard, you can adjust the HID descriptor to mimic a standard input
device. Microchip used to provide virtual mouse firmware which
basically moved the mouse cursor around when you plugged the device
in. This use case also doesn't require libhid, since the OS input
subsystem would handle the events the same way it would read from your
primary mouse and keyboard.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/libhid-discuss/attachments/20100108/0367dd6d/attachment.htm>
Tim Nicholson
2010-01-08 13:55:26 UTC
Permalink
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/libhid-discuss/attachments/20100108/548b3e3a/attachment.htm>
Charles Lepple
2010-01-09 13:25:42 UTC
Permalink
The Microchip URL where the download can be found is http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2651&param=en534494
. (The framework comes in the form of a zip file which,
unfortunately, is pretty large even by modern standards).
Is this the .zip file with a .exe in it? Or the legacy
"LPCUSBDK_Labs_V3.zip" file?
I have not made any changes to the demo source code as yet, as I was
just trying to interface with the standard demo software as a first
step.
If it's files from the .exe, and the source code license isn't too
restrictive, can you post just the key files somewhere? (I don't have
any Windows machines running here.)
My final application will not be much more complex as all I need
to do is detect some key presses and read the ADC on the PIC. The
ability to read and write single 64-byte buffers is all I am looking
for. I will have a look at libusb, to see if I can make any sense
of that.
By the way, when I mention "libusb", I am referring to the legacy
version, libusb-0.1.12. There is a new version out (1.0), but your
embedded Linux host might not have packages for it.

You might want to compare the libhid source code and API documentation
to that of libusb:

libhid: hid_opening.c File Reference

http://libusb.sourceforge.net/doc/

In the case of finding and opening a USB device, libhid is not doing
much besides wrapping the libusb calls.
My biggest problem is I am very new to USB and I am finding all the
terminology difficult to get my head around. All of the Microchip
texts and examples are designed for Windows developers which is fine
except my final application will be running on embedded Linux and I
have not really had anything to do with Windows software development
since the mid 90's. I have tried looking at the USB specifications
but trying to tie it altogether is not proving very easy - I am
suffering from information overload!
Any pointers would be much appreciated. I just need to understand
what functions I need to call to establish a connection and transfer
data to and fro.
That's the thing - the answer to that question depends heavily on the
firmware on the device.

For HID-class devices, there are two main paths: control transfers,
which allow you to pick which report you want (moot in your case,
since you only want either the input report or the output report, and
the direction of transfer is encoded into the request), and interrupt
transfers, which simply get the next available input* report from the
device, or send a an output report to the device.

Again, since your report descriptor only has one report in each
direction, and no Report ID fields, this simplifies things somewhat.

In an ideal world, the firmware would treat the control transfers and
input transfers similarly, reading and writing the same buffers. When
I was working with the PIC16C765, I don't think that was the case.

[*] Directions are all relative to the host computer: PIC-to-PC is
input, and PC-to-PIC is output.

Also, you might search here to see if there is already some example
code that could talk to the default firmware:

http://mcuee.blogspot.com/search/label/USB
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/libhid-discuss/attachments/20100109/9d27bb3a/attachment.htm>
Tim Nicholson
2010-01-10 15:04:17 UTC
Permalink
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/libhid-discuss/attachments/20100110/0295a745/attachment.htm>
Charles Lepple
2010-01-10 16:41:39 UTC
Permalink
Thanks for all your help, I am pretty much there now and I am
beginning to understand how USB hangs together much better. It
always amazes me how something that seems so complicated can become
so much easier with just a pointer in the right direction - Thanks.
Glad to hear it. It's unfortunate that we're stuck with all of the HID
layers of abstraction just to make it easier to talk to USB devices on
older versions of Windows (without a custom driver).

I probably should have mentioned this earlier, but Jan Axelson's "USB
Complete" is a great desk reference, covering everything from high-
level USB APIs down to the electrical signalling. And the USB and HID
Class specifications are not nearly as inaccessible as you might
imagine (the PDFs are easy to search).

John Parsons
2010-01-09 06:23:16 UTC
Permalink
I am trying to write an interface in C so I can communicate with a
PIC chip via USB using libhid, but I do not understand how to use
the path information I am seeing to send and receive massages.
Hello Tim,
I too am working on my first USB project, and using Microchip's low pin
count development kit. I've been able to get my initial rev working
with Microchip's windows application, but would like to transfer
development to Linux. libhid may be a solution if I can figure out how
to make it work.

Please keep us informed of your progress.

Thanks,
John Parsons
jfparsons at fastmail.fm
--
--
http://www.fastmail.fm - Faster than the air-speed velocity of an
unladen european swallow
Loading...