aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/keycode.h13
-rw-r--r--common/mousekey.c106
-rw-r--r--common/mousekey.h39
-rw-r--r--keyboard/hhkb/keymap.c8
4 files changed, 103 insertions, 63 deletions
diff --git a/common/keycode.h b/common/keycode.h
index 4ed78a46a..f9331cdbf 100644
--- a/common/keycode.h
+++ b/common/keycode.h
@@ -29,10 +29,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
29#define IS_MOD(code) (KC_LCTRL <= (code) && (code) <= KC_RGUI) 29#define IS_MOD(code) (KC_LCTRL <= (code) && (code) <= KC_RGUI)
30 30
31#define IS_FN(code) (KC_FN0 <= (code) && (code) <= KC_FN7) 31#define IS_FN(code) (KC_FN0 <= (code) && (code) <= KC_FN7)
32#define IS_MOUSEKEY(code) (KC_MS_UP <= (code) && (code) <= KC_MS_WH_RIGHT) 32#define IS_MOUSEKEY(code) (KC_MS_UP <= (code) && (code) <= KC_MS_ACCEL2)
33#define IS_MOUSEKEY_MOVE(code) (KC_MS_UP <= (code) && (code) <= KC_MS_RIGHT) 33#define IS_MOUSEKEY_MOVE(code) (KC_MS_UP <= (code) && (code) <= KC_MS_RIGHT)
34#define IS_MOUSEKEY_BUTTON(code) (KC_MS_BTN1 <= (code) && (code) <= KC_MS_BTN5) 34#define IS_MOUSEKEY_BUTTON(code) (KC_MS_BTN1 <= (code) && (code) <= KC_MS_BTN5)
35#define IS_MOUSEKEY_WHEEL(code) (KC_MS_WH_UP <= (code) && (code) <= KC_MS_WH_RIGHT) 35#define IS_MOUSEKEY_WHEEL(code) (KC_MS_WH_UP <= (code) && (code) <= KC_MS_WH_RIGHT)
36#define IS_MOUSEKEY_ACCEL(code) (KC_MS_ACCEL0 <= (code) && (code) <= KC_MS_ACCEL2)
36 37
37#define IS_SPECIAL(code) ((0xB0 <= (code) && (code) <= 0xDF) || (0xE8 <= (code) && (code) <= 0xFF)) 38#define IS_SPECIAL(code) ((0xB0 <= (code) && (code) <= 0xDF) || (0xE8 <= (code) && (code) <= 0xFF))
38#define IS_CONSUMER(code) (KC_MUTE <= (code) && (code) <= KC_WFAV) 39#define IS_CONSUMER(code) (KC_MUTE <= (code) && (code) <= KC_WFAV)
@@ -120,6 +121,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
120#define KC_WH_D KC_MS_WH_DOWN 121#define KC_WH_D KC_MS_WH_DOWN
121#define KC_WH_L KC_MS_WH_LEFT 122#define KC_WH_L KC_MS_WH_LEFT
122#define KC_WH_R KC_MS_WH_RIGHT 123#define KC_WH_R KC_MS_WH_RIGHT
124#define KC_ACL0 KC_MS_ACCEL0
125#define KC_ACL1 KC_MS_ACCEL1
126#define KC_ACL2 KC_MS_ACCEL2
123/* Sytem Control */ 127/* Sytem Control */
124#define KC_PWR KC_SYSTEM_POWER 128#define KC_PWR KC_SYSTEM_POWER
125#define KC_SLEP KC_SYSTEM_SLEEP 129#define KC_SLEP KC_SYSTEM_SLEEP
@@ -429,13 +433,16 @@ enum internal_special_keycodes {
429 KC_MS_BTN2, 433 KC_MS_BTN2,
430 KC_MS_BTN3, 434 KC_MS_BTN3,
431 KC_MS_BTN4, 435 KC_MS_BTN4,
432 KC_MS_BTN5, 436 KC_MS_BTN5, /* 0xF8 */
433 /* Mousekey wheel */ 437 /* Mousekey wheel */
434 KC_MS_WH_UP, 438 KC_MS_WH_UP,
435 KC_MS_WH_DOWN, 439 KC_MS_WH_DOWN,
436 KC_MS_WH_LEFT, 440 KC_MS_WH_LEFT,
437 KC_MS_WH_RIGHT, /* 0xFC */ 441 KC_MS_WH_RIGHT, /* 0xFC */
438 /* 0xFD-FF vacant for future use */ 442 /* Mousekey accel */
443 KC_MS_ACCEL0,
444 KC_MS_ACCEL1,
445 KC_MS_ACCEL2 /* 0xFF */
439}; 446};
440 447
441#endif /* KEYCODE_H */ 448#endif /* KEYCODE_H */
diff --git a/common/mousekey.c b/common/mousekey.c
index 99e6d34ff..b8af3e59c 100644
--- a/common/mousekey.c
+++ b/common/mousekey.c
@@ -27,40 +27,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
27 27
28 28
29static uint8_t mousekey_repeat = 0; 29static uint8_t mousekey_repeat = 0;
30static uint8_t mousekey_accel = 0;
30 31
31static void mousekey_debug(void); 32static void mousekey_debug(void);
32 33
33 34
34/* max value on report descriptor */
35#define MOUSEKEY_MOVE_MAX 127
36#define MOUSEKEY_WHEEL_MAX 15
37
38#ifndef MOUSEKEY_MOVE_DELTA
39#define MOUSEKEY_MOVE_DELTA 5
40#endif
41#ifndef MOUSEKEY_WHEEL_DELTA
42#define MOUSEKEY_WHEEL_DELTA 1
43#endif
44#ifndef MOUSEKEY_DELAY
45#define MOUSEKEY_DELAY 300
46#endif
47#ifndef MOUSEKEY_INTERVAL
48#define MOUSEKEY_INTERVAL 50
49#endif
50#ifndef MOUSEKEY_MAX_SPEED
51#define MOUSEKEY_MAX_SPEED 10
52#endif
53#ifndef MOUSEKEY_TIME_TO_MAX
54#define MOUSEKEY_TIME_TO_MAX 20
55#endif
56#ifndef MOUSEKEY_WHEEL_MAX_SPEED
57#define MOUSEKEY_WHEEL_MAX_SPEED 8
58#endif
59#ifndef MOUSEKEY_WHEEL_TIME_TO_MAX
60#define MOUSEKEY_WHEEL_TIME_TO_MAX 40
61#endif
62
63
64/* 35/*
65 * Mouse keys acceleration algorithm 36 * Mouse keys acceleration algorithm
66 * http://en.wikipedia.org/wiki/Mouse_keys 37 * http://en.wikipedia.org/wiki/Mouse_keys
@@ -68,18 +39,18 @@ static void mousekey_debug(void);
68 * speed = delta * max_speed * (repeat / time_to_max)**((1000+curve)/1000) 39 * speed = delta * max_speed * (repeat / time_to_max)**((1000+curve)/1000)
69 */ 40 */
70/* milliseconds between the initial key press and first repeated motion event (0-2550) */ 41/* milliseconds between the initial key press and first repeated motion event (0-2550) */
71static uint8_t mk_delay = MOUSEKEY_DELAY/10; 42uint8_t mk_delay = MOUSEKEY_DELAY/10;
72/* milliseconds between repeated motion events (0-255) */ 43/* milliseconds between repeated motion events (0-255) */
73static uint8_t mk_interval = MOUSEKEY_INTERVAL; 44uint8_t mk_interval = MOUSEKEY_INTERVAL;
74/* steady speed (in action_delta units) applied each event (0-255) */ 45/* steady speed (in action_delta units) applied each event (0-255) */
75static uint8_t mk_max_speed = MOUSEKEY_MAX_SPEED; 46uint8_t mk_max_speed = MOUSEKEY_MAX_SPEED;
76/* number of events (count) accelerating to steady speed (0-255) */ 47/* number of events (count) accelerating to steady speed (0-255) */
77static uint8_t mk_time_to_max = MOUSEKEY_TIME_TO_MAX; 48uint8_t mk_time_to_max = MOUSEKEY_TIME_TO_MAX;
78/* ramp used to reach maximum pointer speed (NOT SUPPORTED) */ 49/* ramp used to reach maximum pointer speed (NOT SUPPORTED) */
79//static int8_t mk_curve = 0; 50//int8_t mk_curve = 0;
80 51/* wheel params */
81static uint8_t mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED; 52uint8_t mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED;
82static uint8_t mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX; 53uint8_t mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX;
83 54
84 55
85static uint16_t last_timer = 0; 56static uint16_t last_timer = 0;
@@ -88,25 +59,39 @@ static uint16_t last_timer = 0;
88static uint8_t move_unit(void) 59static uint8_t move_unit(void)
89{ 60{
90 uint16_t unit; 61 uint16_t unit;
91 if (mousekey_repeat > mk_time_to_max) { 62 if (mousekey_accel & (1<<0)) {
63 unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed)/4;
64 } else if (mousekey_accel & (1<<1)) {
65 unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed)/2;
66 } else if (mousekey_accel & (1<<2)) {
67 unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed);
68 } else if (mousekey_repeat == 0) {
69 unit = MOUSEKEY_MOVE_DELTA;
70 } else if (mousekey_repeat >= mk_time_to_max) {
92 unit = MOUSEKEY_MOVE_DELTA * mk_max_speed; 71 unit = MOUSEKEY_MOVE_DELTA * mk_max_speed;
93 } else { 72 } else {
94 unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed * mousekey_repeat) / mk_time_to_max; 73 unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed * mousekey_repeat) / mk_time_to_max;
95 } 74 }
96 if (unit == 0) return 1; 75 return (unit > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : (unit == 0 ? 1 : unit));
97 return (unit > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : unit);
98} 76}
99 77
100static uint8_t wheel_unit(void) 78static uint8_t wheel_unit(void)
101{ 79{
102 uint16_t unit; 80 uint16_t unit;
103 if (mousekey_repeat > mk_time_to_max) { 81 if (mousekey_accel & (1<<0)) {
82 unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed)/4;
83 } else if (mousekey_accel & (1<<1)) {
84 unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed)/2;
85 } else if (mousekey_accel & (1<<2)) {
86 unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed);
87 } else if (mousekey_repeat == 0) {
88 unit = MOUSEKEY_WHEEL_DELTA;
89 } else if (mousekey_repeat >= mk_time_to_max) {
104 unit = MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed; 90 unit = MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed;
105 } else { 91 } else {
106 unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed * mousekey_repeat) / mk_wheel_time_to_max; 92 unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed * mousekey_repeat) / mk_wheel_time_to_max;
107 } 93 }
108 if (unit == 0) return 1; 94 return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : (unit == 0 ? 1 : unit));
109 return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : unit);
110} 95}
111 96
112void mousekey_task(void) 97void mousekey_task(void)
@@ -126,6 +111,7 @@ void mousekey_task(void)
126 if (mouse_report.y > 0) mouse_report.y = move_unit(); 111 if (mouse_report.y > 0) mouse_report.y = move_unit();
127 if (mouse_report.y < 0) mouse_report.y = move_unit() * -1; 112 if (mouse_report.y < 0) mouse_report.y = move_unit() * -1;
128 113
114 /* diagonal move [1/sqrt(2) = 0.7] */
129 if (mouse_report.x && mouse_report.y) { 115 if (mouse_report.x && mouse_report.y) {
130 mouse_report.x *= 0.7; 116 mouse_report.x *= 0.7;
131 mouse_report.y *= 0.7; 117 mouse_report.y *= 0.7;
@@ -141,19 +127,22 @@ void mousekey_task(void)
141 127
142void mousekey_on(uint8_t code) 128void mousekey_on(uint8_t code)
143{ 129{
144 if (code == KC_MS_UP) mouse_report.y = MOUSEKEY_MOVE_DELTA * -1; 130 if (code == KC_MS_UP) mouse_report.y = move_unit() * -1;
145 else if (code == KC_MS_DOWN) mouse_report.y = MOUSEKEY_MOVE_DELTA; 131 else if (code == KC_MS_DOWN) mouse_report.y = move_unit();
146 else if (code == KC_MS_LEFT) mouse_report.x = MOUSEKEY_MOVE_DELTA * -1; 132 else if (code == KC_MS_LEFT) mouse_report.x = move_unit() * -1;
147 else if (code == KC_MS_RIGHT) mouse_report.x = MOUSEKEY_MOVE_DELTA; 133 else if (code == KC_MS_RIGHT) mouse_report.x = move_unit();
148 else if (code == KC_MS_WH_UP) mouse_report.v = MOUSEKEY_WHEEL_DELTA; 134 else if (code == KC_MS_WH_UP) mouse_report.v = wheel_unit();
149 else if (code == KC_MS_WH_DOWN) mouse_report.v = MOUSEKEY_WHEEL_DELTA * -1; 135 else if (code == KC_MS_WH_DOWN) mouse_report.v = wheel_unit() * -1;
150 else if (code == KC_MS_WH_LEFT) mouse_report.h = MOUSEKEY_WHEEL_DELTA * -1; 136 else if (code == KC_MS_WH_LEFT) mouse_report.h = wheel_unit() * -1;
151 else if (code == KC_MS_WH_RIGHT) mouse_report.h = MOUSEKEY_WHEEL_DELTA; 137 else if (code == KC_MS_WH_RIGHT) mouse_report.h = wheel_unit();
152 else if (code == KC_MS_BTN1) mouse_report.buttons |= MOUSE_BTN1; 138 else if (code == KC_MS_BTN1) mouse_report.buttons |= MOUSE_BTN1;
153 else if (code == KC_MS_BTN2) mouse_report.buttons |= MOUSE_BTN2; 139 else if (code == KC_MS_BTN2) mouse_report.buttons |= MOUSE_BTN2;
154 else if (code == KC_MS_BTN3) mouse_report.buttons |= MOUSE_BTN3; 140 else if (code == KC_MS_BTN3) mouse_report.buttons |= MOUSE_BTN3;
155 else if (code == KC_MS_BTN4) mouse_report.buttons |= MOUSE_BTN4; 141 else if (code == KC_MS_BTN4) mouse_report.buttons |= MOUSE_BTN4;
156 else if (code == KC_MS_BTN5) mouse_report.buttons |= MOUSE_BTN5; 142 else if (code == KC_MS_BTN5) mouse_report.buttons |= MOUSE_BTN5;
143 else if (code == KC_MS_ACCEL0) mousekey_accel |= (1<<0);
144 else if (code == KC_MS_ACCEL1) mousekey_accel |= (1<<1);
145 else if (code == KC_MS_ACCEL2) mousekey_accel |= (1<<2);
157} 146}
158 147
159void mousekey_off(uint8_t code) 148void mousekey_off(uint8_t code)
@@ -171,6 +160,9 @@ void mousekey_off(uint8_t code)
171 else if (code == KC_MS_BTN3) mouse_report.buttons &= ~MOUSE_BTN3; 160 else if (code == KC_MS_BTN3) mouse_report.buttons &= ~MOUSE_BTN3;
172 else if (code == KC_MS_BTN4) mouse_report.buttons &= ~MOUSE_BTN4; 161 else if (code == KC_MS_BTN4) mouse_report.buttons &= ~MOUSE_BTN4;
173 else if (code == KC_MS_BTN5) mouse_report.buttons &= ~MOUSE_BTN5; 162 else if (code == KC_MS_BTN5) mouse_report.buttons &= ~MOUSE_BTN5;
163 else if (code == KC_MS_ACCEL0) mousekey_accel &= ~(1<<0);
164 else if (code == KC_MS_ACCEL1) mousekey_accel &= ~(1<<1);
165 else if (code == KC_MS_ACCEL2) mousekey_accel &= ~(1<<2);
174 166
175 if (mouse_report.x == 0 && mouse_report.y == 0 && mouse_report.v == 0 && mouse_report.h == 0) 167 if (mouse_report.x == 0 && mouse_report.y == 0 && mouse_report.v == 0 && mouse_report.h == 0)
176 mousekey_repeat = 0; 168 mousekey_repeat = 0;
@@ -186,17 +178,19 @@ void mousekey_send(void)
186void mousekey_clear(void) 178void mousekey_clear(void)
187{ 179{
188 mouse_report = (report_mouse_t){}; 180 mouse_report = (report_mouse_t){};
181 mousekey_repeat = 0;
182 mousekey_accel = 0;
189} 183}
190 184
191static void mousekey_debug(void) 185static void mousekey_debug(void)
192{ 186{
193 if (!debug_mouse) return; 187 if (!debug_mouse) return;
194 print("mousekey [btn|x y v h]rep: ["); 188 print("mousekey [btn|x y v h](rep/acl): [");
195 phex(mouse_report.buttons); print("|"); 189 phex(mouse_report.buttons); print("|");
196 phex(mouse_report.x); print(" "); 190 phex(mouse_report.x); print(" ");
197 phex(mouse_report.y); print(" "); 191 phex(mouse_report.y); print(" ");
198 phex(mouse_report.v); print(" "); 192 phex(mouse_report.v); print(" ");
199 phex(mouse_report.h); print("]"); 193 phex(mouse_report.h); print("](");
200 phex(mousekey_repeat); 194 phex(mousekey_repeat); print("/");
201 print("\n"); 195 phex(mousekey_accel); print(")\n");
202} 196}
diff --git a/common/mousekey.h b/common/mousekey.h
index 3006c4634..ac26a46c8 100644
--- a/common/mousekey.h
+++ b/common/mousekey.h
@@ -21,6 +21,45 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
21#include <stdbool.h> 21#include <stdbool.h>
22#include "host.h" 22#include "host.h"
23 23
24
25/* max value on report descriptor */
26#define MOUSEKEY_MOVE_MAX 127
27#define MOUSEKEY_WHEEL_MAX 127
28
29#ifndef MOUSEKEY_MOVE_DELTA
30#define MOUSEKEY_MOVE_DELTA 5
31#endif
32#ifndef MOUSEKEY_WHEEL_DELTA
33#define MOUSEKEY_WHEEL_DELTA 1
34#endif
35#ifndef MOUSEKEY_DELAY
36#define MOUSEKEY_DELAY 300
37#endif
38#ifndef MOUSEKEY_INTERVAL
39#define MOUSEKEY_INTERVAL 50
40#endif
41#ifndef MOUSEKEY_MAX_SPEED
42#define MOUSEKEY_MAX_SPEED 10
43#endif
44#ifndef MOUSEKEY_TIME_TO_MAX
45#define MOUSEKEY_TIME_TO_MAX 20
46#endif
47#ifndef MOUSEKEY_WHEEL_MAX_SPEED
48#define MOUSEKEY_WHEEL_MAX_SPEED 16
49#endif
50#ifndef MOUSEKEY_WHEEL_TIME_TO_MAX
51#define MOUSEKEY_WHEEL_TIME_TO_MAX 40
52#endif
53
54
55uint8_t mk_delay;
56uint8_t mk_interval;
57uint8_t mk_max_speed;
58uint8_t mk_time_to_max;
59uint8_t mk_wheel_max_speed;
60uint8_t mk_wheel_time_to_max;
61
62
24void mousekey_task(void); 63void mousekey_task(void);
25void mousekey_on(uint8_t code); 64void mousekey_on(uint8_t code);
26void mousekey_off(uint8_t code); 65void mousekey_off(uint8_t code);
diff --git a/keyboard/hhkb/keymap.c b/keyboard/hhkb/keymap.c
index 3cfa5ff33..659a540b1 100644
--- a/keyboard/hhkb/keymap.c
+++ b/keyboard/hhkb/keymap.c
@@ -59,7 +59,7 @@ static const uint8_t PROGMEM fn_layer[] = {
59 2, // Fn2 59 2, // Fn2
60 3, // Fn3 60 3, // Fn3
61 3, // Fn4 61 3, // Fn4
62 4, // Fn5 62 5, // Fn5
63 0, // Fn6 63 0, // Fn6
64 0 // Fn7 64 0 // Fn7
65}; 65};
@@ -162,9 +162,9 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
162 LGUI,LALT, BTN1, RALT,FN4), 162 LGUI,LALT, BTN1, RALT,FN4),
163#else 163#else
164 KEYMAP(ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \ 164 KEYMAP(ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL, \
165 TAB, WH_L,WH_U,MS_U,WH_D,WH_R,WH_L,WH_D,WH_U,WH_R,NO, NO, NO, BSPC, \ 165 TAB, NO, NO, NO, NO, NO, WH_L,WH_D,WH_U,WH_R,NO, NO, NO, BSPC, \
166 LCTL,NO, MS_L,MS_D,MS_R,NO, MS_L,MS_D,MS_U,MS_R,FN3, NO, ENT, \ 166 LCTL,NO, ACL0,ACL1,ACL2,NO, MS_L,MS_D,MS_U,MS_R,FN3, NO, ENT, \
167 LSFT,BTN4,BTN5,BTN1,BTN2,BTN3,BTN2,BTN1,BTN4,BTN5,NO, RSFT,NO, \ 167 LSFT,NO, NO, NO, NO, BTN3,BTN2,BTN1,BTN4,BTN5,NO, RSFT,NO, \
168 LGUI,LALT, BTN1, RALT,FN4), 168 LGUI,LALT, BTN1, RALT,FN4),
169#endif 169#endif
170 170