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).
11 Note: This is not recommended, you may encounter jerky movement or unsent inputs. Please use interrupt or USART version if possible.
16 PS2_MOUSE_ENABLE = yes
17 PS2_USE_BUSYWAIT = yes
20 In your keyboard config.h:
23 #ifdef PS2_USE_BUSYWAIT
24 # define PS2_CLOCK_PORT PORTD
25 # define PS2_CLOCK_PIN PIND
26 # define PS2_CLOCK_DDR DDRD
27 # define PS2_CLOCK_BIT 1
28 # define PS2_DATA_PORT PORTD
29 # define PS2_DATA_PIN PIND
30 # define PS2_DATA_DDR DDRD
31 # define PS2_DATA_BIT 2
37 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.
42 PS2_MOUSE_ENABLE = yes
46 In your keyboard config.h:
50 #define PS2_CLOCK_PORT PORTD
51 #define PS2_CLOCK_PIN PIND
52 #define PS2_CLOCK_DDR DDRD
53 #define PS2_CLOCK_BIT 2
54 #define PS2_DATA_PORT PORTD
55 #define PS2_DATA_PIN PIND
56 #define PS2_DATA_DDR DDRD
57 #define PS2_DATA_BIT 5
59 #define PS2_INT_INIT() do { \
60 EICRA |= ((1<<ISC21) | \
63 #define PS2_INT_ON() do { \
66 #define PS2_INT_OFF() do { \
67 EIMSK &= ~(1<<INT2); \
69 #define PS2_INT_VECT INT2_vect
75 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.
80 PS2_MOUSE_ENABLE = yes
84 In your keyboard config.h:
88 #define PS2_CLOCK_PORT PORTD
89 #define PS2_CLOCK_PIN PIND
90 #define PS2_CLOCK_DDR DDRD
91 #define PS2_CLOCK_BIT 5
92 #define PS2_DATA_PORT PORTD
93 #define PS2_DATA_PIN PIND
94 #define PS2_DATA_DDR DDRD
95 #define PS2_DATA_BIT 2
97 /* synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling edge */
98 /* set DDR of CLOCK as input to be slave */
99 #define PS2_USART_INIT() do { \
100 PS2_CLOCK_DDR &= ~(1<<PS2_CLOCK_BIT); \
101 PS2_DATA_DDR &= ~(1<<PS2_DATA_BIT); \
102 UCSR1C = ((1 << UMSEL10) | \
111 #define PS2_USART_RX_INT_ON() do { \
112 UCSR1B = ((1 << RXCIE1) | \
115 #define PS2_USART_RX_POLL_ON() do { \
116 UCSR1B = (1 << RXEN1); \
118 #define PS2_USART_OFF() do { \
120 UCSR1B &= ~((1 << RXEN1) | \
123 #define PS2_USART_RX_READY (UCSR1A & (1<<RXC1))
124 #define PS2_USART_RX_DATA UDR1
125 #define PS2_USART_ERROR (UCSR1A & ((1<<FE1) | (1<<DOR1) | (1<<UPE1)))
126 #define PS2_USART_RX_VECT USART1_RX_vect
130 ### Additional Settings
132 #### PS/2 mouse features
134 These enable settings supported by the PS/2 mouse protocol: http://www.computer-engineering.org/ps2mouse/
137 /* Use remote mode instead of the default stream mode (see link) */
138 #define PS2_MOUSE_USE_REMOTE_MODE
140 /* Enable the scrollwheel or scroll gesture on your mouse or touchpad */
141 #define PS2_MOUSE_ENABLE_SCROLLING
143 /* Some mice will need a scroll mask to be configured. The default is 0xFF. */
144 #define PS2_MOUSE_SCROLL_MASK 0x0F
146 /* Applies a transformation to the movement before sending to the host (see link) */
147 #define PS2_MOUSE_USE_2_1_SCALING
149 /* The time to wait after initializing the ps2 host */
150 #define PS2_MOUSE_INIT_DELAY 1000 /* Default */
153 You can also call the following functions from ps2_mouse.h
156 void ps2_mouse_disable_data_reporting(void);
158 void ps2_mouse_enable_data_reporting(void);
160 void ps2_mouse_set_remote_mode(void);
162 void ps2_mouse_set_stream_mode(void);
164 void ps2_mouse_set_scaling_2_1(void);
166 void ps2_mouse_set_scaling_1_1(void);
168 void ps2_mouse_set_resolution(ps2_mouse_resolution_t resolution);
170 void ps2_mouse_set_sample_rate(ps2_mouse_sample_rate_t sample_rate);
175 Use the following defines to change the sensitivity and speed of the mouse.
176 Note: you can also use `ps2_mouse_set_resolution` for the same effect (not supported on most touchpads).
179 #define PS2_MOUSE_X_MULTIPLIER 3
180 #define PS2_MOUSE_Y_MULTIPLIER 3
181 #define PS2_MOUSE_V_MULTIPLIER 1
186 If you're using a trackpoint, you will likely want to be able to use it for scrolling.
187 Its possible to enable a "scroll button/s" that when pressed will cause the mouse to scroll instead of moving.
188 To enable the feature, you must set a scroll button mask as follows:
191 #define PS2_MOUSE_SCROLL_BTN_MASK (1<<PS2_MOUSE_BUTTON_MIDDLE) /* Default */
194 To disable the scroll button feature:
197 #define PS2_MOUSE_SCROLL_BTN_MASK 0
200 The available buttons are:
203 #define PS2_MOUSE_BTN_LEFT 0
204 #define PS2_MOUSE_BTN_RIGHT 1
205 #define PS2_MOUSE_BTN_MIDDLE 2
208 You can also combine buttons in the mask by `|`ing them together.
210 Once you've configured your scroll button mask, you must configure the scroll button send interval.
211 This is the interval before which if the scroll buttons were released they would be sent to the host.
212 After this interval, they will cause the mouse to scroll and will not be sent.
215 #define PS2_MOUSE_SCROLL_BTN_SEND 300 /* Default */
218 To disable sending the scroll buttons:
220 #define PS2_MOUSE_SCROLL_BTN_SEND 0
223 Fine control over the scrolling is supported with the following defines:
226 #define PS2_MOUSE_SCROLL_DIVISOR_H 2
227 #define PS2_MOUSE_SCROLL_DIVISOR_V 2
232 To debug the mouse, add `debug_mouse = true` or enable via bootmagic.
235 /* To debug the mouse reports */
236 #define PS2_MOUSE_DEBUG_HID
237 #define PS2_MOUSE_DEBUG_RAW