diff options
Diffstat (limited to 'docs/feature_ps2_mouse.md')
-rw-r--r-- | docs/feature_ps2_mouse.md | 238 |
1 files changed, 238 insertions, 0 deletions
diff --git a/docs/feature_ps2_mouse.md b/docs/feature_ps2_mouse.md new file mode 100644 index 000000000..8629b28cf --- /dev/null +++ b/docs/feature_ps2_mouse.md | |||
@@ -0,0 +1,238 @@ | |||
1 | ## PS/2 Mouse Support | ||
2 | |||
3 | Its possible to hook up a PS/2 mouse (for example touchpads or trackpoints) to your keyboard as a composite device. | ||
4 | |||
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. | ||
6 | |||
7 | There are three available modes for hooking up PS/2 devices: USART (best), interrupts (better) or busywait (not recommended). | ||
8 | |||
9 | ### Busywait version | ||
10 | |||
11 | Note: This is not recommended, you may encounter jerky movement or unsent inputs. Please use interrupt or USART version if possible. | ||
12 | |||
13 | In rules.mk: | ||
14 | |||
15 | ``` | ||
16 | PS2_MOUSE_ENABLE = yes | ||
17 | PS2_USE_BUSYWAIT = yes | ||
18 | ``` | ||
19 | |||
20 | In your keyboard config.h: | ||
21 | |||
22 | ``` | ||
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 | ||
32 | #endif | ||
33 | ``` | ||
34 | |||
35 | ### Interrupt version | ||
36 | |||
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. | ||
38 | |||
39 | In rules.mk: | ||
40 | |||
41 | ``` | ||
42 | PS2_MOUSE_ENABLE = yes | ||
43 | PS2_USE_INT = yes | ||
44 | ``` | ||
45 | |||
46 | In your keyboard config.h: | ||
47 | |||
48 | ``` | ||
49 | #ifdef PS2_USE_INT | ||
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 | ||
58 | |||
59 | #define PS2_INT_INIT() do { \ | ||
60 | EICRA |= ((1<<ISC21) | \ | ||
61 | (0<<ISC20)); \ | ||
62 | } while (0) | ||
63 | #define PS2_INT_ON() do { \ | ||
64 | EIMSK |= (1<<INT2); \ | ||
65 | } while (0) | ||
66 | #define PS2_INT_OFF() do { \ | ||
67 | EIMSK &= ~(1<<INT2); \ | ||
68 | } while (0) | ||
69 | #define PS2_INT_VECT INT2_vect | ||
70 | #endif | ||
71 | ``` | ||
72 | |||
73 | ### USART version | ||
74 | |||
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. | ||
76 | |||
77 | In rules.mk: | ||
78 | |||
79 | ``` | ||
80 | PS2_MOUSE_ENABLE = yes | ||
81 | PS2_USE_USART = yes | ||
82 | ``` | ||
83 | |||
84 | In your keyboard config.h: | ||
85 | |||
86 | ``` | ||
87 | #ifdef PS2_USE_USART | ||
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 | ||
96 | |||
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) | \ | ||
103 | (3 << UPM10) | \ | ||
104 | (0 << USBS1) | \ | ||
105 | (3 << UCSZ10) | \ | ||
106 | (0 << UCPOL1)); \ | ||
107 | UCSR1A = 0; \ | ||
108 | UBRR1H = 0; \ | ||
109 | UBRR1L = 0; \ | ||
110 | } while (0) | ||
111 | #define PS2_USART_RX_INT_ON() do { \ | ||
112 | UCSR1B = ((1 << RXCIE1) | \ | ||
113 | (1 << RXEN1)); \ | ||
114 | } while (0) | ||
115 | #define PS2_USART_RX_POLL_ON() do { \ | ||
116 | UCSR1B = (1 << RXEN1); \ | ||
117 | } while (0) | ||
118 | #define PS2_USART_OFF() do { \ | ||
119 | UCSR1C = 0; \ | ||
120 | UCSR1B &= ~((1 << RXEN1) | \ | ||
121 | (1 << TXEN1)); \ | ||
122 | } while (0) | ||
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 | ||
127 | #endif | ||
128 | ``` | ||
129 | |||
130 | ### Additional Settings | ||
131 | |||
132 | #### PS/2 mouse features | ||
133 | |||
134 | These enable settings supported by the PS/2 mouse protocol: http://www.computer-engineering.org/ps2mouse/ | ||
135 | |||
136 | ``` | ||
137 | /* Use remote mode instead of the default stream mode (see link) */ | ||
138 | #define PS2_MOUSE_USE_REMOTE_MODE | ||
139 | |||
140 | /* Enable the scrollwheel or scroll gesture on your mouse or touchpad */ | ||
141 | #define PS2_MOUSE_ENABLE_SCROLLING | ||
142 | |||
143 | /* Some mice will need a scroll mask to be configured. The default is 0xFF. */ | ||
144 | #define PS2_MOUSE_SCROLL_MASK 0x0F | ||
145 | |||
146 | /* Applies a transformation to the movement before sending to the host (see link) */ | ||
147 | #define PS2_MOUSE_USE_2_1_SCALING | ||
148 | |||
149 | /* The time to wait after initializing the ps2 host */ | ||
150 | #define PS2_MOUSE_INIT_DELAY 1000 /* Default */ | ||
151 | ``` | ||
152 | |||
153 | You can also call the following functions from ps2_mouse.h | ||
154 | |||
155 | ``` | ||
156 | void ps2_mouse_disable_data_reporting(void); | ||
157 | |||
158 | void ps2_mouse_enable_data_reporting(void); | ||
159 | |||
160 | void ps2_mouse_set_remote_mode(void); | ||
161 | |||
162 | void ps2_mouse_set_stream_mode(void); | ||
163 | |||
164 | void ps2_mouse_set_scaling_2_1(void); | ||
165 | |||
166 | void ps2_mouse_set_scaling_1_1(void); | ||
167 | |||
168 | void ps2_mouse_set_resolution(ps2_mouse_resolution_t resolution); | ||
169 | |||
170 | void ps2_mouse_set_sample_rate(ps2_mouse_sample_rate_t sample_rate); | ||
171 | ``` | ||
172 | |||
173 | #### Fine control | ||
174 | |||
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). | ||
177 | |||
178 | ``` | ||
179 | #define PS2_MOUSE_X_MULTIPLIER 3 | ||
180 | #define PS2_MOUSE_Y_MULTIPLIER 3 | ||
181 | #define PS2_MOUSE_V_MULTIPLIER 1 | ||
182 | ``` | ||
183 | |||
184 | #### Scroll button | ||
185 | |||
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: | ||
189 | |||
190 | ``` | ||
191 | #define PS2_MOUSE_SCROLL_BTN_MASK (1<<PS2_MOUSE_BUTTON_MIDDLE) /* Default */ | ||
192 | ``` | ||
193 | |||
194 | To disable the scroll button feature: | ||
195 | |||
196 | ``` | ||
197 | #define PS2_MOUSE_SCROLL_BTN_MASK 0 | ||
198 | ``` | ||
199 | |||
200 | The available buttons are: | ||
201 | |||
202 | ``` | ||
203 | #define PS2_MOUSE_BTN_LEFT 0 | ||
204 | #define PS2_MOUSE_BTN_RIGHT 1 | ||
205 | #define PS2_MOUSE_BTN_MIDDLE 2 | ||
206 | ``` | ||
207 | |||
208 | You can also combine buttons in the mask by `|`ing them together. | ||
209 | |||
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. | ||
213 | |||
214 | ``` | ||
215 | #define PS2_MOUSE_SCROLL_BTN_SEND 300 /* Default */ | ||
216 | ``` | ||
217 | |||
218 | To disable sending the scroll buttons: | ||
219 | ``` | ||
220 | #define PS2_MOUSE_SCROLL_BTN_SEND 0 | ||
221 | ``` | ||
222 | |||
223 | Fine control over the scrolling is supported with the following defines: | ||
224 | |||
225 | ``` | ||
226 | #define PS2_MOUSE_SCROLL_DIVISOR_H 2 | ||
227 | #define PS2_MOUSE_SCROLL_DIVISOR_V 2 | ||
228 | ``` | ||
229 | |||
230 | #### Debug settings | ||
231 | |||
232 | To debug the mouse, add `debug_mouse = true` or enable via bootmagic. | ||
233 | |||
234 | ``` | ||
235 | /* To debug the mouse reports */ | ||
236 | #define PS2_MOUSE_DEBUG_HID | ||
237 | #define PS2_MOUSE_DEBUG_RAW | ||
238 | ``` | ||