aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/protocol/ps2_mouse.h
diff options
context:
space:
mode:
authorclimbalima <climbalima@gmail.com>2016-12-10 23:15:47 -0500
committerclimbalima <climbalima@gmail.com>2016-12-10 23:15:47 -0500
commit73d60182969023984ff275117d49a4824c6987d0 (patch)
treefdac811b117c49f78de04c407d4bef76e6df5772 /tmk_core/protocol/ps2_mouse.h
parent56515ba5034e83c598891686cfdc43c186e5d487 (diff)
parent985a091a739c99736d5b17de5161831488dbc219 (diff)
downloadqmk_firmware-73d60182969023984ff275117d49a4824c6987d0.tar.gz
qmk_firmware-73d60182969023984ff275117d49a4824c6987d0.zip
Merge branch 'master' of https://github.com/jackhumbert/qmk_firmware
Diffstat (limited to 'tmk_core/protocol/ps2_mouse.h')
-rw-r--r--tmk_core/protocol/ps2_mouse.h131
1 files changed, 121 insertions, 10 deletions
diff --git a/tmk_core/protocol/ps2_mouse.h b/tmk_core/protocol/ps2_mouse.h
index 27d9790d4..3c93a4634 100644
--- a/tmk_core/protocol/ps2_mouse.h
+++ b/tmk_core/protocol/ps2_mouse.h
@@ -19,16 +19,61 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
19#define PS2_MOUSE_H 19#define PS2_MOUSE_H
20 20
21#include <stdbool.h> 21#include <stdbool.h>
22#include "debug.h"
22 23
23#define PS2_MOUSE_READ_DATA 0xEB 24#define PS2_MOUSE_SEND(command, message) \
25do { \
26 uint8_t rcv = ps2_host_send(command); \
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) \
34do { \
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) \
45do { \
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) \
57do { \
58 uint8_t rcv = ps2_host_recv_response(); \
59 if (debug_mouse) { \
60 print((message)); \
61 xprintf(" result: %X, error: %X \n", rcv, ps2_error); \
62 } \
63} while(0)
64
65static enum ps2_mouse_mode_e {
66 PS2_MOUSE_STREAM_MODE,
67 PS2_MOUSE_REMOTE_MODE,
68} ps2_mouse_mode = PS2_MOUSE_STREAM_MODE;
24 69
25/* 70/*
26 * Data format: 71 * Data format:
27 * byte|7 6 5 4 3 2 1 0 72 * byte|7 6 5 4 3 2 1 0
28 * ----+-------------------------------------------------------------- 73 * ----+----------------------------------------------------------------
29 * 0|Yovflw Xovflw Ysign Xsign 1 Middle Right Left 74 * 0|[Yovflw][Xovflw][Ysign ][Xsign ][ 1 ][Middle][Right ][Left ]
30 * 1| X movement(0-255) 75 * 1|[ X movement(0-255) ]
31 * 2| Y movement(0-255) 76 * 2|[ Y movement(0-255) ]
32 */ 77 */
33#define PS2_MOUSE_BTN_MASK 0x07 78#define PS2_MOUSE_BTN_MASK 0x07
34#define PS2_MOUSE_BTN_LEFT 0 79#define PS2_MOUSE_BTN_LEFT 0
@@ -39,10 +84,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
39#define PS2_MOUSE_X_OVFLW 6 84#define PS2_MOUSE_X_OVFLW 6
40#define PS2_MOUSE_Y_OVFLW 7 85#define PS2_MOUSE_Y_OVFLW 7
41 86
42
43/*
44 * Scroll by mouse move with pressing button
45 */
46/* mouse button to start scrolling; set 0 to disable scroll */ 87/* mouse button to start scrolling; set 0 to disable scroll */
47#ifndef PS2_MOUSE_SCROLL_BTN_MASK 88#ifndef PS2_MOUSE_SCROLL_BTN_MASK
48#define PS2_MOUSE_SCROLL_BTN_MASK (1<<PS2_MOUSE_BTN_MIDDLE) 89#define PS2_MOUSE_SCROLL_BTN_MASK (1<<PS2_MOUSE_BTN_MIDDLE)
@@ -58,9 +99,79 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
58#ifndef PS2_MOUSE_SCROLL_DIVISOR_H 99#ifndef PS2_MOUSE_SCROLL_DIVISOR_H
59#define PS2_MOUSE_SCROLL_DIVISOR_H 2 100#define PS2_MOUSE_SCROLL_DIVISOR_H 2
60#endif 101#endif
102/* multiply reported mouse values by these */
103#ifndef PS2_MOUSE_X_MULTIPLIER
104#define PS2_MOUSE_X_MULTIPLIER 1
105#endif
106#ifndef PS2_MOUSE_Y_MULTIPLIER
107#define PS2_MOUSE_Y_MULTIPLIER 1
108#endif
109#ifndef PS2_MOUSE_V_MULTIPLIER
110#define PS2_MOUSE_V_MULTIPLIER 1
111#endif
112/* For some mice this will need to be 0x0F */
113#ifndef PS2_MOUSE_SCROLL_MASK
114#define PS2_MOUSE_SCROLL_MASK 0xFF
115#endif
116#ifndef PS2_MOUSE_INIT_DELAY
117#define PS2_MOUSE_INIT_DELAY 1000
118#endif
61 119
120enum 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,
136};
137
138typedef 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;
144
145typedef 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;
154
155void ps2_mouse_init(void);
156
157void ps2_mouse_init_user(void);
62 158
63uint8_t ps2_mouse_init(void);
64void ps2_mouse_task(void); 159void ps2_mouse_task(void);
65 160
161void ps2_mouse_disable_data_reporting(void);
162
163void ps2_mouse_enable_data_reporting(void);
164
165void ps2_mouse_set_remote_mode(void);
166
167void ps2_mouse_set_stream_mode(void);
168
169void ps2_mouse_set_scaling_2_1(void);
170
171void ps2_mouse_set_scaling_1_1(void);
172
173void ps2_mouse_set_resolution(ps2_mouse_resolution_t resolution);
174
175void ps2_mouse_set_sample_rate(ps2_mouse_sample_rate_t sample_rate);
176
66#endif 177#endif