aboutsummaryrefslogtreecommitdiff
path: root/keyboards/mitosis/keymaps/mjt/keymap.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/mitosis/keymaps/mjt/keymap.c')
-rw-r--r--keyboards/mitosis/keymaps/mjt/keymap.c329
1 files changed, 329 insertions, 0 deletions
diff --git a/keyboards/mitosis/keymaps/mjt/keymap.c b/keyboards/mitosis/keymaps/mjt/keymap.c
new file mode 100644
index 000000000..01443d5f4
--- /dev/null
+++ b/keyboards/mitosis/keymaps/mjt/keymap.c
@@ -0,0 +1,329 @@
1// this is the style you want to emulate.
2// This is the canonical layout file for the Quantum project. If you want to add another keyboard,
3
4#include "mitosis.h"
5#ifdef AUDIO_ENABLE
6 #include "audio.h"
7#endif
8#include "eeconfig.h"
9
10// Each layer gets a name for readability, which is then used in the keymap matrix below.
11// The underscores don't mean anything - you can have a layer called STUFF or any other name.
12// Layer names don't all need to be of the same length, obviously, and you can also skip them
13// entirely and just use numbers.
14enum mitosis_layers
15{
16 _QWERTY,
17 _SHIFTED,
18 _FUNCTIONPC,
19 _FUNCTIONMAC,
20 _FUNCSHIFT,
21 _ADJUST
22};
23
24enum mitosis_keycodes
25{
26 FNKEY = SAFE_RANGE,
27 SHIFT,
28 MACSLEEP,
29 FNMAC,
30 FNPC,
31 DYNAMIC_MACRO_RANGE,
32};
33
34
35// Macro definitions for readability
36enum mitosis_macros
37{
38 VOLU,
39 VOLD,
40 ESCM
41};
42
43
44#include "dynamic_macro.h"
45
46#define LONGPRESS_DELAY 150
47#define LAYER_TOGGLE_DELAY 900
48
49// Fillers to make layering more clear
50#define _______ KC_TRNS
51#define __MOD__ KC_TRNS
52#define XXXXXXX KC_NO
53
54const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
55 [_QWERTY] = { /* QWERTY adapted to this crazy thing */
56 {KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P },
57 {KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN },
58 {SFT_T(KC_Z), KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, SFT_T(KC_SLSH) },
59 {XXXXXXX, KC_LCTL, M(ESCM), KC_TAB, KC_QUOT, KC_LEFT, KC_DOWN, KC_UP, KC_RIGHT, XXXXXXX },
60 {XXXXXXX, KC_LALT, KC_LGUI, KC_SPC, SHIFT, FNKEY, KC_BSPC, KC_ENT, MO(_ADJUST), XXXXXXX }
61 },
62
63
64 [_SHIFTED] = { /* Shifted Layer, layered so that tri_layer can be used, or selectively
65 able to modify individual key's shifted behaviour */
66 {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______ },
67 {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______ },
68 {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______ },
69 {XXXXXXX, __MOD__, KC_DEL, _______, _______, _______, _______, _______, _______, XXXXXXX },
70 {XXXXXXX, __MOD__, __MOD__, _______, __MOD__, __MOD__, _______, _______, KC_NO, XXXXXXX }
71 },
72
73
74 [_FUNCTIONPC] = { /* Function Layer mimicks planck's raise layer somewhat */
75 {KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0 },
76 {LCTL(KC_A), LCTL(KC_S), _______, LCTL(KC_F),_______, _______, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC },
77 {LCTL(KC_Z), LCTL(KC_X), LCTL(KC_C), LCTL(KC_V),_______, _______, KC_BSLS, _______, _______, KC_QUOT },
78 {XXXXXXX, __MOD__, KC_DEL, _______, KC_GRV, KC_HOME, KC_PGDN, KC_PGUP, KC_END, XXXXXXX },
79 {XXXXXXX, __MOD__, __MOD__, _______, __MOD__, __MOD__, _______, KC_PSCR, KC_NO, XXXXXXX }
80 },
81
82 [_FUNCTIONMAC] = { /* Function Layer mimicks planck's raise layer somewhat */
83 {KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0 },
84 {LGUI(KC_A), LGUI(KC_S), _______, LGUI(KC_F),_______, _______, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC },
85 {LGUI(KC_Z), LGUI(KC_X), LGUI(KC_C), LGUI(KC_V),_______, _______, KC_BSLS, _______, _______, KC_QUOT },
86 {XXXXXXX, __MOD__, KC_DEL, _______, KC_GRV, KC_HOME, KC_PGDN, KC_PGUP, KC_END, XXXXXXX },
87 {XXXXXXX, __MOD__, __MOD__, _______, __MOD__, __MOD__, _______, KC_PSCR, KC_NO, XXXXXXX }
88 },
89
90 [_FUNCSHIFT] = { /* Function Shifted Layer mimicks planck's lower layer somewhat */
91 {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______ },
92 {KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, _______, _______, KC_LCBR, KC_RCBR },
93 {KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, _______, _______ },
94 {XXXXXXX, __MOD__, KC_DEL, _______, KC_TILD, _______, _______, _______, _______, XXXXXXX },
95 {XXXXXXX, __MOD__, __MOD__, _______, __MOD__, __MOD__, _______, _______, _______, XXXXXXX }
96 },
97
98
99 [_ADJUST] = { /* Adjust layer for fancy stuff and macros */
100 {RESET, FNPC, _______, _______, _______, _______, DYN_REC_START1, DYN_REC_START2, _______, _______ },
101 {FNMAC, _______, AU_ON, AU_OFF, _______, _______, _______, _______, MACSLEEP, _______ },
102 {MUV_DE, MUV_IN, MU_ON, MU_OFF, _______, _______, KC_MUTE, KC_MPRV, KC_MNXT, KC_MPLY },
103 {XXXXXXX, __MOD__, _______, _______, _______, _______, DYN_MACRO_PLAY1, DYN_MACRO_PLAY2, _______, XXXXXXX },
104 {XXXXXXX, __MOD__, __MOD__, _______, __MOD__, __MOD__, _______, _______, __MOD__, XXXXXXX }
105 }
106
107};
108
109#ifdef AUDIO_ENABLE
110
111float tone_startup[][2] = SONG(STARTUP_SOUND);
112float tone_qwerty[][2] = SONG(QWERTY_SOUND);
113float tone_dyn_macro_rec[][2] = SONG(DVORAK_SOUND);
114float tone_dyn_macro_play[][2] = SONG(COLEMAK_SOUND);
115float tone_fnpc[][2] = SONG(PLOVER_SOUND);
116float tone_fnmac[][2] = SONG(PLOVER_GOODBYE_SOUND);
117float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
118
119float tone_goodbye[][2] = SONG(GOODBYE_SOUND);
120#endif
121
122const uint16_t PROGMEM fn_actions[] = {
123
124};
125static uint16_t function_layer = _FUNCTIONMAC;
126static uint16_t key_timer;
127
128void persistent_function_layer_set(uint16_t new_function_layer) {
129 // eeconfig_update_function_layer(new_function_layer);
130 function_layer = new_function_layer;
131 // should clear layers to avoid getting stuck.
132}
133
134const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
135{
136 // MACRODOWN only works in this function
137 switch(id) {
138
139 //switch multiplexing for media, short tap for volume up, long press for play/pause
140 case VOLU:
141 if (record->event.pressed) {
142 key_timer = timer_read(); // if the key is being pressed, we start the timer.
143 } else { // this means the key was just released, so we can figure out how long it was pressed for (tap or "held down").
144 if (timer_elapsed(key_timer) > LONGPRESS_DELAY) { // LONGPRESS_DELAY being 150ms, the threshhold we pick for counting something as a tap.
145 return MACRO(T(MPLY), END);
146 } else {
147 return MACRO(T(VOLU), END);
148 }
149 }
150 break;
151
152 //switch multiplexing for media, short tap for volume down, long press for next track
153 case VOLD:
154 if (record->event.pressed) {
155 key_timer = timer_read();
156 } else {
157 if (timer_elapsed(key_timer) > LONGPRESS_DELAY) {
158 return MACRO(T(MNXT), END);
159 } else {
160 return MACRO(T(VOLD), END);
161 }
162 }
163 break;
164
165 //switch multiplexing for escape, short tap for escape, long press for context menu
166 case ESCM:
167 if (record->event.pressed) {
168 key_timer = timer_read();
169 } else {
170 if (timer_elapsed(key_timer) > LONGPRESS_DELAY) {
171 return MACRO(T(APP), END);
172 } else {
173 return MACRO(T(ESC), END);
174 }
175 }
176 break;
177 }
178 return MACRO_NONE;
179};
180
181static bool singular_key = false;
182
183bool process_record_user(uint16_t keycode, keyrecord_t *record) {
184 uint16_t macro_kc = (keycode == MO(_ADJUST) ? DYN_REC_STOP : keycode);
185 if (!process_record_dynamic_macro(macro_kc, record)) {
186 return false;
187 }
188 uint8_t layer;
189 layer = biton32(layer_state); // get the current layer
190
191 //custom layer handling for tri_layer,
192 switch (keycode) {
193 case MACSLEEP:
194 if (record->event.pressed) {
195 // ACTION_MODS_KEY(MOD_LCTL | MOD_LSFT, KC_POWER);
196 register_code(KC_RSFT);
197 register_code(KC_RCTL);
198 register_code(KC_POWER);
199 unregister_code(KC_POWER);
200 unregister_code(KC_RCTL);
201 unregister_code(KC_RSFT);
202 }
203 return false;
204 break;
205 case FNKEY:
206 if (record->event.pressed) {
207 key_timer = timer_read();
208 singular_key = true;
209 // layer_on(_FUNCTION);
210 layer_on(function_layer);
211 } else {
212 if (timer_elapsed(key_timer) < LAYER_TOGGLE_DELAY || !singular_key) {
213 layer_off(function_layer);
214 }
215 }
216 update_tri_layer(function_layer, _SHIFTED, _FUNCSHIFT);
217 return false;
218 break;
219 //SHIFT is handled as LSHIFT in the general case
220 case SHIFT:
221 if (record->event.pressed) {
222 key_timer = timer_read();
223 singular_key = true;
224 layer_on(_SHIFTED);
225 register_code(KC_LSFT);
226 } else {
227 if (timer_elapsed(key_timer) < LAYER_TOGGLE_DELAY || !singular_key) {
228 layer_off(_SHIFTED);
229 unregister_code(KC_LSFT);
230 }
231 }
232 update_tri_layer(function_layer, _SHIFTED, _FUNCSHIFT);
233 return false;
234 break;
235 case FNPC:
236 if (record->event.pressed) {
237 persistent_function_layer_set(_FUNCTIONPC);
238 #ifdef AUDIO_ENABLE
239 PLAY_NOTE_ARRAY(tone_fnpc, false, 0);
240 #endif
241 }
242 return false;
243 break;
244 case FNMAC:
245 if (record->event.pressed) {
246 persistent_function_layer_set(_FUNCTIONMAC);
247 #ifdef AUDIO_ENABLE
248 PLAY_NOTE_ARRAY(tone_fnmac, false, 0);
249 #endif
250 }
251 return false;
252 break;
253 //If any other key was pressed during the layer mod hold period,
254 //then the layer mod was used momentarily, and should block latching
255 default:
256 singular_key = false;
257 break;
258 }
259
260 //FUNCSHIFT has been shifted by the SHIFT handling, some keys need to be excluded
261 if (layer == _FUNCSHIFT) {
262 //F1-F12 should be sent as unshifted keycodes,
263 //and ] needs to be unshifted or it is sent as }
264 if ( (keycode >= KC_F1 && keycode <= KC_F12)
265 || keycode == KC_RBRC ) {
266 if (record->event.pressed) {
267 unregister_mods(MOD_LSFT);
268 } else {
269 register_mods(MOD_LSFT);
270 }
271 }
272 }
273
274 return true;
275};
276
277#ifdef AUDIO_ENABLE
278
279void startup_user()
280{
281 _delay_ms(20); // gets rid of tick
282 PLAY_NOTE_ARRAY(tone_startup, false, 0);
283}
284
285void shutdown_user()
286{
287 PLAY_NOTE_ARRAY(tone_goodbye, false, 0);
288 _delay_ms(150);
289 stop_all_notes();
290}
291
292void music_on_user(void)
293{
294 music_scale_user();
295}
296
297void music_scale_user(void)
298{
299 PLAY_NOTE_ARRAY(music_scale, false, 0);
300}
301
302#endif
303
304void matrix_scan_user(void) {
305 uint8_t layer = biton32(layer_state);
306
307 switch (layer) {
308 case _QWERTY:
309 set_led_off;
310 break;
311 case _FUNCTIONMAC:
312 set_led_blue;
313 break;
314 case _FUNCTIONPC:
315 set_led_cyan;
316 break;
317 case _SHIFTED:
318 set_led_red;
319 break;
320 case _FUNCSHIFT:
321 set_led_green;
322 break;
323 case _ADJUST:
324 set_led_white;
325 break;
326 default:
327 break;
328 }
329};