aboutsummaryrefslogtreecommitdiff
path: root/common/keymap.c
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2013-02-20 11:16:13 +0900
committertmk <nobody@nowhere>2013-02-20 11:48:15 +0900
commite0f960a576e090808e5cc25c5368441c11f36ea6 (patch)
treeafe64cce00a34b99aeb9b6b989ab08e803b3d4b2 /common/keymap.c
parentabf0b04d14629de35968ee07e3bb587eebccf68b (diff)
downloadqmk_firmware-e0f960a576e090808e5cc25c5368441c11f36ea6.tar.gz
qmk_firmware-e0f960a576e090808e5cc25c5368441c11f36ea6.zip
Add overlay framework
Diffstat (limited to 'common/keymap.c')
-rw-r--r--common/keymap.c91
1 files changed, 59 insertions, 32 deletions
diff --git a/common/keymap.c b/common/keymap.c
index 078615814..3f13d4497 100644
--- a/common/keymap.c
+++ b/common/keymap.c
@@ -14,13 +14,71 @@ GNU General Public License for more details.
14You should have received a copy of the GNU General Public License 14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>. 15along 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 "debug.h"
21 24
22 25
23action_t keymap_keycode_to_action(uint8_t keycode) 26static action_t keycode_to_action(uint8_t keycode);
27
28#ifdef USE_KEYMAP_V2
29/* converts key to action */
30action_t action_for_key(uint8_t layer, key_t key)
31{
32 uint8_t keycode = keymap_key_to_keycode(layer, key);
33 switch (keycode) {
34 case KC_FN0 ... KC_FN31:
35 return keymap_fn_to_action(keycode);
36 default:
37 return keycode_to_action(keycode);
38 }
39}
40
41__attribute__ ((weak))
42void action_function(keyrecord_t *event, uint8_t id, uint8_t opt)
43{
44}
45#else
46/*
47 * legacy keymap support
48 */
49/* translation for legacy keymap */
50action_t action_for_key(uint8_t layer, key_t key)
51{
52 /* convert from legacy keycode to action */
53 /* layer 16-31 indicate 'overlay' but not supported in legacy keymap */
54 uint8_t keycode = keymap_get_keycode((layer & OVERLAY_MASK), key.row, key.col);
55 action_t action;
56 switch (keycode) {
57 case KC_FN0 ... KC_FN31:
58 {
59 uint8_t layer = keymap_fn_layer(FN_INDEX(keycode));
60 uint8_t key = keymap_fn_keycode(FN_INDEX(keycode));
61 if (key) {
62 action.code = ACTION_KEYMAP_TAP_KEY(layer, key);
63 } else {
64 action.code = ACTION_KEYMAP_MOMENTARY(layer);
65 }
66 }
67 return action;
68 default:
69 return keycode_to_action(keycode);
70 }
71}
72/* not used for legacy keymap */
73void action_function(keyrecord_t *event, uint8_t id, uint8_t opt)
74{
75}
76#endif
77
78
79
80/* translates keycode to action */
81static 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))
58action_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))
82void action_function(keyrecord_t *event, uint8_t id, uint8_t opt)
83{
84}