aboutsummaryrefslogtreecommitdiff
path: root/protocol
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2013-11-20 15:28:58 +0900
committertmk <nobody@nowhere>2013-11-20 15:28:58 +0900
commitc6abcb6d893f6ef843ed98be3d45bd804cfe295a (patch)
tree4724b02aad271f6e8d9decf1e2588e7dd5b5c00d /protocol
parentd7f663a1ea4487a6dc5be76085eff7b00bec9704 (diff)
downloadqmk_firmware-c6abcb6d893f6ef843ed98be3d45bd804cfe295a.tar.gz
qmk_firmware-c6abcb6d893f6ef843ed98be3d45bd804cfe295a.zip
Add build options of ps2_mouse
Diffstat (limited to 'protocol')
-rw-r--r--protocol/ps2_mouse.c86
-rw-r--r--protocol/ps2_mouse.h21
2 files changed, 61 insertions, 46 deletions
diff --git a/protocol/ps2_mouse.c b/protocol/ps2_mouse.c
index ff730196c..ea629655f 100644
--- a/protocol/ps2_mouse.c
+++ b/protocol/ps2_mouse.c
@@ -22,23 +22,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
22#include "ps2_mouse.h" 22#include "ps2_mouse.h"
23#include "report.h" 23#include "report.h"
24#include "host.h" 24#include "host.h"
25 25#include "timer.h"
26#define PS2_MOUSE_DEBUG 26#include "print.h"
27#ifdef PS2_MOUSE_DEBUG 27#include "debug.h"
28# include "print.h"
29# include "debug.h"
30#else
31# define print(s)
32# define phex(h)
33# define phex16(h)
34#endif
35 28
36 29
37static report_mouse_t mouse_report = {}; 30static report_mouse_t mouse_report = {};
38 31
39 32
40static void ps2_mouse_print_raw_data(void); 33static void print_usb_data(void);
41static void ps2_mouse_print_usb_data(void);
42 34
43 35
44/* supports only 3 button mouse at this time */ 36/* supports only 3 button mouse at this time */
@@ -77,10 +69,6 @@ uint8_t ps2_mouse_init(void) {
77 return 0; 69 return 0;
78} 70}
79 71
80/* scroll support
81 * TODO: should be build option
82 */
83#define PS2_MOUSE_SCROLL_BUTTON 0x04
84#define X_IS_NEG (mouse_report.buttons & (1<<PS2_MOUSE_X_SIGN)) 72#define X_IS_NEG (mouse_report.buttons & (1<<PS2_MOUSE_X_SIGN))
85#define Y_IS_NEG (mouse_report.buttons & (1<<PS2_MOUSE_Y_SIGN)) 73#define Y_IS_NEG (mouse_report.buttons & (1<<PS2_MOUSE_Y_SIGN))
86#define X_IS_OVF (mouse_report.buttons & (1<<PS2_MOUSE_X_OVFLW)) 74#define X_IS_OVF (mouse_report.buttons & (1<<PS2_MOUSE_X_OVFLW))
@@ -107,7 +95,12 @@ void ps2_mouse_task(void)
107 if (mouse_report.x || mouse_report.y || 95 if (mouse_report.x || mouse_report.y ||
108 ((mouse_report.buttons ^ buttons_prev) & PS2_MOUSE_BTN_MASK)) { 96 ((mouse_report.buttons ^ buttons_prev) & PS2_MOUSE_BTN_MASK)) {
109 97
110 ps2_mouse_print_raw_data(); 98#ifdef PS2_MOUSE_DEBUG
99 print("ps2_mouse raw: [");
100 phex(mouse_report.buttons); print("|");
101 print_hex8((uint8_t)mouse_report.x); print(" ");
102 print_hex8((uint8_t)mouse_report.y); print("]\n");
103#endif
111 104
112 buttons_prev = mouse_report.buttons; 105 buttons_prev = mouse_report.buttons;
113 106
@@ -132,37 +125,47 @@ void ps2_mouse_task(void)
132 mouse_report.y = -mouse_report.y; 125 mouse_report.y = -mouse_report.y;
133 126
134 127
135 if ((mouse_report.buttons & PS2_MOUSE_SCROLL_BUTTON) == PS2_MOUSE_SCROLL_BUTTON) { 128#if PS2_MOUSE_SCROLL_BTN_MASK
136 if (scroll_state == SCROLL_NONE) scroll_state = SCROLL_BTN; 129 static uint16_t scroll_button_time = 0;
130 if ((mouse_report.buttons & (PS2_MOUSE_SCROLL_BTN_MASK)) == (PS2_MOUSE_SCROLL_BTN_MASK)) {
131 if (scroll_state == SCROLL_NONE) {
132 scroll_button_time = timer_read();
133 scroll_state = SCROLL_BTN;
134 }
137 135
138 // doesn't send Scroll Button 136 // doesn't send Scroll Button
139 mouse_report.buttons &= ~PS2_MOUSE_SCROLL_BUTTON; 137 //mouse_report.buttons &= ~(PS2_MOUSE_SCROLL_BTN_MASK);
140 138
141 if (mouse_report.x || mouse_report.y) { 139 if (mouse_report.x || mouse_report.y) {
142 scroll_state = SCROLL_SENT; 140 scroll_state = SCROLL_SENT;
143 141
144 mouse_report.v = -mouse_report.y/2; 142 mouse_report.v = -mouse_report.y/(PS2_MOUSE_SCROLL_DIVISOR_V);
145 mouse_report.h = mouse_report.x/2; 143 mouse_report.h = mouse_report.x/(PS2_MOUSE_SCROLL_DIVISOR_H);
146 mouse_report.x = 0; 144 mouse_report.x = 0;
147 mouse_report.y = 0; 145 mouse_report.y = 0;
146 //host_mouse_send(&mouse_report);
147 }
148 }
149 else if ((mouse_report.buttons & (PS2_MOUSE_SCROLL_BTN_MASK)) == 0) {
150#if PS2_MOUSE_SCROLL_BTN_SEND
151 if (scroll_state == SCROLL_BTN &&
152 TIMER_DIFF_16(timer_read(), scroll_button_time) < PS2_MOUSE_SCROLL_BTN_SEND) {
153 // send Scroll Button(down and up at once) when not scrolled
154 mouse_report.buttons |= (PS2_MOUSE_SCROLL_BTN_MASK);
148 host_mouse_send(&mouse_report); 155 host_mouse_send(&mouse_report);
156 _delay_ms(100);
157 mouse_report.buttons &= ~(PS2_MOUSE_SCROLL_BTN_MASK);
149 } 158 }
150 } else if (scroll_state == SCROLL_BTN && 159#endif
151 (mouse_report.buttons & PS2_MOUSE_SCROLL_BUTTON) == 0) {
152 scroll_state = SCROLL_NONE; 160 scroll_state = SCROLL_NONE;
161 }
162 // doesn't send Scroll Button
163 mouse_report.buttons &= ~(PS2_MOUSE_SCROLL_BTN_MASK);
164#endif
153 165
154 // send Scroll Button(down and up at once) when not scrolled
155 mouse_report.buttons |= PS2_MOUSE_SCROLL_BUTTON;
156 host_mouse_send(&mouse_report);
157 _delay_ms(100);
158 mouse_report.buttons &= ~PS2_MOUSE_SCROLL_BUTTON;
159 host_mouse_send(&mouse_report);
160 } else {
161 scroll_state = SCROLL_NONE;
162 166
163 host_mouse_send(&mouse_report); 167 host_mouse_send(&mouse_report);
164 } 168 print_usb_data();
165 ps2_mouse_print_usb_data();
166 } 169 }
167 // clear report 170 // clear report
168 mouse_report.x = 0; 171 mouse_report.x = 0;
@@ -172,19 +175,10 @@ void ps2_mouse_task(void)
172 mouse_report.buttons = 0; 175 mouse_report.buttons = 0;
173} 176}
174 177
175static void ps2_mouse_print_raw_data(void) 178static void print_usb_data(void)
176{
177 if (!debug_mouse) return;
178 print("ps2_mouse raw [btn|x y]: [");
179 phex(mouse_report.buttons); print("|");
180 print_hex8((uint8_t)mouse_report.x); print(" ");
181 print_hex8((uint8_t)mouse_report.y); print("]\n");
182}
183
184static void ps2_mouse_print_usb_data(void)
185{ 179{
186 if (!debug_mouse) return; 180 if (!debug_mouse) return;
187 print("ps2_mouse usb [btn|x y v h]: ["); 181 print("ps2_mouse usb: [");
188 phex(mouse_report.buttons); print("|"); 182 phex(mouse_report.buttons); print("|");
189 print_hex8((uint8_t)mouse_report.x); print(" "); 183 print_hex8((uint8_t)mouse_report.x); print(" ");
190 print_hex8((uint8_t)mouse_report.y); print(" "); 184 print_hex8((uint8_t)mouse_report.y); print(" ");
diff --git a/protocol/ps2_mouse.h b/protocol/ps2_mouse.h
index 305a9bdba..27d9790d4 100644
--- a/protocol/ps2_mouse.h
+++ b/protocol/ps2_mouse.h
@@ -39,6 +39,27 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
39#define PS2_MOUSE_X_OVFLW 6 39#define PS2_MOUSE_X_OVFLW 6
40#define PS2_MOUSE_Y_OVFLW 7 40#define PS2_MOUSE_Y_OVFLW 7
41 41
42
43/*
44 * Scroll by mouse move with pressing button
45 */
46/* mouse button to start scrolling; set 0 to disable scroll */
47#ifndef PS2_MOUSE_SCROLL_BTN_MASK
48#define PS2_MOUSE_SCROLL_BTN_MASK (1<<PS2_MOUSE_BTN_MIDDLE)
49#endif
50/* send button event when button is released within this value(ms); set 0 to disable */
51#ifndef PS2_MOUSE_SCROLL_BTN_SEND
52#define PS2_MOUSE_SCROLL_BTN_SEND 300
53#endif
54/* divide virtical and horizontal mouse move by this to convert to scroll move */
55#ifndef PS2_MOUSE_SCROLL_DIVISOR_V
56#define PS2_MOUSE_SCROLL_DIVISOR_V 2
57#endif
58#ifndef PS2_MOUSE_SCROLL_DIVISOR_H
59#define PS2_MOUSE_SCROLL_DIVISOR_H 2
60#endif
61
62
42uint8_t ps2_mouse_init(void); 63uint8_t ps2_mouse_init(void);
43void ps2_mouse_task(void); 64void ps2_mouse_task(void);
44 65