diff options
| author | tmk <nobody@nowhere> | 2013-01-15 19:04:58 +0900 |
|---|---|---|
| committer | tmk <nobody@nowhere> | 2013-01-16 13:21:35 +0900 |
| commit | 9f95e9cc27f2edf4336124b01c05d03dcd5ee5ac (patch) | |
| tree | 807687c0c202bd3c03eb8aad1a040285d8576ca1 | |
| parent | f609712da3b94ea36612a6f210bd6ce902b74631 (diff) | |
| download | qmk_firmware-9f95e9cc27f2edf4336124b01c05d03dcd5ee5ac.tar.gz qmk_firmware-9f95e9cc27f2edf4336124b01c05d03dcd5ee5ac.zip | |
Add support partly for modifier with tap key.
| -rw-r--r-- | common/action.c | 249 | ||||
| -rw-r--r-- | common/action.h | 161 | ||||
| -rw-r--r-- | keyboard/hhkb/keymap.c | 18 |
3 files changed, 239 insertions, 189 deletions
diff --git a/common/action.c b/common/action.c index 389fc5df1..7299a874a 100644 --- a/common/action.c +++ b/common/action.c | |||
| @@ -10,11 +10,12 @@ | |||
| 10 | #include "action.h" | 10 | #include "action.h" |
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | |||
| 14 | |||
| 15 | static void process(keyevent_t event, action_t action); | 13 | static void process(keyevent_t event, action_t action); |
| 16 | static void register_code(uint8_t code); | 14 | static void register_code(uint8_t code); |
| 17 | static void unregister_code(uint8_t code); | 15 | static void unregister_code(uint8_t code); |
| 16 | static void add_mods(uint8_t mods); | ||
| 17 | static void del_mods(uint8_t mods); | ||
| 18 | static void set_mods(uint8_t mods); | ||
| 18 | static void clear_keyboard(void); | 19 | static void clear_keyboard(void); |
| 19 | static void clear_keyboard_but_mods(void); | 20 | static void clear_keyboard_but_mods(void); |
| 20 | static bool sending_anykey(void); | 21 | static bool sending_anykey(void); |
| @@ -24,7 +25,6 @@ static void layer_switch(uint8_t new_layer); | |||
| 24 | /* tap */ | 25 | /* tap */ |
| 25 | #define TAP_TIME 200 | 26 | #define TAP_TIME 200 |
| 26 | static keyevent_t last_event = {}; | 27 | static keyevent_t last_event = {}; |
| 27 | static uint16_t last_event_time = 0; | ||
| 28 | static uint8_t tap_count = 0; | 28 | static uint8_t tap_count = 0; |
| 29 | 29 | ||
| 30 | /* layer */ | 30 | /* layer */ |
| @@ -32,6 +32,7 @@ uint8_t default_layer = 0; | |||
| 32 | uint8_t current_layer = 0; | 32 | uint8_t current_layer = 0; |
| 33 | keyrecord_t delaying_layer = {}; | 33 | keyrecord_t delaying_layer = {}; |
| 34 | 34 | ||
| 35 | /* waiting keys buffer */ | ||
| 35 | #define WAITING_KEYS_BUFFER 3 | 36 | #define WAITING_KEYS_BUFFER 3 |
| 36 | static keyrecord_t waiting_keys[WAITING_KEYS_BUFFER] = {}; | 37 | static keyrecord_t waiting_keys[WAITING_KEYS_BUFFER] = {}; |
| 37 | static uint8_t waiting_keys_head = 0; | 38 | static uint8_t waiting_keys_head = 0; |
| @@ -75,16 +76,87 @@ static void waiting_keys_process_in_current_layer(void) | |||
| 75 | } | 76 | } |
| 76 | 77 | ||
| 77 | 78 | ||
| 79 | void action_exec(keyevent_t event) | ||
| 80 | { | ||
| 81 | /* When delaying layer switch */ | ||
| 82 | if (delaying_layer.action.code) { | ||
| 83 | /* Layer switch when tap time elapses or waiting key is released */ | ||
| 84 | if ((timer_elapsed(delaying_layer.event.time) > TAP_TIME) || | ||
| 85 | (!event.pressed && waiting_keys_has(event.key))) { | ||
| 86 | /* layer switch */ | ||
| 87 | switch (delaying_layer.action.kind.id) { | ||
| 88 | case ACT_LAYER_PRESSED: | ||
| 89 | layer_switch(delaying_layer.action.layer.opt); | ||
| 90 | break; | ||
| 91 | case ACT_LAYER_BIT: | ||
| 92 | layer_switch(current_layer | delaying_layer.action.layer.opt); | ||
| 93 | break; | ||
| 94 | } | ||
| 95 | delaying_layer = (keyrecord_t){}; | ||
| 96 | |||
| 97 | /* Process waiting keys in new layer */ | ||
| 98 | waiting_keys_process_in_current_layer(); | ||
| 99 | } | ||
| 100 | /* when delaying layer key is released within delay term */ | ||
| 101 | else if (!event.pressed && KEYEQ(event.key, delaying_layer.event.key)) { | ||
| 102 | /* tap key down */ | ||
| 103 | debug("tap[delaying_layer](register): fist\n"); | ||
| 104 | uint8_t tmp_mods = host_get_mods(); | ||
| 105 | host_set_mods(delaying_layer.mods); | ||
| 106 | register_code(delaying_layer.action.layer.code); | ||
| 107 | delaying_layer = (keyrecord_t){}; | ||
| 108 | host_set_mods(tmp_mods); | ||
| 109 | |||
| 110 | /* process waiting keys */ | ||
| 111 | waiting_keys_process_in_current_layer(); | ||
| 112 | } | ||
| 113 | } | ||
| 114 | |||
| 115 | // not real event. event just to update delaying layer. | ||
| 116 | if (IS_NOEVENT(event)) { | ||
| 117 | return; | ||
| 118 | } | ||
| 119 | |||
| 120 | /* count tap when key is up */ | ||
| 121 | if (KEYEQ(event.key, last_event.key) && timer_elapsed(last_event.time) <= TAP_TIME) { | ||
| 122 | if (!event.pressed) tap_count++; | ||
| 123 | } else { | ||
| 124 | tap_count = 0; | ||
| 125 | } | ||
| 126 | |||
| 127 | action_t action = keymap_get_action(current_layer, event.key.row, event.key.col); | ||
| 128 | |||
| 129 | // TODO: all key events(pressed, released) should be recorded? | ||
| 130 | /* postpone key-down events while delaying layer */ | ||
| 131 | if (delaying_layer.action.code) { | ||
| 132 | if (event.pressed) { | ||
| 133 | waiting_keys_enqueue(event, action); | ||
| 134 | } else { | ||
| 135 | process(event, action); | ||
| 136 | } | ||
| 137 | } else { | ||
| 138 | process(event, action); | ||
| 139 | } | ||
| 140 | |||
| 141 | /* last event */ | ||
| 142 | last_event = event; | ||
| 143 | } | ||
| 144 | |||
| 145 | |||
| 78 | static void process(keyevent_t event, action_t action) | 146 | static void process(keyevent_t event, action_t action) |
| 79 | { | 147 | { |
| 80 | //action_t action = keymap_get_action(current_layer, event.key.row, event.key.col); | 148 | //action_t action = keymap_get_action(current_layer, event.key.row, event.key.col); |
| 81 | debug("action: "); debug_hex16(action.code); debug("\n"); | 149 | debug("action: "); debug_hex16(action.code); |
| 82 | 150 | if (event.pressed) debug("[down]\n"); else debug("[up]\n"); | |
| 83 | 151 | ||
| 84 | switch (action.kind.id) { | 152 | switch (action.kind.id) { |
| 85 | /* Key and Mods */ | 153 | /* Key and Mods */ |
| 86 | case ACT_LMODS: | 154 | case ACT_LMODS: |
| 87 | // normal key or key plus mods | 155 | // |pressed |released |
| 156 | // --------------+---------------------------------+------------ | ||
| 157 | // key |down(key) |up(key) | ||
| 158 | // mods |add(mods) |del(mods) | ||
| 159 | // key with mods |add(mods), down(key), unset(mods)|up(key) | ||
| 88 | if (event.pressed) { | 160 | if (event.pressed) { |
| 89 | uint8_t tmp_mods = host_get_mods(); | 161 | uint8_t tmp_mods = host_get_mods(); |
| 90 | if (action.key.mods) { | 162 | if (action.key.mods) { |
| @@ -105,6 +177,11 @@ static void process(keyevent_t event, action_t action) | |||
| 105 | } | 177 | } |
| 106 | break; | 178 | break; |
| 107 | case ACT_RMODS: | 179 | case ACT_RMODS: |
| 180 | // |pressed |released | ||
| 181 | // --------------+---------------------------------+------------ | ||
| 182 | // key |down(key) |up(key) | ||
| 183 | // mods |add(mods) |del(mods) | ||
| 184 | // key with mods |add(mods), down(key), unset(mods)|up(key) | ||
| 108 | if (event.pressed) { | 185 | if (event.pressed) { |
| 109 | uint8_t tmp_mods = host_get_mods(); | 186 | uint8_t tmp_mods = host_get_mods(); |
| 110 | if (action.key.mods) { | 187 | if (action.key.mods) { |
| @@ -124,9 +201,49 @@ static void process(keyevent_t event, action_t action) | |||
| 124 | unregister_code(action.key.code); | 201 | unregister_code(action.key.code); |
| 125 | } | 202 | } |
| 126 | break; | 203 | break; |
| 127 | case ACT_LMOD_TAP: | 204 | case ACT_LMODS_TAP: |
| 205 | if (event.pressed) { | ||
| 206 | if (tap_count == 0) { | ||
| 207 | add_mods(action.key.mods); | ||
| 208 | } else { | ||
| 209 | debug("tap[lmods](register): "); debug_hex(tap_count); debug("\n"); | ||
| 210 | register_code(action.key.code); | ||
| 211 | } | ||
| 212 | } else { | ||
| 213 | if (tap_count == 0) { | ||
| 214 | del_mods(action.key.mods); | ||
| 215 | } else if (tap_count == 1) { | ||
| 216 | debug("tap[lmods](register/unregister): "); debug_hex(tap_count); debug("\n"); | ||
| 217 | del_mods(action.key.mods); | ||
| 218 | register_code(action.key.code); | ||
| 219 | unregister_code(action.key.code); | ||
| 220 | } else { | ||
| 221 | debug("tap[lmods](unregister): "); debug_hex(tap_count); debug("\n"); | ||
| 222 | unregister_code(action.key.code); | ||
| 223 | } | ||
| 224 | } | ||
| 128 | break; | 225 | break; |
| 129 | case ACT_RMOD_TAP: | 226 | case ACT_RMODS_TAP: |
| 227 | if (event.pressed) { | ||
| 228 | if (tap_count == 0) { | ||
| 229 | add_mods(action.key.mods<<4); | ||
| 230 | } else { | ||
| 231 | debug("tap[rmods](register): "); debug_hex(tap_count); debug("\n"); | ||
| 232 | register_code(action.key.code); | ||
| 233 | } | ||
| 234 | } else { | ||
| 235 | if (tap_count == 0) { | ||
| 236 | del_mods(action.key.mods<<4); | ||
| 237 | } else if (tap_count == 1) { | ||
| 238 | debug("tap[rmods](register/unregister): "); debug_hex(tap_count); debug("\n"); | ||
| 239 | del_mods(action.key.mods<<4); | ||
| 240 | register_code(action.key.code); | ||
| 241 | unregister_code(action.key.code); | ||
| 242 | } else { | ||
| 243 | debug("tap[rmods](unregister): "); debug_hex(tap_count); debug("\n"); | ||
| 244 | unregister_code(action.key.code); | ||
| 245 | } | ||
| 246 | } | ||
| 130 | break; | 247 | break; |
| 131 | 248 | ||
| 132 | /* other HID usage */ | 249 | /* other HID usage */ |
| @@ -186,6 +303,7 @@ static void process(keyevent_t event, action_t action) | |||
| 186 | // with tap key | 303 | // with tap key |
| 187 | if (event.pressed) { | 304 | if (event.pressed) { |
| 188 | if (tap_count == 0) { | 305 | if (tap_count == 0) { |
| 306 | // not tapping yet | ||
| 189 | if (host_has_anykey()) { | 307 | if (host_has_anykey()) { |
| 190 | register_code(action.layer.code); | 308 | register_code(action.layer.code); |
| 191 | } else { | 309 | } else { |
| @@ -197,22 +315,14 @@ static void process(keyevent_t event, action_t action) | |||
| 197 | }; | 315 | }; |
| 198 | } | 316 | } |
| 199 | } else if (tap_count > 0) { | 317 | } else if (tap_count > 0) { |
| 200 | debug("tap: "); debug_hex(tap_count); debug("\n"); | 318 | // pressed after tapping |
| 319 | debug("tap[layer](register): "); debug_hex(tap_count); debug("\n"); | ||
| 201 | register_code(action.layer.code); | 320 | register_code(action.layer.code); |
| 202 | } | 321 | } |
| 203 | } else { | 322 | } else { |
| 204 | // tap key | 323 | // released after tapping |
| 205 | if (KEYEQ(event.key, delaying_layer.event.key) && | 324 | debug("tap[layer](unregister): "); debug_hex(tap_count); debug("\n"); |
| 206 | timer_elapsed(delaying_layer.event.time) <= TAP_TIME) { | 325 | unregister_code(action.layer.code); |
| 207 | uint8_t tmp_mods = host_get_mods(); | ||
| 208 | host_set_mods(delaying_layer.mods); | ||
| 209 | register_code(delaying_layer.action.layer.code); | ||
| 210 | host_set_mods(tmp_mods); | ||
| 211 | unregister_code(delaying_layer.action.layer.code); | ||
| 212 | } else { | ||
| 213 | unregister_code(action.layer.code); | ||
| 214 | } | ||
| 215 | delaying_layer = (keyrecord_t){}; | ||
| 216 | } | 326 | } |
| 217 | break; | 327 | break; |
| 218 | } | 328 | } |
| @@ -220,7 +330,7 @@ static void process(keyevent_t event, action_t action) | |||
| 220 | case ACT_LAYER_RELEASED: | 330 | case ACT_LAYER_RELEASED: |
| 221 | switch (action.layer.code) { | 331 | switch (action.layer.code) { |
| 222 | case 0x00: | 332 | case 0x00: |
| 223 | if (event.pressed) { | 333 | if (!event.pressed) { |
| 224 | layer_switch(action.layer.opt); | 334 | layer_switch(action.layer.opt); |
| 225 | } | 335 | } |
| 226 | break; | 336 | break; |
| @@ -274,7 +384,7 @@ static void process(keyevent_t event, action_t action) | |||
| 274 | }; | 384 | }; |
| 275 | } | 385 | } |
| 276 | } else if (tap_count > 0) { | 386 | } else if (tap_count > 0) { |
| 277 | debug("tap: "); debug_hex(tap_count); debug("\n"); | 387 | debug("tap[layer_bit](register): "); debug_hex(tap_count); debug("\n"); |
| 278 | register_code(action.layer.code); | 388 | register_code(action.layer.code); |
| 279 | } | 389 | } |
| 280 | } else { | 390 | } else { |
| @@ -348,77 +458,6 @@ static void process(keyevent_t event, action_t action) | |||
| 348 | } | 458 | } |
| 349 | } | 459 | } |
| 350 | 460 | ||
| 351 | void action_exec(keyevent_t event) | ||
| 352 | { | ||
| 353 | /* | ||
| 354 | debug("key["); debug_hex8(event.key.row); debug(":"); debug_hex8(event.key.col); | ||
| 355 | if (event.pressed) debug("]down\n"); else debug("]up\n"); | ||
| 356 | */ | ||
| 357 | |||
| 358 | /* When delaying layer switch */ | ||
| 359 | if (delaying_layer.action.code) { | ||
| 360 | /* Layer switch when tap time elapses or waiting key is released */ | ||
| 361 | if ((timer_elapsed(delaying_layer.event.time) > TAP_TIME) || | ||
| 362 | (!event.pressed && waiting_keys_has(event.key))) { | ||
| 363 | /* layer switch */ | ||
| 364 | switch (delaying_layer.action.kind.id) { | ||
| 365 | case ACT_LAYER_PRESSED: | ||
| 366 | layer_switch(delaying_layer.action.layer.opt); | ||
| 367 | break; | ||
| 368 | case ACT_LAYER_BIT: | ||
| 369 | layer_switch(current_layer | delaying_layer.action.layer.opt); | ||
| 370 | break; | ||
| 371 | } | ||
| 372 | delaying_layer = (keyrecord_t){}; | ||
| 373 | |||
| 374 | /* Process waiting keys in new layer */ | ||
| 375 | waiting_keys_process_in_current_layer(); | ||
| 376 | } | ||
| 377 | /* when delaying layer key is released within delay term */ | ||
| 378 | else if (!event.pressed && KEYEQ(event.key, delaying_layer.event.key)) { | ||
| 379 | /* tap key down */ | ||
| 380 | uint8_t tmp_mods = host_get_mods(); | ||
| 381 | host_set_mods(delaying_layer.mods); | ||
| 382 | register_code(delaying_layer.action.layer.code); | ||
| 383 | delaying_layer = (keyrecord_t){}; | ||
| 384 | host_set_mods(tmp_mods); | ||
| 385 | |||
| 386 | /* process waiting keys */ | ||
| 387 | waiting_keys_process_in_current_layer(); | ||
| 388 | } | ||
| 389 | } | ||
| 390 | |||
| 391 | // not real event. event just to update delaying layer. | ||
| 392 | if (IS_NOEVENT(event)) { | ||
| 393 | return; | ||
| 394 | } | ||
| 395 | |||
| 396 | /* count tap when key is up */ | ||
| 397 | if (KEYEQ(event.key, last_event.key) && timer_elapsed(last_event.time) <= TAP_TIME) { | ||
| 398 | if (!event.pressed) tap_count++; | ||
| 399 | } else { | ||
| 400 | tap_count = 0; | ||
| 401 | } | ||
| 402 | |||
| 403 | action_t action = keymap_get_action(current_layer, event.key.row, event.key.col); | ||
| 404 | |||
| 405 | // TODO: all key events(pressed, released) should be recorded? | ||
| 406 | /* postpone key-down events while delaying layer */ | ||
| 407 | if (delaying_layer.action.code) { | ||
| 408 | if (event.pressed) { | ||
| 409 | waiting_keys_enqueue(event, action); | ||
| 410 | } else { | ||
| 411 | process(event, action); | ||
| 412 | } | ||
| 413 | } else { | ||
| 414 | process(event, action); | ||
| 415 | } | ||
| 416 | |||
| 417 | /* last event */ | ||
| 418 | last_event = event; | ||
| 419 | } | ||
| 420 | |||
| 421 | |||
| 422 | static void register_code(uint8_t code) | 461 | static void register_code(uint8_t code) |
| 423 | { | 462 | { |
| 424 | if (code == KC_NO) { | 463 | if (code == KC_NO) { |
| @@ -449,6 +488,28 @@ static void unregister_code(uint8_t code) | |||
| 449 | } | 488 | } |
| 450 | } | 489 | } |
| 451 | 490 | ||
| 491 | static void add_mods(uint8_t mods) | ||
| 492 | { | ||
| 493 | if (mods) { | ||
| 494 | host_add_mods(mods); | ||
| 495 | host_send_keyboard_report(); | ||
| 496 | } | ||
| 497 | } | ||
| 498 | |||
| 499 | static void del_mods(uint8_t mods) | ||
| 500 | { | ||
| 501 | if (mods) { | ||
| 502 | host_del_mods(mods); | ||
| 503 | host_send_keyboard_report(); | ||
| 504 | } | ||
| 505 | } | ||
| 506 | |||
| 507 | static void set_mods(uint8_t mods) | ||
| 508 | { | ||
| 509 | host_set_mods(mods); | ||
| 510 | host_send_keyboard_report(); | ||
| 511 | } | ||
| 512 | |||
| 452 | static void clear_keyboard(void) | 513 | static void clear_keyboard(void) |
| 453 | { | 514 | { |
| 454 | host_clear_mods(); | 515 | host_clear_mods(); |
diff --git a/common/action.h b/common/action.h index 942ce191a..3115c67f4 100644 --- a/common/action.h +++ b/common/action.h | |||
| @@ -5,55 +5,57 @@ | |||
| 5 | 5 | ||
| 6 | 6 | ||
| 7 | /* Key Action(16bit code) | 7 | /* Key Action(16bit code) |
| 8 | 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 | 8 | |
| 9 | ------------------------------------------------ | 9 | Keyboard Keys |
| 10 | ACT_LMODS(0000) | 10 | ------------- |
| 11 | 0 0 0 0| 0 0 0 0| 0 0 0 0 0 0| 0 0 No action | 11 | ACT_LMODS(0000): |
| 12 | 0 0 0 0| 0 0 0 0| keycode(8) Key | 12 | 0000|0000|000000|00 No action |
| 13 | 0 0 0 0| mods(4) | 0 0 0 0 0 0| 0 0 Lmods Momentary | 13 | 0000|mods|000000|00 Left mods Momentary |
| 14 | 0 0 0 0| mods(4) | 0 0 0 0 0 0| 0 1 Lmods OneShot | 14 | 0000|mods|000000|01 Left mods OneShot |
| 15 | 0 0 0 0| mods(4) | 0 0 0 0 0 0| 1 0 (reserved) | 15 | 0000|mods|000000|10 (reserved) |
| 16 | 0 0 0 0| mods(4) | 0 0 0 0 0 0| 1 1 (reserved) | 16 | 0000|mods|000000|11 (reserved) |
| 17 | 0 0 0 0| mods(4) | keycode(8) Key+Lmods | 17 | 0000|0000| keycode Key |
| 18 | 18 | 0000|mods| keycode Key+Left mods | |
| 19 | ACT_RMODS(0001) | 19 | |
| 20 | 0 0 0 1| 0 0 0 0| 0 0 0 0 0 0 0 0 No action(not used) | 20 | ACT_RMODS(0001): |
| 21 | 0 0 0 1| 0 0 0 0| keycode(8) Key(not used) | 21 | 0001|0000|000000|00 No action |
| 22 | 0 0 0 1| mods(4) | 0 0 0 0 0 0| 0 0 Rmods Momentary | 22 | 0001|mods|000000|00 Right mods Momentary |
| 23 | 0 0 0 1| mods(4) | 0 0 0 0 0 0| 0 1 Rmods OneShot | 23 | 0001|mods|000000|01 Right mods OneShot |
| 24 | 0 0 0 1| mods(4) | 0 0 0 0 0 0| 1 0 (reserved) | 24 | 0001|mods|000000|10 (reserved) |
| 25 | 0 0 0 1| mods(4) | 0 0 0 0 0 0| 1 1 (reserved) | 25 | 0001|mods|000000|11 (reserved) |
| 26 | 0 0 0 1| mods(4) | keycode(8) Key+Rmod | 26 | 0001|0000| keycode Key |
| 27 | 27 | 0001|mods| keycode Key+Right mods | |
| 28 | ACT_LMODS_TAP(0010) | 28 | |
| 29 | 0 0 1 0| 0 0 0 0| X X X X X X X X (reserved)[00-FF] | 29 | ACT_LMODS_TAP(0010): |
| 30 | 0 0 1 0| mods(4) | 0 0 0 0 0 0| X X (reserved) | 30 | 0010|mods| keycode Left mods+tap Key |
| 31 | 0 0 1 0| mods(4) | keycode(8) Lmods+tap Key | 31 | |
| 32 | 0 0 1 0| mods(4) | 1 1 1 1| X X X X (reserved)[F0-FF] | 32 | ACT_RMODS_TAP(0011): |
| 33 | 33 | 0011|mods| keycode Right mods+tap Key | |
| 34 | ACT_RMODS_TAP(0011) | ||
| 35 | 0 0 1 1| 0 0 0 0| X X X X X X X X (reserved)[00-FF] | ||
| 36 | 0 0 1 1| mods(4) | 0 0 0 0 0 0| X X (reserved) | ||
| 37 | 0 0 1 1| mods(4) | keycode(8) Rmods+tap Key | ||
| 38 | 0 0 1 1| mods(4) | 1 1 1 1| X X X X (reserved)[F0-FF] | ||
| 39 | 34 | ||
| 40 | ACT_USAGE - other HID usage than keyboard | 35 | |
| 41 | 0 1 0 0| 0 0| usage(10) System usage | 36 | Other HID Usage |
| 42 | 0 1 0 0| 0 1| usage(10) Consumer usage | 37 | --------------- |
| 43 | 0 1 0 0| 1 0| usage(10) (reserved) | 38 | This action handles other usages than keyboard. |
| 44 | 0 1 0 0| 1 1| usage(10) (reserved) | 39 | ACT_USAGE(0100): |
| 45 | 40 | 0100|00| usage(10) System control(0x80) - General Desktop page(0x01) | |
| 46 | ACT_MOUSEKEY(0110) | 41 | 0100|01| usage(10) Consumer control(0x01) - Consumer page(0x0C) |
| 47 | 0 1 0 1| X X X X| keycode(8) Mouse key | 42 | 0100|10| usage(10) (reserved) |
| 48 | ??? TODO: refactor | 43 | 0100|11| usage(10) (reserved) |
| 49 | 0 1 0 1| 0 0 X X| accel(5) |cursor(3) Mouse key | 44 | |
| 50 | 0 1 0 1| 0 1 X X| accel(5) |wheel(3) Mouse key | 45 | |
| 51 | 0 1 0 1| 1 0 X X| button(8) Mouse key | 46 | Mouse Keys |
| 52 | 0 1 0 1| 1 1 X X| button(8) Mouse key | 47 | ---------- |
| 53 | ??? | 48 | ACT_MOUSEKEY(0110): |
| 54 | 49 | 0101|XXXX| keycode Mouse key | |
| 55 | Layer Action | 50 | |
| 56 | ------------ | 51 | |
| 52 | Layer Actions | ||
| 53 | ------------- | ||
| 54 | ACT_LAYER_PRESSED(1000): Set layer on key pressed | ||
| 55 | ACT_LAYER_RELEASED(1001): Set layer on key released | ||
| 56 | ACT_LAYER_BIT(1010): On/Off layer bit | ||
| 57 | ACT_LAYER_EXT(1011): Extentions | ||
| 58 | |||
| 57 | 1000|LLLL|0000 0000 set layer L when pressed | 59 | 1000|LLLL|0000 0000 set layer L when pressed |
| 58 | 1001|LLLL|0000 0000 set layer L when released | 60 | 1001|LLLL|0000 0000 set layer L when released |
| 59 | 1010|BBBB|0000 0000 on/off bit B when pressed/released | 61 | 1010|BBBB|0000 0000 on/off bit B when pressed/released |
| @@ -79,16 +81,19 @@ Layer Action | |||
| 79 | 1011|0001| keyocde set default layer when released[tap is ignored/not used] | 81 | 1011|0001| keyocde set default layer when released[tap is ignored/not used] |
| 80 | 82 | ||
| 81 | 83 | ||
| 82 | ACT_MACRO(1100) | 84 | Extensions(11XX) |
| 83 | 1 1 0 0| option(4) | macro-table id(8) Macro play(Flash) | 85 | ---------------- |
| 84 | 1 1 0 0| option(4) | macro-table id(8) Macro play(EEPROM) | 86 | NOTE: NOT FIXED |
| 85 | 1 1 0 0| 1 1 1 1| macro-table id(8) Macro record | 87 | |
| 88 | ACT_MACRO(1100): | ||
| 89 | 1100|opt | id(8) Macro play | ||
| 90 | 1100|1111| id(8) Macro record | ||
| 86 | 91 | ||
| 87 | ACT_COMMAND(1110) | 92 | ACT_COMMAND(1110): |
| 88 | 1 1 1 0| option(4) | comamnd id(8) Built-in Command exec | 93 | 1110|opt | id(8) Built-in Command exec |
| 89 | 94 | ||
| 90 | ACT_FUNCTION(1111) | 95 | ACT_FUNCTION(1111): |
| 91 | 1 1 1 1| function address(4K range) Function | 96 | 1111| address(12) Function |
| 92 | Macro record(dynamicly) | 97 | Macro record(dynamicly) |
| 93 | Macro play(dynamicly) | 98 | Macro play(dynamicly) |
| 94 | TODO: modifier + [tap key /w mod] | 99 | TODO: modifier + [tap key /w mod] |
| @@ -98,19 +103,22 @@ TODO: modifier + [tap key /w mod] | |||
| 98 | */ | 103 | */ |
| 99 | 104 | ||
| 100 | enum action_id { | 105 | enum action_id { |
| 101 | ACT_LMODS = 0b0000, | 106 | ACT_LMODS = 0b0000, |
| 102 | ACT_RMODS = 0b0001, | 107 | ACT_RMODS = 0b0001, |
| 103 | ACT_LMOD_TAP = 0b0010, | 108 | ACT_LMODS_TAP = 0b0010, |
| 104 | ACT_RMOD_TAP = 0b0011, | 109 | ACT_RMODS_TAP = 0b0011, |
| 105 | ACT_USAGE = 0b0100, | 110 | |
| 106 | ACT_MOUSEKEY = 0b0101, | 111 | ACT_USAGE = 0b0100, |
| 107 | ACT_LAYER_PRESSED = 0b1000, | 112 | ACT_MOUSEKEY = 0b0101, |
| 108 | ACT_LAYER_RELEASED = 0b1001, | 113 | |
| 109 | ACT_LAYER_BIT = 0b1010, | 114 | ACT_LAYER_PRESSED = 0b1000, |
| 110 | ACT_LAYER_EXT = 0b1011, | 115 | ACT_LAYER_RELEASED = 0b1001, |
| 111 | ACT_MACRO = 0b1100, | 116 | ACT_LAYER_BIT = 0b1010, |
| 112 | ACT_COMMAND = 0b1110, | 117 | ACT_LAYER_EXT = 0b1011, |
| 113 | ACT_FUNCTION = 0b1111 | 118 | |
| 119 | ACT_MACRO = 0b1100, | ||
| 120 | ACT_COMMAND = 0b1110, | ||
| 121 | ACT_FUNCTION = 0b1111 | ||
| 114 | }; | 122 | }; |
| 115 | 123 | ||
| 116 | // TODO: not portable across compiler/endianness? | 124 | // TODO: not portable across compiler/endianness? |
| @@ -169,20 +177,13 @@ typedef struct { | |||
| 169 | 177 | ||
| 170 | 178 | ||
| 171 | void action_exec(keyevent_t event); | 179 | void action_exec(keyevent_t event); |
| 172 | /* | ||
| 173 | void key_action(uint8_t code, keyevent_t event); | ||
| 174 | void mod_action(uint8_t code, keyevent_t event); | ||
| 175 | void fn_action(uint8_t code, keyevent_t event); | ||
| 176 | */ | ||
| 177 | 180 | ||
| 178 | 181 | ||
| 182 | // TODO: proper names | ||
| 179 | /* action_t utility */ | 183 | /* action_t utility */ |
| 180 | /* | ||
| 181 | #define ACTION_NO { .code = 0 } | ||
| 182 | #define ACTION(kind, param) { .code = ((kind)<<12 | (param)) } | ||
| 183 | */ | ||
| 184 | #define ACTION_NO 0 | 184 | #define ACTION_NO 0 |
| 185 | #define ACTION(kind, param) ((kind)<<12 | (param)) | 185 | #define ACTION(kind, param) ((kind)<<12 | (param)) |
| 186 | #define MOD_BITS(mods) (((mods)>>4 | (mods)) & 0x0F) | ||
| 186 | 187 | ||
| 187 | /* Key & Mods */ | 188 | /* Key & Mods */ |
| 188 | #define ACTION_KEY(key) ACTION(ACT_LMODS, key) | 189 | #define ACTION_KEY(key) ACTION(ACT_LMODS, key) |
| @@ -197,8 +198,8 @@ void fn_action(uint8_t code, keyevent_t event); | |||
| 197 | #define ACTION_RMODS_SWITCH(mods, tap) ACTION(ACT_RMODS, (mods)<<8 | 0xF0 | (tap)) | 198 | #define ACTION_RMODS_SWITCH(mods, tap) ACTION(ACT_RMODS, (mods)<<8 | 0xF0 | (tap)) |
| 198 | #define ACTION_RMODS_TOGGLE(mods, tap) ACTION(ACT_RMODS, (mods)<<8 | 0xF1 | (tap)) | 199 | #define ACTION_RMODS_TOGGLE(mods, tap) ACTION(ACT_RMODS, (mods)<<8 | 0xF1 | (tap)) |
| 199 | /* Mods + Tap key */ | 200 | /* Mods + Tap key */ |
| 200 | #define ACTION_LMODS_TAP(mods, key) ACTION(ACT_LMODS_TAP,(mods)<<8 | (key)) | 201 | #define ACTION_LMODS_TAP(mods, key) ACTION(ACT_LMODS_TAP, MOD_BITS(mods)<<8 | (key)) |
| 201 | #define ACTION_RMODS_TAP(mods, key) ACTION(ACT_RMODS_TAP,(mods)<<8 | (key)) | 202 | #define ACTION_RMODS_TAP(mods, key) ACTION(ACT_RMODS_TAP, MOD_BITS(mods)<<8 | (key)) |
| 202 | 203 | ||
| 203 | /* Layer Switch */ | 204 | /* Layer Switch */ |
| 204 | #define ACTION_LAYER_SET_ON_PRESSED(layer) ACTION(ACT_LAYER_PRESSED, (layer)<<8 | 0x00) | 205 | #define ACTION_LAYER_SET_ON_PRESSED(layer) ACTION(ACT_LAYER_PRESSED, (layer)<<8 | 0x00) |
diff --git a/keyboard/hhkb/keymap.c b/keyboard/hhkb/keymap.c index 38461290b..e29b37b16 100644 --- a/keyboard/hhkb/keymap.c +++ b/keyboard/hhkb/keymap.c | |||
| @@ -51,18 +51,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | 53 | ||
| 54 | /* | ||
| 55 | static const action_t PROGMEM fn_actions[] = { | ||
| 56 | ACTION_LAYER_TO_DEFAULT_ON_RELEASED, // Fn0 | ||
| 57 | ACTION_LAYER_SET_ON_PRESSED(1), // Fn1 | ||
| 58 | ACTION_LAYER_SET_TAP_KEY(2, KC_SLASH), // Fn2 | ||
| 59 | ACTION_LAYER_SET_TAP_KEY(3, KC_SCLN), // Fn3 | ||
| 60 | ACTION_LAYER_SET_ON_PRESSED(3), // Fn4 | ||
| 61 | ACTION_LAYER_SET_TAP_KEY(5, KC_SPC), // Fn5 | ||
| 62 | ACTION_NO, // Fn6 | ||
| 63 | ACTION_NO, // Fn7 | ||
| 64 | }; | ||
| 65 | */ | ||
| 66 | static const uint16_t PROGMEM fn_actions[] = { | 54 | static const uint16_t PROGMEM fn_actions[] = { |
| 67 | ACTION_LAYER_TO_DEFAULT_ON_RELEASED, // Fn0 | 55 | ACTION_LAYER_TO_DEFAULT_ON_RELEASED, // Fn0 |
| 68 | ACTION_LAYER_SET_ON_PRESSED(1), // Fn1 | 56 | ACTION_LAYER_SET_ON_PRESSED(1), // Fn1 |
| @@ -70,8 +58,8 @@ static const uint16_t PROGMEM fn_actions[] = { | |||
| 70 | ACTION_LAYER_SET_TAP_KEY(3, KC_SCLN), // Fn3 | 58 | ACTION_LAYER_SET_TAP_KEY(3, KC_SCLN), // Fn3 |
| 71 | ACTION_LAYER_SET_ON_PRESSED(3), // Fn4 | 59 | ACTION_LAYER_SET_ON_PRESSED(3), // Fn4 |
| 72 | ACTION_LAYER_SET_TAP_KEY(5, KC_SPC), // Fn5 | 60 | ACTION_LAYER_SET_TAP_KEY(5, KC_SPC), // Fn5 |
| 73 | ACTION_NO, // Fn6 | 61 | ACTION_LMODS_TAP(MOD_BIT(KC_LCTL), KC_BSPC), // Fn6 |
| 74 | ACTION_NO, // Fn7 | 62 | ACTION_RMODS_TAP(MOD_BIT(KC_RCTL), KC_ENT), // Fn7 |
| 75 | }; | 63 | }; |
| 76 | 64 | ||
| 77 | 65 | ||
| @@ -91,7 +79,7 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |||
| 91 | */ | 79 | */ |
| 92 | KEYMAP(ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSLS,GRV, \ | 80 | KEYMAP(ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSLS,GRV, \ |
| 93 | TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSPC, \ | 81 | TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSPC, \ |
| 94 | LCTL,A, S, D, F, G, H, J, K, L, FN3, QUOT,ENT, \ | 82 | FN6, A, S, D, F, G, H, J, K, L, FN3, QUOT,FN7, \ |
| 95 | LSFT,Z, X, C, V, B, N, M, COMM,DOT, FN2, RSFT,FN1, \ | 83 | LSFT,Z, X, C, V, B, N, M, COMM,DOT, FN2, RSFT,FN1, \ |
| 96 | LGUI,LALT, FN5, RALT,FN4), | 84 | LGUI,LALT, FN5, RALT,FN4), |
| 97 | 85 | ||
