diff options
Diffstat (limited to 'common/keymap.c')
| -rw-r--r-- | common/keymap.c | 91 |
1 files changed, 59 insertions, 32 deletions
diff --git a/common/keymap.c b/common/keymap.c index 078615814..aa8d944a7 100644 --- a/common/keymap.c +++ b/common/keymap.c | |||
| @@ -14,13 +14,71 @@ GNU General Public License for more details. | |||
| 14 | You should have received a copy of the GNU General Public License | 14 | You should have received a copy of the GNU General Public License |
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | */ | 16 | */ |
| 17 | #include <avr/pgmspace.h> | ||
| 17 | #include "keymap.h" | 18 | #include "keymap.h" |
| 18 | #include "report.h" | 19 | #include "report.h" |
| 19 | #include "keycode.h" | 20 | #include "keycode.h" |
| 21 | #include "layer_switch.h" | ||
| 20 | #include "action.h" | 22 | #include "action.h" |
| 23 | #include "action_macro.h" | ||
| 24 | #include "debug.h" | ||
| 21 | 25 | ||
| 22 | 26 | ||
| 23 | action_t keymap_keycode_to_action(uint8_t keycode) | 27 | static action_t keycode_to_action(uint8_t keycode); |
| 28 | |||
| 29 | #ifdef USE_KEYMAP_V2 | ||
| 30 | /* converts key to action */ | ||
| 31 | action_t action_for_key(uint8_t layer, key_t key) | ||
| 32 | { | ||
| 33 | uint8_t keycode = keymap_key_to_keycode(layer, key); | ||
| 34 | switch (keycode) { | ||
| 35 | case KC_FN0 ... KC_FN31: | ||
| 36 | return keymap_fn_to_action(keycode); | ||
| 37 | default: | ||
| 38 | return keycode_to_action(keycode); | ||
| 39 | } | ||
| 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 | |||
| 70 | |||
| 71 | __attribute__ ((weak)) | ||
| 72 | const prog_macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) { return MACRO_NONE; } | ||
| 73 | |||
| 74 | __attribute__ ((weak)) | ||
| 75 | void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) {} | ||
| 76 | |||
| 77 | |||
| 78 | |||
| 79 | |||
| 80 | /* translates keycode to action */ | ||
| 81 | static action_t keycode_to_action(uint8_t keycode) | ||
| 24 | { | 82 | { |
| 25 | action_t action; | 83 | action_t action; |
| 26 | switch (keycode) { | 84 | switch (keycode) { |
| @@ -51,34 +109,3 @@ action_t keymap_keycode_to_action(uint8_t keycode) | |||
| 51 | } | 109 | } |
| 52 | return action; | 110 | return action; |
| 53 | } | 111 | } |
| 54 | |||
| 55 | #ifndef NO_LEGACY_KEYMAP_SUPPORT | ||
| 56 | /* legacy support with weak reference */ | ||
| 57 | __attribute__ ((weak)) | ||
| 58 | action_t action_for_key(uint8_t layer, key_t key) | ||
| 59 | { | ||
| 60 | /* convert from legacy keycode to action */ | ||
| 61 | uint8_t keycode = keymap_get_keycode(layer, key.row, key.col); | ||
| 62 | action_t action; | ||
| 63 | switch (keycode) { | ||
| 64 | case KC_FN0 ... KC_FN31: | ||
| 65 | { | ||
| 66 | uint8_t layer = keymap_fn_layer(FN_INDEX(keycode)); | ||
| 67 | uint8_t key = keymap_fn_keycode(FN_INDEX(keycode)); | ||
| 68 | if (key) { | ||
| 69 | action.code = ACTION_LAYER_SET_TAP_KEY(layer, key); | ||
| 70 | } else { | ||
| 71 | action.code = ACTION_LAYER_SET_MOMENTARY(layer); | ||
| 72 | } | ||
| 73 | } | ||
| 74 | return action; | ||
| 75 | default: | ||
| 76 | return keymap_keycode_to_action(keycode); | ||
| 77 | } | ||
| 78 | } | ||
| 79 | #endif | ||
| 80 | |||
| 81 | __attribute__ ((weak)) | ||
| 82 | void action_function(keyrecord_t *event, uint8_t id, uint8_t opt) | ||
| 83 | { | ||
| 84 | } | ||
