i8042.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*++
  2. Copyright (c) 2012 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. i8042.h
  5. Abstract:
  6. This header contains definitions for the 8042 keyboard controller support.
  7. Author:
  8. Evan Green 21-Dec-2012
  9. --*/
  10. //
  11. // ------------------------------------------------------------------- Includes
  12. //
  13. #include <minoca/usrinput/usrinput.h>
  14. //
  15. // --------------------------------------------------------------------- Macros
  16. //
  17. //
  18. // ---------------------------------------------------------------- Definitions
  19. //
  20. //
  21. // Define commands that can be sent to the 8042 keyboard controller (on the
  22. // Control port).
  23. //
  24. #define I8042_COMMAND_READ_COMMAND_BYTE 0x20
  25. #define I8042_COMMAND_WRITE_COMMAND_BYTE 0x60
  26. #define I8042_COMMAND_DISABLE_MOUSE_PORT 0xA7
  27. #define I8042_COMMAND_ENABLE_MOUSE_PORT 0xA8
  28. #define I8042_COMMAND_TEST_MOUSE_PORT 0xA9
  29. #define I8042_COMMAND_WRITE_TO_MOUSE 0xD4
  30. #define I8042_COMMAND_SELF_TEST 0xAA
  31. #define I8042_COMMAND_INTERFACE_TEST 0xAB
  32. #define I8042_COMMAND_DISABLE_KEYBOARD 0xAD
  33. #define I8042_COMMAND_ENABLE_KEYBOARD 0xAE
  34. #define I8042_COMMAND_READ_INPUT_PORT 0xC0
  35. #define I8042_COMMAND_READ_OUTPUT_PORT 0xD0
  36. #define I8042_COMMAND_WRITE_OUTPUT_PORT 0xD1
  37. #define I8042_COMMAND_READ_TEST_INPUTS 0xE0
  38. #define I8042_COMMAND_RESET 0xFE
  39. //
  40. // Define the amount of time to wait for a command in milliseconds.
  41. //
  42. #define I8042_COMMAND_TIMEOUT 1000
  43. #define I8042_SELF_TEST_SUCCESS 0x55
  44. #define I8042_PORT_TEST_SUCCESS 0x00
  45. #define I8042_PORT_TEST_CLOCK_STUCK_LOW 0x01
  46. #define I8042_PORT_TEST_CLOCK_STUCK_HIGH 0x02
  47. #define I8042_PORT_TEST_DATA_STUCK_LOW 0x03
  48. #define I8042_PORT_TEST_DATA_STUCK_HIGH 0x04
  49. //
  50. // Define commands that can be sent to the keyboard.
  51. //
  52. #define KEYBOARD_COMMAND_SET_LEDS 0xED
  53. #define KEYBOARD_COMMAND_ECHO 0xEE
  54. #define KEYBOARD_COMMAND_GET_SET_SCAN_SET 0xF0
  55. #define KEYBOARD_COMMAND_IDENTIFY 0xF2
  56. #define KEYBOARD_COMMAND_SET_TYPEMATIC 0xF3
  57. #define KEYBOARD_COMMAND_ENABLE 0xF4
  58. #define KEYBOARD_COMMAND_RESET_AND_DISABLE 0xF5
  59. #define KEYBOARD_COMMAND_SET_DEFAULTS 0xF6
  60. #define KEYBOARD_COMMAND_RESEND 0xFE
  61. #define KEYBOARD_COMMAND_RESET 0xFF
  62. //
  63. // Define the parameter value that indicates "no parameter".
  64. //
  65. #define KEYBOARD_COMMAND_NO_PARAMETER 0xFF
  66. //
  67. // Define commands that can be sent to the mouse.
  68. //
  69. #define MOUSE_COMMAND_SET_1_1_SCALING 0xE6
  70. #define MOUSE_COMMAND_SET_2_1_SCALING 0xE7
  71. #define MOUSE_COMMAND_SET_RESOLUTION 0xE8
  72. #define MOUSE_COMMAND_GET_INFORMATION 0xE9
  73. #define MOUSE_COMMAND_READ_ID 0xF2
  74. #define MOUSE_COMMAND_SET_SAMPLE_RATE 0xF3
  75. #define MOUSE_COMMAND_ENABLE 0xF4
  76. #define MOUSE_COMMAND_DISABLE 0xF5
  77. #define MOUSE_COMMAND_SET_DEFAULTS 0xF6
  78. #define MOUSE_COMMAND_RESET 0xFF
  79. //
  80. // Define typematic rate and delay values. Rates are defined with decimal
  81. // places, so 26_7 means 26.7 reports per second.
  82. //
  83. #define TYPEMATIC_DELAY_250MS (0 << 5)
  84. #define TYPEMATIC_DELAY_500MS (1 << 5)
  85. #define TYPEMATIC_DELAY_750MS (2 << 5)
  86. #define TYPEMATIC_DELAY_1000MS (3 << 5)
  87. #define TYPEMATIC_RATE_30_0 0
  88. #define TYPEMATIC_RATE_26_7 1
  89. #define TYPEMATIC_RATE_24_0 2
  90. #define TYPEMATIC_RATE_21_8 3
  91. #define TYPEMATIC_RATE_20_0 4
  92. #define TYPEMATIC_RATE_18_5 5
  93. #define TYPEMATIC_RATE_17_1 6
  94. #define TYPEMATIC_RATE_16_0 7
  95. #define TYPEMATIC_RATE_15_0 8
  96. #define TYPEMATIC_RATE_13_3 9
  97. #define TYPEMATIC_RATE_12_0 10
  98. #define TYPEMATIC_RATE_10_9 11
  99. #define TYPEMATIC_RATE_10_0 12
  100. #define TYPEMATIC_RATE_9_2 13
  101. #define TYPEMATIC_RATE_8_6 14
  102. #define TYPEMATIC_RATE_8_0 15
  103. #define TYPEMATIC_RATE_7_5 16
  104. #define TYPEMATIC_RATE_6_7 17
  105. #define TYPEMATIC_RATE_6_0 18
  106. #define TYPEMATIC_RATE_5_5 19
  107. #define TYPEMATIC_RATE_5_0 20
  108. #define TYPEMATIC_RATE_4_6 21
  109. #define TYPEMATIC_RATE_4_3 22
  110. #define TYPEMATIC_RATE_4_0 23
  111. #define TYPEMATIC_RATE_3_7 24
  112. #define TYPEMATIC_RATE_3_3 25
  113. #define TYPEMATIC_RATE_3_0 26
  114. #define TYPEMATIC_RATE_2_7 27
  115. #define TYPEMATIC_RATE_2_5 28
  116. #define TYPEMATIC_RATE_2_3 29
  117. #define TYPEMATIC_RATE_2_1 30
  118. #define TYPEMATIC_RATE_2_0 31
  119. //
  120. // Define the default typematic rate and delay value.
  121. //
  122. #define DEFAULT_TYPEMATIC_VALUE (TYPEMATIC_DELAY_250MS | TYPEMATIC_RATE_30_0)
  123. //
  124. // Define keyboard return codes.
  125. //
  126. #define KEYBOARD_STATUS_INVALID 0x00
  127. #define KEYBOARD_STATUS_ACKNOWLEDGE 0xFA
  128. #define KEYBOARD_STATUS_RESEND 0xFE
  129. #define KEYBOARD_STATUS_OVERRUN 0xFF
  130. #define KEYBOARD_BAT_PASS 0xAA
  131. //
  132. // Define keyboard LED state bits.
  133. //
  134. #define KEYBOARD_LED_SCROLL_LOCK 0x01
  135. #define KEYBOARD_LED_NUM_LOCK 0x02
  136. #define KEYBOARD_LED_CAPS_LOCK 0x04
  137. //
  138. // Define identify command responses that come from mice.
  139. //
  140. #define PS2_STANDARD_MOUSE 0x00
  141. #define PS2_MOUSE_WITH_SCROLL_WHEEL 0x03
  142. #define PS2_FIVE_BUTTON_MOUSE 0x04
  143. //
  144. // Define the scan code for set 1 that means 2 bytes are required.
  145. //
  146. #define SCAN_CODE_1_EXTENDED_CODE 0xE0
  147. //
  148. // Define the scan code for set 1 that means 3 bytes are required.
  149. //
  150. #define SCAN_CODE_1_EXTENDED_2_CODE 0xE1
  151. //
  152. // ------------------------------------------------------ Data Type Definitions
  153. //
  154. //
  155. // -------------------------------------------------------------------- Globals
  156. //
  157. //
  158. // -------------------------------------------------------- Function Prototypes
  159. //
  160. KEYBOARD_KEY
  161. I8042ConvertScanCodeToKey (
  162. UCHAR ScanCode1,
  163. UCHAR ScanCode2,
  164. UCHAR ScanCode3,
  165. PBOOL KeyUp
  166. );
  167. /*++
  168. Routine Description:
  169. This routine converts a scan code sequence into a key.
  170. Arguments:
  171. ScanCode1 - Supplies the first scan code.
  172. ScanCode2 - Supplies an optional second scan code.
  173. ScanCode3 - Supplies an optional third scan code.
  174. KeyUp - Supplies a pointer where a boolean will be returned indicating
  175. whether the key is being released (TRUE) or pressed (FALSE).
  176. Return Value:
  177. Returns the keyboard key code associated with this scan code sequence.
  178. --*/