aboutsummaryrefslogtreecommitdiff
path: root/common/keymap.c
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2013-03-11 15:35:55 +0900
committertmk <nobody@nowhere>2013-03-11 15:35:55 +0900
commit48433a5e9988647a737234c11dd9db4080fd4a4e (patch)
tree4af03a20658cb7e6cd43f9c65dfa002f1b544332 /common/keymap.c
parent5d6b848a157a2e94859949961297d40da6a77527 (diff)
parentef8439bddb2d7fe5fd95faf2b6bebd8235acf160 (diff)
downloadqmk_firmware-48433a5e9988647a737234c11dd9db4080fd4a4e.tar.gz
qmk_firmware-48433a5e9988647a737234c11dd9db4080fd4a4e.zip
Merge branch 'eeprom_config'
Diffstat (limited to 'common/keymap.c')
-rw-r--r--common/keymap.c86
1 files changed, 48 insertions, 38 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
27static action_t keycode_to_action(uint8_t keycode); 27static 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 */
31action_t action_for_key(uint8_t layer, key_t key) 31action_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 */
46action_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))
72const prog_macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) { return MACRO_NONE; } 45const 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))
75void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) {} 52void 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))
94uint8_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))
102action_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