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.

258 lines
6.7 KiB

  1. ## PS/2 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. ### Busywait Version
  6. Note: This is not recommended, you may encounter jerky movement or unsent inputs. Please use interrupt or USART version if possible.
  7. In rules.mk:
  8. ```
  9. PS2_MOUSE_ENABLE = yes
  10. PS2_USE_BUSYWAIT = yes
  11. ```
  12. In your keyboard config.h:
  13. ```
  14. #ifdef PS2_USE_BUSYWAIT
  15. # define PS2_CLOCK_PORT PORTD
  16. # define PS2_CLOCK_PIN PIND
  17. # define PS2_CLOCK_DDR DDRD
  18. # define PS2_CLOCK_BIT 1
  19. # define PS2_DATA_PORT PORTD
  20. # define PS2_DATA_PIN PIND
  21. # define PS2_DATA_DDR DDRD
  22. # define PS2_DATA_BIT 2
  23. #endif
  24. ```
  25. ### Interrupt Version
  26. 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.
  27. In rules.mk:
  28. ```
  29. PS2_MOUSE_ENABLE = yes
  30. PS2_USE_INT = yes
  31. ```
  32. In your keyboard config.h:
  33. ```
  34. #ifdef PS2_USE_INT
  35. #define PS2_CLOCK_PORT PORTD
  36. #define PS2_CLOCK_PIN PIND
  37. #define PS2_CLOCK_DDR DDRD
  38. #define PS2_CLOCK_BIT 2
  39. #define PS2_DATA_PORT PORTD
  40. #define PS2_DATA_PIN PIND
  41. #define PS2_DATA_DDR DDRD
  42. #define PS2_DATA_BIT 5
  43. #define PS2_INT_INIT() do { \
  44. EICRA |= ((1<<ISC21) | \
  45. (0<<ISC20)); \
  46. } while (0)
  47. #define PS2_INT_ON() do { \
  48. EIMSK |= (1<<INT2); \
  49. } while (0)
  50. #define PS2_INT_OFF() do { \
  51. EIMSK &= ~(1<<INT2); \
  52. } while (0)
  53. #define PS2_INT_VECT INT2_vect
  54. #endif
  55. ```
  56. ### USART Version
  57. 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.
  58. In rules.mk:
  59. ```
  60. PS2_MOUSE_ENABLE = yes
  61. PS2_USE_USART = yes
  62. ```
  63. In your keyboard config.h:
  64. ```
  65. #ifdef PS2_USE_USART
  66. #define PS2_CLOCK_PORT PORTD
  67. #define PS2_CLOCK_PIN PIND
  68. #define PS2_CLOCK_DDR DDRD
  69. #define PS2_CLOCK_BIT 5
  70. #define PS2_DATA_PORT PORTD
  71. #define PS2_DATA_PIN PIND
  72. #define PS2_DATA_DDR DDRD
  73. #define PS2_DATA_BIT 2
  74. /* synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling edge */
  75. /* set DDR of CLOCK as input to be slave */
  76. #define PS2_USART_INIT() do { \
  77. PS2_CLOCK_DDR &= ~(1<<PS2_CLOCK_BIT); \
  78. PS2_DATA_DDR &= ~(1<<PS2_DATA_BIT); \
  79. UCSR1C = ((1 << UMSEL10) | \
  80. (3 << UPM10) | \
  81. (0 << USBS1) | \
  82. (3 << UCSZ10) | \
  83. (0 << UCPOL1)); \
  84. UCSR1A = 0; \
  85. UBRR1H = 0; \
  86. UBRR1L = 0; \
  87. } while (0)
  88. #define PS2_USART_RX_INT_ON() do { \
  89. UCSR1B = ((1 << RXCIE1) | \
  90. (1 << RXEN1)); \
  91. } while (0)
  92. #define PS2_USART_RX_POLL_ON() do { \
  93. UCSR1B = (1 << RXEN1); \
  94. } while (0)
  95. #define PS2_USART_OFF() do { \
  96. UCSR1C = 0; \
  97. UCSR1B &= ~((1 << RXEN1) | \
  98. (1 << TXEN1)); \
  99. } while (0)
  100. #define PS2_USART_RX_READY (UCSR1A & (1<<RXC1))
  101. #define PS2_USART_RX_DATA UDR1
  102. #define PS2_USART_ERROR (UCSR1A & ((1<<FE1) | (1<<DOR1) | (1<<UPE1)))
  103. #define PS2_USART_RX_VECT USART1_RX_vect
  104. #endif
  105. ```
  106. ### Additional Settings
  107. #### PS/2 Mouse Features
  108. These enable settings supported by the PS/2 mouse protocol: http://www.computer-engineering.org/ps2mouse/
  109. ```
  110. /* Use remote mode instead of the default stream mode (see link) */
  111. #define PS2_MOUSE_USE_REMOTE_MODE
  112. /* Enable the scrollwheel or scroll gesture on your mouse or touchpad */
  113. #define PS2_MOUSE_ENABLE_SCROLLING
  114. /* Some mice will need a scroll mask to be configured. The default is 0xFF. */
  115. #define PS2_MOUSE_SCROLL_MASK 0x0F
  116. /* Applies a transformation to the movement before sending to the host (see link) */
  117. #define PS2_MOUSE_USE_2_1_SCALING
  118. /* The time to wait after initializing the ps2 host */
  119. #define PS2_MOUSE_INIT_DELAY 1000 /* Default */
  120. ```
  121. You can also call the following functions from ps2_mouse.h
  122. ```
  123. void ps2_mouse_disable_data_reporting(void);
  124. void ps2_mouse_enable_data_reporting(void);
  125. void ps2_mouse_set_remote_mode(void);
  126. void ps2_mouse_set_stream_mode(void);
  127. void ps2_mouse_set_scaling_2_1(void);
  128. void ps2_mouse_set_scaling_1_1(void);
  129. void ps2_mouse_set_resolution(ps2_mouse_resolution_t resolution);
  130. void ps2_mouse_set_sample_rate(ps2_mouse_sample_rate_t sample_rate);
  131. ```
  132. #### Fine Control
  133. Use the following defines to change the sensitivity and speed of the mouse.
  134. Note: you can also use `ps2_mouse_set_resolution` for the same effect (not supported on most touchpads).
  135. ```
  136. #define PS2_MOUSE_X_MULTIPLIER 3
  137. #define PS2_MOUSE_Y_MULTIPLIER 3
  138. #define PS2_MOUSE_V_MULTIPLIER 1
  139. ```
  140. #### Scroll Button
  141. If you're using a trackpoint, you will likely want to be able to use it for scrolling.
  142. Its possible to enable a "scroll button/s" that when pressed will cause the mouse to scroll instead of moving.
  143. To enable the feature, you must set a scroll button mask as follows:
  144. ```
  145. #define PS2_MOUSE_SCROLL_BTN_MASK (1<<PS2_MOUSE_BUTTON_MIDDLE) /* Default */
  146. ```
  147. To disable the scroll button feature:
  148. ```
  149. #define PS2_MOUSE_SCROLL_BTN_MASK 0
  150. ```
  151. The available buttons are:
  152. ```
  153. #define PS2_MOUSE_BTN_LEFT 0
  154. #define PS2_MOUSE_BTN_RIGHT 1
  155. #define PS2_MOUSE_BTN_MIDDLE 2
  156. ```
  157. You can also combine buttons in the mask by `|`ing them together.
  158. Once you've configured your scroll button mask, you must configure the scroll button send interval.
  159. This is the interval before which if the scroll buttons were released they would be sent to the host.
  160. After this interval, they will cause the mouse to scroll and will not be sent.
  161. ```
  162. #define PS2_MOUSE_SCROLL_BTN_SEND 300 /* Default */
  163. ```
  164. To disable sending the scroll buttons:
  165. ```
  166. #define PS2_MOUSE_SCROLL_BTN_SEND 0
  167. ```
  168. Fine control over the scrolling is supported with the following defines:
  169. ```
  170. #define PS2_MOUSE_SCROLL_DIVISOR_H 2
  171. #define PS2_MOUSE_SCROLL_DIVISOR_V 2
  172. ```
  173. #### Invert Mouse and Scroll Axes
  174. To invert the X and Y axes you can put:
  175. ```
  176. #define PS2_MOUSE_INVERT_X
  177. #define PS2_MOUSE_INVERT_Y
  178. ```
  179. into config.h.
  180. To reverse the scroll axes you can put:
  181. ```
  182. #define PS2_MOUSE_INVERT_H
  183. #define PS2_MOUSE_INVERT_V
  184. ```
  185. into config.h.
  186. #### Debug Settings
  187. To debug the mouse, add `debug_mouse = true` or enable via bootmagic.
  188. ```
  189. /* To debug the mouse reports */
  190. #define PS2_MOUSE_DEBUG_HID
  191. #define PS2_MOUSE_DEBUG_RAW
  192. ```