📄 x194.html
字号:
<!DOCTYPE HTML PUBLIC "-//Norman Walsh//DTD DocBook HTML 1.0//EN"><HTML><HEAD><TITLE>USB Human Interface Device (HID) Configuration</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet"><LINKREL="HOME"TITLE="The Linux USB sub-system"HREF="book1.html"><LINKREL="UP"TITLE="How to get USB devices working under Linux"HREF="c122.html"><LINKREL="PREVIOUS"TITLE="USB Device Filesystem"HREF="x173.html"><LINKREL="NEXT"TITLE="USB Scanner Support"HREF="x291.html"></HEAD><BODY><DIVCLASS="NAVHEADER"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">The Linux USB sub-system</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="x173.html">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 2. How to get USB devices working under Linux</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="x291.html">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="AEN194">USB Human Interface Device (HID) Configuration</A></H1><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="AEN196">General HID Configuration</A></H2><P>There are two options for using a USB mouse or a USB keyboard - thestandalone Boot Protocol (HIDBP) way and the full featured HID driverway. The Boot Protocol way is generally inferior, and this documentdescribes the full featured way. The Boot Protocol way may beappropriate for embedded systems and other systems with resourceconstraints and no real need for the full keyboard and mousecapabilities.</P><P>It is important to remember that the HID driver handles those devices(or actually those interfaces on each device) that claim to complywith the <AHREF="http://www.usb.org/developers/data/devclass/hid1_1.pdf"TARGET="_top">Human InterfaceDevice (HID) specification</A>. However the HID specificationdoesn't say anything about what the HID driver should do withinformation received from a HID device, or where the information thatis sent to a device comes from, since this is obviously dependent onwhat the device is supposed to be doing, and what the operating systemis. Linux (at the operating system kernel level) supports fourinterfaces to a HID device - keyboard, mouse, joystick and a genericinterface, known as the event interface. These are implemented by theInput device level.</P></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="AEN201">HID Mouse Configuration</A></H2><P>In the kernel configuration stage, you need to turn on<TTCLASS="USERINPUT"><B>USB Human Interface Device (HID) support</B></TT> in the<TTCLASS="USERINPUT"><B>USB support</B></TT> and<TTCLASS="USERINPUT"><B>Mouse Support</B></TT> in the <TTCLASS="USERINPUT"><B>Input coresupport</B></TT>. You don't need to worry about the screenresolution entries for a normal mouse - these are for mouse-likedevices such as a graphics tablet. Do <ICLASS="EMPHASIS">not</I> turn on<TTCLASS="USERINPUT"><B>USB HIDBP Mouse support</B></TT>. Perform the normalkernel rebuild and installation steps. If you are installing asmodules, you need to load the <TTCLASS="FILENAME">input.o</TT>,<TTCLASS="FILENAME">hid.o</TT> and <TTCLASS="FILENAME">mousedev.o</TT> modules.</P><P>Plug in a USB mouse and check that your mouse has been correctly sensedby the kernel. If you don't have a kernel message, look for thechanges to <TTCLASS="FILENAME">/proc/bus/usb/devices</TT>.</P><P>Since USB supports multiple identical devices, you can have multiplemice plugged in. You can get each mouse seperately, or you can getthem all mixed together. You almost always want the mixed version, andthat is what will be used in this example.You need to set up a device node entry for the mixed mice. It iscustomary to create the entries for this device in the<TTCLASS="FILENAME">/dev/input/</TT> directory. Use the following commands:<TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="SCREEN">mkdir /dev/inputmknod /dev/input/mice c 13 63</PRE></TD></TR></TABLE></P><P>If you <TTCLASS="USERINPUT"><B>cat /dev/input/mice</B></TT> you should seesome bizarre looking characters as you move the mouse or click anyof the buttons.</P><P>If you want to use the mouse under X, you have various options. Which oneyou select is dependent on what version of XFree86 you are using andwhether you are using only USB for yourmouse (or mice), or whether you want to use a USB mouse and someother kind of pointer device.</P><P><P></P><UL><LI><P> You need to edit the <TTCLASS="FILENAME">XF86Config</TT> file (usually <TTCLASS="FILENAME">/usr/X11R6/lib/X11/XF86Config</TT> or <TTCLASS="FILENAME">/etc/X11/XF86Config</TT>).</P></LI><LI><P>If you are using XFree86 version 4.0 or later,add a <SPANCLASS="SYSTEMITEM">InputDevice</SPAN> section that lookslike the following:<TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN">Section "InputDevice" Identifier "USB Mice" Driver "mouse" Option "Protocol" "IMPS/2" Option "Device" "/dev/input/mice"EndSection</PRE></TD></TR></TABLE>or, if you want to use a wheel mouse, something like:<TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN">Section "InputDevice" Identifier "USB Mice" Driver "mouse" Option "Protocol" "IMPS/2" Option "Device" "/dev/input/mice" Option "ZAxisMapping" "4 5" Option "Buttons" "5"EndSection</PRE></TD></TR></TABLE>may be more useful. Consult the XFree86 documentation for a detailedexplaination and more examples.</P><P>You also need to add an entry to each applicable<SPANCLASS="SYSTEMITEM">ServerLayout</SPAN> Section. These are normally at theend of the configuration file. If you only have a USB mouse (or USB mice),then replace the line with the <SPANCLASS="SYSTEMITEM">"CorePointer"</SPAN> entrywith the following line:<TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> InputDevice "USB Mice" "CorePointer"</PRE></TD></TR></TABLE>If you want to use both a USB mouse (or USB mice) and some other kind of pointerdevice, then add (do not replace) the following line to the applicable<SPANCLASS="SYSTEMITEM">ServerLayout</SPAN> sections:<TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> InputDevice "USB Mice" "SendCoreEvents"</PRE></TD></TR></TABLE></P></LI><LI><P>If you are using only a USB mouse (or USB mice) with XFree86 3.3,edit the <SPANCLASS="SYSTEMITEM">Pointer</SPAN> section so that itlooks like the following:<TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN">Section "Pointer" Protocol "IMPS/2" Device "/dev/input/mice"EndSection</PRE></TD></TR></TABLE></P></LI><LI><P>If you are trying to use a USB mouse (or USB mice) in additionto another pointer type device with XFree86 3.3,then you need to use the <SPANCLASS="SYSTEMITEM">XInput</SPAN> extensions. Keep the existing <SPANCLASS="SYSTEMITEM">Pointer</SPAN> (or modify it as required for the other device if youare doing an initial installation), and add the following entry (anywhere sensible, ideally in the <SPANCLASS="SYSTEMITEM">Input devices</SPAN> area):<TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN">Section "Xinput" SubSection "Mouse" DeviceName "USB Mice" Protocol "IMPS/2" Port "/dev/input/mice" AlwaysCore EndSubSectionEndSection</PRE></TD></TR></TABLE></P></LI><LI><P>Restart the X server. If you don't have any mouse support atthis point, remember that Ctrl-Alt-F1 will get you a virtual terminalthat you can use to kill the xserver and start debugging from the errormessages.</P></LI></UL></P><P>If you want to use the mouse under gpm, run (or kill and restart if itis already running) gpm with the following options.<TTCLASS="USERINPUT"><B>gpm -m /dev/input/mice -t imps2</B></TT>(as superuser remember). You can make this the default if you edit theinitialisation files. These are typically named something like <TTCLASS="FILENAME">rc.d</TT> and are in <TTCLASS="FILENAME">/etc/rc.d/</TT> onRedHat distributions.</P><P>If you have both a USB mouse (or USB mice) and some other kind of pointerdevice, you may wish to use gpm in repeater mode. If you have a PS/2 mouseon <TTCLASS="FILENAME">/dev/psaux</TT> and a USB mouse (or USB mice) on<TTCLASS="FILENAME">/dev/input/mice</TT>, then the following gpm commandwould probably be appropriate:<TTCLASS="USERINPUT"><B>gpm -m /dev/input/mice -t imps2 -M -m /dev/psaux -t ps2 -R imps2</B></TT>.Note that this will make the output appear on <TTCLASS="FILENAME">/dev/gpmdata</TT>,which is a FIFO and does not need to be created in advance. You can use this asthe mouse "device" to non-X programs, and both mice will work together.</P></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="AEN260">Keyboard Configuration</A></H2><P>You may not need any operating system support at all to use a USB keyboardif you have a PC architecture.There are several BIOS available where the BIOS can provide USB supportfrom a keyboard plugged into the root hub on the motherboard. This may ormay not work through other hubs and does not normally work withadd-in boards, so you might want to add in support anyway. You definately wantto add keyboard support if you add any operating system support, as the LinuxUSB support will disable the BIOS support. You also need to use Linux USBkeyboard support if you want to use any of the "multimedia" types keys thatare provided with some USB keybords.</P><P>In the kernel configuration stage, you need to turn on<TTCLASS="USERINPUT"><B>USB Human Interface Device (HID) support</B></TT> in<TTCLASS="USERINPUT"><B>USB support</B></TT> and <TTCLASS="USERINPUT"><B>Keyboardsupport</B></TT> in <TTCLASS="USERINPUT"><B>Input core support</B></TT>. Do<ICLASS="EMPHASIS">not</I> turn on <TTCLASS="USERINPUT"><B>USB HIDBP Keyboardsupport</B></TT>. Perform the normal kernel rebuild andinstallation steps. If you are installing as modules, you need to loadthe <TTCLASS="FILENAME">hid.o</TT>, <TTCLASS="FILENAME">input.o</TT> and<TTCLASS="FILENAME">keybdev.o</TT> modules.</P><P>Check the kernel logs to ensure that your keyboard is being correctly sensedby the kernel.</P><P>At this point, you should be able to use your USB keyboard asa normal keyboard. Be aware that LILO is not USB aware, and thatunless your BIOS supports a USB keyboard, you may not be able toselect a non-default boot image using the USB keyboard. I havepersonally used only a USB keyboard (and USB mouse) and haveexperienced no problems.</P></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="AEN275">USB Joystick and Gamepad support</A></H2><P>In the kernel configuration stage, you need to turn on<TTCLASS="USERINPUT"><B>USB Human Interface Device (HID) support</B></TT> in<TTCLASS="USERINPUT"><B>USB support</B></TT> and<TTCLASS="USERINPUT"><B>Joystick support</B></TT> in <TTCLASS="USERINPUT"><B>Input coresupport</B></TT>. Perform the normal kernel rebuild and installation steps.If you are installing as modules, you need to loadthe <TTCLASS="FILENAME">hid.o</TT>, <TTCLASS="FILENAME">input.o</TT> and<TTCLASS="FILENAME">joydev.o</TT> modules.</P><P>You need to set up a device node entry for the joystick. It iscustomary to create the entries for USB device in the<TTCLASS="FILENAME">/dev/input/</TT> directory. You can use the followingcommands to create four device nodes, although there is no reason whyyou can not use more:<TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="SCREEN">mknod /dev/input/js0 c 13 0mknod /dev/input/js1 c 13 1mknod /dev/input/js2 c 13 2mknod /dev/input/js3 c 13 3</PRE></TD></TR></TABLE></P><P>If you plug in a gamepad or joystick and<TTCLASS="USERINPUT"><B>cat /dev/input/js0</B></TT> you should seesome bizarre looking characters as you move the stick or click anyof the buttons.</P><P>You should now be able to use the USB joystick or gamepad with anyof the normal games or other joystick compatible applications.</P></DIV></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="x173.html">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="book1.html">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="x291.html">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">USB Device Filesystem</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="c122.html">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">USB Scanner Support</TD></TR></TABLE></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -