Commit | Line | Data |
---|---|---|
a074364c | 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> | |
d059624b PIN |
22 | #include "debug.h" |
23 | ||
24 | #define PS2_MOUSE_SEND(command, message) \ | |
25 | do { \ | |
aaa58a8d | 26 | __attribute__ ((unused)) uint8_t rcv = ps2_host_send(command); \ |
d059624b PIN |
27 | if (debug_mouse) { \ |
28 | print((message)); \ | |
29 | xprintf(" command: %X, result: %X, error: %X \n", command, rcv, ps2_error); \ | |
30 | } \ | |
31 | } while(0) | |
32 | ||
33 | #define PS2_MOUSE_SEND_SAFE(command, message) \ | |
34 | do { \ | |
35 | if (PS2_MOUSE_STREAM_MODE == ps2_mouse_mode) { \ | |
36 | ps2_mouse_disable_data_reporting(); \ | |
37 | } \ | |
38 | PS2_MOUSE_SEND(command, message); \ | |
39 | if (PS2_MOUSE_STREAM_MODE == ps2_mouse_mode) { \ | |
40 | ps2_mouse_enable_data_reporting(); \ | |
41 | } \ | |
42 | } while(0) | |
43 | ||
44 | #define PS2_MOUSE_SET_SAFE(command, value, message) \ | |
45 | do { \ | |
46 | if (PS2_MOUSE_STREAM_MODE == ps2_mouse_mode) { \ | |
47 | ps2_mouse_disable_data_reporting(); \ | |
48 | } \ | |
49 | PS2_MOUSE_SEND(command, message); \ | |
50 | PS2_MOUSE_SEND(value, "Sending value"); \ | |
51 | if (PS2_MOUSE_STREAM_MODE == ps2_mouse_mode) { \ | |
52 | ps2_mouse_enable_data_reporting(); \ | |
53 | } \ | |
54 | } while(0) | |
55 | ||
56 | #define PS2_MOUSE_RECEIVE(message) \ | |
57 | do { \ | |
aaa58a8d | 58 | __attribute__ ((unused)) uint8_t rcv = ps2_host_recv_response(); \ |
d059624b PIN |
59 | if (debug_mouse) { \ |
60 | print((message)); \ | |
61 | xprintf(" result: %X, error: %X \n", rcv, ps2_error); \ | |
62 | } \ | |
63 | } while(0) | |
64 | ||
aaa58a8d | 65 | __attribute__ ((unused)) |
d059624b PIN |
66 | static enum ps2_mouse_mode_e { |
67 | PS2_MOUSE_STREAM_MODE, | |
68 | PS2_MOUSE_REMOTE_MODE, | |
69 | } ps2_mouse_mode = PS2_MOUSE_STREAM_MODE; | |
a074364c | 70 | |
a074364c | 71 | /* |
72 | * Data format: | |
73 | * byte|7 6 5 4 3 2 1 0 | |
d639e08a | 74 | * ----+---------------------------------------------------------------- |
75 | * 0|[Yovflw][Xovflw][Ysign ][Xsign ][ 1 ][Middle][Right ][Left ] | |
76 | * 1|[ X movement(0-255) ] | |
77 | * 2|[ Y movement(0-255) ] | |
a074364c | 78 | */ |
79 | #define PS2_MOUSE_BTN_MASK 0x07 | |
80 | #define PS2_MOUSE_BTN_LEFT 0 | |
81 | #define PS2_MOUSE_BTN_RIGHT 1 | |
82 | #define PS2_MOUSE_BTN_MIDDLE 2 | |
83 | #define PS2_MOUSE_X_SIGN 4 | |
84 | #define PS2_MOUSE_Y_SIGN 5 | |
85 | #define PS2_MOUSE_X_OVFLW 6 | |
86 | #define PS2_MOUSE_Y_OVFLW 7 | |
87 | ||
a074364c | 88 | /* mouse button to start scrolling; set 0 to disable scroll */ |
89 | #ifndef PS2_MOUSE_SCROLL_BTN_MASK | |
90 | #define PS2_MOUSE_SCROLL_BTN_MASK (1<<PS2_MOUSE_BTN_MIDDLE) | |
91 | #endif | |
92 | /* send button event when button is released within this value(ms); set 0 to disable */ | |
93 | #ifndef PS2_MOUSE_SCROLL_BTN_SEND | |
94 | #define PS2_MOUSE_SCROLL_BTN_SEND 300 | |
95 | #endif | |
96 | /* divide virtical and horizontal mouse move by this to convert to scroll move */ | |
97 | #ifndef PS2_MOUSE_SCROLL_DIVISOR_V | |
98 | #define PS2_MOUSE_SCROLL_DIVISOR_V 2 | |
99 | #endif | |
100 | #ifndef PS2_MOUSE_SCROLL_DIVISOR_H | |
101 | #define PS2_MOUSE_SCROLL_DIVISOR_H 2 | |
102 | #endif | |
d639e08a | 103 | /* multiply reported mouse values by these */ |
104 | #ifndef PS2_MOUSE_X_MULTIPLIER | |
105 | #define PS2_MOUSE_X_MULTIPLIER 1 | |
106 | #endif | |
107 | #ifndef PS2_MOUSE_Y_MULTIPLIER | |
108 | #define PS2_MOUSE_Y_MULTIPLIER 1 | |
109 | #endif | |
110 | #ifndef PS2_MOUSE_V_MULTIPLIER | |
111 | #define PS2_MOUSE_V_MULTIPLIER 1 | |
112 | #endif | |
113 | /* For some mice this will need to be 0x0F */ | |
114 | #ifndef PS2_MOUSE_SCROLL_MASK | |
115 | #define PS2_MOUSE_SCROLL_MASK 0xFF | |
116 | #endif | |
9f41544e OP |
117 | #ifndef PS2_MOUSE_INIT_DELAY |
118 | #define PS2_MOUSE_INIT_DELAY 1000 | |
119 | #endif | |
d639e08a | 120 | |
121 | enum ps2_mouse_command_e { | |
122 | PS2_MOUSE_RESET = 0xFF, | |
123 | PS2_MOUSE_RESEND = 0xFE, | |
124 | PS2_MOSUE_SET_DEFAULTS = 0xF6, | |
125 | PS2_MOUSE_DISABLE_DATA_REPORTING = 0xF5, | |
126 | PS2_MOUSE_ENABLE_DATA_REPORTING = 0xF4, | |
127 | PS2_MOUSE_SET_SAMPLE_RATE = 0xF3, | |
128 | PS2_MOUSE_GET_DEVICE_ID = 0xF2, | |
129 | PS2_MOUSE_SET_REMOTE_MODE = 0xF0, | |
130 | PS2_MOUSE_SET_WRAP_MODE = 0xEC, | |
131 | PS2_MOUSE_READ_DATA = 0xEB, | |
132 | PS2_MOUSE_SET_STREAM_MODE = 0xEA, | |
133 | PS2_MOUSE_STATUS_REQUEST = 0xE9, | |
134 | PS2_MOUSE_SET_RESOLUTION = 0xE8, | |
135 | PS2_MOUSE_SET_SCALING_2_1 = 0xE7, | |
136 | PS2_MOUSE_SET_SCALING_1_1 = 0xE6, | |
137 | }; | |
138 | ||
139 | typedef enum ps2_mouse_resolution_e { | |
140 | PS2_MOUSE_1_COUNT_MM, | |
141 | PS2_MOUSE_2_COUNT_MM, | |
142 | PS2_MOUSE_4_COUNT_MM, | |
143 | PS2_MOUSE_8_COUNT_MM, | |
144 | } ps2_mouse_resolution_t; | |
a074364c | 145 | |
d639e08a | 146 | typedef enum ps2_mouse_sample_rate_e { |
147 | PS2_MOUSE_10_SAMPLES_SEC = 10, | |
148 | PS2_MOUSE_20_SAMPLES_SEC = 20, | |
149 | PS2_MOUSE_40_SAMPLES_SEC = 40, | |
150 | PS2_MOUSE_60_SAMPLES_SEC = 60, | |
151 | PS2_MOUSE_80_SAMPLES_SEC = 80, | |
152 | PS2_MOUSE_100_SAMPLES_SEC = 100, | |
153 | PS2_MOUSE_200_SAMPLES_SEC = 200, | |
154 | } ps2_mouse_sample_rate_t; | |
155 | ||
156 | void ps2_mouse_init(void); | |
a074364c | 157 | |
d059624b PIN |
158 | void ps2_mouse_init_user(void); |
159 | ||
a074364c | 160 | void ps2_mouse_task(void); |
161 | ||
d639e08a | 162 | void ps2_mouse_disable_data_reporting(void); |
163 | ||
164 | void ps2_mouse_enable_data_reporting(void); | |
165 | ||
166 | void ps2_mouse_set_remote_mode(void); | |
167 | ||
168 | void ps2_mouse_set_stream_mode(void); | |
169 | ||
170 | void ps2_mouse_set_scaling_2_1(void); | |
171 | ||
172 | void ps2_mouse_set_scaling_1_1(void); | |
173 | ||
174 | void ps2_mouse_set_resolution(ps2_mouse_resolution_t resolution); | |
175 | ||
176 | void ps2_mouse_set_sample_rate(ps2_mouse_sample_rate_t sample_rate); | |
177 | ||
a074364c | 178 | #endif |