aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2013-07-23 07:54:14 +0900
committertmk <nobody@nowhere>2013-07-23 07:56:28 +0900
commit5b425731c5b662d107ba0f970a7ae7c7fe97d01b (patch)
tree25c8f53490930e4e70638211cec159f86e4018d5
parent25aec56c082936a463d609357a04332c97c9940b (diff)
parent6aaa6e0ef9aa1e464b67723fd4cdd0d63b2c861d (diff)
downloadqmk_firmware-5b425731c5b662d107ba0f970a7ae7c7fe97d01b.tar.gz
qmk_firmware-5b425731c5b662d107ba0f970a7ae7c7fe97d01b.zip
Merge branch 'macro_mediakey'(Fix issue #42)
-rw-r--r--common/action.c12
-rw-r--r--common/action_code.h6
-rw-r--r--common/action_macro.c30
-rw-r--r--common/action_macro.h96
-rw-r--r--common/keycode.h2
-rw-r--r--doc/keymap.md10
-rw-r--r--keyboard/hhkb/keymap.c16
7 files changed, 88 insertions, 84 deletions
diff --git a/common/action.c b/common/action.c
index a42a7a4ae..c22f681fb 100644
--- a/common/action.c
+++ b/common/action.c
@@ -373,6 +373,12 @@ void register_code(uint8_t code)
373 host_add_mods(MOD_BIT(code)); 373 host_add_mods(MOD_BIT(code));
374 host_send_keyboard_report(); 374 host_send_keyboard_report();
375 } 375 }
376 else if IS_SYSTEM(code) {
377 host_system_send(KEYCODE2SYSTEM(code));
378 }
379 else if IS_CONSUMER(code) {
380 host_consumer_send(KEYCODE2CONSUMER(code));
381 }
376} 382}
377 383
378void unregister_code(uint8_t code) 384void unregister_code(uint8_t code)
@@ -400,6 +406,12 @@ void unregister_code(uint8_t code)
400 host_del_mods(MOD_BIT(code)); 406 host_del_mods(MOD_BIT(code));
401 host_send_keyboard_report(); 407 host_send_keyboard_report();
402 } 408 }
409 else if IS_SYSTEM(code) {
410 host_system_send(0);
411 }
412 else if IS_CONSUMER(code) {
413 host_consumer_send(0);
414 }
403} 415}
404 416
405void add_mods(uint8_t mods) 417void add_mods(uint8_t mods)
diff --git a/common/action_code.h b/common/action_code.h
index df6ce9998..45e974a66 100644
--- a/common/action_code.h
+++ b/common/action_code.h
@@ -33,9 +33,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
33 * r: Left/Right flag(Left:0, Right:1) 33 * r: Left/Right flag(Left:0, Right:1)
34 * 34 *
35 * ACT_MODS_TAP(001r): 35 * ACT_MODS_TAP(001r):
36 * 0010|mods|0000 0000 Modifiers with OneShot 36 * 001r|mods|0000 0000 Modifiers with OneShot
37 * 0010|mods|0000 00xx (reserved) 37 * 001r|mods|0000 00xx (reserved)
38 * 0010|mods| keycode Modifiers with Tap Key 38 * 001r|mods| keycode Modifiers with Tap Key
39 * 39 *
40 * 40 *
41 * Other Keys(01xx) 41 * Other Keys(01xx)
diff --git a/common/action_macro.c b/common/action_macro.c
index 29cfd23df..cc7ac18a0 100644
--- a/common/action_macro.c
+++ b/common/action_macro.c
@@ -36,31 +36,31 @@ void action_macro_play(const macro_t *macro_p)
36 if (!macro_p) return; 36 if (!macro_p) return;
37 while (true) { 37 while (true) {
38 switch (MACRO_READ()) { 38 switch (MACRO_READ()) {
39 case INTERVAL: 39 case KEY_DOWN:
40 interval = MACRO_READ();
41 debug("INTERVAL("); debug_dec(interval); debug(")\n");
42 break;
43 case WAIT:
44 MACRO_READ(); 40 MACRO_READ();
45 debug("WAIT("); debug_dec(macro); debug(")\n"); 41 dprintf("KEY_DOWN(%02X)\n", macro);
46 { uint8_t ms = macro; while (ms--) _delay_ms(1); } 42 register_code(macro);
47 break; 43 break;
48 case MODS_DOWN: 44 case KEY_UP:
49 MACRO_READ(); 45 MACRO_READ();
50 debug("MODS_DOWN("); debug_hex(macro); debug(")\n"); 46 dprintf("KEY_UP(%02X)\n", macro);
51 add_mods(macro); 47 unregister_code(macro);
52 break; 48 break;
53 case MODS_UP: 49 case WAIT:
54 MACRO_READ(); 50 MACRO_READ();
55 debug("MODS_UP("); debug_hex(macro); debug(")\n"); 51 dprintf("WAIT(%u)\n", macro);
56 del_mods(macro); 52 { uint8_t ms = macro; while (ms--) _delay_ms(1); }
53 break;
54 case INTERVAL:
55 interval = MACRO_READ();
56 dprintf("INTERVAL(%u)\n", interval);
57 break; 57 break;
58 case 0x04 ... 0x73: 58 case 0x04 ... 0x73:
59 debug("DOWN("); debug_hex(macro); debug(")\n"); 59 dprintf("DOWN(%02X)\n", macro);
60 register_code(macro); 60 register_code(macro);
61 break; 61 break;
62 case 0x84 ... 0xF3: 62 case 0x84 ... 0xF3:
63 debug("UP("); debug_hex(macro); debug(")\n"); 63 dprintf("UP(%02X)\n", macro);
64 unregister_code(macro&0x7F); 64 unregister_code(macro&0x7F);
65 break; 65 break;
66 case END: 66 case END:
diff --git a/common/action_macro.h b/common/action_macro.h
index eea8ef57d..621826308 100644
--- a/common/action_macro.h
+++ b/common/action_macro.h
@@ -35,80 +35,68 @@ void action_macro_play(const macro_t *macro_p);
35 35
36 36
37 37
38/* TODO: NOT FINISHED 38/* Macro commands
39normal mode command: 39 * code(0x04-73) // key down(1byte)
40 key(down): 0x04-7f/73(F24) 40 * code(0x04-73) | 0x80 // key up(1byte)
41 key(up): 0x84-ff 41 * { KEY_DOWN, code(0x04-0xff) } // key down(2bytes)
42command: 0x00-03, 0x80-83(0x74-7f, 0xf4-ff) 42 * { KEY_UP, code(0x04-0xff) } // key up(2bytes)
43 mods down 0x00 43 * WAIT // wait milli-seconds
44 mods up 0x01 44 * INTERVAL // set interval between macro commands
45 wait 0x02 45 * END // stop macro execution
46 interval 0x03 46 *
47 extkey down 0x80 47 * Ideas(Not implemented):
48 extkey up 0x81 48 * modifiers
49 ext commad 0x82 49 * system usage
50 ext mode 0x83 50 * consumer usage
51 end 0xff 51 * unicode usage
52 52 * function call
53extension mode command: NOT IMPLEMENTED 53 * conditionals
54 key down 0x00 54 * loop
55 key up 0x01 55 */
56 key down + wait
57 key up + wait
58 mods push
59 mods pop
60 wait
61 interval
62 if
63 loop
64 push
65 pop
66 all up
67 end
68*/
69enum macro_command_id{ 56enum macro_command_id{
70 /* 0x00 - 0x03 */ 57 /* 0x00 - 0x03 */
71 END = 0x00, 58 END = 0x00,
72 MODS_DOWN = 0x01, 59 KEY_DOWN,
73 MODS_UP = 0x02, 60 KEY_UP,
74 MODS_SET, 61
75 MODS_PUSH, 62 /* 0x04 - 0x73 (reserved for keycode down) */
76 MODS_POP,
77 63
64 /* 0x74 - 0x83 */
78 WAIT = 0x74, 65 WAIT = 0x74,
79 INTERVAL, 66 INTERVAL,
80 /* 0x74 - 0x7f */
81 /* 0x80 - 0x84 */
82 67
83 EXT_DOWN, 68 /* 0x84 - 0xf3 (reserved for keycode up) */
84 EXT_UP,
85 EXT_WAIT,
86 EXT_INTERVAL,
87 COMPRESSION_MODE,
88 69
89 EXTENSION_MODE = 0xff, 70 /* 0xf4 - 0xff */
90}; 71};
91 72
92 73
93/* normal mode */ 74/* TODO: keycode:0x04-0x73 can be handled by 1byte command else 2bytes are needed
94#define DOWN(key) (key) 75 * if keycode between 0x04 and 0x73
95#define UP(key) ((key) | 0x80) 76 * keycode / (keycode|0x80)
96#define TYPE(key) (key), (key | 0x80) 77 * else
97#define MODS_DOWN(mods) MODS_DOWN, (mods) 78 * {KEY_DOWN, keycode} / {KEY_UP, keycode}
98#define MODS_UP(mods) MODS_UP, (mods) 79*/
80#define DOWN(key) KEY_DOWN, (key)
81#define UP(key) KEY_UP, (key)
82#define TYPE(key) DOWN(key), UP(key)
99#define WAIT(ms) WAIT, (ms) 83#define WAIT(ms) WAIT, (ms)
100#define INTERVAL(ms) INTERVAL, (ms) 84#define INTERVAL(ms) INTERVAL, (ms)
101 85
86/* key down */
102#define D(key) DOWN(KC_##key) 87#define D(key) DOWN(KC_##key)
88/* key up */
103#define U(key) UP(KC_##key) 89#define U(key) UP(KC_##key)
90/* key type */
104#define T(key) TYPE(KC_##key) 91#define T(key) TYPE(KC_##key)
105#define MD(key) MODS_DOWN(MOD_BIT(KC_##key)) 92/* wait */
106#define MU(key) MODS_UP(MOD_BIT(KC_##key))
107#define W(ms) WAIT(ms) 93#define W(ms) WAIT(ms)
94/* interval */
108#define I(ms) INTERVAL(ms) 95#define I(ms) INTERVAL(ms)
109 96
110 97/* for backward comaptibility */
111/* extension mode */ 98#define MD(key) DOWN(KC_##key)
99#define MU(key) UP(KC_##key)
112 100
113 101
114#endif /* ACTION_MACRO_H */ 102#endif /* ACTION_MACRO_H */
diff --git a/common/keycode.h b/common/keycode.h
index acbec07d2..77d5b79ba 100644
--- a/common/keycode.h
+++ b/common/keycode.h
@@ -30,7 +30,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
30 30
31 31
32#define IS_SPECIAL(code) ((0xA5 <= (code) && (code) <= 0xDF) || (0xE8 <= (code) && (code) <= 0xFF)) 32#define IS_SPECIAL(code) ((0xA5 <= (code) && (code) <= 0xDF) || (0xE8 <= (code) && (code) <= 0xFF))
33#define IS_SYSTEM(code) (KC_POWER <= (code) && (code) <= KC_WAKE) 33#define IS_SYSTEM(code) (KC_PWR <= (code) && (code) <= KC_WAKE)
34#define IS_CONSUMER(code) (KC_MUTE <= (code) && (code) <= KC_WFAV) 34#define IS_CONSUMER(code) (KC_MUTE <= (code) && (code) <= KC_WFAV)
35#define IS_FN(code) (KC_FN0 <= (code) && (code) <= KC_FN31) 35#define IS_FN(code) (KC_FN0 <= (code) && (code) <= KC_FN31)
36#define IS_MOUSEKEY(code) (KC_MS_UP <= (code) && (code) <= KC_MS_ACCEL2) 36#define IS_MOUSEKEY(code) (KC_MS_UP <= (code) && (code) <= KC_MS_ACCEL2)
diff --git a/doc/keymap.md b/doc/keymap.md
index 7d979eb7c..e4728b507 100644
--- a/doc/keymap.md
+++ b/doc/keymap.md
@@ -363,21 +363,19 @@ Default Layer also has bitwise operations, they are executed when key is release
363 363
364`Macro` action indicates complex key strokes. 364`Macro` action indicates complex key strokes.
365 365
366 MACRO( MD(LSHIFT), D(D), END ) 366 MACRO( D(LSHIFT), D(D), END )
367 MACRO( U(D), MU(LSHIFT), END ) 367 MACRO( U(D), U(LSHIFT), END )
368 MACRO( I(255), T(H), T(E), T(L), T(L), W(255), T(O), END ) 368 MACRO( I(255), T(H), T(E), T(L), T(L), W(255), T(O), END )
369 369
370#### 2.3.1 Normal mode 370#### 2.3.1 Macro Commands
371- **I()** change interavl of stroke. 371- **I()** change interavl of stroke.
372- **D()** press key 372- **D()** press key
373- **U()** release key 373- **U()** release key
374- **T()** type key(press and release) 374- **T()** type key(press and release)
375- **W()** wait 375- **W()** wait
376- **MD()** modifier down
377- **MU()** modifier up
378- **END** end mark 376- **END** end mark
379 377
380#### 2.3.2 Extended mode 378#### 2.3.2 Examples
381 379
382***TODO: sample impl*** 380***TODO: sample impl***
383See `keyboard/hhkb/keymap.c` for sample. 381See `keyboard/hhkb/keymap.c` for sample.
diff --git a/keyboard/hhkb/keymap.c b/keyboard/hhkb/keymap.c
index 265fb8729..faa62dd7e 100644
--- a/keyboard/hhkb/keymap.c
+++ b/keyboard/hhkb/keymap.c
@@ -67,7 +67,7 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
67 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSPC, \ 67 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSPC, \
68 LCTL,A, S, D, F, G, H, J, K, L, FN3, QUOT,FN4, \ 68 LCTL,A, S, D, F, G, H, J, K, L, FN3, QUOT,FN4, \
69 FN5,Z, X, C, V, B, N, M, COMM,DOT, FN2, RSFT,FN1, \ 69 FN5,Z, X, C, V, B, N, M, COMM,DOT, FN2, RSFT,FN1, \
70 LGUI,LALT, FN6, RALT,NO), 70 LGUI,LALT, FN6, RALT,RGUI),
71 71
72 /* Layer 1: HHKB mode (HHKB Fn) 72 /* Layer 1: HHKB mode (HHKB Fn)
73 * ,-----------------------------------------------------------. 73 * ,-----------------------------------------------------------.
@@ -179,6 +179,7 @@ enum macro_id {
179 LSHIFT_PAREN, 179 LSHIFT_PAREN,
180 RSHIFT_PAREN, 180 RSHIFT_PAREN,
181 HELLO, 181 HELLO,
182 VOLUP,
182}; 183};
183 184
184 185
@@ -203,6 +204,7 @@ static const uint16_t PROGMEM fn_actions[] = {
203// [13] = ACTION_MACRO_TAP(LSHIFT_PAREN), // Macro: LShift with tap '(' 204// [13] = ACTION_MACRO_TAP(LSHIFT_PAREN), // Macro: LShift with tap '('
204// [14] = ACTION_MACRO_TAP(RSHIFT_PAREN), // Macro: RShift with tap ')' 205// [14] = ACTION_MACRO_TAP(RSHIFT_PAREN), // Macro: RShift with tap ')'
205// [15] = ACTION_MACRO(HELLO), // Macro: say hello 206// [15] = ACTION_MACRO(HELLO), // Macro: say hello
207// [9] = ACTION_MACRO(VOLUP), // Macro: media key
206}; 208};
207 209
208 210
@@ -218,23 +220,27 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
218 case LSHIFT_PAREN: 220 case LSHIFT_PAREN:
219 if (tap.count > 0 && !tap.interrupted) { 221 if (tap.count > 0 && !tap.interrupted) {
220 return (event.pressed ? 222 return (event.pressed ?
221 MACRO( MD(LSHIFT), D(9), U(9), MU(LSHIFT), END ) : MACRO_NONE); 223 MACRO( D(LSHIFT), D(9), U(9), U(LSHIFT), END ) : MACRO_NONE);
222 } else { 224 } else {
223 return (event.pressed ? 225 return (event.pressed ?
224 MACRO( MD(LSHIFT), END ) : MACRO( MU(LSHIFT), END ) ); 226 MACRO( D(LSHIFT), END ) : MACRO( U(LSHIFT), END ) );
225 } 227 }
226 case RSHIFT_PAREN: 228 case RSHIFT_PAREN:
227 if (tap.count > 0 && !tap.interrupted) { 229 if (tap.count > 0 && !tap.interrupted) {
228 return (event.pressed ? 230 return (event.pressed ?
229 MACRO( MD(RSHIFT), D(0), U(0), MU(RSHIFT), END ) : MACRO_NONE); 231 MACRO( D(RSHIFT), D(0), U(0), U(RSHIFT), END ) : MACRO_NONE);
230 } else { 232 } else {
231 return (event.pressed ? 233 return (event.pressed ?
232 MACRO( MD(RSHIFT), END ) : MACRO( MU(RSHIFT), END ) ); 234 MACRO( D(RSHIFT), END ) : MACRO( U(RSHIFT), END ) );
233 } 235 }
234 case HELLO: 236 case HELLO:
235 return (event.pressed ? 237 return (event.pressed ?
236 MACRO( I(0), T(H), T(E), T(L), T(L), W(255), T(O), END ) : 238 MACRO( I(0), T(H), T(E), T(L), T(L), W(255), T(O), END ) :
237 MACRO_NONE ); 239 MACRO_NONE );
240 case VOLUP:
241 return (event.pressed ?
242 MACRO( D(VOLU), U(VOLU), END ) :
243 MACRO_NONE );
238 } 244 }
239 return MACRO_NONE; 245 return MACRO_NONE;
240} 246}