summaryrefslogtreecommitdiff
path: root/keyboards/cospad/keymaps/detrus/keymap.c
blob: af56305e5ceaa1412739e238bb56bceb49bddfe7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
#include QMK_KEYBOARD_H
#include "led.h"
#include <print.h>

#ifdef RGBLIGHT_ENABLE
#include "rgblight.h"
#endif

// Each layer gets a name for readability, which is then used in the keymap matrix below.
enum cospad_layers {
	_QWERTY_LAYER,
	_QWERTZ_LAYER,
	_COLEMA_LAYER,
	_DVORAK_LAYER,
	_QWERTY_LOWER_LAYER,
	_QWERTZ_LOWER_LAYER,
	_COLEMA_LOWER_LAYER,
	_DVORAK_LOWER_LAYER,
	_RAISE_LAYER,
	_ALTER_LAYER,
};

// To switch the default layer used for the layout, there are special keycodes.
// Which onces detected below serve to switch it.
enum cospad_keycodes {
	QWERTY = SAFE_RANGE,
	QWERTZ,
	COLEMAK,
	DVORAK
};

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {

	/* Keymap _QWERTY_LAYER: Default layer
	 * ,-----------------------.
	 * |  T  |  G  |  B  | Alt |
	 * |-----|-----|-----|-----|
	 * |  R  |  F  |  V  | LOW |
	 * |-----|-----|-----|-----|
	 * |  E  |  D  |  C  |     |
	 * |-----|-----|-----| Spc |
	 * |  W  |  S  |  X  |     |
	 * |-----|-----|-----|-----|
	 * |  Q  |  A  |  Z  | RAI |
	 * |-----|-----|-----|-----|
	 * | Esc | Tab | Sft | Ctl |
	 * `-----------------------'
	 *
	 *   And it's LOWER layer
	 * ,-----------------------.
	 * |  P  |  ;  |  /  | Alt |
	 * |-----|-----|-----|-----|
	 * |  O  |  L  |  .  | LOW |
	 * |-----|-----|-----|-----|
	 * |  I  |  K  |  ,  |     |
	 * |-----|-----|-----| Ent |
	 * |  U  |  J  |  M  |     |
	 * |-----|-----|-----|-----|
	 * |  Y  |  H  |  N  | RAI |
	 * |-----|-----|-----|-----|
	 * | Esc | Tab | Sft | Ctl |
	 * `-----------------------'
	 */
	[_QWERTY_LAYER] = LAYOUT_gamepad_6x4(
			KC_T,    KC_G,    KC_B,    KC_LALT,  \
			KC_R,    KC_F,    KC_V,    MO(_QWERTY_LOWER_LAYER),\
			KC_E,    KC_D,    KC_C,              \
			KC_W,    KC_S,    KC_X,    KC_SPACE, \
			KC_Q,    KC_A,    KC_Z,    MO(_RAISE_LAYER),\
			KC_GESC, KC_TAB,  KC_LSFT, KC_LCTRL),
	[_QWERTY_LOWER_LAYER] = LAYOUT_gamepad_6x4(
			KC_P,    KC_SCLN, KC_SLSH, KC_LALT,  \
			KC_O,    KC_L,    KC_DOT,  _______,  \
			KC_I,    KC_K,    KC_COMM,           \
			KC_U,    KC_J,    KC_M,    KC_ENTER, \
			KC_Y,    KC_H,    KC_N,    _______,  \
			_______, _______,  _______, _______),



	/* Keymap _QWERTZ_LAYER: Alternate default layer
	 * ,-----------------------.
	 * |  T  |  G  |  B  | Alt |
	 * |-----|-----|-----|-----|
	 * |  R  |  F  |  V  | LOW |
	 * |-----|-----|-----|-----|
	 * |  E  |  D  |  C  |     |
	 * |-----|-----|-----| Spc |
	 * |  W  |  S  |  X  |     |
	 * |-----|-----|-----|-----|
	 * |  Q  |  A  |  Y  | RAI |
	 * |-----|-----|-----|-----|
	 * | Esc | Tab | Sft | Ctl |
	 * `-----------------------'
	 *
	 *   And it's LOWER layer
	 * ,-----------------------.
	 * |  P  |  ;  |  /  | Alt |
	 * |-----|-----|-----|-----|
	 * |  O  |  L  |  >  | LOW |
	 * |-----|-----|-----|-----|
	 * |  I  |  K  |  <  |     |
	 * |-----|-----|-----| Ent |
	 * |  U  |  J  |  M  |     |
	 * |-----|-----|-----|-----|
	 * |  Z  |  H  |  N  | RAI |
	 * |-----|-----|-----|-----|
	 * | Esc | Tab | Sft | Ctl |
	 * `-----------------------'
	 */
	[_QWERTZ_LAYER] = LAYOUT_gamepad_6x4(
			KC_T,    KC_G,    KC_B,    KC_LALT,  \
			KC_R,    KC_F,    KC_V,    MO(_QWERTZ_LOWER_LAYER),\
			KC_E,    KC_D,    KC_C,              \
			KC_W,    KC_S,    KC_X,    KC_SPACE, \
			KC_Q,    KC_A,    KC_Y,    MO(_RAISE_LAYER),\
			KC_GESC, KC_TAB,  KC_LSFT, KC_LCTRL),
	[_QWERTZ_LOWER_LAYER] = LAYOUT_gamepad_6x4(
			KC_P,    KC_SCLN, KC_SLSH, KC_LALT,  \
			KC_O,    KC_L,    KC_DOT,  _______,  \
			KC_I,    KC_K,    KC_COMM,           \
			KC_U,    KC_J,    KC_M,    KC_ENTER, \
			KC_Z,    KC_H,    KC_N,    _______,  \
			_______, _______, _______, _______),



	/* Keymap _COLEMA_LAYER: Alternate default layer
	 * ,-----------------------.
	 * |  G  |  D  |  B  | Alt |
	 * |-----|-----|-----|-----|
	 * |  P  |  T  |  V  | LOW |
	 * |-----|-----|-----|-----|
	 * |  F  |  S  |  C  |     |
	 * |-----|-----|-----| Spc |
	 * |  W  |  R  |  X  |     |
	 * |-----|-----|-----|-----|
	 * |  Q  |  A  |  Z  | RAI |
	 * |-----|-----|-----|-----|
	 * | Esc | Tab | Sft | Ctl |
	 * `-----------------------'
	 *
	 *   And it's LOWER layer
	 * ,-----------------------.
	 * |  ;  |  O  |  /  | Alt |
	 * |-----|-----|-----|-----|
	 * |  Y  |  I  |  .  | LOW |
	 * |-----|-----|-----|-----|
	 * |  U  |  E  |  ,  |     |
	 * |-----|-----|-----| Ent |
	 * |  L  |  N  |  M  |     |
	 * |-----|-----|-----|-----|
	 * |  J  |  H  |  K  | RAI |
	 * |-----|-----|-----|-----|
	 * | Esc | Tab | Sft | Ctl |
	 * `-----------------------'
	 */
	[_COLEMA_LAYER] = LAYOUT_gamepad_6x4(
			KC_T,    KC_D,     KC_B,    KC_LALT,  \
			KC_R,    KC_T,     KC_V,    MO(_COLEMA_LOWER_LAYER),\
			KC_E,    KC_S,     KC_C,              \
			KC_W,    KC_R,     KC_X,    KC_SPACE, \
			KC_Q,    KC_A,     KC_Z,    MO(_RAISE_LAYER),\
			KC_GESC, KC_TAB,   KC_LSFT, KC_LCTRL),
	[_COLEMA_LOWER_LAYER] = LAYOUT_gamepad_6x4(
			KC_SCLN, KC_O,     KC_SLSH, _______,  \
			KC_Y,    KC_I,     KC_DOT,  _______,  \
			KC_U,    KC_E,     KC_COMM,           \
			KC_L,    KC_N,     KC_M,    KC_ENTER, \
			KC_J,    KC_H,     KC_K,    _______,  \
			KC_F,    KC_G,     _______, _______),



	/* Keymap _DVORAK_LAYER: Alternate default layer
	 * ,-----------------------.
	 * |  Y  |  I  |  X  | Alt |
	 * |-----|-----|-----|-----|
	 * |  P  |  U  |  K  | LOW |
	 * |-----|-----|-----|-----|
	 * |  .  |  E  |  J  |     |
	 * |-----|-----|-----| Spc |
	 * |  ,  |  O  |  Q  |     |
	 * |-----|-----|-----|-----|
	 * |  '  |  A  |  ;  | RAI |
	 * |-----|-----|-----|-----|
	 * | Esc | Tab | Sft | Ctl |
	 * `-----------------------'
	 *
	 *   And it's LOWER layer
	 * ,-----------------------.
	 * |  L  |  S  |  Z  | Alt |
	 * |-----|-----|-----|-----|
	 * |  R  |  N  |  V  | LOW |
	 * |-----|-----|-----|-----|
	 * |  C  |  T  |  W  |     |
	 * |-----|-----|-----| Ent |
	 * |  G  |  H  |  M  |     |
	 * |-----|-----|-----|-----|
	 * |  F  |  D  |  B  | RAI |
	 * |-----|-----|-----|-----|
	 * | Esc | Tab | Sft | Ctl |
	 * `-----------------------'
	 */
	[_DVORAK_LAYER] = LAYOUT_gamepad_6x4(
			KC_Y,    KC_I,    KC_X,    KC_LALT,   \
			KC_P,    KC_U,    KC_K,    MO(_DVORAK_LOWER_LAYER),\
			KC_DOT,  KC_E,    KC_J,               \
			KC_COMM, KC_O,    KC_A,    KC_SPACE,  \
			KC_QUOT, KC_A,    KC_SCLN, MO(_RAISE_LAYER),\
			KC_GESC, KC_TAB,  KC_LSFT, KC_LCTRL),
	[_DVORAK_LOWER_LAYER] = LAYOUT_gamepad_6x4(
			KC_L,    KC_S,    KC_Z,    KC_LALT, \
			KC_R,    KC_N,    KC_V,    _______, \
			KC_C,    KC_T,    KC_W,             \
			KC_G,    KC_H,    KC_M,    KC_ENTER,\
			KC_F,    KC_D,    KC_B,    _______, \
			_______, _______, _______, _______),



	/* Keymap _RAISE_LAYER: Additional layer to access more
	 * ,-----------------------.
	 * |  5  |  0  | del | Alt |
	 * |-----|-----|-----|-----|
	 * |  4  |  9  | ->  | LOW |
	 * |-----|-----|-----|-----|
	 * |  3  |  8  |  <- |     |
	 * |-----|-----|-----| Spc |
	 * |  2  |  7  | ->  |     |
	 * |-----|-----|-----|-----|
	 * |  1  |  6  |  <- | RAI |
	 * |-----|-----|-----|-----|
	 * | Esc | Tab | Sft | Ctl |
	 * `-----------------------'
	 */
	[_RAISE_LAYER] = LAYOUT_gamepad_6x4(
			KC_5,    KC_0,   KC_BSPC,  _______, \
			KC_4,    KC_9,   KC_RIGHT, _______, \
			KC_3,    KC_8,   KC_UP,             \
			KC_2,    KC_7,   KC_DOWN,  _______, \
			KC_1,    KC_6,   KC_LEFT,  _______, \
			_______, _______, _______, _______),



	/* Keymap _ALTER_LAYER: Function layer used to control the Leds
	 *                     and use media buttons
	 * ,----------------------------------------.
	 * | Val Dec | Bl Toggle  | Qwertz  | Super |
	 * |---------|------------|---------|-------|
	 * | Val Inc |   Bl Off   | Qwerty  |       |
	 * |---------|------------|---------|-------|
	 * | Sat Dec |   Bl On    | Colemak |       |
	 * |---------|------------|---------|       |
	 * | Sat Inc | RGB Toggle | Dvorak  |       |
	 * |---------|------------|---------|-------|
	 * | Hue Dec |  RGB Next  | Vol Dwn |       |
	 * |---------|------------|---------|-------|
	 * | Hue Inc |  RGB Prev  | Vol Up  | Reset |
	 * `----------------------------------------'
	 */
	[_ALTER_LAYER] = LAYOUT_gamepad_6x4(
			RGB_VAD, BL_TOGG,  QWERTZ,  KC_LGUI, \
			RGB_VAI, BL_OFF,   QWERTY,  _______, \
			RGB_SAD, BL_ON,    COLEMAK,          \
			RGB_SAI, RGB_TOG,  DVORAK,  _______, \
			RGB_HUD, RGB_MOD,  KC_VOLD, _______, \
			RGB_HUI, RGB_RMOD, KC_VOLU, RESET),
};

// Makes sure to update the good tri-layer if a layer changes
layer_state_t layer_state_set_user(layer_state_t state) {
	switch (biton32(default_layer_state)) {
		case _QWERTY_LAYER:
			state = update_tri_layer_state(state, _RAISE_LAYER, _QWERTY_LOWER_LAYER, _ALTER_LAYER);
			break;
		case _QWERTZ_LAYER:
			state = update_tri_layer_state(state, _RAISE_LAYER, _QWERTZ_LOWER_LAYER, _ALTER_LAYER);
			break;
		case _COLEMA_LAYER:
			state = update_tri_layer_state(state, _RAISE_LAYER, _COLEMA_LOWER_LAYER, _ALTER_LAYER);
			break;
		case _DVORAK_LAYER:
			state = update_tri_layer_state(state, _RAISE_LAYER, _DVORAK_LOWER_LAYER, _ALTER_LAYER);
			break;
	}
	return state;
}

// Makes the tri-layer
uint32_t default_layer_state_set_kb(uint32_t state) {
	switch (biton32(state)) {
		case _QWERTY_LAYER:
			state = update_tri_layer_state(state, _RAISE_LAYER, _QWERTZ_LOWER_LAYER, _ALTER_LAYER);
			state = update_tri_layer_state(state, _RAISE_LAYER, _COLEMA_LOWER_LAYER, _ALTER_LAYER);
			state = update_tri_layer_state(state, _RAISE_LAYER, _DVORAK_LOWER_LAYER, _ALTER_LAYER);
			layer_move(_QWERTY_LAYER);
			break;
		case _QWERTZ_LAYER:
			state = update_tri_layer_state(state, _RAISE_LAYER, _QWERTY_LOWER_LAYER, _ALTER_LAYER);
			state = update_tri_layer_state(state, _RAISE_LAYER, _COLEMA_LOWER_LAYER, _ALTER_LAYER);
			state = update_tri_layer_state(state, _RAISE_LAYER, _DVORAK_LOWER_LAYER, _ALTER_LAYER);
			layer_move(_QWERTZ_LAYER);
			break;
		case _COLEMA_LAYER:
			state = update_tri_layer_state(state, _RAISE_LAYER, _QWERTY_LOWER_LAYER, _ALTER_LAYER);
			state = update_tri_layer_state(state, _RAISE_LAYER, _QWERTZ_LOWER_LAYER, _ALTER_LAYER);
			state = update_tri_layer_state(state, _RAISE_LAYER, _DVORAK_LOWER_LAYER, _ALTER_LAYER);
			layer_move(_COLEMA_LAYER);
			break;
		case _DVORAK_LAYER:
			state = update_tri_layer_state(state, _RAISE_LAYER, _QWERTY_LOWER_LAYER, _ALTER_LAYER);
			state = update_tri_layer_state(state, _RAISE_LAYER, _QWERTZ_LOWER_LAYER, _ALTER_LAYER);
			state = update_tri_layer_state(state, _RAISE_LAYER, _COLEMA_LOWER_LAYER, _ALTER_LAYER);
			layer_move(_DVORAK_LAYER);
			break;
	}
	return state;
}

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
	switch (keycode) {
		case BL_TOGG:
			if (record->event.pressed) {
				cospad_bl_led_togg();
			}
			return false;
		case BL_ON:
			if (record->event.pressed) {
				cospad_bl_led_on();
			}
			return false;
		case BL_OFF:
			if (record->event.pressed) {
				cospad_bl_led_off();
			}
			return false;
		case QWERTY:
			if (record->event.pressed) {
				set_single_persistent_default_layer(_QWERTY_LAYER);
				print("switched to QWERTY layout\n");
			}
			return false;
			break;
		case QWERTZ:
			if (record->event.pressed) {
				set_single_persistent_default_layer(_QWERTZ_LAYER);
			}
			return false;
			break;
		case COLEMAK:
			if (record->event.pressed) {
				set_single_persistent_default_layer(_COLEMA_LAYER);
			}
			return false;
			break;
		case DVORAK:
			if (record->event.pressed) {
				set_single_persistent_default_layer(_DVORAK_LAYER);
			}
			return false;
			break;
		default:
			return true;
	}
}