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.

177 lines
6.4 KiB

  1. /*
  2. Copyright 2011 Jun Wako <wakojun@gmail.com>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #ifndef PS2_MOUSE_H
  15. #define PS2_MOUSE_H
  16. #include <stdbool.h>
  17. #include "debug.h"
  18. #define PS2_MOUSE_SEND(command, message) \
  19. do { \
  20. __attribute__((unused)) uint8_t rcv = ps2_host_send(command); \
  21. if (debug_mouse) { \
  22. print((message)); \
  23. xprintf(" command: %X, result: %X, error: %X \n", command, rcv, ps2_error); \
  24. } \
  25. } while (0)
  26. #define PS2_MOUSE_SEND_SAFE(command, message) \
  27. do { \
  28. if (PS2_MOUSE_STREAM_MODE == ps2_mouse_mode) { \
  29. ps2_mouse_disable_data_reporting(); \
  30. } \
  31. PS2_MOUSE_SEND(command, message); \
  32. if (PS2_MOUSE_STREAM_MODE == ps2_mouse_mode) { \
  33. ps2_mouse_enable_data_reporting(); \
  34. } \
  35. } while (0)
  36. #define PS2_MOUSE_SET_SAFE(command, value, message) \
  37. do { \
  38. if (PS2_MOUSE_STREAM_MODE == ps2_mouse_mode) { \
  39. ps2_mouse_disable_data_reporting(); \
  40. } \
  41. PS2_MOUSE_SEND(command, message); \
  42. PS2_MOUSE_SEND(value, "Sending value"); \
  43. if (PS2_MOUSE_STREAM_MODE == ps2_mouse_mode) { \
  44. ps2_mouse_enable_data_reporting(); \
  45. } \
  46. } while (0)
  47. #define PS2_MOUSE_RECEIVE(message) \
  48. do { \
  49. __attribute__((unused)) uint8_t rcv = ps2_host_recv_response(); \
  50. if (debug_mouse) { \
  51. print((message)); \
  52. xprintf(" result: %X, error: %X \n", rcv, ps2_error); \
  53. } \
  54. } while (0)
  55. __attribute__((unused)) static enum ps2_mouse_mode_e {
  56. PS2_MOUSE_STREAM_MODE,
  57. PS2_MOUSE_REMOTE_MODE,
  58. } ps2_mouse_mode = PS2_MOUSE_STREAM_MODE;
  59. /*
  60. * Data format:
  61. * byte|7 6 5 4 3 2 1 0
  62. * ----+----------------------------------------------------------------
  63. * 0|[Yovflw][Xovflw][Ysign ][Xsign ][ 1 ][Middle][Right ][Left ]
  64. * 1|[ X movement(0-255) ]
  65. * 2|[ Y movement(0-255) ]
  66. */
  67. #define PS2_MOUSE_BTN_MASK 0x07
  68. #define PS2_MOUSE_BTN_LEFT 0
  69. #define PS2_MOUSE_BTN_RIGHT 1
  70. #define PS2_MOUSE_BTN_MIDDLE 2
  71. #define PS2_MOUSE_X_SIGN 4
  72. #define PS2_MOUSE_Y_SIGN 5
  73. #define PS2_MOUSE_X_OVFLW 6
  74. #define PS2_MOUSE_Y_OVFLW 7
  75. /* mouse button to start scrolling; set 0 to disable scroll */
  76. #ifndef PS2_MOUSE_SCROLL_BTN_MASK
  77. # define PS2_MOUSE_SCROLL_BTN_MASK (1 << PS2_MOUSE_BTN_MIDDLE)
  78. #endif
  79. /* send button event when button is released within this value(ms); set 0 to disable */
  80. #ifndef PS2_MOUSE_SCROLL_BTN_SEND
  81. # define PS2_MOUSE_SCROLL_BTN_SEND 300
  82. #endif
  83. /* divide virtical and horizontal mouse move by this to convert to scroll move */
  84. #ifndef PS2_MOUSE_SCROLL_DIVISOR_V
  85. # define PS2_MOUSE_SCROLL_DIVISOR_V 2
  86. #endif
  87. #ifndef PS2_MOUSE_SCROLL_DIVISOR_H
  88. # define PS2_MOUSE_SCROLL_DIVISOR_H 2
  89. #endif
  90. /* multiply reported mouse values by these */
  91. #ifndef PS2_MOUSE_X_MULTIPLIER
  92. # define PS2_MOUSE_X_MULTIPLIER 1
  93. #endif
  94. #ifndef PS2_MOUSE_Y_MULTIPLIER
  95. # define PS2_MOUSE_Y_MULTIPLIER 1
  96. #endif
  97. #ifndef PS2_MOUSE_V_MULTIPLIER
  98. # define PS2_MOUSE_V_MULTIPLIER 1
  99. #endif
  100. /* For some mice this will need to be 0x0F */
  101. #ifndef PS2_MOUSE_SCROLL_MASK
  102. # define PS2_MOUSE_SCROLL_MASK 0xFF
  103. #endif
  104. #ifndef PS2_MOUSE_INIT_DELAY
  105. # define PS2_MOUSE_INIT_DELAY 1000
  106. #endif
  107. enum ps2_mouse_command_e {
  108. PS2_MOUSE_RESET = 0xFF,
  109. PS2_MOUSE_RESEND = 0xFE,
  110. PS2_MOSUE_SET_DEFAULTS = 0xF6,
  111. PS2_MOUSE_DISABLE_DATA_REPORTING = 0xF5,
  112. PS2_MOUSE_ENABLE_DATA_REPORTING = 0xF4,
  113. PS2_MOUSE_SET_SAMPLE_RATE = 0xF3,
  114. PS2_MOUSE_GET_DEVICE_ID = 0xF2,
  115. PS2_MOUSE_SET_REMOTE_MODE = 0xF0,
  116. PS2_MOUSE_SET_WRAP_MODE = 0xEC,
  117. PS2_MOUSE_READ_DATA = 0xEB,
  118. PS2_MOUSE_SET_STREAM_MODE = 0xEA,
  119. PS2_MOUSE_STATUS_REQUEST = 0xE9,
  120. PS2_MOUSE_SET_RESOLUTION = 0xE8,
  121. PS2_MOUSE_SET_SCALING_2_1 = 0xE7,
  122. PS2_MOUSE_SET_SCALING_1_1 = 0xE6,
  123. };
  124. typedef enum ps2_mouse_resolution_e {
  125. PS2_MOUSE_1_COUNT_MM,
  126. PS2_MOUSE_2_COUNT_MM,
  127. PS2_MOUSE_4_COUNT_MM,
  128. PS2_MOUSE_8_COUNT_MM,
  129. } ps2_mouse_resolution_t;
  130. typedef enum ps2_mouse_sample_rate_e {
  131. PS2_MOUSE_10_SAMPLES_SEC = 10,
  132. PS2_MOUSE_20_SAMPLES_SEC = 20,
  133. PS2_MOUSE_40_SAMPLES_SEC = 40,
  134. PS2_MOUSE_60_SAMPLES_SEC = 60,
  135. PS2_MOUSE_80_SAMPLES_SEC = 80,
  136. PS2_MOUSE_100_SAMPLES_SEC = 100,
  137. PS2_MOUSE_200_SAMPLES_SEC = 200,
  138. } ps2_mouse_sample_rate_t;
  139. void ps2_mouse_init(void);
  140. void ps2_mouse_init_user(void);
  141. void ps2_mouse_task(void);
  142. void ps2_mouse_disable_data_reporting(void);
  143. void ps2_mouse_enable_data_reporting(void);
  144. void ps2_mouse_set_remote_mode(void);
  145. void ps2_mouse_set_stream_mode(void);
  146. void ps2_mouse_set_scaling_2_1(void);
  147. void ps2_mouse_set_scaling_1_1(void);
  148. void ps2_mouse_set_resolution(ps2_mouse_resolution_t resolution);
  149. void ps2_mouse_set_sample_rate(ps2_mouse_sample_rate_t sample_rate);
  150. #endif