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 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 uint8_t rcv = ps2_host_recv_response(); \
61 xprintf(" result: %X, error: %X \n", rcv, ps2_error); \
65 static enum ps2_mouse_mode_e
{
66 PS2_MOUSE_STREAM_MODE
,
67 PS2_MOUSE_REMOTE_MODE
,
68 } ps2_mouse_mode
= PS2_MOUSE_STREAM_MODE
;
72 * byte|7 6 5 4 3 2 1 0
73 * ----+----------------------------------------------------------------
74 * 0|[Yovflw][Xovflw][Ysign ][Xsign ][ 1 ][Middle][Right ][Left ]
75 * 1|[ X movement(0-255) ]
76 * 2|[ Y movement(0-255) ]
78 #define PS2_MOUSE_BTN_MASK 0x07
79 #define PS2_MOUSE_BTN_LEFT 0
80 #define PS2_MOUSE_BTN_RIGHT 1
81 #define PS2_MOUSE_BTN_MIDDLE 2
82 #define PS2_MOUSE_X_SIGN 4
83 #define PS2_MOUSE_Y_SIGN 5
84 #define PS2_MOUSE_X_OVFLW 6
85 #define PS2_MOUSE_Y_OVFLW 7
87 /* mouse button to start scrolling; set 0 to disable scroll */
88 #ifndef PS2_MOUSE_SCROLL_BTN_MASK
89 #define PS2_MOUSE_SCROLL_BTN_MASK (1<<PS2_MOUSE_BTN_MIDDLE)
91 /* send button event when button is released within this value(ms); set 0 to disable */
92 #ifndef PS2_MOUSE_SCROLL_BTN_SEND
93 #define PS2_MOUSE_SCROLL_BTN_SEND 300
95 /* divide virtical and horizontal mouse move by this to convert to scroll move */
96 #ifndef PS2_MOUSE_SCROLL_DIVISOR_V
97 #define PS2_MOUSE_SCROLL_DIVISOR_V 2
99 #ifndef PS2_MOUSE_SCROLL_DIVISOR_H
100 #define PS2_MOUSE_SCROLL_DIVISOR_H 2
102 /* multiply reported mouse values by these */
103 #ifndef PS2_MOUSE_X_MULTIPLIER
104 #define PS2_MOUSE_X_MULTIPLIER 1
106 #ifndef PS2_MOUSE_Y_MULTIPLIER
107 #define PS2_MOUSE_Y_MULTIPLIER 1
109 #ifndef PS2_MOUSE_V_MULTIPLIER
110 #define PS2_MOUSE_V_MULTIPLIER 1
112 /* For some mice this will need to be 0x0F */
113 #ifndef PS2_MOUSE_SCROLL_MASK
114 #define PS2_MOUSE_SCROLL_MASK 0xFF
116 #ifndef PS2_MOUSE_INIT_DELAY
117 #define PS2_MOUSE_INIT_DELAY 1000
120 enum ps2_mouse_command_e
{
121 PS2_MOUSE_RESET
= 0xFF,
122 PS2_MOUSE_RESEND
= 0xFE,
123 PS2_MOSUE_SET_DEFAULTS
= 0xF6,
124 PS2_MOUSE_DISABLE_DATA_REPORTING
= 0xF5,
125 PS2_MOUSE_ENABLE_DATA_REPORTING
= 0xF4,
126 PS2_MOUSE_SET_SAMPLE_RATE
= 0xF3,
127 PS2_MOUSE_GET_DEVICE_ID
= 0xF2,
128 PS2_MOUSE_SET_REMOTE_MODE
= 0xF0,
129 PS2_MOUSE_SET_WRAP_MODE
= 0xEC,
130 PS2_MOUSE_READ_DATA
= 0xEB,
131 PS2_MOUSE_SET_STREAM_MODE
= 0xEA,
132 PS2_MOUSE_STATUS_REQUEST
= 0xE9,
133 PS2_MOUSE_SET_RESOLUTION
= 0xE8,
134 PS2_MOUSE_SET_SCALING_2_1
= 0xE7,
135 PS2_MOUSE_SET_SCALING_1_1
= 0xE6,
138 typedef enum ps2_mouse_resolution_e
{
139 PS2_MOUSE_1_COUNT_MM
,
140 PS2_MOUSE_2_COUNT_MM
,
141 PS2_MOUSE_4_COUNT_MM
,
142 PS2_MOUSE_8_COUNT_MM
,
143 } ps2_mouse_resolution_t
;
145 typedef enum ps2_mouse_sample_rate_e
{
146 PS2_MOUSE_10_SAMPLES_SEC
= 10,
147 PS2_MOUSE_20_SAMPLES_SEC
= 20,
148 PS2_MOUSE_40_SAMPLES_SEC
= 40,
149 PS2_MOUSE_60_SAMPLES_SEC
= 60,
150 PS2_MOUSE_80_SAMPLES_SEC
= 80,
151 PS2_MOUSE_100_SAMPLES_SEC
= 100,
152 PS2_MOUSE_200_SAMPLES_SEC
= 200,
153 } ps2_mouse_sample_rate_t
;
155 void ps2_mouse_init(void);
157 void ps2_mouse_init_user(void);
159 void ps2_mouse_task(void);
161 void ps2_mouse_disable_data_reporting(void);
163 void ps2_mouse_enable_data_reporting(void);
165 void ps2_mouse_set_remote_mode(void);
167 void ps2_mouse_set_stream_mode(void);
169 void ps2_mouse_set_scaling_2_1(void);
171 void ps2_mouse_set_scaling_1_1(void);
173 void ps2_mouse_set_resolution(ps2_mouse_resolution_t resolution
);
175 void ps2_mouse_set_sample_rate(ps2_mouse_sample_rate_t sample_rate
);