logo资料库

linux-HID介绍(包含读写实例).pdf

第1页 / 共64页
第2页 / 共64页
第3页 / 共64页
第4页 / 共64页
第5页 / 共64页
第6页 / 共64页
第7页 / 共64页
第8页 / 共64页
资料共64页,剩余部分请下载后查看
Table of Contents
Chapter 1. Introduction
The Universal Serial Bus
Host Controllers
USB Devices and Transfer Characteristics
Hubs
Data Flow Types
Human Interface Devices (HID)
USB Device Drivers
Chapter 2. Configuring Linux HID support
USB subsystem
Input subsystem
Chapter 3. The HID device interface
What is the hiddev interface
How HID devices relate to the hiddev interface
Getting the version of the hiddev interface
Getting information about the HID device
Determining which Applications a device uses
Reading from the HID device interface
Chapter 4. The event interface
How HID relates to the event interface
Getting the version of the evdev interface
Getting information about the HID device identity
Determining the device capabilities and features
Getting user input from the device
Sending information to the device
Modifying key repeat settings
Chapter 5. Other approaches to Linux HID support
The keyboard interface
The mouse interface
The joystick interface
Force Feedback
A new kernel interface
Chapter 6. HIDDEV examples
Chapter 7. EVDEV examples
Chapter 8. Contributors
Chapter 9. Availability and licensing
Obtaining updates and translations
License
Chapter 10. Corrections
USB HID for Linux USB Brad Hards Sigma Bravo Pty Ltd.
USB HID for Linux USB by Brad Hards This document is an early draft of a guide to using USB Human Interface Devices with the GNU/Linux operating system. It describes how Human Interface Device (HID) class devices are handled, and how to program them, primarily focussing on user-space interfaces. This document is matched to Linux kernel revision 2.4.19-pre7. Some of this information may not work in exactly the same way on earlier or kernel revisions. Known differences to the 2.5. series kernels are also included where appropriate.
Table of Contents I. How Linux handles USB HID devices..........................................................................7 1. Introduction ..............................................................................................................7 The Universal Serial Bus....................................................................................7 Host Controllers..................................................................................................7 USB Devices and Transfer Characteristics ......................................................7 USB Device Drivers ............................................................................................9 2. Configuring Linux HID support..........................................................................11 USB subsystem..................................................................................................11 Input subsystem................................................................................................11 3. The HID device interface ......................................................................................13 What is the hiddev interface ...........................................................................13 How HID devices relate to the hiddev interface..........................................13 Getting the version of the hiddev interface ..................................................13 Getting information about the HID device...................................................14 Determining which Applications a device uses...........................................15 Reading from the HID device interface.........................................................16 4. The event interface.................................................................................................17 How HID relates to the event interface.........................................................17 Getting the version of the evdev interface....................................................17 Getting information about the HID device identity....................................18 Determining the device capabilities and features........................................19 Getting user input from the device ................................................................24 Sending information to the device.................................................................25 Modifying key repeat settings ........................................................................25 5. Other approaches to Linux HID support............................................................27 The keyboard interface ....................................................................................27 The mouse interface .........................................................................................27 The joystick interface........................................................................................27 A new kernel interface.....................................................................................27 II. Examples..........................................................................................................................29 6. HIDDEV examples.................................................................................................29 7. EVDEV examples ...................................................................................................35 III. About this Guide..........................................................................................................59 8. Contributors............................................................................................................59 9. Availability and licensing......................................................................................61 Obtaining updates and translations...............................................................61 License................................................................................................................61 10. Corrections ............................................................................................................63 v
vi
Chapter 1. Introduction The Universal Serial Bus In 1994 an alliance of four industrial partners (Compaq, Intel, Microsoft and NEC) started to specify the Universal Serial Bus (USB). The bus was originally designed with these intentions: • Connection of the PC to the telephone • Ease-of-use • Port expansion The specification (version 1.0) was first released in January 1996, with some changes being issued as version 1.1 in September 1998. The latest version of the specification is Version 2.0, which was release in FIXME. The USB is strictly hierarchical and it is controlled by one host. The host uses a master / slave protocol to communicate with attached USB devices. This means that every kind of communication is initiated by the host and devices cannot establish any direct connection to other devices. This seems to be a drawback in comparison to other bus architectures but it is not because the USB was designed as a compromise of costs and performance. The master / slave protocol solves implicitly problems like collision avoidance or distributed bus arbitration. The current implementation of the USB allows 127 devices to be connected at the same time. Host Controllers Most modern motherboard chipsets provide a USB host controller. Older machines which are not equipped with a USB host controller can be upgraded using a PCI cards with a host controller built in. There are a range of different host controller designs, however the three most com- mon of designs are supported under Linux - Open Host Controller Interface (OHCI), Universal Host Controller Interface (UHCI) and Enhanced Host Controller Interface (EHCI). USB Devices and Transfer Characteristics There are a wide range of USB devices intended for a wide range of purposes, and this means that implementation details can vary widely. A device can be self powered, bus powered or both. The USB can provide a power supply up to 500mA for its devices. If there are only bus powered devices on the bus the maximum power dissipation could be exceeded and therefore self powered devices exist. They need to have their own power supply. Devices that support both power types can switch to self powered mode when attaching an external power supply. 7
Chapter 1. Introduction Hubs Even the maximum communication speed can differ for particular USB devices. The USB specification differentiates between low speed and full speed devices. Low speed devices (such as mice, keyboards, joysticks etc.) communicate at 1.5MBit/s and have only limited capabilities. Full speed devices (such as audio and video systems) can use up to 90% of the 12Mbit/s which is about 10Mbit/s including the protocol overhead. High speed devices (introduced in USB 2.0) can theoretically get to around 400Mbps, although a lot of other factors come into play at this speed. Physically there exist one, two or four USB ports at the rear, front or side panel of a computer. These ports can be used to attach normal devices or a hub. A hub is a USB device which extends the number of ports to connect other USB devices. The maximum number of user devices is reduced by the number of hubs on the bus (i.e. if you attach 50 hubs, then at most 77 (=127-50) additional devices can be attached. Hubs are always full speed (for USB 1.1 compliant hubs) or high speed (for USB 2.0 compliant hubs) devices . If the hub is self powered, then any device can be attached to it. However if the hub is bus powered, then only low power (100mA max) devices can be attached to it. A bus powered hub should not be connected to another bus powered hub - you should alternate between bus powered and self powered hubs. Normally the physical ports of the host controller are handled by a virtual root hub. This hub is simulated by the host controllers device driver and helps to unify the bus topology. So every port can be handled in the same way by the USB subsystem’s hub driver. Data Flow Types The communication on the USB is done in two directions and uses four different transfer types. Data directed from the host to a device is called downstream or OUT transfer. The other direction is called upstream or IN transfer. Depending on the de- vice type different transfer variants are used: • Control transfers are used to request and send reliable short data packets. It is used to configure devices and every one is required to support a minimum set of control commands. The standard commands are: GET_STATUS CLEAR_FEATURE SET_FEATURE SET_ADDRESS GET_DESCRIPTOR SET_DESCRIPTOR GET_CONFIGURATION SET_CONFIGURATION GET_INTERFACE SET_INTERFACE SYNCH_FRAME Further control commands can be used to transfer vendor specific data. • Bulk transfers are used to request or send reliable data packets up to the full bus bandwidth. Devices like scanners or scsi adapters use this transfer type. 8
分享到:
收藏