aboutsummaryrefslogtreecommitdiff
path: root/keyboard/planck/extended_keymap_common.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboard/planck/extended_keymap_common.c')
-rw-r--r--keyboard/planck/extended_keymap_common.c210
1 files changed, 0 insertions, 210 deletions
diff --git a/keyboard/planck/extended_keymap_common.c b/keyboard/planck/extended_keymap_common.c
deleted file mode 100644
index ade850844..000000000
--- a/keyboard/planck/extended_keymap_common.c
+++ /dev/null
@@ -1,210 +0,0 @@
1/*
2Copyright 2012,2013 Jun Wako <wakojun@gmail.com>
3
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
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include "extended_keymap_common.h"
19#include "report.h"
20#include "keycode.h"
21#include "action_layer.h"
22#include "action.h"
23#include "action_macro.h"
24#include "debug.h"
25#include "backlight.h"
26
27static action_t keycode_to_action(uint16_t keycode);
28
29
30/* converts key to action */
31action_t action_for_key(uint8_t layer, keypos_t key)
32{
33 // 16bit keycodes - important
34 uint16_t keycode = keymap_key_to_keycode(layer, key);
35
36 if (keycode >= 0x0100 && keycode < 0x2000) {
37 // Has a modifier
38 action_t action;
39 // Split it up
40 action.code = ACTION_MODS_KEY(keycode >> 8, keycode & 0xFF);
41 return action;
42 } else if (keycode >= 0x2000 && keycode < 0x3000) {
43 // Is a shortcut for function layer, pull last 12bits
44 return keymap_func_to_action(keycode & 0xFFF);
45 } else if (keycode >= 0x3000 && keycode < 0x4000) {
46 action_t action;
47 action.code = ACTION_MACRO(keycode & 0xFF);
48 return action;
49 } else if (keycode >= BL_0 & keycode <= BL_15) {
50 action_t action;
51 action.code = ACTION_BACKLIGHT_LEVEL(keycode & 0x000F);
52 return action;
53 } else if (keycode == BL_DEC) {
54 action_t action;
55 action.code = ACTION_BACKLIGHT_DECREASE();
56 return action;
57 } else if (keycode == BL_INC) {
58 action_t action;
59 action.code = ACTION_BACKLIGHT_INCREASE();
60 return action;
61 } else if (keycode == BL_TOGG) {
62 action_t action;
63 action.code = ACTION_BACKLIGHT_TOGGLE();
64 return action;
65 } else if (keycode == BL_STEP) {
66 action_t action;
67 action.code = ACTION_BACKLIGHT_STEP();
68 return action;
69 } else if (keycode == RESET) {
70 bootloader_jump();
71 return;
72 } else if (keycode > RESET) {
73 // MIDI
74 return;
75 }
76
77 switch (keycode) {
78 case KC_FN0 ... KC_FN31:
79 return keymap_fn_to_action(keycode);
80#ifdef BOOTMAGIC_ENABLE
81 case KC_CAPSLOCK:
82 case KC_LOCKING_CAPS:
83 if (keymap_config.swap_control_capslock || keymap_config.capslock_to_control) {
84 return keycode_to_action(KC_LCTL);
85 }
86 return keycode_to_action(keycode);
87 case KC_LCTL:
88 if (keymap_config.swap_control_capslock) {
89 return keycode_to_action(KC_CAPSLOCK);
90 }
91 return keycode_to_action(KC_LCTL);
92 case KC_LALT:
93 if (keymap_config.swap_lalt_lgui) {
94 if (keymap_config.no_gui) {
95 return keycode_to_action(ACTION_NO);
96 }
97 return keycode_to_action(KC_LGUI);
98 }
99 return keycode_to_action(KC_LALT);
100 case KC_LGUI:
101 if (keymap_config.swap_lalt_lgui) {
102 return keycode_to_action(KC_LALT);
103 }
104 if (keymap_config.no_gui) {
105 return keycode_to_action(ACTION_NO);
106 }
107 return keycode_to_action(KC_LGUI);
108 case KC_RALT:
109 if (keymap_config.swap_ralt_rgui) {
110 if (keymap_config.no_gui) {
111 return keycode_to_action(ACTION_NO);
112 }
113 return keycode_to_action(KC_RGUI);
114 }
115 return keycode_to_action(KC_RALT);
116 case KC_RGUI:
117 if (keymap_config.swap_ralt_rgui) {
118 return keycode_to_action(KC_RALT);
119 }
120 if (keymap_config.no_gui) {
121 return keycode_to_action(ACTION_NO);
122 }
123 return keycode_to_action(KC_RGUI);
124 case KC_GRAVE:
125 if (keymap_config.swap_grave_esc) {
126 return keycode_to_action(KC_ESC);
127 }
128 return keycode_to_action(KC_GRAVE);
129 case KC_ESC:
130 if (keymap_config.swap_grave_esc) {
131 return keycode_to_action(KC_GRAVE);
132 }
133 return keycode_to_action(KC_ESC);
134 case KC_BSLASH:
135 if (keymap_config.swap_backslash_backspace) {
136 return keycode_to_action(KC_BSPACE);
137 }
138 return keycode_to_action(KC_BSLASH);
139 case KC_BSPACE:
140 if (keymap_config.swap_backslash_backspace) {
141 return keycode_to_action(KC_BSLASH);
142 }
143 return keycode_to_action(KC_BSPACE);
144#endif
145 default:
146 return keycode_to_action(keycode);
147 }
148}
149
150
151/* Macro */
152__attribute__ ((weak))
153const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
154{
155 return MACRO_NONE;
156}
157
158/* Function */
159__attribute__ ((weak))
160void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
161{
162}
163
164/* translates keycode to action */
165static action_t keycode_to_action(uint16_t keycode)
166{
167 action_t action;
168 switch (keycode) {
169 case KC_A ... KC_EXSEL:
170 case KC_LCTRL ... KC_RGUI:
171 action.code = ACTION_KEY(keycode);
172 break;
173 case KC_SYSTEM_POWER ... KC_SYSTEM_WAKE:
174 action.code = ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(keycode));
175 break;
176 case KC_AUDIO_MUTE ... KC_WWW_FAVORITES:
177 action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(keycode));
178 break;
179 case KC_MS_UP ... KC_MS_ACCEL2:
180 action.code = ACTION_MOUSEKEY(keycode);
181 break;
182 case KC_TRNS:
183 action.code = ACTION_TRANSPARENT;
184 break;
185 default:
186 action.code = ACTION_NO;
187 break;
188 }
189 return action;
190}
191
192
193/* translates key to keycode */
194uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
195{
196 // Read entire word (16bits)
197 return pgm_read_word(&keymaps[(layer)][(key.row)][(key.col)]);
198}
199
200/* translates Fn keycode to action */
201action_t keymap_fn_to_action(uint16_t keycode)
202{
203 return (action_t){ .code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]) };
204}
205
206action_t keymap_func_to_action(uint16_t keycode)
207{
208 // For FUNC without 8bit limit
209 return (action_t){ .code = pgm_read_word(&fn_actions[(int)keycode]) };
210}