aboutsummaryrefslogtreecommitdiff
path: root/keyboard/atomic/extended_keymap_common.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboard/atomic/extended_keymap_common.c')
-rw-r--r--keyboard/atomic/extended_keymap_common.c208
1 files changed, 208 insertions, 0 deletions
diff --git a/keyboard/atomic/extended_keymap_common.c b/keyboard/atomic/extended_keymap_common.c
new file mode 100644
index 000000000..841b24943
--- /dev/null
+++ b/keyboard/atomic/extended_keymap_common.c
@@ -0,0 +1,208 @@
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
27
28static action_t keycode_to_action(uint16_t keycode);
29
30
31/* converts key to action */
32action_t action_for_key(uint8_t layer, keypos_t key)
33{
34 // 16bit keycodes - important
35 uint16_t keycode = keymap_key_to_keycode(layer, key);
36
37 if (keycode >= 0x0100 && keycode < 0x2000) {
38 // Has a modifier
39 action_t action;
40 // Split it up
41 action.code = ACTION_MODS_KEY(keycode >> 8, keycode & 0xFF);
42 return action;
43 } else if (keycode >= 0x2000 && keycode < 0x3000) {
44 // Is a shortcut for function layer, pull last 12bits
45 return keymap_func_to_action(keycode & 0xFFF);
46 } else if (keycode >= 0x3000 && keycode < 0x4000) {
47 action_t action;
48 action.code = ACTION_MACRO(keycode & 0xFF);
49 return action;
50 } else if (keycode >= BL_0 & keycode <= BL_15) {
51 action_t action;
52 action.code = ACTION_BACKLIGHT_LEVEL(keycode & 0x000F);
53 return action;
54 } else if (keycode == BL_DEC) {
55 action_t action;
56 action.code = ACTION_BACKLIGHT_DECREASE();
57 return action;
58 } else if (keycode == BL_INC) {
59 action_t action;
60 action.code = ACTION_BACKLIGHT_INCREASE();
61 return action;
62 } else if (keycode == BL_TOGG) {
63 action_t action;
64 action.code = ACTION_BACKLIGHT_TOGGLE();
65 return action;
66 } else if (keycode == BL_STEP) {
67 action_t action;
68 action.code = ACTION_BACKLIGHT_STEP();
69 return action;
70 } else if (keycode == RESET) {
71 bootloader_jump();
72 return;
73 }
74
75 switch (keycode) {
76 case KC_FN0 ... KC_FN31:
77 return keymap_fn_to_action(keycode);
78#ifdef BOOTMAGIC_ENABLE
79 case KC_CAPSLOCK:
80 case KC_LOCKING_CAPS:
81 if (keymap_config.swap_control_capslock || keymap_config.capslock_to_control) {
82 return keycode_to_action(KC_LCTL);
83 }
84 return keycode_to_action(keycode);
85 case KC_LCTL:
86 if (keymap_config.swap_control_capslock) {
87 return keycode_to_action(KC_CAPSLOCK);
88 }
89 return keycode_to_action(KC_LCTL);
90 case KC_LALT:
91 if (keymap_config.swap_lalt_lgui) {
92 if (keymap_config.no_gui) {
93 return keycode_to_action(ACTION_NO);
94 }
95 return keycode_to_action(KC_LGUI);
96 }
97 return keycode_to_action(KC_LALT);
98 case KC_LGUI:
99 if (keymap_config.swap_lalt_lgui) {
100 return keycode_to_action(KC_LALT);
101 }
102 if (keymap_config.no_gui) {
103 return keycode_to_action(ACTION_NO);
104 }
105 return keycode_to_action(KC_LGUI);
106 case KC_RALT:
107 if (keymap_config.swap_ralt_rgui) {
108 if (keymap_config.no_gui) {
109 return keycode_to_action(ACTION_NO);
110 }
111 return keycode_to_action(KC_RGUI);
112 }
113 return keycode_to_action(KC_RALT);
114 case KC_RGUI:
115 if (keymap_config.swap_ralt_rgui) {
116 return keycode_to_action(KC_RALT);
117 }
118 if (keymap_config.no_gui) {
119 return keycode_to_action(ACTION_NO);
120 }
121 return keycode_to_action(KC_RGUI);
122 case KC_GRAVE:
123 if (keymap_config.swap_grave_esc) {
124 return keycode_to_action(KC_ESC);
125 }
126 return keycode_to_action(KC_GRAVE);
127 case KC_ESC:
128 if (keymap_config.swap_grave_esc) {
129 return keycode_to_action(KC_GRAVE);
130 }
131 return keycode_to_action(KC_ESC);
132 case KC_BSLASH:
133 if (keymap_config.swap_backslash_backspace) {
134 return keycode_to_action(KC_BSPACE);
135 }
136 return keycode_to_action(KC_BSLASH);
137 case KC_BSPACE:
138 if (keymap_config.swap_backslash_backspace) {
139 return keycode_to_action(KC_BSLASH);
140 }
141 return keycode_to_action(KC_BSPACE);
142#endif
143 default:
144 return keycode_to_action(keycode);
145 }
146}
147
148
149/* Macro */
150__attribute__ ((weak))
151const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
152{
153 return MACRO_NONE;
154}
155
156/* Function */
157__attribute__ ((weak))
158void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
159{
160}
161
162/* translates keycode to action */
163static action_t keycode_to_action(uint16_t keycode)
164{
165 action_t action;
166 switch (keycode) {
167 case KC_A ... KC_EXSEL:
168 case KC_LCTRL ... KC_RGUI:
169 action.code = ACTION_KEY(keycode);
170 break;
171 case KC_SYSTEM_POWER ... KC_SYSTEM_WAKE:
172 action.code = ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(keycode));
173 break;
174 case KC_AUDIO_MUTE ... KC_WWW_FAVORITES:
175 action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(keycode));
176 break;
177 case KC_MS_UP ... KC_MS_ACCEL2:
178 action.code = ACTION_MOUSEKEY(keycode);
179 break;
180 case KC_TRNS:
181 action.code = ACTION_TRANSPARENT;
182 break;
183 default:
184 action.code = ACTION_NO;
185 break;
186 }
187 return action;
188}
189
190
191/* translates key to keycode */
192uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
193{
194 // Read entire word (16bits)
195 return pgm_read_word(&keymaps[(layer)][(key.row)][(key.col)]);
196}
197
198/* translates Fn keycode to action */
199action_t keymap_fn_to_action(uint16_t keycode)
200{
201 return (action_t){ .code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]) };
202}
203
204action_t keymap_func_to_action(uint16_t keycode)
205{
206 // For FUNC without 8bit limit
207 return (action_t){ .code = pgm_read_word(&fn_actions[(int)keycode]) };
208}