2 Copyright 2011 Jun Wako <wakojun@gmail.com>
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.
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.
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/>.
24 #define PS2_MOUSE_SEND(command, message) \
26 __attribute__ ((unused)) uint8_t rcv = ps2_host_send(command); \
29 xprintf(" command: %X, result: %X, error: %X \n", command, rcv, ps2_error); \
33 #define PS2_MOUSE_SEND_SAFE(command, message) \
35 if (PS2_MOUSE_STREAM_MODE == ps2_mouse_mode) { \
36 ps2_mouse_disable_data_reporting(); \
38 PS2_MOUSE_SEND(command, message); \
39 if (PS2_MOUSE_STREAM_MODE == ps2_mouse_mode) { \
40 ps2_mouse_enable_data_reporting(); \
44 #define PS2_MOUSE_SET_SAFE(command, value, message) \
46 if (PS2_MOUSE_STREAM_MODE == ps2_mouse_mode) { \
47 ps2_mouse_disable_data_reporting(); \
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(); \
56 #define PS2_MOUSE_RECEIVE(message) \
58 __attribute__ ((unused)) uint8_t rcv = ps2_host_recv_response(); \
61 xprintf(" result: %X, error: %X \n", rcv, ps2_error); \
65 __attribute__ ((unused))
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;
73 * byte|7 6 5 4 3 2 1 0
74 * ----+----------------------------------------------------------------
75 * 0|[Yovflw][Xovflw][Ysign ][Xsign ][ 1 ][Middle][Right ][Left ]
76 * 1|[ X movement(0-255) ]
77 * 2|[ Y movement(0-255) ]
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
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)
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
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
100 #ifndef PS2_MOUSE_SCROLL_DIVISOR_H
101 #define PS2_MOUSE_SCROLL_DIVISOR_H 2
103 /* multiply reported mouse values by these */
104 #ifndef PS2_MOUSE_X_MULTIPLIER
105 #define PS2_MOUSE_X_MULTIPLIER 1
107 #ifndef PS2_MOUSE_Y_MULTIPLIER
108 #define PS2_MOUSE_Y_MULTIPLIER 1
110 #ifndef PS2_MOUSE_V_MULTIPLIER
111 #define PS2_MOUSE_V_MULTIPLIER 1
113 /* For some mice this will need to be 0x0F */
114 #ifndef PS2_MOUSE_SCROLL_MASK
115 #define PS2_MOUSE_SCROLL_MASK 0xFF
117 #ifndef PS2_MOUSE_INIT_DELAY
118 #define PS2_MOUSE_INIT_DELAY 1000
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,
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;
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;
156 void ps2_mouse_init(void);
158 void ps2_mouse_init_user(void);
160 void ps2_mouse_task(void);
162 void ps2_mouse_disable_data_reporting(void);
164 void ps2_mouse_enable_data_reporting(void);
166 void ps2_mouse_set_remote_mode(void);
168 void ps2_mouse_set_stream_mode(void);
170 void ps2_mouse_set_scaling_2_1(void);
172 void ps2_mouse_set_scaling_1_1(void);
174 void ps2_mouse_set_resolution(ps2_mouse_resolution_t resolution);
176 void ps2_mouse_set_sample_rate(ps2_mouse_sample_rate_t sample_rate);