aboutsummaryrefslogtreecommitdiff
path: root/keyboards/ergodox/keymaps/belak/keymap.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/ergodox/keymaps/belak/keymap.c')
-rw-r--r--keyboards/ergodox/keymaps/belak/keymap.c367
1 files changed, 367 insertions, 0 deletions
diff --git a/keyboards/ergodox/keymaps/belak/keymap.c b/keyboards/ergodox/keymaps/belak/keymap.c
new file mode 100644
index 000000000..d10567a78
--- /dev/null
+++ b/keyboards/ergodox/keymaps/belak/keymap.c
@@ -0,0 +1,367 @@
1#include "ergodox.h"
2#include "debug.h"
3#include "action_layer.h"
4#include "eeconfig.h"
5
6#define LAYER_ON(pos) ((layer_state) & (1<<(pos)))
7#define _______ KC_TRNS
8
9#define EECONFIG_BELAK_MAGIC (uint16_t)0xBE42
10
11// NOTE: This is just a number that's a bit beyond the end of what's already
12// defined. As there is no other define we can base this on, it may need to be
13// changed in the future. The initial value here is used as a placeholder with a
14// magic word, similar to the normal eeconfig. Note that all the storage being
15// used needs to fit inside the 32 bytes of the Ergodox Infinity.
16#define EECONFIG_BELAK (uint16_t *)16
17
18// The correct way to do this would be how the normal eeconfig handles it and
19// use a bitfield. However, the eeprom has a ton of space which isn't being
20// used so I don't really care and have a separate byte for every setting.
21#define EECONFIG_BELAK_SWAP_GUI_CTRL (uint8_t *)18
22
23static uint8_t swap_gui_ctrl = 0;
24static uint8_t td_led_override = 0;
25
26enum belak_keycodes {
27 // Function codes
28 BEL_F0 = SAFE_RANGE,
29 BEL_F1,
30
31 E_SHRUG,
32 E_TFLIP,
33 E_TSET,
34};
35
36inline void tap(uint16_t keycode) {
37 register_code(keycode);
38 unregister_code(keycode);
39};
40
41// TODO: Add LED support to the tap dance by using the advanced macro
42#define LTOGGLE TD(TD_LAYER_TOGGLE)
43
44#define BASE 0 // default layer
45#define SYMB 1 // symbols
46#define NUMP 2 // numpad
47#define SWPH 3 // swap gui/ctrl on the hands
48
49enum belak_td {
50 TD_LAYER_TOGGLE = 0,
51};
52
53void belak_td_each(qk_tap_dance_state_t *state, void *user_data);
54void belak_td_finished(qk_tap_dance_state_t *state, void *user_data);
55void belak_td_reset(qk_tap_dance_state_t *state, void *user_data);
56
57qk_tap_dance_action_t tap_dance_actions[] = {
58 [TD_LAYER_TOGGLE] = ACTION_TAP_DANCE_FN_ADVANCED(belak_td_each, belak_td_finished, belak_td_reset),
59};
60
61const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
62/* Keymap 0: Basic layer
63 *
64 * ,--------------------------------------------------. ,--------------------------------------------------.
65 * | Esc | 1 | 2 | 3 | 4 | 5 | L1 | | L2 | 6 | 7 | 8 | 9 | 0 | = |
66 * |--------+------+------+------+------+-------------| |------+------+------+------+------+------+--------|
67 * | Tab | Q | W | E | R | T | [ | | ] | Y | U | I | O | P | - |
68 * |--------+------+------+------+------+------| | | |------+------+------+------+------+--------|
69 * | \ | A | S | D | F | G |------| |------| H | J | K | L | ; | ' |
70 * |--------+------+------+------+------+------| LGui | | RGui |------+------+------+------+------+--------|
71 * | LShift | Z | X | C | V | B | | | | N | M | , | . | / | RShift |
72 * `--------+------+------+------+------+-------------' `-------------+------+------+------+------+--------'
73 * |Layers| LCtrl| Left | Right| LAlt | | RAlt | Up | Down | RCtrl|Layers|
74 * `----------------------------------' `----------------------------------'
75 * ,-------------. ,--------------.
76 * | ~L2 | Ins | | Grv | ~L1 |
77 * ,-------|------|------| |------+-------+-------.
78 * | Back | | Home | | PgUp | | |
79 * | Space | Del |------| |------| Enter | Space |
80 * | | | End | | PgDn | | |
81 * `---------------------' `----------------------'
82 */
83 [BASE] = KEYMAP( // layer 0 : default
84 // left hand
85 KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, TG(SYMB),
86 KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_LBRC,
87 CTL_T(KC_BSLS), KC_A, KC_S, KC_D, KC_F, KC_G,
88 KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_LGUI,
89 LTOGGLE, KC_LCTRL, KC_LEFT,KC_RGHT,KC_LALT,
90 MO(NUMP),KC_INS,
91 KC_HOME,
92 CTL_T(KC_BSPC),GUI_T(KC_DEL),KC_END,
93 // right hand
94 TG(NUMP), KC_6, KC_7, KC_8, KC_9, KC_0, KC_EQL,
95 KC_RBRC, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_MINS,
96 KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
97 KC_RGUI, KC_N, KC_M, KC_COMM,KC_DOT, KC_SLSH, KC_RSFT,
98 KC_RALT,KC_UP, KC_DOWN,KC_RCTRL, LTOGGLE,
99 KC_GRV, MO(SYMB),
100 KC_PGUP,
101 KC_PGDN, GUI_T(KC_ENT), CTL_T(KC_SPC)
102 ),
103/* Keymap 1: Symbol Layer
104 *
105 * ,--------------------------------------------------. ,--------------------------------------------------.
106 * | | F1 | F2 | F3 | F4 | F5 | | | | F6 | F7 | F8 | F9 | F10 | F11 |
107 * |--------+------+------+------+------+-------------| |------+------+------+------+------+------+--------|
108 * | | ! | @ | { | } | | | | | | Up | | Up | | | F12 |
109 * |--------+------+------+------+------+------| TFLIP| | TSET |------+------+------+------+------+--------|
110 * | | # | $ | ( | ) | ` |------| |------| Down | Left | Down | Rght | | |
111 * |--------+------+------+------+------+------| | | |------+------+------+------+------+--------|
112 * | | % | ^ | [ | ] | ~ | SHRUG| | | & | | | | | |
113 * `--------+------+------+------+------+-------------' `-------------+------+------+------+------+--------'
114 * |LClear| | | | | | | | | |LClear|
115 * `----------------------------------' `----------------------------------'
116 * ,-------------. ,-------------.
117 * | TOGL | | | | TOGL |
118 * ,------|------|------| |------+------+------.
119 * | | | | | | | |
120 * | | |------| |------| | |
121 * | | | | | | | |
122 * `--------------------' `--------------------'
123 */
124 [SYMB] = KEYMAP(
125 // left hand
126 _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, E_TFLIP,
127 _______, KC_EXLM, KC_AT, KC_LCBR, KC_RCBR, KC_PIPE, E_TSET,
128 _______, KC_HASH, KC_DLR, KC_LPRN, KC_RPRN, KC_GRV,
129 _______, KC_PERC, KC_CIRC, KC_LBRC, KC_RBRC, KC_TILD, E_SHRUG,
130 BEL_F1, _______, _______, _______, _______,
131 BEL_F0, _______,
132 _______,
133 _______, _______, _______,
134 // right hand
135 _______, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11,
136 _______, KC_UP, _______, KC_UP, _______, _______, KC_F12,
137 KC_DOWN, KC_LEFT, KC_DOWN, KC_RGHT, _______, _______,
138 _______, KC_AMPR, _______, _______, _______, _______, _______,
139 _______, _______, _______, _______, BEL_F1,
140 _______, BEL_F0,
141 _______,
142 _______, _______, _______
143 ),
144/* Keymap 2: Numpad Layer
145 *
146 * ,--------------------------------------------------. ,--------------------------------------------------.
147 * | | | | | | | | | | | | | | | |
148 * |--------+------+------+------+------+-------------| |------+------+------+------+------+------+--------|
149 * | | | | | | | | | | | 7 | 8 | 9 | * | |
150 * |--------+------+------+------+------+------| | | |------+------+------+------+------+--------|
151 * | | | | | | |------| |------| | 4 | 5 | 6 | + | |
152 * |--------+------+------+------+------+------| | | |------+------+------+------+------+--------|
153 * | | | | | | | | | | | 1 | 2 | 3 | \ | |
154 * `--------+------+------+------+------+-------------' `-------------+------+------+------+------+--------'
155 * |LClear| | | | | | 0 | 0 | . | = |LClear|
156 * `----------------------------------' `----------------------------------'
157 * ,-------------. ,-------------.
158 * | TOGL | | | | TOGL |
159 * ,------|------|------| |------+------+------.
160 * | | | | | | | |
161 * | | |------| |------| | |
162 * | | | | | | | |
163 * `--------------------' `--------------------'
164 */
165 [NUMP] = KEYMAP(
166 // left hand
167 _______, _______, _______, _______, _______, _______, _______,
168 _______, _______, _______, _______, _______, _______, _______,
169 _______, _______, _______, _______, _______, _______,
170 _______, _______, _______, _______, _______, _______, _______,
171 BEL_F1, _______, _______, _______, _______,
172 BEL_F0, _______,
173 _______,
174 _______, _______, _______,
175 // right hand
176 _______, _______, _______, _______, _______, _______, _______,
177 _______, _______, KC_7, KC_8, KC_9, KC_ASTR, _______,
178 _______, KC_4, KC_5, KC_6, KC_PLUS, _______,
179 _______, _______, KC_1, KC_2, KC_3, KC_BSLS, _______,
180 KC_0, KC_0, KC_DOT, KC_EQL, BEL_F1,
181 _______, BEL_F0,
182 _______,
183 _______, _______, _______
184 ),
185/* Keymap 3: Swap control and gui on the thumb */
186 [SWPH] = KEYMAP(
187 // left hand
188 _______, _______, _______, _______, _______, _______, _______,
189 _______, _______, _______, _______, _______, _______, _______,
190 _______, _______, _______, _______, _______, _______,
191 _______, _______, _______, _______, _______, _______, _______,
192 _______, _______, _______, _______, _______,
193 _______, _______,
194 _______,
195 GUI_T(KC_BSPC), CTL_T(KC_DEL), _______,
196 // right hand
197 _______, _______, _______, _______, _______, _______, _______,
198 _______, _______, _______, _______, _______, _______, _______,
199 _______, _______, _______, _______, _______, _______,
200 _______, _______, _______, _______, _______, _______, _______,
201 _______, _______, _______, _______, _______,
202 _______, _______,
203 _______,
204 _______, CTL_T(KC_ENT), GUI_T(KC_SPC)
205 ),
206};
207
208// Runs just one time when the keyboard initializes.
209void matrix_init_user(void) {
210 // If our magic word wasn't set properly, we need to zero out the settings.
211 if (eeprom_read_word(EECONFIG_BELAK) != EECONFIG_BELAK_MAGIC) {
212 eeprom_update_word(EECONFIG_BELAK, EECONFIG_BELAK_MAGIC);
213 eeprom_update_byte(EECONFIG_BELAK_SWAP_GUI_CTRL, 0);
214 }
215
216 if (eeprom_read_byte(EECONFIG_BELAK_SWAP_GUI_CTRL)) {
217 layer_on(SWPH);
218 swap_gui_ctrl = 1;
219 }
220};
221
222// Runs constantly in the background, in a loop.
223void matrix_scan_user(void) {
224 ergodox_board_led_off();
225 ergodox_right_led_1_off();
226 ergodox_right_led_2_off();
227 ergodox_right_led_3_off();
228
229 switch (td_led_override) {
230 case 1:
231 ergodox_right_led_1_on();
232 break;
233 case 2:
234 ergodox_right_led_2_on();
235 break;
236 default:
237 // Layer 1 and 2 are both overlay layers, so they could both be on. This
238 // means we can't use the lazy check of checking for the first significant
239 // bit.
240 if (LAYER_ON(SYMB)) {
241 ergodox_right_led_1_on();
242 }
243 if (LAYER_ON(NUMP)) {
244 ergodox_right_led_2_on();
245 }
246 }
247};
248
249bool process_record_user(uint16_t keycode, keyrecord_t *record) {
250 switch (keycode) {
251 case BEL_F0:
252 if(record->event.pressed){
253 swap_gui_ctrl = !swap_gui_ctrl;
254 eeprom_update_byte(EECONFIG_BELAK_SWAP_GUI_CTRL, swap_gui_ctrl);
255
256 if (swap_gui_ctrl) {
257 layer_on(SWPH);
258 } else {
259 layer_off(SWPH);
260 }
261
262 return false;
263 }
264 break;
265 case BEL_F1:
266 if(record->event.pressed){
267 layer_off(SYMB);
268 layer_off(NUMP);
269
270 return false;
271 }
272 break;
273 case E_SHRUG: // ¯\_(ツ)_/¯
274 if (record->event.pressed) {
275 process_unicode((0x00AF|QK_UNICODE), record); // Hand
276 tap(KC_BSLS); // Arm
277 register_code(KC_RSFT);
278 tap(KC_UNDS); // Arm
279 tap(KC_LPRN); // Head
280 unregister_code(KC_RSFT);
281 process_unicode((0x30C4|QK_UNICODE), record); // Face
282 register_code(KC_RSFT);
283 tap(KC_RPRN); // Head
284 tap(KC_UNDS); // Arm
285 unregister_code(KC_RSFT);
286 tap(KC_SLSH); // Arm
287 process_unicode((0x00AF|QK_UNICODE), record); // Hand
288 }
289 return false;
290 break;
291 case E_TFLIP: // (╯°□°)╯ ︵ ┻━┻
292 if (record->event.pressed) {
293 register_code(KC_RSFT);
294 tap(KC_9);
295 unregister_code(KC_RSFT);
296 process_unicode((0x256F|QK_UNICODE), record); // Arm
297 process_unicode((0x00B0|QK_UNICODE), record); // Eye
298 process_unicode((0x25A1|QK_UNICODE), record); // Mouth
299 process_unicode((0x00B0|QK_UNICODE), record); // Eye
300 register_code(KC_RSFT);
301 tap(KC_0);
302 unregister_code(KC_RSFT);
303 process_unicode((0x256F|QK_UNICODE), record); // Arm
304 tap(KC_SPC);
305 process_unicode((0x0361|QK_UNICODE), record); // Flippy
306 tap(KC_SPC);
307 process_unicode((0x253B|QK_UNICODE), record); // Table
308 process_unicode((0x2501|QK_UNICODE), record); // Table
309 process_unicode((0x253B|QK_UNICODE), record); // Table
310 }
311 return false;
312 break;
313 case E_TSET: // ┬──┬ ノ( ゜-゜ノ)
314 if (record->event.pressed) {
315 process_unicode((0x252C|QK_UNICODE), record); // Table
316 process_unicode((0x2500|QK_UNICODE), record); // Table
317 process_unicode((0x2500|QK_UNICODE), record); // Table
318 process_unicode((0x252C|QK_UNICODE), record); // Table
319 tap(KC_SPC);
320 process_unicode((0x30CE|QK_UNICODE), record); // Arm
321 register_code(KC_RSFT);
322 tap(KC_9);
323 unregister_code(KC_RSFT);
324 tap(KC_SPC);
325 process_unicode((0x309C|QK_UNICODE), record); // Eye
326 tap(KC_MINS);
327 process_unicode((0x309C|QK_UNICODE), record); // Eye
328 process_unicode((0x30CE|QK_UNICODE), record); // Arm
329 register_code(KC_RSFT);
330 tap(KC_0);
331 unregister_code(KC_RSFT);
332 }
333 return false;
334 break;
335 }
336
337 return true;
338}
339
340void belak_td_each(qk_tap_dance_state_t *state, void *user_data) {
341 switch (state->count) {
342 case 1:
343 td_led_override = 1;
344 break;
345 case 2:
346 td_led_override = 2;
347 break;
348 default:
349 reset_tap_dance(state);
350 }
351}
352
353void belak_td_finished(qk_tap_dance_state_t *state, void *user_data) {
354 switch (state->count) {
355 case 1:
356 layer_on(SYMB);
357 break;
358 case 2:
359 layer_on(NUMP);
360 break;
361 }
362 td_led_override = 0;
363}
364
365void belak_td_reset(qk_tap_dance_state_t *state, void *user_data) {
366 td_led_override = 0;
367}