3 Its possible to hook up a PS/2 mouse (for example touchpads or trackpoints) to your keyboard as a composite device.
5 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.
7 There are three available modes for hooking up PS/2 devices: USART (best), interrupts (better) or busywait (not recommended).
9 ### The Cirtuitry between Trackpoint and Controller
11 To get the things working, a 4.7K drag is needed between the two lines DATA and CLK and the line 5+.
15 DATA ----------+--------- PIN
19 MODULE 5+ --------+--+--------- PWR CONTROLLER
23 CLK ------+------------ PIN
29 Note: This is not recommended, you may encounter jerky movement or unsent inputs. Please use interrupt or USART version if possible.
34 PS2_MOUSE_ENABLE = yes
35 PS2_USE_BUSYWAIT = yes
38 In your keyboard config.h:
41 #ifdef PS2_USE_BUSYWAIT
42 # define PS2_CLOCK_PORT PORTD
43 # define PS2_CLOCK_PIN PIND
44 # define PS2_CLOCK_DDR DDRD
45 # define PS2_CLOCK_BIT 1
46 # define PS2_DATA_PORT PORTD
47 # define PS2_DATA_PIN PIND
48 # define PS2_DATA_DDR DDRD
49 # define PS2_DATA_BIT 2
55 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.
60 PS2_MOUSE_ENABLE = yes
64 In your keyboard config.h:
68 #define PS2_CLOCK_PORT PORTD
69 #define PS2_CLOCK_PIN PIND
70 #define PS2_CLOCK_DDR DDRD
71 #define PS2_CLOCK_BIT 2
72 #define PS2_DATA_PORT PORTD
73 #define PS2_DATA_PIN PIND
74 #define PS2_DATA_DDR DDRD
75 #define PS2_DATA_BIT 5
77 #define PS2_INT_INIT() do { \
78 EICRA |= ((1<<ISC21) | \
81 #define PS2_INT_ON() do { \
84 #define PS2_INT_OFF() do { \
85 EIMSK &= ~(1<<INT2); \
87 #define PS2_INT_VECT INT2_vect
93 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.
98 PS2_MOUSE_ENABLE = yes
102 In your keyboard config.h:
106 #define PS2_CLOCK_PORT PORTD
107 #define PS2_CLOCK_PIN PIND
108 #define PS2_CLOCK_DDR DDRD
109 #define PS2_CLOCK_BIT 5
110 #define PS2_DATA_PORT PORTD
111 #define PS2_DATA_PIN PIND
112 #define PS2_DATA_DDR DDRD
113 #define PS2_DATA_BIT 2
115 /* synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling edge */
116 /* set DDR of CLOCK as input to be slave */
117 #define PS2_USART_INIT() do { \
118 PS2_CLOCK_DDR &= ~(1<<PS2_CLOCK_BIT); \
119 PS2_DATA_DDR &= ~(1<<PS2_DATA_BIT); \
120 UCSR1C = ((1 << UMSEL10) | \
129 #define PS2_USART_RX_INT_ON() do { \
130 UCSR1B = ((1 << RXCIE1) | \
133 #define PS2_USART_RX_POLL_ON() do { \
134 UCSR1B = (1 << RXEN1); \
136 #define PS2_USART_OFF() do { \
138 UCSR1B &= ~((1 << RXEN1) | \
141 #define PS2_USART_RX_READY (UCSR1A & (1<<RXC1))
142 #define PS2_USART_RX_DATA UDR1
143 #define PS2_USART_ERROR (UCSR1A & ((1<<FE1) | (1<<DOR1) | (1<<UPE1)))
144 #define PS2_USART_RX_VECT USART1_RX_vect
148 ### Additional Settings
150 #### PS/2 Mouse Features
152 These enable settings supported by the PS/2 mouse protocol: http://www.computer-engineering.org/ps2mouse/
155 /* Use remote mode instead of the default stream mode (see link) */
156 #define PS2_MOUSE_USE_REMOTE_MODE
158 /* Enable the scrollwheel or scroll gesture on your mouse or touchpad */
159 #define PS2_MOUSE_ENABLE_SCROLLING
161 /* Some mice will need a scroll mask to be configured. The default is 0xFF. */
162 #define PS2_MOUSE_SCROLL_MASK 0x0F
164 /* Applies a transformation to the movement before sending to the host (see link) */
165 #define PS2_MOUSE_USE_2_1_SCALING
167 /* The time to wait after initializing the ps2 host */
168 #define PS2_MOUSE_INIT_DELAY 1000 /* Default */
171 You can also call the following functions from ps2_mouse.h
174 void ps2_mouse_disable_data_reporting(void);
176 void ps2_mouse_enable_data_reporting(void);
178 void ps2_mouse_set_remote_mode(void);
180 void ps2_mouse_set_stream_mode(void);
182 void ps2_mouse_set_scaling_2_1(void);
184 void ps2_mouse_set_scaling_1_1(void);
186 void ps2_mouse_set_resolution(ps2_mouse_resolution_t resolution);
188 void ps2_mouse_set_sample_rate(ps2_mouse_sample_rate_t sample_rate);
193 Use the following defines to change the sensitivity and speed of the mouse.
194 Note: you can also use `ps2_mouse_set_resolution` for the same effect (not supported on most touchpads).
197 #define PS2_MOUSE_X_MULTIPLIER 3
198 #define PS2_MOUSE_Y_MULTIPLIER 3
199 #define PS2_MOUSE_V_MULTIPLIER 1
204 If you're using a trackpoint, you will likely want to be able to use it for scrolling.
205 Its possible to enable a "scroll button/s" that when pressed will cause the mouse to scroll instead of moving.
206 To enable the feature, you must set a scroll button mask as follows:
209 #define PS2_MOUSE_SCROLL_BTN_MASK (1<<PS2_MOUSE_BUTTON_MIDDLE) /* Default */
212 To disable the scroll button feature:
215 #define PS2_MOUSE_SCROLL_BTN_MASK 0
218 The available buttons are:
221 #define PS2_MOUSE_BTN_LEFT 0
222 #define PS2_MOUSE_BTN_RIGHT 1
223 #define PS2_MOUSE_BTN_MIDDLE 2
226 You can also combine buttons in the mask by `|`ing them together.
228 Once you've configured your scroll button mask, you must configure the scroll button send interval.
229 This is the interval before which if the scroll buttons were released they would be sent to the host.
230 After this interval, they will cause the mouse to scroll and will not be sent.
233 #define PS2_MOUSE_SCROLL_BTN_SEND 300 /* Default */
236 To disable sending the scroll buttons:
238 #define PS2_MOUSE_SCROLL_BTN_SEND 0
241 Fine control over the scrolling is supported with the following defines:
244 #define PS2_MOUSE_SCROLL_DIVISOR_H 2
245 #define PS2_MOUSE_SCROLL_DIVISOR_V 2
248 #### Invert Mouse and Scroll Axes
250 To invert the X and Y axes you can put:
253 #define PS2_MOUSE_INVERT_X
254 #define PS2_MOUSE_INVERT_Y
259 To reverse the scroll axes you can put:
262 #define PS2_MOUSE_INVERT_H
263 #define PS2_MOUSE_INVERT_V
270 To debug the mouse, add `debug_mouse = true` or enable via bootmagic.
273 /* To debug the mouse reports */
274 #define PS2_MOUSE_DEBUG_HID
275 #define PS2_MOUSE_DEBUG_RAW