aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common.mk11
-rw-r--r--common/keyboard.c15
-rw-r--r--protocol.mk25
-rw-r--r--protocol/pjrc.mk6
-rw-r--r--protocol/ps2_mouse.c122
5 files changed, 95 insertions, 84 deletions
diff --git a/common.mk b/common.mk
index 5b70db949..2ca06daae 100644
--- a/common.mk
+++ b/common.mk
@@ -25,6 +25,7 @@ endif
25ifdef MOUSEKEY_ENABLE 25ifdef MOUSEKEY_ENABLE
26 SRC += $(COMMON_DIR)/mousekey.c 26 SRC += $(COMMON_DIR)/mousekey.c
27 OPT_DEFS += -DMOUSEKEY_ENABLE 27 OPT_DEFS += -DMOUSEKEY_ENABLE
28 OPT_DEFS += -DMOUSE_ENABLE
28endif 29endif
29 30
30ifdef EXTRAKEY_ENABLE 31ifdef EXTRAKEY_ENABLE
@@ -47,16 +48,6 @@ ifdef NKRO_ENABLE
47 OPT_DEFS += -DNKRO_ENABLE 48 OPT_DEFS += -DNKRO_ENABLE
48endif 49endif
49 50
50ifdef PS2_MOUSE_ENABLE
51 SRC += $(COMMON_DIR)/ps2.c \
52 $(COMMON_DIR)/ps2_mouse.c
53 OPT_DEFS += -DPS2_MOUSE_ENABLE
54endif
55
56ifdef $(or MOUSEKEY_ENABLE, PS2_MOUSE_ENABLE)
57 OPT_DEFS += -DMOUSE_ENABLE
58endif
59
60ifdef SLEEP_LED_ENABLE 51ifdef SLEEP_LED_ENABLE
61 SRC += $(COMMON_DIR)/sleep_led.c 52 SRC += $(COMMON_DIR)/sleep_led.c
62 OPT_DEFS += -DSLEEP_LED_ENABLE 53 OPT_DEFS += -DSLEEP_LED_ENABLE
diff --git a/common/keyboard.c b/common/keyboard.c
index 601e3abe1..63a58b218 100644
--- a/common/keyboard.c
+++ b/common/keyboard.c
@@ -30,8 +30,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
30#include "sendchar.h" 30#include "sendchar.h"
31#include "bootmagic.h" 31#include "bootmagic.h"
32#include "eeconfig.h" 32#include "eeconfig.h"
33#include "mousekey.h"
34#include "backlight.h" 33#include "backlight.h"
34#ifdef MOUSEKEY_ENABLE
35# include "mousekey.h"
36#endif
37#ifdef PS2_MOUSE_ENABLE
38# include "ps2_mouse.h"
39#endif
35 40
36 41
37#ifdef MATRIX_HAS_GHOST 42#ifdef MATRIX_HAS_GHOST
@@ -111,10 +116,18 @@ void keyboard_task(void)
111 action_exec(TICK); 116 action_exec(TICK);
112 117
113MATRIX_LOOP_END: 118MATRIX_LOOP_END:
119
114#ifdef MOUSEKEY_ENABLE 120#ifdef MOUSEKEY_ENABLE
115 // mousekey repeat & acceleration 121 // mousekey repeat & acceleration
116 mousekey_task(); 122 mousekey_task();
117#endif 123#endif
124
125#ifdef PS2_MOUSE_ENABLE
126 if (ps2_mouse_read() == 0) {
127 ps2_mouse_usb_send();
128 }
129#endif
130
118 // update LED 131 // update LED
119 if (led_status != host_keyboard_leds()) { 132 if (led_status != host_keyboard_leds()) {
120 led_status = host_keyboard_leds(); 133 led_status = host_keyboard_leds();
diff --git a/protocol.mk b/protocol.mk
index 1442c5206..0d5f06c7e 100644
--- a/protocol.mk
+++ b/protocol.mk
@@ -1,2 +1,27 @@
1PROTOCOL_DIR = protocol
2
3
4ifdef PS2_MOUSE_ENABLE
5 SRC += $(PROTOCOL_DIR)/ps2_mouse.c
6 OPT_DEFS += -DPS2_MOUSE_ENABLE
7 OPT_DEFS += -DMOUSE_ENABLE
8endif
9
10ifdef PS2_USE_BUSYWAIT
11 SRC += protocol/ps2.c
12 OPT_DEFS += -DPS2_USE_BUSYWAIT
13endif
14
15ifdef PS2_USE_INT
16 SRC += protocol/ps2.c
17 OPT_DEFS += -DPS2_USE_INT
18endif
19
20ifdef PS2_USE_USART
21 SRC += protocol/ps2_usart.c
22 OPT_DEFS += -DPS2_USE_USART
23endif
24
25
1# Search Path 26# Search Path
2VPATH += $(TOP_DIR)/protocol 27VPATH += $(TOP_DIR)/protocol
diff --git a/protocol/pjrc.mk b/protocol/pjrc.mk
index 27f908b1c..5a4461382 100644
--- a/protocol/pjrc.mk
+++ b/protocol/pjrc.mk
@@ -7,7 +7,11 @@ SRC += $(PJRC_DIR)/main.c \
7 $(PJRC_DIR)/usb.c 7 $(PJRC_DIR)/usb.c
8 8
9# Option modules 9# Option modules
10ifdef $(or MOUSEKEY_ENABLE, PS2_MOUSE_ENABLE) 10ifdef MOUSEKEY_ENABLE
11 SRC += $(PJRC_DIR)/usb_mouse.c
12endif
13
14ifdef PS2_MOUSE_ENABLE
11 SRC += $(PJRC_DIR)/usb_mouse.c 15 SRC += $(PJRC_DIR)/usb_mouse.c
12endif 16endif
13 17
diff --git a/protocol/ps2_mouse.c b/protocol/ps2_mouse.c
index f796b2b4d..701d97213 100644
--- a/protocol/ps2_mouse.c
+++ b/protocol/ps2_mouse.c
@@ -1,5 +1,5 @@
1/* 1/*
2Copyright 2011 Jun Wako <wakojun@gmail.com> 2Copyright 2011,2013 Jun Wako <wakojun@gmail.com>
3 3
4This program is free software: you can redistribute it and/or modify 4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by 5it under the terms of the GNU General Public License as published by
@@ -32,27 +32,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
32# define phex16(h) 32# define phex16(h)
33#endif 33#endif
34 34
35// disable when errors occur 255 times.
36#define ERROR_RETURN() do { \
37 if (ps2_error) { \
38 if (ps2_mouse_error_count < 255) { \
39 ps2_mouse_error_count++; \
40 } else { \
41 ps2_mouse_error_count = 0; \
42 ps2_mouse_enable = false; \
43 } \
44 return ps2_error; \
45 } \
46} while (0)
47 35
48
49/*
50TODO
51----
52- Stream mode
53- Tracpoint command support: needed
54- Middle button + move = Wheel traslation
55*/
56bool ps2_mouse_enable = true; 36bool ps2_mouse_enable = true;
57uint8_t ps2_mouse_x = 0; 37uint8_t ps2_mouse_x = 0;
58uint8_t ps2_mouse_y = 0; 38uint8_t ps2_mouse_y = 0;
@@ -69,85 +49,50 @@ uint8_t ps2_mouse_init(void) {
69 49
70 ps2_host_init(); 50 ps2_host_init();
71 51
72 // Reset 52 // Not reliable: sometime fail to initialize mouse
73 rcv = ps2_host_send(0xFF);
74 print("ps2_mouse_init: send 0xFF: ");
75 phex(ps2_error); print("\n");
76 ERROR_RETURN();
77 53
78 // ACK 54 // send Reset
79 rcv = ps2_host_recv(); 55 _delay_ms(1000); // wait for powering up
80 print("ps2_mouse_init: read ACK: "); 56 rcv = ps2_host_send(0xFF);
57 print("ps2_mouse_init: send Reset: ");
81 phex(rcv); phex(ps2_error); print("\n"); 58 phex(rcv); phex(ps2_error); print("\n");
82 ERROR_RETURN();
83 59
84 // BAT takes some time 60 // read completion code of BAT
85 _delay_ms(100); 61 //_delay_ms(1000); // wait for Basic Assurance Test
86 rcv = ps2_host_recv(); 62 rcv = ps2_host_recv();
87 print("ps2_mouse_init: read BAT: "); 63 print("ps2_mouse_init: read BAT: ");
88 phex(rcv); phex(ps2_error); print("\n"); 64 phex(rcv); phex(ps2_error); print("\n");
89 ERROR_RETURN();
90 65
91 // Device ID 66 // read Device ID
92 rcv = ps2_host_recv(); 67 rcv = ps2_host_recv();
93 print("ps2_mouse_init: read DevID: "); 68 print("ps2_mouse_init: read DevID: ");
94 phex(rcv); phex(ps2_error); print("\n"); 69 phex(rcv); phex(ps2_error); print("\n");
95 ERROR_RETURN();
96 70
97 // Enable data reporting 71 // send Enable Data Reporting
98 ps2_host_send(0xF4); 72 rcv = ps2_host_send(0xF4);
99 print("ps2_mouse_init: send 0xF4: "); 73 print("ps2_mouse_init: send 0xF4: ");
100 phex(ps2_error); print("\n");
101 ERROR_RETURN();
102
103 // ACK
104 rcv = ps2_host_recv();
105 print("ps2_mouse_init: read ACK: ");
106 phex(rcv); phex(ps2_error); print("\n"); 74 phex(rcv); phex(ps2_error); print("\n");
107 ERROR_RETURN();
108 75
109 // Set Remote mode 76 // send Set Remote mode
110 ps2_host_send(0xF0); 77 rcv = ps2_host_send(0xF0);
111 print("ps2_mouse_init: send 0xF0: "); 78 print("ps2_mouse_init: send 0xF0: ");
112 phex(ps2_error); print("\n");
113 ERROR_RETURN();
114
115 // ACK
116 rcv = ps2_host_recv();
117 print("ps2_mouse_init: read ACK: ");
118 phex(rcv); phex(ps2_error); print("\n"); 79 phex(rcv); phex(ps2_error); print("\n");
119 ERROR_RETURN();
120 80
121 return 0; 81 return 0;
122} 82}
123 83
124/*
125Data format:
126 bit: 7 6 5 4 3 2 1 0
127-----------------------------------------------------------------------
1280 btn: Yovflw Xovflw Ysign Xsign 1 Middle Right Left
1291 x: X movement(0-255)
1302 y: Y movement(0-255)
131*/
132uint8_t ps2_mouse_read(void) 84uint8_t ps2_mouse_read(void)
133{ 85{
134 uint8_t rcv; 86 uint8_t rcv;
135 87
136 if (!ps2_mouse_enable) return 1; 88 if (!ps2_mouse_enable) return 1;
137 89
138 ps2_host_send(0xEB); 90 rcv = ps2_host_send(0xEB);
139 ERROR_RETURN();
140
141 rcv=ps2_host_recv();
142 ERROR_RETURN();
143 91
144 if(rcv==0xFA) { 92 if(rcv==0xFA) {
145 ps2_mouse_btn = ps2_host_recv(); 93 ps2_mouse_btn = ps2_host_recv_response();
146 ERROR_RETURN(); 94 ps2_mouse_x = ps2_host_recv_response();
147 ps2_mouse_x = ps2_host_recv(); 95 ps2_mouse_y = ps2_host_recv_response();
148 ERROR_RETURN();
149 ps2_mouse_y = ps2_host_recv();
150 ERROR_RETURN();
151 } 96 }
152 return 0; 97 return 0;
153} 98}
@@ -216,3 +161,36 @@ void ps2_mouse_print(void)
216 phex(ps2_mouse_x); print(" "); 161 phex(ps2_mouse_x); print(" ");
217 phex(ps2_mouse_y); print("\n"); 162 phex(ps2_mouse_y); print("\n");
218} 163}
164
165
166/* PS/2 Mouse Synopsis
167 * http://www.computer-engineering.org/ps2mouse/
168 *
169 * Command:
170 * 0xFF: Reset
171 * 0xF6: Set Defaults Sampling; rate=100, resolution=4cnt/mm, scaling=1:1, reporting=disabled
172 * 0xF5: Disable Data Reporting
173 * 0xF4: Enable Data Reporting
174 * 0xF3: Set Sample Rate
175 * 0xF2: Get Device ID
176 * 0xF0: Set Remote Mode
177 * 0xEB: Read Data
178 * 0xEA: Set Stream Mode
179 * 0xE9: Status Request
180 * 0xE8: Set Resolution
181 * 0xE7: Set Scaling 2:1
182 * 0xE6: Set Scaling 1:1
183 *
184 * Mode:
185 * Stream Mode: devices sends the data when it changs its state
186 * Remote Mode: host polls the data periodically
187 *
188 * This code uses Remote Mode and polls the data with Read Data(0xEB).
189 *
190 * Data format:
191 * byte|7 6 5 4 3 2 1 0
192 * ----+--------------------------------------------------------------
193 * 0|Yovflw Xovflw Ysign Xsign 1 Middle Right Left
194 * 1| X movement(0-255)
195 * 2| Y movement(0-255)
196 */