Leaked source code of windows server 2003
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.

364 lines
11 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. analog.h
  5. Abstract: Contains definitions specific to analog joysticks.
  6. Environment:
  7. Kernel mode
  8. @@BEGIN_DDKSPLIT
  9. Author:
  10. MarcAnd 03-Jan-99 Split from hidgame.h and hidjoy.c
  11. Revision History:
  12. @@END_DDKSPLIT
  13. --*/
  14. #ifndef __ANALOG_H__
  15. #define __ANALOG_H__
  16. /*
  17. * If you change any of the scaling or timeout values you have to check
  18. * that overflows are still avoided under reasonable circumstances.
  19. */
  20. /*
  21. * The timeout value should be passed in DEVICE_EXTENSION.oemData.Timeout
  22. * so these limits are a sanity check and default value
  23. * The largest expected value is 8mS, use 10 for safety
  24. */
  25. #define ANALOG_POLL_TIMEOUT_MIN ( 100L )
  26. #define ANALOG_POLL_TIMEOUT_DFT ( 10000L )
  27. #define ANALOG_POLL_TIMEOUT_MAX ( 20000L )
  28. /*
  29. * Slowest CPU frequency considered when calibrating the CPU timer
  30. * against the performance counter.
  31. */
  32. #define HIDGAME_SLOWEST_X86_HZ ( 45000000 )
  33. /*
  34. * Valid axis values are scaled such that a poll of exactly
  35. * ANALOG_POLL_TIMEOUT_MAX mS should return this value
  36. * Any analog value greater than this is a timeout
  37. */
  38. #define AXIS_FULL_SCALE ( ANALOG_POLL_TIMEOUT_MAX )
  39. /*
  40. * Number of bits to shift left to get a scaled value
  41. * This is used so that we can always use an integer multiply of the
  42. * number of counter ticks the poll took to scale the value.
  43. */
  44. #define SCALE_SHIFT 16
  45. /*
  46. * Macro to calculate a scaling factor from a (ULONGLONG)frequency
  47. */
  48. #if AXIS_FULL_SCALE == ANALOG_POLL_TIMEOUT_MAX
  49. #define CALCULATE_SCALE( _Freq_ ) \
  50. (ULONG)( ( (ULONGLONG)( 1000000 ) << SCALE_SHIFT ) \
  51. / _Freq_ )
  52. #else
  53. #define CALCULATE_SCALE( _Freq_ ) \
  54. (ULONG)( ( (ULONGLONG)AXIS_FULL_SCALE \
  55. * ( (ULONGLONG)( 1000000 ) << SCALE_SHIFT ) ) \
  56. / ANALOG_POLL_TIMEOUT_MAX ) \
  57. / _Freq_ )
  58. #endif
  59. #define HGM_NUMBER_DESCRIPTORS ( 1 )
  60. #define MAX_AXES ( 4 )
  61. #define PORT_BUTTONS ( 4 )
  62. #define MAX_BUTTONS ( 10 )
  63. #define INVALID_INDEX ( 0x80 )
  64. /* Specific settings for joystick hardware */
  65. #define JOY_HWS_HASZ ( 0x00000001l ) /* has Z info? */
  66. #define JOY_HWS_HASPOV ( 0x00000002l ) /* point of view hat present */
  67. #define JOY_HWS_POVISBUTTONCOMBOS ( 0x00000004l ) /* pov done through combo of buttons */
  68. #define JOY_HWS_POVISPOLL ( 0x00000008l ) /* pov done through polling */
  69. #define JOY_HWS_ISYOKE ( 0x00000010l ) /* joystick is a flight yoke */
  70. #define JOY_HWS_ISGAMEPAD ( 0x00000020l ) /* joystick is a game pad */
  71. #define JOY_HWS_ISCARCTRL ( 0x00000040l ) /* joystick is a car controller */
  72. #define JOY_HWS_HASR ( 0x00080000l ) /* has R (4th axis) info */
  73. #define JOY_HWS_HASU ( 0x00800000l ) /* has U (5th axis) info */
  74. #define JOY_HWS_HASV ( 0x01000000l ) /* has V (6th axis) info */
  75. /*
  76. * The following flags are for changing which gameport bit should be polled
  77. * for an axis. These are only interpreted by the analog driver and could
  78. * therefore be safely reinterpreted in other ways by other drivers.
  79. */
  80. /* X defaults to J1 X axis */
  81. #define JOY_HWS_XISJ1Y ( 0x00000080l ) /* X is on J1 Y axis */
  82. #define JOY_HWS_XISJ2X ( 0x00000100l ) /* X is on J2 X axis */
  83. #define JOY_HWS_XISJ2Y ( 0x00000200l ) /* X is on J2 Y axis */
  84. /* Y defaults to J1 Y axis */
  85. #define JOY_HWS_YISJ1X ( 0x00000400l ) /* Y is on J1 X axis */
  86. #define JOY_HWS_YISJ2X ( 0x00000800l ) /* Y is on J2 X axis */
  87. #define JOY_HWS_YISJ2Y ( 0x00001000l ) /* Y is on J2 Y axis */
  88. /* Z defaults to J2 Y axis */
  89. #define JOY_HWS_ZISJ1X ( 0x00002000l ) /* Z is on J1 X axis */
  90. #define JOY_HWS_ZISJ1Y ( 0x00004000l ) /* Z is on J1 Y axis */
  91. #define JOY_HWS_ZISJ2X ( 0x00008000l ) /* Z is on J2 X axis */
  92. /* POV defaults to J2 Y axis, if it is not button based */
  93. #define JOY_HWS_POVISJ1X ( 0x00010000l ) /* pov done through J1 X axis */
  94. #define JOY_HWS_POVISJ1Y ( 0x00020000l ) /* pov done through J1 Y axis */
  95. #define JOY_HWS_POVISJ2X ( 0x00040000l ) /* pov done through J2 X axis */
  96. /* R defaults to J2 X axis */
  97. #define JOY_HWS_RISJ1X ( 0x00100000l ) /* R done through J1 X axis */
  98. #define JOY_HWS_RISJ1Y ( 0x00200000l ) /* R done through J1 Y axis */
  99. #define JOY_HWS_RISJ2Y ( 0x00400000l ) /* R done through J2 X axis */
  100. /*
  101. * If POV is button-combo we overload this meaningless axis selection bit
  102. * to indicate a second POV.
  103. */
  104. #define JOY_HWS_HASPOV2 JOY_HWS_POVISJ2X
  105. /*****************************************************************************
  106. *
  107. * @doc EXTERNAL
  108. *
  109. * @struct HIDGAME_INPUT_DATA |
  110. *
  111. * Our HID reports always have 4 axis values (one of which may be a
  112. * polled POV), 2 digital POVs and 10 buttons.
  113. * Depending on the HWS flags and number of buttons some of the
  114. * fields will report constant data.
  115. *
  116. * Note, this structure should be byte aligned so that the
  117. * sizeof(it) is the same as HID will calculate given the report
  118. * descriptor. (In this case it happens to be aligned anyway.)
  119. *
  120. * @field ULONG | Axis[MAX_AXES] |
  121. *
  122. * Axes data values.
  123. *
  124. * @field UCHAR | hatswitch[2] |
  125. *
  126. * digital POVs (derived from button combos)
  127. *
  128. * @field UCHAR | Button[MAX_BUTTONS] |
  129. *
  130. * Button data values.
  131. *
  132. *****************************************************************************/
  133. #include <pshpack1.h>
  134. typedef struct _HIDGAME_INPUT_DATA
  135. {
  136. ULONG Axis[MAX_AXES];
  137. UCHAR hatswitch[2];
  138. UCHAR Button[MAX_BUTTONS];
  139. } HIDGAME_INPUT_DATA, *PHIDGAME_INPUT_DATA;
  140. typedef struct _HIDGAME_INPUT_DATA UNALIGNED *PUHIDGAME_INPUT_DATA;
  141. #include <poppack.h>
  142. /*****************************************************************************
  143. *
  144. * @doc EXTERNAL
  145. *
  146. * @struct OEMDATA |
  147. *
  148. * OEMData is send to gameEnum as a parameter to IOCTL_EXPOSE_HARDWARE.
  149. * Defined as 8 DWORDS. We interpert them here
  150. *
  151. * @field USHORT | VID |
  152. *
  153. * Vendor ID
  154. *
  155. * @field USHORT | PID |
  156. *
  157. * Product ID
  158. *
  159. * @field ULONG | joy_hws_dwFlags |
  160. *
  161. * The dwFlags fields for the device ( Usually read from the registry )
  162. *
  163. * @field ULONG | Timeout |
  164. *
  165. * Global timeout for device polling in micro seconds
  166. *
  167. * @field ULONG | Reserved |
  168. *
  169. * Reserved for future use.
  170. *
  171. *
  172. *****************************************************************************/
  173. typedef struct _OEMDATA
  174. {
  175. USHORT VID;
  176. USHORT PID;
  177. ULONG joy_hws_dwFlags;
  178. ULONG Timeout;
  179. ULONG Reserved;
  180. } OEMDATA, *POEMDATA;
  181. typedef struct _HIDGAME_OEM_DATA
  182. {
  183. union
  184. {
  185. OEMDATA OemData[2];
  186. GAMEENUM_OEM_DATA Game_Oem_Data;
  187. };
  188. } HIDGAME_OEM_DATA, *PHIDGAME_OEM_DATA;
  189. /*****************************************************************************
  190. *
  191. * @doc EXTERNAL
  192. *
  193. * @struct ANALOG_DEVICE |
  194. *
  195. * Analog Device specific data.
  196. *
  197. * @field USHORT | nAxes |
  198. *
  199. * Number of axis this device has.
  200. *
  201. * @field USHORT | nButtons|
  202. *
  203. * Number of buttons this device has.
  204. *
  205. * @field HIDGAME_OEM_DATA | HidGameOemData |
  206. *
  207. * The OEM Data field ( Contains joy_hws_dwFlags, vid & pid )
  208. *
  209. * @field ULONG | ScaledTimeout |
  210. * The number value at which an axis is considered to be not present.
  211. *
  212. * @field ULONG | ScaledThreshold |
  213. *
  214. * The minimum resolution of a polling cycle.
  215. * This is used to detect if we've been
  216. * pre-empted or interrupted during a polling loop.
  217. *
  218. * @field ULONG | LastGoodAxis[MAX_AXES] |
  219. *
  220. * Value of the axes on last good poll.
  221. *
  222. * @field UCHAR | LastGoodButton[PORT_BUTTONS] |
  223. *
  224. * Value of the buttons on last good poll.
  225. *
  226. * @field int | AxisMap[MAX_AXES] |
  227. *
  228. * Index of axes remapping.
  229. *
  230. * @field int | povMap |
  231. *
  232. * Index of axis where POV is mapped.
  233. *
  234. * @field UCHAR | resistiveInputMask |
  235. *
  236. * Resisitive Input mask.
  237. *
  238. * @field UCHAR | bSiblingState |
  239. *
  240. * Indicates the state of an expose sibling\remove self transition
  241. *
  242. * @field BOOLEAN | fSiblingFound |
  243. *
  244. * Set to true if this device has a sibling.
  245. *
  246. *****************************************************************************/
  247. typedef struct _ANALOG_DEVICE
  248. {
  249. /*
  250. * Number of axis
  251. */
  252. USHORT nAxes;
  253. /*
  254. * Number of buttons
  255. */
  256. USHORT nButtons;
  257. /*
  258. * Oem Data Field
  259. */
  260. HIDGAME_OEM_DATA HidGameOemData;
  261. /*
  262. * The value at which an axis in considered not present.
  263. */
  264. ULONG ScaledTimeout;
  265. /*
  266. * The minimum resolution of a polling cycle.
  267. * This is used to detect if we've been pre-empted or interrupted
  268. * during a polling loop.
  269. */
  270. ULONG ScaledThreshold;
  271. /*
  272. * Last known good values. Returned if an axis result is corrupted
  273. */
  274. ULONG LastGoodAxis[4];
  275. UCHAR LastGoodButton[4];
  276. /*
  277. * Indexes used to map the data returned from a poll to the axes values
  278. * declared by the device.
  279. */
  280. int AxisMap[MAX_AXES];
  281. /*
  282. * Index of polled POV axis in the poll results
  283. */
  284. int povMap;
  285. /*
  286. * Cutoff poll value between on and off for axes treated as buttons
  287. */
  288. ULONG button5limit;
  289. ULONG button6limit;
  290. /*
  291. * Resisitive Input mask
  292. */
  293. UCHAR resistiveInputMask;
  294. /*
  295. * Set to true if the device has siblings
  296. */
  297. BOOLEAN fSiblingFound;
  298. } ANALOG_DEVICE, *PANALOG_DEVICE;
  299. #endif /* __ANALOG_H__ */