]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/protocol/ps2_mouse.h
Refactored and improved ps2 mouse feature
[qmk_firmware.git] / tmk_core / protocol / ps2_mouse.h
1 /*
2 Copyright 2011 Jun Wako <wakojun@gmail.com>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifndef PS2_MOUSE_H
19 #define  PS2_MOUSE_H
20
21 #include <stdbool.h>
22
23 /*
24  * Data format:
25  * byte|7       6       5       4       3       2       1       0
26  * ----+----------------------------------------------------------------
27  *    0|[Yovflw][Xovflw][Ysign ][Xsign ][ 1    ][Middle][Right ][Left  ]
28  *    1|[                    X movement(0-255)                         ]
29  *    2|[                    Y movement(0-255)                         ]
30  */
31 #define PS2_MOUSE_BTN_MASK      0x07
32 #define PS2_MOUSE_BTN_LEFT      0
33 #define PS2_MOUSE_BTN_RIGHT     1
34 #define PS2_MOUSE_BTN_MIDDLE    2
35 #define PS2_MOUSE_X_SIGN        4
36 #define PS2_MOUSE_Y_SIGN        5
37 #define PS2_MOUSE_X_OVFLW       6
38 #define PS2_MOUSE_Y_OVFLW       7
39
40 /* mouse button to start scrolling; set 0 to disable scroll */
41 #ifndef PS2_MOUSE_SCROLL_BTN_MASK
42 #define PS2_MOUSE_SCROLL_BTN_MASK       (1<<PS2_MOUSE_BTN_MIDDLE)
43 #endif
44 /* send button event when button is released within this value(ms); set 0 to disable  */
45 #ifndef PS2_MOUSE_SCROLL_BTN_SEND
46 #define PS2_MOUSE_SCROLL_BTN_SEND       300
47 #endif
48 /* divide virtical and horizontal mouse move by this to convert to scroll move */
49 #ifndef PS2_MOUSE_SCROLL_DIVISOR_V
50 #define PS2_MOUSE_SCROLL_DIVISOR_V      2
51 #endif
52 #ifndef PS2_MOUSE_SCROLL_DIVISOR_H
53 #define PS2_MOUSE_SCROLL_DIVISOR_H      2
54 #endif
55 /* multiply reported mouse values by these */
56 #ifndef PS2_MOUSE_X_MULTIPLIER
57 #define PS2_MOUSE_X_MULTIPLIER          1
58 #endif
59 #ifndef PS2_MOUSE_Y_MULTIPLIER
60 #define PS2_MOUSE_Y_MULTIPLIER          1
61 #endif
62 #ifndef PS2_MOUSE_V_MULTIPLIER
63 #define PS2_MOUSE_V_MULTIPLIER          1
64 #endif
65 /* For some mice this will need to be 0x0F */
66 #ifndef PS2_MOUSE_SCROLL_MASK       
67 #define PS2_MOUSE_SCROLL_MASK           0xFF 
68 #endif
69
70 enum ps2_mouse_command_e {
71     PS2_MOUSE_RESET = 0xFF,
72     PS2_MOUSE_RESEND = 0xFE,
73     PS2_MOSUE_SET_DEFAULTS = 0xF6,
74     PS2_MOUSE_DISABLE_DATA_REPORTING = 0xF5,
75     PS2_MOUSE_ENABLE_DATA_REPORTING = 0xF4,
76     PS2_MOUSE_SET_SAMPLE_RATE = 0xF3,
77     PS2_MOUSE_GET_DEVICE_ID = 0xF2,
78     PS2_MOUSE_SET_REMOTE_MODE = 0xF0,
79     PS2_MOUSE_SET_WRAP_MODE = 0xEC,
80     PS2_MOUSE_READ_DATA = 0xEB,
81     PS2_MOUSE_SET_STREAM_MODE = 0xEA,
82     PS2_MOUSE_STATUS_REQUEST = 0xE9,
83     PS2_MOUSE_SET_RESOLUTION = 0xE8,
84     PS2_MOUSE_SET_SCALING_2_1 = 0xE7,
85     PS2_MOUSE_SET_SCALING_1_1 = 0xE6,
86 };
87
88 typedef enum ps2_mouse_resolution_e {
89     PS2_MOUSE_1_COUNT_MM,
90     PS2_MOUSE_2_COUNT_MM,
91     PS2_MOUSE_4_COUNT_MM,
92     PS2_MOUSE_8_COUNT_MM,   
93 } ps2_mouse_resolution_t;
94
95 typedef enum ps2_mouse_sample_rate_e {
96     PS2_MOUSE_10_SAMPLES_SEC = 10,
97     PS2_MOUSE_20_SAMPLES_SEC = 20,
98     PS2_MOUSE_40_SAMPLES_SEC = 40,
99     PS2_MOUSE_60_SAMPLES_SEC = 60,
100     PS2_MOUSE_80_SAMPLES_SEC = 80,
101     PS2_MOUSE_100_SAMPLES_SEC = 100,
102     PS2_MOUSE_200_SAMPLES_SEC = 200,
103 } ps2_mouse_sample_rate_t;
104
105 void ps2_mouse_init(void);
106
107 void ps2_mouse_task(void);
108
109 void ps2_mouse_disable_data_reporting(void);
110
111 void ps2_mouse_enable_data_reporting(void);
112
113 void ps2_mouse_set_remote_mode(void);
114
115 void ps2_mouse_set_stream_mode(void);
116
117 void ps2_mouse_set_scaling_2_1(void);
118
119 void ps2_mouse_set_scaling_1_1(void);
120
121 void ps2_mouse_set_resolution(ps2_mouse_resolution_t resolution);
122
123 void ps2_mouse_set_sample_rate(ps2_mouse_sample_rate_t sample_rate);
124
125 #endif