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.

349 lines
9.2 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_ENABLE = yes
  24. PS2_DRIVER = busywait
  25. ```
  26. In your keyboard config.h:
  27. ```c
  28. #ifdef PS2_DRIVER_BUSYWAIT
  29. # define PS2_CLOCK_PIN D1
  30. # define PS2_DATA_PIN D2
  31. #endif
  32. ```
  33. ### Interrupt Version (AVR/ATMega32u4) :id=interrupt-version-avr
  34. 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.
  35. In rules.mk:
  36. ```make
  37. PS2_MOUSE_ENABLE = yes
  38. PS2_ENABLE = yes
  39. PS2_DRIVER = interrupt
  40. ```
  41. In your keyboard config.h:
  42. ```c
  43. #ifdef PS2_DRIVER_INTERRUPT
  44. #define PS2_CLOCK_PIN D2
  45. #define PS2_DATA_PIN D5
  46. #define PS2_INT_INIT() do { \
  47. EICRA |= ((1<<ISC21) | \
  48. (0<<ISC20)); \
  49. } while (0)
  50. #define PS2_INT_ON() do { \
  51. EIMSK |= (1<<INT2); \
  52. } while (0)
  53. #define PS2_INT_OFF() do { \
  54. EIMSK &= ~(1<<INT2); \
  55. } while (0)
  56. #define PS2_INT_VECT INT2_vect
  57. #endif
  58. ```
  59. ### Interrupt Version (ARM chibios) :id=interrupt-version-chibios
  60. 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.
  61. In rules.mk:
  62. ```
  63. PS2_MOUSE_ENABLE = yes
  64. PS2_ENABLE = yes
  65. PS2_DRIVER = interrupt
  66. ```
  67. In your keyboard config.h:
  68. ```c
  69. #define PS2_CLOCK_PIN A8
  70. #define PS2_DATA_PIN A9
  71. ```
  72. And in the chibios specifig halconf.h:
  73. ```c
  74. #define PAL_USE_CALLBACKS TRUE
  75. ```
  76. ### USART Version :id=usart-version
  77. 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.
  78. In rules.mk:
  79. ```make
  80. PS2_MOUSE_ENABLE = yes
  81. PS2_ENABLE = yes
  82. PS2_DRIVER = usart
  83. ```
  84. In your keyboard config.h:
  85. ```c
  86. #ifdef PS2_DRIVER_USART
  87. #define PS2_CLOCK_PIN D5
  88. #define PS2_DATA_PIN D2
  89. /* synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling edge */
  90. /* set DDR of CLOCK as input to be slave */
  91. #define PS2_USART_INIT() do { \
  92. PS2_CLOCK_DDR &= ~(1<<PS2_CLOCK_BIT); \
  93. PS2_DATA_DDR &= ~(1<<PS2_DATA_BIT); \
  94. UCSR1C = ((1 << UMSEL10) | \
  95. (3 << UPM10) | \
  96. (0 << USBS1) | \
  97. (3 << UCSZ10) | \
  98. (0 << UCPOL1)); \
  99. UCSR1A = 0; \
  100. UBRR1H = 0; \
  101. UBRR1L = 0; \
  102. } while (0)
  103. #define PS2_USART_RX_INT_ON() do { \
  104. UCSR1B = ((1 << RXCIE1) | \
  105. (1 << RXEN1)); \
  106. } while (0)
  107. #define PS2_USART_RX_POLL_ON() do { \
  108. UCSR1B = (1 << RXEN1); \
  109. } while (0)
  110. #define PS2_USART_OFF() do { \
  111. UCSR1C = 0; \
  112. UCSR1B &= ~((1 << RXEN1) | \
  113. (1 << TXEN1)); \
  114. } while (0)
  115. #define PS2_USART_RX_READY (UCSR1A & (1<<RXC1))
  116. #define PS2_USART_RX_DATA UDR1
  117. #define PS2_USART_ERROR (UCSR1A & ((1<<FE1) | (1<<DOR1) | (1<<UPE1)))
  118. #define PS2_USART_RX_VECT USART1_RX_vect
  119. #endif
  120. ```
  121. ### RP2040 PIO Version :id=rp2040-pio-version
  122. The `PIO` subsystem is a Raspberry Pi RP2040 specific implementation, using the integrated PIO peripheral and is therefore only available on this MCU.
  123. There are strict requirements for pin ordering but any pair of GPIO pins can be used. The GPIO used for clock must be directly after data, see the included info.json snippet for an example of correct order.
  124. You may optionally switch the PIO peripheral used with the following define in config.h:
  125. ```c
  126. #define PS2_PIO_USE_PIO1 // Force the usage of PIO1 peripheral, by default the PS2 implementation uses the PIO0 peripheral
  127. ```
  128. Example info.json content:
  129. ```json
  130. "ps2": {
  131. "clock_pin": "GP1",
  132. "data_pin": "GP0",
  133. "driver": "vendor",
  134. "enabled": true,
  135. "mouse_enabled": true
  136. }
  137. ```
  138. ## Additional Settings :id=additional-settings
  139. ### PS/2 Mouse Features :id=ps2-mouse-features
  140. These enable settings supported by the PS/2 mouse protocol.
  141. ```c
  142. /* Use remote mode instead of the default stream mode (see link) */
  143. #define PS2_MOUSE_USE_REMOTE_MODE
  144. /* Enable the scrollwheel or scroll gesture on your mouse or touchpad */
  145. #define PS2_MOUSE_ENABLE_SCROLLING
  146. /* Some mice will need a scroll mask to be configured. The default is 0xFF. */
  147. #define PS2_MOUSE_SCROLL_MASK 0x0F
  148. /* Applies a transformation to the movement before sending to the host (see link) */
  149. #define PS2_MOUSE_USE_2_1_SCALING
  150. /* The time to wait after initializing the ps2 host */
  151. #define PS2_MOUSE_INIT_DELAY 1000 /* Default */
  152. ```
  153. You can also call the following functions from ps2_mouse.h
  154. ```c
  155. void ps2_mouse_disable_data_reporting(void);
  156. void ps2_mouse_enable_data_reporting(void);
  157. void ps2_mouse_set_remote_mode(void);
  158. void ps2_mouse_set_stream_mode(void);
  159. void ps2_mouse_set_scaling_2_1(void);
  160. void ps2_mouse_set_scaling_1_1(void);
  161. void ps2_mouse_set_resolution(ps2_mouse_resolution_t resolution);
  162. void ps2_mouse_set_sample_rate(ps2_mouse_sample_rate_t sample_rate);
  163. ```
  164. ### Fine Control :id=fine-control
  165. Use the following defines to change the sensitivity and speed of the mouse.
  166. Note: you can also use `ps2_mouse_set_resolution` for the same effect (not supported on most touchpads).
  167. ```c
  168. #define PS2_MOUSE_X_MULTIPLIER 3
  169. #define PS2_MOUSE_Y_MULTIPLIER 3
  170. #define PS2_MOUSE_V_MULTIPLIER 1
  171. ```
  172. ### Scroll Button :id=scroll-button
  173. If you're using a trackpoint, you will likely want to be able to use it for scrolling.
  174. It's possible to enable a "scroll button/s" that when pressed will cause the mouse to scroll instead of moving.
  175. To enable the feature, you must set a scroll button mask as follows:
  176. ```c
  177. #define PS2_MOUSE_SCROLL_BTN_MASK (1<<PS2_MOUSE_BTN_MIDDLE) /* Default */
  178. ```
  179. To disable the scroll button feature:
  180. ```c
  181. #define PS2_MOUSE_SCROLL_BTN_MASK 0
  182. ```
  183. The available buttons are:
  184. ```c
  185. #define PS2_MOUSE_BTN_LEFT 0
  186. #define PS2_MOUSE_BTN_RIGHT 1
  187. #define PS2_MOUSE_BTN_MIDDLE 2
  188. ```
  189. You can also combine buttons in the mask by `|`ing them together.
  190. Once you've configured your scroll button mask, you must configure the scroll button send interval.
  191. This is the interval before which if the scroll buttons were released they would be sent to the host.
  192. After this interval, they will cause the mouse to scroll and will not be sent.
  193. ```c
  194. #define PS2_MOUSE_SCROLL_BTN_SEND 300 /* Default */
  195. ```
  196. To disable sending the scroll buttons:
  197. ```c
  198. #define PS2_MOUSE_SCROLL_BTN_SEND 0
  199. ```
  200. Fine control over the scrolling is supported with the following defines:
  201. ```c
  202. #define PS2_MOUSE_SCROLL_DIVISOR_H 2
  203. #define PS2_MOUSE_SCROLL_DIVISOR_V 2
  204. ```
  205. ### Invert Mouse buttons :id=invert-buttons
  206. To invert the left & right buttons you can put:
  207. ```c
  208. #define PS2_MOUSE_INVERT_BUTTONS
  209. ```
  210. into config.h.
  211. ### Invert Mouse and Scroll Axes :id=invert-mouse-and-scroll-axes
  212. To invert the X and Y axes you can put:
  213. ```c
  214. #define PS2_MOUSE_INVERT_X
  215. #define PS2_MOUSE_INVERT_Y
  216. ```
  217. into config.h.
  218. To reverse the scroll axes you can put:
  219. ```c
  220. #define PS2_MOUSE_INVERT_H
  221. #define PS2_MOUSE_INVERT_V
  222. ```
  223. into config.h.
  224. ### Rotate Mouse Axes :id=rotate-mouse-axes
  225. Transform the output of the device with a clockwise rotation of 90, 180, or 270
  226. degrees.
  227. When compensating for device orientation, rotate the output the same amount in
  228. the opposite direction. E.g. if the normal device orientation is considered to
  229. be North-facing, compensate as follows:
  230. ```c
  231. #define PS2_MOUSE_ROTATE 270 /* Compensate for East-facing device orientation. */
  232. ```
  233. ```c
  234. #define PS2_MOUSE_ROTATE 180 /* Compensate for South-facing device orientation. */
  235. ```
  236. ```c
  237. #define PS2_MOUSE_ROTATE 90 /* Compensate for West-facing device orientation. */
  238. ```
  239. ### Debug Settings :id=debug-settings
  240. To debug the mouse, add `debug_mouse = true` or enable via bootmagic.
  241. ```c
  242. /* To debug the mouse reports */
  243. #define PS2_MOUSE_DEBUG_HID
  244. #define PS2_MOUSE_DEBUG_RAW
  245. ```
  246. ### Movement Hook :id=movement-hook
  247. Process mouse movement in the keymap before it is sent to the host. Example
  248. uses include filtering noise, adding acceleration, and automatically activating
  249. a layer. To use, define the following function in your keymap:
  250. ```c
  251. void ps2_mouse_moved_user(report_mouse_t *mouse_report);
  252. ```