Subversion Repositories pentevo

Rev

Rev 299 | Rev 656 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #ifndef PS2_H
  2. #define PS2_H
  3.  
  4. /**
  5.  * @file
  6.  * @brief PS/2 mouse and keyboard support.
  7.  * @author http://www.nedopc.com
  8.  *
  9.  * PS/2 keyboard support (read only).
  10.  *
  11.  * PS/2 mouse support (read/write).
  12.  * ZX Kempston mouse interface emulation.
  13.  *
  14.  * Support PS/2 mouses:
  15.  * - "microsoft" mouses with wheel (4bytes data);
  16.  * - classic mouses (3bytes data).
  17.  */
  18.  
  19. /**
  20.  * Decode received data.
  21.  * @return decoded data.
  22.  * @param count - counter.
  23.  * @param shifter - received bits.
  24.  */
  25. UBYTE ps2_decode(UBYTE count, UWORD shifter);
  26.  
  27. /**
  28.  * Encode (prepare) sended data.
  29.  * @return encoded data.
  30.  * @param data - data to send.
  31.  */
  32. UWORD ps2_encode(UBYTE data);
  33.  
  34. /** Timeout value for PS/2 keyboard. */
  35. #define PS2KEYBOARD_TIMEOUT 20
  36.  
  37. /** Command to reset PS2 keyboard. */
  38. #define PS2KEYBOARD_CMD_RESET 0xFF
  39. /** Command to enable PS2 keyboard. */
  40. #define PS2KEYBOARD_CMD_ENABLE 0xF4
  41. /** Command to set leds on PS2 keyboard. */
  42. #define PS2KEYBOARD_CMD_SETLED 0xED
  43.  
  44. /** "Caps Lock" led bit in set leds command on PS2 keyboard. */
  45. #define PS2KEYBOARD_LED_CAPSLOCK 0x04
  46. /** "Num Lock" led bit in set leds command on PS2 keyboard. */
  47. #define PS2KEYBOARD_LED_NUMLOCK 0x02
  48. /** "Scroll Lock" led bit in set leds command on PS2 keyboard. */
  49. #define PS2KEYBOARD_LED_SCROLLOCK 0x01
  50.  
  51. /** Received PS/2 keyboard data register. */
  52. extern volatile UWORD ps2keyboard_shifter;
  53. /** Counter of current PS/2 keyboard data bit. */
  54. extern volatile UBYTE ps2keyboard_count;
  55. /** Timeout register for detecting PS/2 keyboard timeouts. */
  56. extern volatile UBYTE ps2keyboard_timeout;
  57. /** Counter of stages PS/2 keyboard command. */
  58. extern volatile UBYTE ps2keyboard_cmd_count;
  59. /** Current PS/2 keyboard command (0 - none). */
  60. extern volatile UBYTE ps2keyboard_cmd;
  61.  
  62. /** PS2 keyboards log. */
  63. extern volatile UBYTE  ps2keyboard_log[15];
  64. /** PS2 keyboards log length (0xFF - overload). */
  65. extern volatile UBYTE  ps2keyboard_log_len;
  66.  
  67. /** Reset PS2 keyboard log. */
  68. void ps2keyboard_reset_log(void);
  69.  
  70. /**
  71.  * Get data from PS2 keyboard log.
  72.  * @return data byte (0 - log empty, 0xFF - log overload).
  73.  */
  74. UBYTE ps2keyboard_from_log(void);
  75.  
  76. /**
  77.  * Send command to PS/2 keboard.
  78.  * @param cmd [in] - command.
  79.  */
  80. void ps2keyboard_send_cmd(UBYTE cmd);
  81.  
  82. /** PS/2 keyboard task. */
  83. void ps2keyboard_task(void);
  84.  
  85. /**
  86.  * Parsing PS/2 keboard recived bytes .
  87.  * @param recbyte [in] - received byte.
  88.  */
  89. void ps2keyboard_parse(UBYTE recbyte);
  90.  
  91. /** Timeout for waiting response from mouse. */
  92. #define PS2MOUSE_TIMEOUT 20
  93. /** Received/sended PS/2 mouse data register. */
  94. extern volatile UWORD ps2mouse_shifter;
  95. /** Counter of current PS/2 mouse data bit. */
  96. extern volatile UBYTE ps2mouse_count;
  97. /** Timeout register for detecting PS/2 mouse timeouts. */
  98. extern volatile UBYTE ps2mouse_timeout;
  99. /** Index of PS/2 mouse initialization step (@see ps2mouse_init_sequence). */
  100. extern volatile UBYTE ps2mouse_initstep;
  101. /** Counter of PS/2 mouse response bytes. */
  102. extern volatile UBYTE ps2mouse_resp_count;
  103. /** Current PS/2 keyboard command (0 - none). */
  104. extern volatile UBYTE ps2mouse_cmd;
  105.  
  106. /** Command to reset PS2 mouse. */
  107. #define PS2MOUSE_CMD_RESET          0xFF
  108. /** Command get type of PS2 mouse. */
  109. #define PS2MOUSE_CMD_GET_TYPE       0xF2
  110. /** Command to set resolution PS2 mouse. */
  111. #define PS2MOUSE_CMD_SET_RESOLUTION 0xE8
  112.  
  113. /** PS/2 mouse task. */
  114. void ps2mouse_task(void);
  115.  
  116. /**
  117.  * Set PS/2 mouse resolution.
  118.  * If left and right mouse buttons and some keyboard button pressed then resolution set.
  119.  * @param code [in] - control codes:
  120.  *        <B>0x7C</B> (keypad '*') - set default resolution;
  121.  *        <B>0x79</B> (keypad '+') - inc resolution;
  122.  *        <B>0x7B</B> (keypad '-') - dec resolution.
  123.  */
  124. void ps2mouse_set_resolution(UBYTE code);
  125.  
  126. #endif //PS2_H
  127.  
  128.