Subversion Repositories pentevo

Rev

Rev 520 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed | ?url?

  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. /** Reset PS2 keyboard log. */
  63. void ps2keyboard_reset_log(void);
  64.  
  65. /**
  66.  * Get data from PS2 keyboard log.
  67.  * @return data byte (0 - log empty, 0xFF - log overload).
  68.  */
  69. UBYTE ps2keyboard_from_log(void);
  70.  
  71. /**
  72.  * Send command to PS/2 keboard.
  73.  * @param cmd [in] - command.
  74.  */
  75. void ps2keyboard_send_cmd(UBYTE cmd);
  76.  
  77. /** PS/2 keyboard task. */
  78. void ps2keyboard_task(void);
  79.  
  80. /**
  81.  * Parsing PS/2 keboard recived bytes .
  82.  * @param recbyte [in] - received byte.
  83.  */
  84. void ps2keyboard_parse(UBYTE recbyte);
  85.  
  86. /** Timeout for waiting response from mouse. */
  87. #define PS2MOUSE_TIMEOUT 20
  88. /** Received/sended PS/2 mouse data register. */
  89. extern volatile UWORD ps2mouse_shifter;
  90. /** Counter of current PS/2 mouse data bit. */
  91. extern volatile UBYTE ps2mouse_count;
  92. /** Timeout register for detecting PS/2 mouse timeouts. */
  93. extern volatile UBYTE ps2mouse_timeout;
  94. /** Index of PS/2 mouse initialization step (@see ps2mouse_init_sequence). */
  95. extern volatile UBYTE ps2mouse_initstep;
  96. /** Counter of PS/2 mouse response bytes. */
  97. extern volatile UBYTE ps2mouse_resp_count;
  98. /** Current PS/2 keyboard command (0 - none). */
  99. extern volatile UBYTE ps2mouse_cmd;
  100.  
  101. /** Command to reset PS2 mouse. */
  102. #define PS2MOUSE_CMD_RESET          0xFF
  103. /** Command get type of PS2 mouse. */
  104. #define PS2MOUSE_CMD_GET_TYPE       0xF2
  105. /** Command to set resolution PS2 mouse. */
  106. #define PS2MOUSE_CMD_SET_RESOLUTION 0xE8
  107.  
  108. /** PS/2 mouse task. */
  109. void ps2mouse_task(void);
  110.  
  111. /**
  112.  * Set PS/2 mouse resolution.
  113.  * If left and right mouse buttons and some keyboard button pressed then resolution set.
  114.  * @param code [in] - control codes:
  115.  *        <B>0x7C</B> (keypad '*') - set default resolution;
  116.  *        <B>0x79</B> (keypad '+') - inc resolution;
  117.  *        <B>0x7B</B> (keypad '-') - dec resolution.
  118.  */
  119. void ps2mouse_set_resolution(UBYTE code);
  120.  
  121. #endif //PS2_H
  122.  
  123.