aboutsummaryrefslogtreecommitdiff
path: root/quantum/keymap_common.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/keymap_common.c')
-rw-r--r--quantum/keymap_common.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c
index 833e5a8f8..6cf4f031f 100644
--- a/quantum/keymap_common.c
+++ b/quantum/keymap_common.c
@@ -1,5 +1,5 @@
1/* 1/*
2Copyright 2012,2013 Jun Wako <wakojun@gmail.com> 2Copyright 2012-2017 Jun Wako <wakojun@gmail.com>
3 3
4This program is free software: you can redistribute it and/or modify 4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by 5it under the terms of the GNU General Public License as published by
@@ -48,12 +48,10 @@ action_t action_for_key(uint8_t layer, keypos_t key)
48 48
49 action_t action; 49 action_t action;
50 uint8_t action_layer, when, mod; 50 uint8_t action_layer, when, mod;
51 // The arm-none-eabi compiler generates out of bounds warnings when using the fn_actions directly for some reason
52 const uint16_t* actions = fn_actions;
53 51
54 switch (keycode) { 52 switch (keycode) {
55 case KC_FN0 ... KC_FN31: 53 case KC_FN0 ... KC_FN31:
56 action.code = pgm_read_word(&actions[FN_INDEX(keycode)]); 54 action.code = keymap_function_id_to_action(FN_INDEX(keycode));
57 break; 55 break;
58 case KC_A ... KC_EXSEL: 56 case KC_A ... KC_EXSEL:
59 case KC_LCTRL ... KC_RGUI: 57 case KC_LCTRL ... KC_RGUI:
@@ -79,10 +77,13 @@ action_t action_for_key(uint8_t layer, keypos_t key)
79 case QK_FUNCTION ... QK_FUNCTION_MAX: ; 77 case QK_FUNCTION ... QK_FUNCTION_MAX: ;
80 // Is a shortcut for function action_layer, pull last 12bits 78 // Is a shortcut for function action_layer, pull last 12bits
81 // This means we have 4,096 FN macros at our disposal 79 // This means we have 4,096 FN macros at our disposal
82 action.code = pgm_read_word(&actions[(int)keycode & 0xFFF]); 80 action.code = keymap_function_id_to_action( (int)keycode & 0xFFF );
83 break; 81 break;
84 case QK_MACRO ... QK_MACRO_MAX: 82 case QK_MACRO ... QK_MACRO_MAX:
85 action.code = ACTION_MACRO(keycode & 0xFF); 83 if (keycode & 0x800) // tap macros have upper bit set
84 action.code = ACTION_MACRO_TAP(keycode & 0xFF);
85 else
86 action.code = ACTION_MACRO(keycode & 0xFF);
86 break; 87 break;
87 case QK_LAYER_TAP ... QK_LAYER_TAP_MAX: 88 case QK_LAYER_TAP ... QK_LAYER_TAP_MAX:
88 action.code = ACTION_LAYER_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF); 89 action.code = ACTION_LAYER_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF);
@@ -118,8 +119,11 @@ action_t action_for_key(uint8_t layer, keypos_t key)
118 mod = keycode & 0xFF; 119 mod = keycode & 0xFF;
119 action.code = ACTION_MODS_ONESHOT(mod); 120 action.code = ACTION_MODS_ONESHOT(mod);
120 break; 121 break;
122 case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
123 action.code = ACTION_LAYER_TAP_TOGGLE(keycode & 0xFF);
124 break;
121 case QK_MOD_TAP ... QK_MOD_TAP_MAX: 125 case QK_MOD_TAP ... QK_MOD_TAP_MAX:
122 action.code = ACTION_MODS_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF); 126 action.code = ACTION_MODS_TAP_KEY((keycode >> 0x8) & 0x1F, keycode & 0xFF);
123 break; 127 break;
124 #ifdef BACKLIGHT_ENABLE 128 #ifdef BACKLIGHT_ENABLE
125 case BL_0 ... BL_15: 129 case BL_0 ... BL_15:
@@ -163,9 +167,17 @@ void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
163{ 167{
164} 168}
165 169
166/* translates key to keycode */ 170// translates key to keycode
171__attribute__ ((weak))
167uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key) 172uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
168{ 173{
169 // Read entire word (16bits) 174 // Read entire word (16bits)
170 return pgm_read_word(&keymaps[(layer)][(key.row)][(key.col)]); 175 return pgm_read_word(&keymaps[(layer)][(key.row)][(key.col)]);
171} 176}
177
178// translates function id to action
179__attribute__ ((weak))
180uint16_t keymap_function_id_to_action( uint16_t function_id )
181{
182 return pgm_read_word(&fn_actions[function_id]);
183}