diff options
| author | tmk <nobody@nowhere> | 2013-03-11 14:39:06 +0900 |
|---|---|---|
| committer | tmk <nobody@nowhere> | 2013-03-11 14:39:06 +0900 |
| commit | 1d5bbb55f28eb2e9eff0543753b8cb85f3b94282 (patch) | |
| tree | 534a649228ca71c394a29ec38c4452804620c297 /common | |
| parent | fe2230cf60efdc5dafb85356e54b8b87cd52c3a3 (diff) | |
| download | qmk_firmware-1d5bbb55f28eb2e9eff0543753b8cb85f3b94282.tar.gz qmk_firmware-1d5bbb55f28eb2e9eff0543753b8cb85f3b94282.zip | |
Fix legacy keymap support
- need to define USE_LEGACY_KEYMAP to use legacy keymap
Diffstat (limited to 'common')
| -rw-r--r-- | common/keymap.c | 86 | ||||
| -rw-r--r-- | common/keymap.h | 21 |
2 files changed, 61 insertions, 46 deletions
diff --git a/common/keymap.c b/common/keymap.c index aa8d944a7..ace3f49b6 100644 --- a/common/keymap.c +++ b/common/keymap.c | |||
| @@ -26,7 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 26 | 26 | ||
| 27 | static action_t keycode_to_action(uint8_t keycode); | 27 | static action_t keycode_to_action(uint8_t keycode); |
| 28 | 28 | ||
| 29 | #ifdef USE_KEYMAP_V2 | 29 | |
| 30 | /* converts key to action */ | 30 | /* converts key to action */ |
| 31 | action_t action_for_key(uint8_t layer, key_t key) | 31 | action_t action_for_key(uint8_t layer, key_t key) |
| 32 | { | 32 | { |
| @@ -38,42 +38,20 @@ action_t action_for_key(uint8_t layer, key_t key) | |||
| 38 | return keycode_to_action(keycode); | 38 | return keycode_to_action(keycode); |
| 39 | } | 39 | } |
| 40 | } | 40 | } |
| 41 | #else | ||
| 42 | /* | ||
| 43 | * legacy keymap support | ||
| 44 | */ | ||
| 45 | /* translation for legacy keymap */ | ||
| 46 | action_t action_for_key(uint8_t layer, key_t key) | ||
| 47 | { | ||
| 48 | /* convert from legacy keycode to action */ | ||
| 49 | /* layer 16-31 indicate 'overlay' but not supported in legacy keymap */ | ||
| 50 | uint8_t keycode = keymap_get_keycode((layer & OVERLAY_MASK), key.row, key.col); | ||
| 51 | action_t action; | ||
| 52 | switch (keycode) { | ||
| 53 | case KC_FN0 ... KC_FN31: | ||
| 54 | { | ||
| 55 | uint8_t layer = keymap_fn_layer(FN_INDEX(keycode)); | ||
| 56 | uint8_t key = keymap_fn_keycode(FN_INDEX(keycode)); | ||
| 57 | if (key) { | ||
| 58 | action.code = ACTION_KEYMAP_TAP_KEY(layer, key); | ||
| 59 | } else { | ||
| 60 | action.code = ACTION_KEYMAP_MOMENTARY(layer); | ||
| 61 | } | ||
| 62 | } | ||
| 63 | return action; | ||
| 64 | default: | ||
| 65 | return keycode_to_action(keycode); | ||
| 66 | } | ||
| 67 | } | ||
| 68 | #endif | ||
| 69 | 41 | ||
| 70 | 42 | ||
| 43 | /* Macro */ | ||
| 71 | __attribute__ ((weak)) | 44 | __attribute__ ((weak)) |
| 72 | const prog_macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) { return MACRO_NONE; } | 45 | const prog_macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) |
| 46 | { | ||
| 47 | return MACRO_NONE; | ||
| 48 | } | ||
| 73 | 49 | ||
| 50 | /* Function */ | ||
| 74 | __attribute__ ((weak)) | 51 | __attribute__ ((weak)) |
| 75 | void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) {} | 52 | void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) |
| 76 | 53 | { | |
| 54 | } | ||
| 77 | 55 | ||
| 78 | 56 | ||
| 79 | 57 | ||
| @@ -83,14 +61,9 @@ static action_t keycode_to_action(uint8_t keycode) | |||
| 83 | action_t action; | 61 | action_t action; |
| 84 | switch (keycode) { | 62 | switch (keycode) { |
| 85 | case KC_A ... KC_EXSEL: | 63 | case KC_A ... KC_EXSEL: |
| 64 | case KC_LCTRL ... KC_RGUI: | ||
| 86 | action.code = ACTION_KEY(keycode); | 65 | action.code = ACTION_KEY(keycode); |
| 87 | break; | 66 | break; |
| 88 | case KC_LCTRL ... KC_LGUI: | ||
| 89 | action.code = ACTION_LMOD(keycode); | ||
| 90 | break; | ||
| 91 | case KC_RCTRL ... KC_RGUI: | ||
| 92 | action.code = ACTION_RMOD(keycode); | ||
| 93 | break; | ||
| 94 | case KC_SYSTEM_POWER ... KC_SYSTEM_WAKE: | 67 | case KC_SYSTEM_POWER ... KC_SYSTEM_WAKE: |
| 95 | action.code = ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(keycode)); | 68 | action.code = ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(keycode)); |
| 96 | break; | 69 | break; |
| @@ -109,3 +82,40 @@ static action_t keycode_to_action(uint8_t keycode) | |||
| 109 | } | 82 | } |
| 110 | return action; | 83 | return action; |
| 111 | } | 84 | } |
| 85 | |||
| 86 | |||
| 87 | |||
| 88 | #ifdef USE_LEGACY_KEYMAP | ||
| 89 | /* | ||
| 90 | * Legacy keymap support | ||
| 91 | * Consider using new keymap API instead. | ||
| 92 | */ | ||
| 93 | __attribute__ ((weak)) | ||
| 94 | uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) | ||
| 95 | { | ||
| 96 | return keymap_get_keycode(layer, key.row, key.col); | ||
| 97 | } | ||
| 98 | |||
| 99 | |||
| 100 | /* Legacy keymap support */ | ||
| 101 | __attribute__ ((weak)) | ||
| 102 | action_t keymap_fn_to_action(uint8_t keycode) | ||
| 103 | { | ||
| 104 | action_t action = { .code = ACTION_NO }; | ||
| 105 | switch (keycode) { | ||
| 106 | case KC_FN0 ... KC_FN31: | ||
| 107 | { | ||
| 108 | uint8_t layer = keymap_fn_layer(FN_INDEX(keycode)); | ||
| 109 | uint8_t key = keymap_fn_keycode(FN_INDEX(keycode)); | ||
| 110 | if (key) { | ||
| 111 | action.code = ACTION_KEYMAP_TAP_KEY(layer, key); | ||
| 112 | } else { | ||
| 113 | action.code = ACTION_KEYMAP_MOMENTARY(layer); | ||
| 114 | } | ||
| 115 | } | ||
| 116 | return action; | ||
| 117 | default: | ||
| 118 | return action; | ||
| 119 | } | ||
| 120 | } | ||
| 121 | #endif | ||
diff --git a/common/keymap.h b/common/keymap.h index 0c483483f..7efd91f70 100644 --- a/common/keymap.h +++ b/common/keymap.h | |||
| @@ -23,24 +23,29 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 23 | #include "action.h" | 23 | #include "action.h" |
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | #ifdef USE_KEYMAP_V2 | 26 | /* translates key to keycode */ |
| 27 | /* translates key to keycode | ||
| 28 | * layer: 0-15 for base layers | ||
| 29 | * 16-31 for overlays | ||
| 30 | */ | ||
| 31 | uint8_t keymap_key_to_keycode(uint8_t layer, key_t key); | 27 | uint8_t keymap_key_to_keycode(uint8_t layer, key_t key); |
| 28 | |||
| 32 | /* translates Fn keycode to action */ | 29 | /* translates Fn keycode to action */ |
| 33 | action_t keymap_fn_to_action(uint8_t keycode); | 30 | action_t keymap_fn_to_action(uint8_t keycode); |
| 34 | #else | 31 | |
| 35 | #warning "You are using LEGACY KEYAMP. Consider using NEW KEYMAP." | 32 | |
| 33 | |||
| 34 | #ifdef USE_LEGACY_KEYMAP | ||
| 36 | /* | 35 | /* |
| 37 | * legacy keymap support | 36 | * Legacy keymap |
| 37 | * Consider using new keymap API above instead. | ||
| 38 | */ | 38 | */ |
| 39 | /* keycode of key */ | 39 | /* keycode of key */ |
| 40 | __attribute__ ((deprecated)) | ||
| 40 | uint8_t keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t col); | 41 | uint8_t keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t col); |
| 42 | |||
| 41 | /* layer to move during press Fn key */ | 43 | /* layer to move during press Fn key */ |
| 44 | __attribute__ ((deprecated)) | ||
| 42 | uint8_t keymap_fn_layer(uint8_t fn_bits); | 45 | uint8_t keymap_fn_layer(uint8_t fn_bits); |
| 46 | |||
| 43 | /* keycode to send when release Fn key without using */ | 47 | /* keycode to send when release Fn key without using */ |
| 48 | __attribute__ ((deprecated)) | ||
| 44 | uint8_t keymap_fn_keycode(uint8_t fn_bits); | 49 | uint8_t keymap_fn_keycode(uint8_t fn_bits); |
| 45 | #endif | 50 | #endif |
| 46 | 51 | ||
