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