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.

322 lines
8.3 KiB

  1. # PS/2 Mouse Support :id=ps2-mouse-support
  2. Its possible to hook up a PS/2 mouse (for example touchpads or trackpoints) to your keyboard as a composite device.
  3. To hook up a Trackpoint, you need to obtain a Trackpoint module (i.e. harvest from a Thinkpad keyboard), identify the function of each pin of the module, and make the necessary circuitry between controller and Trackpoint module. For more information, please refer to [Trackpoint Hardware](https://deskthority.net/wiki/TrackPoint_Hardware) page on Deskthority Wiki.
  4. There are three available modes for hooking up PS/2 devices: USART (best), interrupts (better) or busywait (not recommended).
  5. ## The Circuitry between Trackpoint and Controller :id=the-circuitry-between-trackpoint-and-controller
  6. To get the things working, a 4.7K drag is needed between the two lines DATA and CLK and the line 5+.
  7. ```
  8. DATA ----------+--------- PIN
  9. |
  10. 4.7K
  11. |
  12. MODULE 5+ --------+--+--------- PWR CONTROLLER
  13. |
  14. 4.7K
  15. |
  16. CLK ------+------------ PIN
  17. ```
  18. ## Busywait Version :id=busywait-version
  19. Note: This is not recommended, you may encounter jerky movement or unsent inputs. Please use interrupt or USART version if possible.
  20. In rules.mk:
  21. ```make
  22. PS2_MOUSE_ENABLE = yes
  23. PS2_USE_BUSYWAIT = yes
  24. ```
  25. In your keyboard config.h:
  26. ```c
  27. #ifdef PS2_USE_BUSYWAIT
  28. # define PS2_CLOCK_PIN D1
  29. # define PS2_DATA_PIN D2
  30. #endif
  31. ```
  32. ### Interrupt Version (AVR/ATMega32u4) :id=interrupt-version-avr
  33. The following example uses D2 for clock and D5 for data. You can use any INT or PCINT pin for clock, and any pin for data.
  34. In rules.mk:
  35. ```make
  36. PS2_MOUSE_ENABLE = yes
  37. PS2_USE_INT = yes
  38. ```
  39. In your keyboard config.h:
  40. ```c
  41. #ifdef PS2_USE_INT
  42. #define PS2_CLOCK_PIN D2
  43. #define PS2_DATA_PIN D5
  44. #define PS2_INT_INIT() do { \
  45. EICRA |= ((1<<ISC21) | \
  46. (0<<ISC20)); \
  47. } while (0)
  48. #define PS2_INT_ON() do { \
  49. EIMSK |= (1<<INT2); \
  50. } while (0)
  51. #define PS2_INT_OFF() do { \
  52. EIMSK &= ~(1<<INT2); \
  53. } while (0)
  54. #define PS2_INT_VECT INT2_vect
  55. #endif
  56. ```
  57. ### Interrupt Version (ARM chibios) :id=interrupt-version-chibios
  58. Pretty much any two pins can be used for the (software) interrupt variant on ARM cores. The example below uses A8 for clock, and A9 for data.
  59. In rules.mk:
  60. ```
  61. PS2_MOUSE_ENABLE = yes
  62. PS2_USE_INT = yes
  63. ```
  64. In your keyboard config.h:
  65. ```c
  66. #define PS2_CLOCK_PIN A8
  67. #define PS2_DATA_PIN A9
  68. ```
  69. And in the chibios specifig halconf.h:
  70. ```c
  71. #define PAL_USE_CALLBACKS TRUE
  72. ```
  73. ### USART Version :id=usart-version
  74. To use USART on the ATMega32u4, you have to use PD5 for clock and PD2 for data. If one of those are unavailable, you need to use interrupt version.
  75. In rules.mk:
  76. ```make
  77. PS2_MOUSE_ENABLE = yes
  78. PS2_USE_USART = yes
  79. ```
  80. In your keyboard config.h:
  81. ```c
  82. #ifdef PS2_USE_USART
  83. #define PS2_CLOCK_PIN D5
  84. #define PS2_DATA_PIN D2
  85. /* synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling edge */
  86. /* set DDR of CLOCK as input to be slave */
  87. #define PS2_USART_INIT() do { \
  88. PS2_CLOCK_DDR &= ~(1<<PS2_CLOCK_BIT); \
  89. PS2_DATA_DDR &= ~(1<<PS2_DATA_BIT); \
  90. UCSR1C = ((1 << UMSEL10) | \
  91. (3 << UPM10) | \
  92. (0 << USBS1) | \
  93. (3 << UCSZ10) | \
  94. (0 << UCPOL1)); \
  95. UCSR1A = 0; \
  96. UBRR1H = 0; \
  97. UBRR1L = 0; \
  98. } while (0)
  99. #define PS2_USART_RX_INT_ON() do { \
  100. UCSR1B = ((1 << RXCIE1) | \
  101. (1 << RXEN1)); \
  102. } while (0)
  103. #define PS2_USART_RX_POLL_ON() do { \
  104. UCSR1B = (1 << RXEN1); \
  105. } while (0)
  106. #define PS2_USART_OFF() do { \
  107. UCSR1C = 0; \
  108. UCSR1B &= ~((1 << RXEN1) | \
  109. (1 << TXEN1)); \
  110. } while (0)
  111. #define PS2_USART_RX_READY (UCSR1A & (1<<RXC1))
  112. #define PS2_USART_RX_DATA UDR1
  113. #define PS2_USART_ERROR (UCSR1A & ((1<<FE1) | (1<<DOR1) | (1<<UPE1)))
  114. #define PS2_USART_RX_VECT USART1_RX_vect
  115. #endif
  116. ```
  117. ## Additional Settings :id=additional-settings
  118. ### PS/2 Mouse Features :id=ps2-mouse-features
  119. These enable settings supported by the PS/2 mouse protocol.
  120. ```c
  121. /* Use remote mode instead of the default stream mode (see link) */
  122. #define PS2_MOUSE_USE_REMOTE_MODE
  123. /* Enable the scrollwheel or scroll gesture on your mouse or touchpad */
  124. #define PS2_MOUSE_ENABLE_SCROLLING
  125. /* Some mice will need a scroll mask to be configured. The default is 0xFF. */
  126. #define PS2_MOUSE_SCROLL_MASK 0x0F
  127. /* Applies a transformation to the movement before sending to the host (see link) */
  128. #define PS2_MOUSE_USE_2_1_SCALING
  129. /* The time to wait after initializing the ps2 host */
  130. #define PS2_MOUSE_INIT_DELAY 1000 /* Default */
  131. ```
  132. You can also call the following functions from ps2_mouse.h
  133. ```c
  134. void ps2_mouse_disable_data_reporting(void);
  135. void ps2_mouse_enable_data_reporting(void);
  136. void ps2_mouse_set_remote_mode(void);
  137. void ps2_mouse_set_stream_mode(void);
  138. void ps2_mouse_set_scaling_2_1(void);
  139. void ps2_mouse_set_scaling_1_1(void);
  140. void ps2_mouse_set_resolution(ps2_mouse_resolution_t resolution);
  141. void ps2_mouse_set_sample_rate(ps2_mouse_sample_rate_t sample_rate);
  142. ```
  143. ### Fine Control :id=fine-control
  144. Use the following defines to change the sensitivity and speed of the mouse.
  145. Note: you can also use `ps2_mouse_set_resolution` for the same effect (not supported on most touchpads).
  146. ```c
  147. #define PS2_MOUSE_X_MULTIPLIER 3
  148. #define PS2_MOUSE_Y_MULTIPLIER 3
  149. #define PS2_MOUSE_V_MULTIPLIER 1
  150. ```
  151. ### Scroll Button :id=scroll-button
  152. If you're using a trackpoint, you will likely want to be able to use it for scrolling.
  153. It's possible to enable a "scroll button/s" that when pressed will cause the mouse to scroll instead of moving.
  154. To enable the feature, you must set a scroll button mask as follows:
  155. ```c
  156. #define PS2_MOUSE_SCROLL_BTN_MASK (1<<PS2_MOUSE_BTN_MIDDLE) /* Default */
  157. ```
  158. To disable the scroll button feature:
  159. ```c
  160. #define PS2_MOUSE_SCROLL_BTN_MASK 0
  161. ```
  162. The available buttons are:
  163. ```c
  164. #define PS2_MOUSE_BTN_LEFT 0
  165. #define PS2_MOUSE_BTN_RIGHT 1
  166. #define PS2_MOUSE_BTN_MIDDLE 2
  167. ```
  168. You can also combine buttons in the mask by `|`ing them together.
  169. Once you've configured your scroll button mask, you must configure the scroll button send interval.
  170. This is the interval before which if the scroll buttons were released they would be sent to the host.
  171. After this interval, they will cause the mouse to scroll and will not be sent.
  172. ```c
  173. #define PS2_MOUSE_SCROLL_BTN_SEND 300 /* Default */
  174. ```
  175. To disable sending the scroll buttons:
  176. ```c
  177. #define PS2_MOUSE_SCROLL_BTN_SEND 0
  178. ```
  179. Fine control over the scrolling is supported with the following defines:
  180. ```c
  181. #define PS2_MOUSE_SCROLL_DIVISOR_H 2
  182. #define PS2_MOUSE_SCROLL_DIVISOR_V 2
  183. ```
  184. ### Invert Mouse buttons :id=invert-buttons
  185. To invert the left & right buttons you can put:
  186. ```c
  187. #define PS2_MOUSE_INVERT_BUTTONS
  188. ```
  189. into config.h.
  190. ### Invert Mouse and Scroll Axes :id=invert-mouse-and-scroll-axes
  191. To invert the X and Y axes you can put:
  192. ```c
  193. #define PS2_MOUSE_INVERT_X
  194. #define PS2_MOUSE_INVERT_Y
  195. ```
  196. into config.h.
  197. To reverse the scroll axes you can put:
  198. ```c
  199. #define PS2_MOUSE_INVERT_H
  200. #define PS2_MOUSE_INVERT_V
  201. ```
  202. into config.h.
  203. ### Rotate Mouse Axes :id=rotate-mouse-axes
  204. Transform the output of the device with a clockwise rotation of 90, 180, or 270
  205. degrees.
  206. When compensating for device orientation, rotate the output the same amount in
  207. the opposite direction. E.g. if the normal device orientation is considered to
  208. be North-facing, compensate as follows:
  209. ```c
  210. #define PS2_MOUSE_ROTATE 270 /* Compensate for East-facing device orientation. */
  211. ```
  212. ```c
  213. #define PS2_MOUSE_ROTATE 180 /* Compensate for South-facing device orientation. */
  214. ```
  215. ```c
  216. #define PS2_MOUSE_ROTATE 90 /* Compensate for West-facing device orientation. */
  217. ```
  218. ### Debug Settings :id=debug-settings
  219. To debug the mouse, add `debug_mouse = true` or enable via bootmagic.
  220. ```c
  221. /* To debug the mouse reports */
  222. #define PS2_MOUSE_DEBUG_HID
  223. #define PS2_MOUSE_DEBUG_RAW
  224. ```
  225. ### Movement Hook :id=movement-hook
  226. Process mouse movement in the keymap before it is sent to the host. Example
  227. uses include filtering noise, adding acceleration, and automatically activating
  228. a layer. To use, define the following function in your keymap:
  229. ```c
  230. void ps2_mouse_moved_user(report_mouse_t *mouse_report);
  231. ```