Subversion Repositories pentevo

Rev

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