Hardware Reference
In-Depth Information
The USB API is fairly large, complex and beyond the scope of this text. But the
curious developer can read more about the libusb API at the website:
http://libusb.sourceforge.net/doc/index.html
In this chapter, you'll examine just the beginnings of a libusb program, so that you
can get a flavor of how the API works.
Include Files
The main include file for Raspbian libusb support is as follows:
#include <usb.h>
The next few pages show a simple USB program, which enumerates USB buses
and devices. Once a device is located, an attempt is made to “claim” it and then release
it (it will print CLAIMED if successful). However, when all of your USB devices are fully
supported by drivers, none will be claimed. This list can be checked against the lsusb
command output.
The next example program was run on a Raspberry Pi with the following USB devices
reported by lsusb :
$ lsusb
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 05ac:1002 Apple, Inc. Extended Keyboard Hub [Mitsumi]
Bus 001 Device 005: ID 0451:2077 Texas Instruments, Inc. TUSB2077 Hub
Bus 001 Device 006: ID 05ac:0204 Apple, Inc.
Bus 001 Device 007: ID 045e:0040 Microsoft Corp. Wheel Mouse Optical
The example program was compiled by the provided make file in the libusb
subdirectory and invoked as follows:
$ ./tusb
Device: 007 045e:0040 class 0.0 protocol 0 device 768, manuf 1, serial 0
0.0.0 class 3
Device: 006 05ac:0204 class 0.0 protocol 0 device 290, manuf 1, serial 0
0.0.0 class 3
0.1.0 class 3
Device: 005 0451:2077 class 9.0 protocol 0 device 256, manuf 0, serial 0
0.0.0 class 9
Device: 004 05ac:1002 class 9.0 protocol 0 device 290, manuf 1, serial 0
0.0.0 class 9
Device: 003 0424:ec00 class 255.0 protocol 1 device 512, manuf 0, serial 0
0.0.0 class 255
 
Search WWH ::




Custom Search