Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

479 lines
12 KiB

  1. <HTML>
  2. <HEAD>
  3. <TITLE>Designing HID Gaming Devices for DirectInput</TITLE>
  4. </HEAD>
  5. <BODY BGCOLOR=#FFFFFF TEXT=#000000 LINK=#000000 VLINK=#808080 ALINK=#000000>
  6. <H2>Designing HID Gaming Devices for DirectInput 5.0x and Beyond</H2>
  7. <ADDRESS>
  8. Raymond Chen<br>
  9. Microsoft Corporation<br>
  10. 4 November 1997
  11. </ADDRESS>
  12. <h3>Abstract</h3>
  13. <p>
  14. When designing a game controller compliant with the
  15. Human Interface Devices (HID)
  16. firmware specification,
  17. <!-- version 1.0 -->
  18. care should be taken to ensure that the device
  19. expresses its capabilities in a manner that
  20. applications can exploit.
  21. This document briefly outlines issues that should be taken into
  22. consideration to allow the device to be used by
  23. the widest range of applications
  24. across a variety of operating system platforms.
  25. <h3>Definitions</h3>
  26. <p>
  27. Since input devices can be oriented in several attitudes,
  28. this document will attempt to avoid using terms such as
  29. "up" and "left". Instead, compass directions will be used
  30. ("north", "west", <i>etc</i>.)
  31. For a control mounted on a horizontal surface, "north" is
  32. typically represented by motion away from the user.
  33. For a control mounted on a vertical surface, "north"
  34. is typically represented by motion away from the earth.
  35. In general, devices should choose a
  36. northerly direction that is intuitively obvious to the user.
  37. <h3>Device Usage and Usage Page</h3>
  38. <p>
  39. For DirectInput to recognize a HID game controller
  40. as a joystick or gamepad,
  41. it must declare its top-level collection as belonging to
  42. the Generic Desktop Page (0x01),
  43. and deploy usage Joystick (0x04) or Game Pad (0x05),
  44. respectively.
  45. <p>
  46. Although devices declared otherwise will still
  47. be accessible to DirectInput applications
  48. which request non-joystick-compatible devices, the vast majority
  49. of gaming applications
  50. restrict themselves to joystick-compatible input
  51. devices.
  52. <h3>Logical and Physical Ranges</h3>
  53. <p>
  54. Absolute axes on gaming devices
  55. should express their physical ranges entirely
  56. with non-negative integers.
  57. Historically, calibration information has been expressed
  58. in unspecified time units, indicating how long it takes the
  59. joystick gameport capacitor to charge after a discharge.
  60. Consequently, applications have assumed that calibration values
  61. are never negative.
  62. <p>
  63. Logical ranges, of course, can indeed be negative. It is
  64. recommended that the device translate its logical range
  65. by the minimum value, thereby making all physical values non-negative.
  66. For example, a joystick might report its X-axis with the logical
  67. range -512 to +511. A corresponding physical range of 0 to +1023
  68. would retain full resolution while ensuring that the resulting
  69. physical values are non-negative.
  70. <p>
  71. It is also recommended that the logical range accurately describes
  72. the full range of motion of the control and that the center position
  73. of the control lie at the midpoint between the minimum and maximum values.
  74. When DirectInput first encounters a device, it uses the
  75. logical range information as the basis for the default calibration.
  76. If a device conforms to this recommendation,
  77. the end-user is relieved of the responsibility of calibration,
  78. allowing your device to be truly Plug-and-Play.
  79. <h3>Absolute <i>versus</i> Relative</h3>
  80. <p>
  81. Applications assume that all axes on a game controller return absolute
  82. coordinates rather than relative coordinates.
  83. If a device reports its axes as relative, applications which use
  84. DirectInput will receive integrated values, but applications which
  85. use the old Multimedia functions to access the device will receive
  86. non-integrated deltas and will likely not handle the values properly.
  87. Furthermore, even applications which use DirectInput typically do
  88. not expect to receive unrestricted values (as would result from
  89. integration of a relative control).
  90. <h3>HID and DirectInput</h3>
  91. <p>
  92. Beginning with Windows 98 and Windows NT 5.0,
  93. DirectInput maps
  94. HID usages to its own concept of axis semantics, named
  95. X, Y, Z, Rx, Ry, Rz (rotations), and Slider.
  96. Again, each application is free to apply arbitrary semantics to each
  97. of these axis types.
  98. <p>
  99. The following table describes how DirectInput maps HID
  100. usages to axis types.
  101. <p align=center>
  102. <table border>
  103. <tr>
  104. <th>Usage Page</th>
  105. <th>Usage</th>
  106. <th>DirectInput</th>
  107. </tr>
  108. <tr>
  109. <td>0x01 (Generic)</td>
  110. <td>0x30 (X)</td>
  111. <td align=center>X</td>
  112. </tr>
  113. <tr>
  114. <td>0x01 (Generic)</td>
  115. <td>0x31 (Y)</td>
  116. <td align=center>Y</td>
  117. </tr>
  118. <tr>
  119. <td>0x01 (Generic)</td>
  120. <td>0x32 (Z)</td>
  121. <td align=center>Z</td>
  122. </tr>
  123. <tr>
  124. <td>0x02 (Simulation)</td>
  125. <td>0xBA (Rudder)</td>
  126. <td align=center>Z</td>
  127. </tr>
  128. <tr>
  129. <td>0x01 (Generic)</td>
  130. <td>0x33 (RX)</td>
  131. <td align=center>Rx</td>
  132. </tr>
  133. <tr>
  134. <td>0x01 (Generic)</td>
  135. <td>0x34 (RY)</td>
  136. <td align=center>Ry</td>
  137. </tr>
  138. <tr>
  139. <td>0x01 (Generic)</td>
  140. <td>0x35 (RZ)</td>
  141. <td align=center>Rz</td>
  142. </tr>
  143. <tr>
  144. <td>0x01 (Generic)</td>
  145. <td>0x36 (Slider)</td>
  146. <td align=center>Slider</td>
  147. </tr>
  148. <tr>
  149. <td>0x01 (Generic)</td>
  150. <td>0x37 (Dial)</td>
  151. <td align=center>Slider</td>
  152. </tr>
  153. <tr>
  154. <td>0x01 (Generic)</td>
  155. <td>0x38 (Wheel)</td>
  156. <td align=center>Slider</td>
  157. </tr>
  158. <tr>
  159. <td>0x02 (Simulation)</td>
  160. <td>0xBB (Throttle)</td>
  161. <td align=center>Slider</td>
  162. </tr>
  163. <tr>
  164. <td>0x01 (Generic)</td>
  165. <td>0x39 (Hatswitch)</td>
  166. <td align=center>POV</td>
  167. </tr>
  168. <tr>
  169. <td>0x09 (Button)</td>
  170. <td>any</td>
  171. <td align=center>Buttons</td>
  172. </tr>
  173. <tr>
  174. <td>any</td>
  175. <td>any (see below)</td>
  176. <td align=center>Buttons</td>
  177. </tr>
  178. </table></p>
  179. <p>
  180. DirectInput treats
  181. any usage on any usage page with bit size of unity
  182. as a button. Furthermore, any usage on the Button page
  183. is treated as a button, even if its bit size is greater than unity.
  184. Under such conditions, DirectInput treats the button as a "button
  185. with intermediate positions". Such a button can report to the application
  186. states such as "half-pressed".
  187. <p>
  188. DirectInput does not limit the number of usages that can map to each
  189. type of axis. Applications designed for DirectInput
  190. typically request up to 128 buttons, four POV's, two sliders, and one
  191. each of X, Y, Z, Rx, Ry, and Rz.
  192. <p>
  193. X and Y axes must report their values as increasing east and south,
  194. respectively. This requirement is in agreement with the HID specification.
  195. <p>
  196. Hat Switch controls must report a Null value when not pressed.
  197. When pressed, the logical minimum value represents north, and increasing
  198. logical values represent directions equally spaced clockwise around the
  199. compass. For example, the following two tables describe two different
  200. types of Hat Switches, one with eight positions and one with four positions.
  201. <p align=center>
  202. <table border>
  203. <tr>
  204. <th>Value</th>
  205. <th>8-direction</th>
  206. <th>4-direction</th>
  207. </tr>
  208. <tr>
  209. <td>Logical Minimum</td>
  210. <td align=right>0</td>
  211. <td align=right>0</td>
  212. </tr>
  213. <tr>
  214. <td>Logical Maximum</td>
  215. <td align=right>7</td>
  216. <td align=right>3</td>
  217. </tr>
  218. <tr>
  219. <td>Null value</td>
  220. <td align=right>-1</td>
  221. <td align=right>-1</td>
  222. </tr>
  223. <tr>
  224. <td>North</td>
  225. <td align=right>0</td>
  226. <td align=right>0</td>
  227. </tr>
  228. <tr>
  229. <td>Northeast</td>
  230. <td align=right>1</td>
  231. <td align=right>N/A</td>
  232. </tr>
  233. <tr>
  234. <td>East</td>
  235. <td align=right>2</td>
  236. <td align=right>1</td>
  237. </tr>
  238. <tr>
  239. <td>Southeast</td>
  240. <td align=right>3</td>
  241. <td align=right>N/A</td>
  242. </tr>
  243. <tr>
  244. <td>South</td>
  245. <td align=right>4</td>
  246. <td align=right>2</td>
  247. </tr>
  248. <tr>
  249. <td>Southwest</td>
  250. <td align=right>5</td>
  251. <td align=right>N/A</td>
  252. </tr>
  253. <tr>
  254. <td>West</td>
  255. <td align=right>6</td>
  256. <td align=right>3</td>
  257. </tr>
  258. <tr>
  259. <td>Northwest</td>
  260. <td align=right>7</td>
  261. <td align=right>N/A</td>
  262. </tr>
  263. </table></p>
  264. <p>
  265. Devices are strongly recommended not to report logical ranges with
  266. higher resolution than physically supported by the device.
  267. For example, a device whose Hat Switch supports four compass directions
  268. could in principle report itself as if it were an 8-direction Hat Switch.
  269. However, devices which do so will mislead applications into believing
  270. that the control supports a higher degree of resolution than it
  271. actually does.
  272. (DirectInput provides a method for applications to query the resolution
  273. of a hat switch, and DirectInput relies on the accuracy of the values
  274. in the report descriptor to report the resolution accurately.)
  275. <p>
  276. DirectInput requires that the Hat Switch reside in its own capability
  277. descriptor. Do not combine the Hat Switch capability with capabilities
  278. for adjacent usages (Wheel and Counted Buffer).
  279. <p>
  280. Although usages not listed in the above table will still be
  281. accessible via DirectInput,
  282. few game applications will take advantage of their existence.
  283. <h3>HID and Legacy Game Controller API's in Windows 98</h3>
  284. <p>
  285. In Windows 98, the HID-to-legacy mapper (JoyHID.VxD)
  286. maps
  287. HID usages to the "classical" joystick axes, named X, Y, Z, R, U, and V.
  288. Each application is free to apply arbitrary semantics to each of these
  289. axes, although the X and Y axes are customarily used for two-dimensional
  290. motion control, and the R control is customarily as a rudder. The Z control
  291. is often used as a throttle.
  292. <p>
  293. (The issue of allowing applications to assign semantics to controls
  294. in an intelligent manner is the subject of a separate document.)
  295. <p>
  296. The following table describes how JOYHID maps HID
  297. usages to "classical" joystick axes, buttons, and POV controllers.
  298. <p align=center>
  299. <table border>
  300. <tr>
  301. <th>Usage Page</th>
  302. <th>Usage</th>
  303. <th>JoyHID.VxD</th>
  304. </tr>
  305. <tr>
  306. <td>0x01 (Generic)</td>
  307. <td>0x30 (X)</td>
  308. <td align=center>X</td>
  309. </tr>
  310. <tr>
  311. <td>0x01 (Generic)</td>
  312. <td>0x31 (Y)</td>
  313. <td align=center>Y</td>
  314. </tr>
  315. <tr>
  316. <td>0x01 (Generic)</td>
  317. <td>0x32 (Z)</td>
  318. <td align=center>Z</td>
  319. </tr>
  320. <tr>
  321. <td>0x02 (Simulation)</td>
  322. <td>0xBB (Throttle)</td>
  323. <td align=center>Z or U</td>
  324. </tr>
  325. <tr>
  326. <td>0x02 (Simulation)</td>
  327. <td>0xBA (Rudder)</td>
  328. <td align=center>R</td>
  329. </tr>
  330. <tr>
  331. <td>0x01 (Generic)</td>
  332. <td>0x35 (RZ)</td>
  333. <td align=center>R</td>
  334. </tr>
  335. <tr>
  336. <td>0x01 (Generic)</td>
  337. <td>0x36 (Slider)</td>
  338. <td align=center>U</td>
  339. </tr>
  340. <tr>
  341. <td>0x01 (Generic)</td>
  342. <td>0x37 (Dial)</td>
  343. <td align=center>U</td>
  344. </tr>
  345. <tr>
  346. <td>0x01 (Generic)</td>
  347. <td>0x33 (RX)</td>
  348. <td align=center>V</td>
  349. </tr>
  350. <tr>
  351. <td>0x09 (Button)</td>
  352. <td>any</td>
  353. <td align=center>Buttons</td>
  354. </tr>
  355. <tr>
  356. <td>0x01 (Generic)</td>
  357. <td>0x39 (Hatswitch)</td>
  358. <td align=center>POV</td>
  359. </tr>
  360. </table></p>
  361. <p>
  362. If more than one control can map to an axis or button or POV, then
  363. the first one on the list is used and the others are ignored.
  364. For example, if a joystick has both a slider and a dial, then
  365. the slider will be mapped to classical axis U, and the dial will be
  366. ignored.
  367. <p>
  368. As a special case, a throttle will be mapped to the Z-axis unless
  369. the Z-axis has already been claimed by the Z control, in which case
  370. it will be mapped to the U-axis. (In such case, the throttle will
  371. displace any slider or dial that would otherwise be mapped to the U-axis.)
  372. <p>
  373. For buttons, all usages reported on the Button page (0x09) will be
  374. reported, but they must be consecutively numbered starting from zero.
  375. <p>
  376. The requirements on X-axis, Y-axis, and Hat Switch controls
  377. which apply to DirectInput also apply here.
  378. <p>
  379. Any usages that do not appear in the above table are ignored by JoyHID.VxD.
  380. <h3>References</h3>
  381. <p>
  382. <cite>
  383. <a href=http://www.usb.org/>Universal Serial Bus</a>
  384. HID Usage Tables</cite>, Version 1.0,
  385. USB Implementers Forum.
  386. <p>
  387. <cite>
  388. <a href=http://www.microsoft.com/directx/resources/dx5ddk.htm>
  389. DirectX 5.0 DDK</a>
  390. </cite>, Microsoft Corporation.
  391. <p>
  392. <cite>
  393. <a href=http://www.microsoft.com/directx/resources/dx5sdk.htm>
  394. DirectX 5.0 SDK</a>
  395. </cite>, Microsoft Corporation.
  396. </BODY>
  397. </HTML>