ps2_mouse.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. /*
  18. * Data format:
  19. * byte|7 6 5 4 3 2 1 0
  20. * ----+----------------------------------------------------------------
  21. * 0|[Yovflw][Xovflw][Ysign ][Xsign ][ 1 ][Middle][Right ][Left ]
  22. * 1|[ X movement(0-255) ]
  23. * 2|[ Y movement(0-255) ]
  24. */
  25. #define PS2_MOUSE_BTN_MASK 0x07
  26. #define PS2_MOUSE_BTN_LEFT 0
  27. #define PS2_MOUSE_BTN_RIGHT 1
  28. #define PS2_MOUSE_BTN_MIDDLE 2
  29. #define PS2_MOUSE_X_SIGN 4
  30. #define PS2_MOUSE_Y_SIGN 5
  31. #define PS2_MOUSE_X_OVFLW 6
  32. #define PS2_MOUSE_Y_OVFLW 7
  33. /* mouse button to start scrolling; set 0 to disable scroll */
  34. #ifndef PS2_MOUSE_SCROLL_BTN_MASK
  35. #define PS2_MOUSE_SCROLL_BTN_MASK (1<<PS2_MOUSE_BTN_MIDDLE)
  36. #endif
  37. /* send button event when button is released within this value(ms); set 0 to disable */
  38. #ifndef PS2_MOUSE_SCROLL_BTN_SEND
  39. #define PS2_MOUSE_SCROLL_BTN_SEND 300
  40. #endif
  41. /* divide virtical and horizontal mouse move by this to convert to scroll move */
  42. #ifndef PS2_MOUSE_SCROLL_DIVISOR_V
  43. #define PS2_MOUSE_SCROLL_DIVISOR_V 2
  44. #endif
  45. #ifndef PS2_MOUSE_SCROLL_DIVISOR_H
  46. #define PS2_MOUSE_SCROLL_DIVISOR_H 2
  47. #endif
  48. /* multiply reported mouse values by these */
  49. #ifndef PS2_MOUSE_X_MULTIPLIER
  50. #define PS2_MOUSE_X_MULTIPLIER 1
  51. #endif
  52. #ifndef PS2_MOUSE_Y_MULTIPLIER
  53. #define PS2_MOUSE_Y_MULTIPLIER 1
  54. #endif
  55. #ifndef PS2_MOUSE_V_MULTIPLIER
  56. #define PS2_MOUSE_V_MULTIPLIER 1
  57. #endif
  58. /* For some mice this will need to be 0x0F */
  59. #ifndef PS2_MOUSE_SCROLL_MASK
  60. #define PS2_MOUSE_SCROLL_MASK 0xFF
  61. #endif
  62. #ifndef PS2_MOUSE_INIT_DELAY
  63. #define PS2_MOUSE_INIT_DELAY 1000
  64. #endif
  65. enum ps2_mouse_command_e {
  66. PS2_MOUSE_RESET = 0xFF,
  67. PS2_MOUSE_RESEND = 0xFE,
  68. PS2_MOSUE_SET_DEFAULTS = 0xF6,
  69. PS2_MOUSE_DISABLE_DATA_REPORTING = 0xF5,
  70. PS2_MOUSE_ENABLE_DATA_REPORTING = 0xF4,
  71. PS2_MOUSE_SET_SAMPLE_RATE = 0xF3,
  72. PS2_MOUSE_GET_DEVICE_ID = 0xF2,
  73. PS2_MOUSE_SET_REMOTE_MODE = 0xF0,
  74. PS2_MOUSE_SET_WRAP_MODE = 0xEC,
  75. PS2_MOUSE_READ_DATA = 0xEB,
  76. PS2_MOUSE_SET_STREAM_MODE = 0xEA,
  77. PS2_MOUSE_STATUS_REQUEST = 0xE9,
  78. PS2_MOUSE_SET_RESOLUTION = 0xE8,
  79. PS2_MOUSE_SET_SCALING_2_1 = 0xE7,
  80. PS2_MOUSE_SET_SCALING_1_1 = 0xE6,
  81. };
  82. typedef enum ps2_mouse_resolution_e {
  83. PS2_MOUSE_1_COUNT_MM,
  84. PS2_MOUSE_2_COUNT_MM,
  85. PS2_MOUSE_4_COUNT_MM,
  86. PS2_MOUSE_8_COUNT_MM,
  87. } ps2_mouse_resolution_t;
  88. typedef enum ps2_mouse_sample_rate_e {
  89. PS2_MOUSE_10_SAMPLES_SEC = 10,
  90. PS2_MOUSE_20_SAMPLES_SEC = 20,
  91. PS2_MOUSE_40_SAMPLES_SEC = 40,
  92. PS2_MOUSE_60_SAMPLES_SEC = 60,
  93. PS2_MOUSE_80_SAMPLES_SEC = 80,
  94. PS2_MOUSE_100_SAMPLES_SEC = 100,
  95. PS2_MOUSE_200_SAMPLES_SEC = 200,
  96. } ps2_mouse_sample_rate_t;
  97. void ps2_mouse_init(void);
  98. void ps2_mouse_task(void);
  99. void ps2_mouse_disable_data_reporting(void);
  100. void ps2_mouse_enable_data_reporting(void);
  101. void ps2_mouse_set_remote_mode(void);
  102. void ps2_mouse_set_stream_mode(void);
  103. void ps2_mouse_set_scaling_2_1(void);
  104. void ps2_mouse_set_scaling_1_1(void);
  105. void ps2_mouse_set_resolution(ps2_mouse_resolution_t resolution);
  106. void ps2_mouse_set_sample_rate(ps2_mouse_sample_rate_t sample_rate);
  107. #endif