2005 07-hidusb


Published on

Published in: Self Improvement, Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

2005 07-hidusb

  1. 1. Linux HID/USB or How I got the !@#%! LED to BlinkBy:Warren Jasper wjasper@tx.ncsu.eduMike Erickson mikee@signalscape.comJuly 14, 2005 1
  2. 2. Overview What is HID? A quick tutorial on Interfaces, Endpoints, Reports, and Usages. The PMD 1208-LS. An example of a low cost USB data acquisition device. hiddev: the Linux HID driver libusb/libhid: An alternative Demos: 2
  3. 3. HID – Human Interface Device Originally intended for mice, keyboards, joysticks and similar devices used by humans to control the operation of computers. Control and Interrupt pipes only n No bulk n No isochronous Proliferated possibly because Windows has ® comprehensive user space support. Many devices now “shoehorned” into HID protocol to avoid writing Windows kernel drivers. 3
  4. 4. HID – Self Describing Host can infer from USB descriptors how to talk to device, especially canonical HID devices. Descriptors can be very complex. n Device n Interface n Endpoint n HID n Physical n Report n Field n Usage “Shoehorned” devices can be lip-numbingly complex Evidence is clear… 4
  5. 5. Evidence is clear… It’s a plot by Microsoft ® 5
  6. 6. Interfacing HID under Linux There are three choices that one can use to interface to a HID device:1. Write a Linux Device Driver2. Use usbhid (/dev/hiddev*)3. Use libusb/libhid 6
  7. 7. Pros: hiddev Comes by default on most Linux distributions. Fairly easy to use (if one knows how) It works from user space without being root. (Don’t forget to chmod /dev/usb/hiddev*) or set permissions in udev 7
  8. 8. Cons: hiddev hiddev is broken under Linux 2.4 hiddev enforces the usage max/min limits, which cause problems in the LS series. hiddev is quite slow. Could not reliable get more than 200-500 Hz through the driver. n Usages are sent a byte at a time!! Lots of delays have to be put into the code for reliable data transfer. Documentation and examples are almost non- existent. Difficult to disassociate the HID driver from the interface. 8
  9. 9. Pros: libusb/libhid Works under 2.4 and 2.6 kernel. Does not enforce usage max/min. Data transfer done through libusb calls, thus much faster then hiddev. n For LS series 3X n For FS series 50X? Works under Linux/Windows, MacOS 9
  10. 10. Cons: libusb/libhid Need to be root or have program run suid unless one configures hotplug. Interfacing with the device with low level libusb calls requires a deeper understanding of the HID interface on the device side. There is no functionality for sending reports from libhid. There are still some timing issues, but more stable then hiddev. Lots of configuration dependencies. 10
  11. 11. Resources Linux Device Drivers, Alessandro Rubini, Corbet and Kroah-Hartman, O’Reilly & Associates. Third edition. ftp://lx10.tx.ncsu.edu:/pub/Linux/drivers http://www.usb.org/developers/hidpage/ http://libhid.alioth.debian.org/ 11
  12. 12. An ExampleLet’s look at an actual code for the PMD- 1208LS. This menu driven code exercises some of the features of the device. 12
  13. 13. cat /proc/bus/usb/devicesT: Bus=01 Lev=01 Prnt=01 Port=02 Cnt=01 Dev#= 3 Spd=1.5MxCh= 0D: Ver= 1.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1P: Vendor=09db ProdID=007a Rev= 1.00S: Manufacturer=MCCS: Product=PMD-1208LSS: SerialNumber=00013237C:* #Ifs= 1 Cfg#= 1 Atr=a0 MxPwr=100mAI: If#= 0 Alt= 0 #EPs= 2 Cls=03(HID ) Sub=00 Prot=00 Driver=hidE: Ad=81(I) Atr=03(Int.) MxPS= 8 Ivl=10msE: Ad=01(O) Atr=03(Int.) MxPS= 8 Ivl=10ms 13
  14. 14. To disassociate the hid driver1. Remove the hid driver. This is rather drastic, and will cause all other hid devices (mouse, keyboard, etc.) not to work.2. In the kernel source /usr/src/linux-XX/drivers/usb/hid-core. There is a blacklist structure: struct hid_blacklist { __u16 idVendor; __u16 idProduct; unsigned quirks; } hid_blacklist[] = { For example: #define USB_VENDOR_ID_MEASUREMENT_COMPUTING 0x09db #define USB_DEVICE_ID_PMD-1208LS 0x007a Then at the bottom of the hid_blacklist[] { USB_VENDOR_ID_MEASUREMENT_COMPUTING, USB_DEVICE_ID_PMD-1024LS, HID_QUIRK_IGNORE }, { 0, 0 } . 14
  15. 15. To disassociate the hid driver3. The third option is the easiest and most flexible. Along with the libhid package there is a program called libhid-detach-device. Example: libhid-detach-device 09db:007a 15
  16. 16. Questions … 16