]> git.gir.st - tmk_keyboard.git/blob - common/keymap.c
Add MACRO action
[tmk_keyboard.git] / common / keymap.c
1 /*
2 Copyright 2013 Jun Wako <wakojun@gmail.com>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
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/>.
16 */
17 #include <avr/pgmspace.h>
18 #include "keymap.h"
19 #include "report.h"
20 #include "keycode.h"
21 #include "layer_switch.h"
22 #include "action.h"
23 #include "action_macro.h"
24 #include "debug.h"
25
26
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
42 __attribute__ ((weak))
43 const prog_macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) { return MACRO_NONE; }
44
45 __attribute__ ((weak))
46 void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) {}
47 #else
48 /*
49 * legacy keymap support
50 */
51 /* translation for legacy keymap */
52 action_t action_for_key(uint8_t layer, key_t key)
53 {
54 /* convert from legacy keycode to action */
55 /* layer 16-31 indicate 'overlay' but not supported in legacy keymap */
56 uint8_t keycode = keymap_get_keycode((layer & OVERLAY_MASK), key.row, key.col);
57 action_t action;
58 switch (keycode) {
59 case KC_FN0 ... KC_FN31:
60 {
61 uint8_t layer = keymap_fn_layer(FN_INDEX(keycode));
62 uint8_t key = keymap_fn_keycode(FN_INDEX(keycode));
63 if (key) {
64 action.code = ACTION_KEYMAP_TAP_KEY(layer, key);
65 } else {
66 action.code = ACTION_KEYMAP_MOMENTARY(layer);
67 }
68 }
69 return action;
70 default:
71 return keycode_to_action(keycode);
72 }
73 }
74 /* not used for legacy keymap */
75 void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
76 {
77 }
78 #endif
79
80
81
82 /* translates keycode to action */
83 static action_t keycode_to_action(uint8_t keycode)
84 {
85 action_t action;
86 switch (keycode) {
87 case KC_A ... KC_EXSEL:
88 action.code = ACTION_KEY(keycode);
89 break;
90 case KC_LCTRL ... KC_LGUI:
91 action.code = ACTION_LMOD(keycode);
92 break;
93 case KC_RCTRL ... KC_RGUI:
94 action.code = ACTION_RMOD(keycode);
95 break;
96 case KC_SYSTEM_POWER ... KC_SYSTEM_WAKE:
97 action.code = ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(keycode));
98 break;
99 case KC_AUDIO_MUTE ... KC_WWW_FAVORITES:
100 action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(keycode));
101 break;
102 case KC_MS_UP ... KC_MS_ACCEL2:
103 action.code = ACTION_MOUSEKEY(keycode);
104 break;
105 case KC_TRNS:
106 action.code = ACTION_TRANSPARENT;
107 break;
108 default:
109 action.code = ACTION_NO;
110 break;
111 }
112 return action;
113 }
Imprint / Impressum