[Keymap] Add soundmonster's keymap for crkbd (#6964)
[jackhill/qmk/firmware.git] / keyboards / crkbd / keymaps / soundmonster / keymap.c
1 #include QMK_KEYBOARD_H
2
3 extern keymap_config_t keymap_config;
4
5 #ifdef RGBLIGHT_ENABLE
6 //Following line allows macro to read current RGB settings
7 extern rgblight_config_t rgblight_config;
8 #endif
9
10 #ifdef OLED_DRIVER_ENABLE
11 static uint32_t oled_timer = 0;
12 #endif
13
14 extern uint8_t is_master;
15
16 // Each layer gets a name for readability, which is then used in the keymap matrix below.
17 // The underscores don't mean anything - you can have a layer called STUFF or any other name.
18 // Layer names don't all need to be of the same length, obviously, and you can also skip them
19 // entirely and just use numbers.
20 enum layers {
21 _QWERTY,
22 _LOWER,
23 _RAISE,
24 _ADJUST
25 };
26
27 // Custom keycodes for layer keys
28 // Dual function escape with left command
29 #define KC_LGESC LGUI_T(KC_ESC)
30
31 enum custom_keycodes {
32 QWERTY = SAFE_RANGE,
33 LOWER,
34 RAISE,
35 ADJUST,
36 RGBRST,
37 KC_RACL // right alt / colon
38 };
39
40 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
41 [_QWERTY] = LAYOUT(
42 //,-----------------------------------------. ,---------------------------------------------.
43 KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
44 //|------+------+------+------+------+------| |------+------+-------+------+-------+--------|
45 KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN,KC_QUOT,
46 //|------+------+------+------+------+------| |------+------+-------+------+-------+--------|
47 KC_LSPO, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M,KC_COMM,KC_DOT,KC_SLSH,KC_RSPC,
48 //|------+------+------+------+------+------+------| |------+------+------+-------+------+-------+--------|
49 KC_LGESC,LOWER, KC_SPC, RCTL_T(KC_ENT), RAISE, KC_RACL
50 //`--------------------' `--------------------'
51 ),
52
53 [_LOWER] = LAYOUT(
54 //,---------------------------------------------. ,-----------------------------------------.
55 KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL,
56 //|------+------+-------+-------+-------+-------| |------+------+------+------+------+------|
57 KC_LCTL, KC_NO,KC_MS_L,KC_MS_D,KC_MS_U,KC_MS_R, KC_LEFT,KC_DOWN,KC_UP,KC_RIGHT,KC_NO,KC_NO,
58 //|------+------+-------+-------+-------+-------| |------+------+------+------+------+------|
59 KC_LSFT, KC_NO,KC_BTN2,KC_WH_D,KC_WH_U,KC_BTN1, KC_HOME,KC_PGDN,KC_PGUP,KC_END,KC_NO,KC_NO,
60 //|------+------+-------+-------+-------+-------+------| |------+------+------+------+------+------+------|
61 KC_LGUI, LOWER,KC_SPC, KC_ENT, RAISE,KC_RALT
62 //`--------------------' `--------------------'
63 ),
64
65 [_RAISE] = LAYOUT(
66 //,-----------------------------------------. ,-----------------------------------------.
67 KC_ESC,KC_EXLM,KC_AT,KC_HASH,KC_DLR,KC_PERC, KC_CIRC,KC_AMPR,KC_ASTR,KC_LPRN,KC_RPRN,KC_BSPC,
68 //|------+------+------+------+------+------| |------+------+------+------+------+------|
69 KC_LCTL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_MINS,KC_EQL,KC_LCBR,KC_RCBR,KC_PIPE,KC_GRV,
70 //|------+------+------+------+------+------| |------+------+------+------+------+------|
71 KC_LSFT, KC_F6, KC_F7, KC_F8, KC_F9,KC_F10, KC_UNDS,KC_PLUS,KC_LBRC,KC_RBRC,KC_BSLS,KC_TILD,
72 //|------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
73 KC_LGUI, LOWER,KC_SPC, KC_ENT, RAISE,KC_RALT
74 //`--------------------' `--------------------'
75 ),
76
77 [_ADJUST] = LAYOUT(
78 //,-----------------------------------------. ,-----------------------------------------.
79 RESET,RGBRST, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,KC__MUTE, KC_NO, KC_NO, KC_NO, KC_NO,
80 //|------+------+------+------+------+------| |------+------+------+------+------+------|
81 RGB_TOG,RGB_HUI,RGB_SAI,RGB_VAI,RGB_SPI,KC_NO, KC_PAUSE,KC__VOLUP, KC_NO, KC_NO, KC_NO, KC_NO,
82 //|------+------+------+------+------+------| |------+------+------+------+------+------|
83 RGB_MOD,RGB_HUD,RGB_SAD,RGB_VAD,RGB_SPD,KC_NO, KC_SCROLLLOCK,KC__VOLDOWN, KC_NO, KC_NO, KC_NO, RGB_RMOD,
84 //|------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
85 KC_LGUI, LOWER,KC_SPC, KC_ENT, RAISE,KC_RALT
86 //`--------------------' `--------------------'
87 )
88 };
89
90 int RGB_current_mode;
91
92 // Setting ADJUST layer RGB back to default
93 void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
94 if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
95 layer_on(layer3);
96 } else {
97 layer_off(layer3);
98 }
99 }
100
101 void matrix_init_user(void) {
102 #ifdef RGBLIGHT_ENABLE
103 RGB_current_mode = rgblight_config.mode;
104 #endif
105 }
106
107 #ifdef OLED_DRIVER_ENABLE
108 oled_rotation_t oled_init_user(oled_rotation_t rotation) { return OLED_ROTATION_270; }
109
110 void render_space(void) {
111 oled_write_P(PSTR(" "), false);
112 }
113
114 void render_mod_status_gui_alt(uint8_t modifiers) {
115 static const char PROGMEM gui_off_1[] = {0x85, 0x86, 0};
116 static const char PROGMEM gui_off_2[] = {0xa5, 0xa6, 0};
117 static const char PROGMEM gui_on_1[] = {0x8d, 0x8e, 0};
118 static const char PROGMEM gui_on_2[] = {0xad, 0xae, 0};
119
120 static const char PROGMEM alt_off_1[] = {0x87, 0x88, 0};
121 static const char PROGMEM alt_off_2[] = {0xa7, 0xa8, 0};
122 static const char PROGMEM alt_on_1[] = {0x8f, 0x90, 0};
123 static const char PROGMEM alt_on_2[] = {0xaf, 0xb0, 0};
124
125 // fillers between the modifier icons bleed into the icon frames
126 static const char PROGMEM off_off_1[] = {0xc5, 0};
127 static const char PROGMEM off_off_2[] = {0xc6, 0};
128 static const char PROGMEM on_off_1[] = {0xc7, 0};
129 static const char PROGMEM on_off_2[] = {0xc8, 0};
130 static const char PROGMEM off_on_1[] = {0xc9, 0};
131 static const char PROGMEM off_on_2[] = {0xca, 0};
132 static const char PROGMEM on_on_1[] = {0xcb, 0};
133 static const char PROGMEM on_on_2[] = {0xcc, 0};
134
135 if(modifiers & MOD_MASK_GUI) {
136 oled_write_P(gui_on_1, false);
137 } else {
138 oled_write_P(gui_off_1, false);
139 }
140
141 if ((modifiers & MOD_MASK_GUI) && (modifiers & MOD_MASK_ALT)) {
142 oled_write_P(on_on_1, false);
143 } else if(modifiers & MOD_MASK_GUI) {
144 oled_write_P(on_off_1, false);
145 } else if(modifiers & MOD_MASK_ALT) {
146 oled_write_P(off_on_1, false);
147 } else {
148 oled_write_P(off_off_1, false);
149 }
150
151 if(modifiers & MOD_MASK_ALT) {
152 oled_write_P(alt_on_1, false);
153 } else {
154 oled_write_P(alt_off_1, false);
155 }
156
157 if(modifiers & MOD_MASK_GUI) {
158 oled_write_P(gui_on_2, false);
159 } else {
160 oled_write_P(gui_off_2, false);
161 }
162
163 if (modifiers & MOD_MASK_GUI & MOD_MASK_ALT) {
164 oled_write_P(on_on_2, false);
165 } else if(modifiers & MOD_MASK_GUI) {
166 oled_write_P(on_off_2, false);
167 } else if(modifiers & MOD_MASK_ALT) {
168 oled_write_P(off_on_2, false);
169 } else {
170 oled_write_P(off_off_2, false);
171 }
172
173 if(modifiers & MOD_MASK_ALT) {
174 oled_write_P(alt_on_2, false);
175 } else {
176 oled_write_P(alt_off_2, false);
177 }
178 }
179
180 void render_mod_status_ctrl_shift(uint8_t modifiers) {
181 static const char PROGMEM ctrl_off_1[] = {0x89, 0x8a, 0};
182 static const char PROGMEM ctrl_off_2[] = {0xa9, 0xaa, 0};
183 static const char PROGMEM ctrl_on_1[] = {0x91, 0x92, 0};
184 static const char PROGMEM ctrl_on_2[] = {0xb1, 0xb2, 0};
185
186 static const char PROGMEM shift_off_1[] = {0x8b, 0x8c, 0};
187 static const char PROGMEM shift_off_2[] = {0xab, 0xac, 0};
188 static const char PROGMEM shift_on_1[] = {0xcd, 0xce, 0};
189 static const char PROGMEM shift_on_2[] = {0xcf, 0xd0, 0};
190
191 // fillers between the modifier icons bleed into the icon frames
192 static const char PROGMEM off_off_1[] = {0xc5, 0};
193 static const char PROGMEM off_off_2[] = {0xc6, 0};
194 static const char PROGMEM on_off_1[] = {0xc7, 0};
195 static const char PROGMEM on_off_2[] = {0xc8, 0};
196 static const char PROGMEM off_on_1[] = {0xc9, 0};
197 static const char PROGMEM off_on_2[] = {0xca, 0};
198 static const char PROGMEM on_on_1[] = {0xcb, 0};
199 static const char PROGMEM on_on_2[] = {0xcc, 0};
200
201 if(modifiers & MOD_MASK_CTRL) {
202 oled_write_P(ctrl_on_1, false);
203 } else {
204 oled_write_P(ctrl_off_1, false);
205 }
206
207 if ((modifiers & MOD_MASK_CTRL) && (modifiers & MOD_MASK_SHIFT)) {
208 oled_write_P(on_on_1, false);
209 } else if(modifiers & MOD_MASK_CTRL) {
210 oled_write_P(on_off_1, false);
211 } else if(modifiers & MOD_MASK_SHIFT) {
212 oled_write_P(off_on_1, false);
213 } else {
214 oled_write_P(off_off_1, false);
215 }
216
217 if(modifiers & MOD_MASK_SHIFT) {
218 oled_write_P(shift_on_1, false);
219 } else {
220 oled_write_P(shift_off_1, false);
221 }
222
223 if(modifiers & MOD_MASK_CTRL) {
224 oled_write_P(ctrl_on_2, false);
225 } else {
226 oled_write_P(ctrl_off_2, false);
227 }
228
229 if (modifiers & MOD_MASK_CTRL & MOD_MASK_SHIFT) {
230 oled_write_P(on_on_2, false);
231 } else if(modifiers & MOD_MASK_CTRL) {
232 oled_write_P(on_off_2, false);
233 } else if(modifiers & MOD_MASK_SHIFT) {
234 oled_write_P(off_on_2, false);
235 } else {
236 oled_write_P(off_off_2, false);
237 }
238
239 if(modifiers & MOD_MASK_SHIFT) {
240 oled_write_P(shift_on_2, false);
241 } else {
242 oled_write_P(shift_off_2, false);
243 }
244 }
245
246 void render_logo(void) {
247 static const char PROGMEM corne_logo[] = {
248 0x80, 0x81, 0x82, 0x83, 0x84,
249 0xa0, 0xa1, 0xa2, 0xa3, 0xa4,
250 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0};
251 oled_write_P(corne_logo, false);
252 oled_write_P(PSTR("corne"), false);
253 }
254
255 void render_layer_state(void) {
256 static const char PROGMEM default_layer[] = {
257 0x20, 0x94, 0x95, 0x96, 0x20,
258 0x20, 0xb4, 0xb5, 0xb6, 0x20,
259 0x20, 0xd4, 0xd5, 0xd6, 0x20, 0};
260 static const char PROGMEM raise_layer[] = {
261 0x20, 0x97, 0x98, 0x99, 0x20,
262 0x20, 0xb7, 0xb8, 0xb9, 0x20,
263 0x20, 0xd7, 0xd8, 0xd9, 0x20, 0};
264 static const char PROGMEM lower_layer[] = {
265 0x20, 0x9a, 0x9b, 0x9c, 0x20,
266 0x20, 0xba, 0xbb, 0xbc, 0x20,
267 0x20, 0xda, 0xdb, 0xdc, 0x20, 0};
268 static const char PROGMEM adjust_layer[] = {
269 0x20, 0x9d, 0x9e, 0x9f, 0x20,
270 0x20, 0xbd, 0xbe, 0xbf, 0x20,
271 0x20, 0xdd, 0xde, 0xdf, 0x20, 0};
272 if(layer_state_is(_ADJUST)) {
273 oled_write_P(adjust_layer, false);
274 } else if(layer_state_is(_LOWER)) {
275 oled_write_P(lower_layer, false);
276 } else if(layer_state_is(_RAISE)) {
277 oled_write_P(raise_layer, false);
278 } else {
279 oled_write_P(default_layer, false);
280 }
281 }
282
283 void render_status_main(void) {
284 render_logo();
285 render_space();
286 render_layer_state();
287 render_space();
288 render_mod_status_gui_alt(get_mods()|get_oneshot_mods());
289 render_mod_status_ctrl_shift(get_mods()|get_oneshot_mods());
290 }
291
292 void render_status_secondary(void) {
293 render_logo();
294 render_space();
295 render_layer_state();
296 render_space();
297 render_mod_status_gui_alt(get_mods()|get_oneshot_mods());
298 render_mod_status_ctrl_shift(get_mods()|get_oneshot_mods());
299 }
300
301 void oled_task_user(void) {
302 if (timer_elapsed32(oled_timer) > 30000) {
303 oled_off();
304 return;
305 }
306 #ifndef SPLIT_KEYBOARD
307 else { oled_on(); }
308 #endif
309
310 if (is_master) {
311 render_status_main(); // Renders the current keyboard state (layer, lock, caps, scroll, etc)
312 } else {
313 render_status_secondary();
314 }
315 }
316
317 #endif
318 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
319 if (record->event.pressed) {
320 #ifdef OLED_DRIVER_ENABLE
321 oled_timer = timer_read32();
322 #endif
323 // set_timelog();
324 }
325 static uint16_t my_colon_timer;
326
327 switch (keycode) {
328 case LOWER:
329 if (record->event.pressed) {
330 layer_on(_LOWER);
331 update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
332 } else {
333 layer_off(_LOWER);
334 update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
335 }
336 return false;
337 case RAISE:
338 if (record->event.pressed) {
339 layer_on(_RAISE);
340 update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
341 } else {
342 layer_off(_RAISE);
343 update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
344 }
345 return false;
346 case ADJUST:
347 if (record->event.pressed) {
348 layer_on(_ADJUST);
349 } else {
350 layer_off(_ADJUST);
351 }
352 return false;
353 case KC_RACL:
354 if (record->event.pressed) {
355 my_colon_timer = timer_read();
356 register_code(KC_RALT);
357 } else {
358 unregister_code(KC_RALT);
359 if (timer_elapsed(my_colon_timer) < TAPPING_TERM) {
360 SEND_STRING(":"); // Change the character(s) to be sent on tap here
361 }
362 }
363 return false;
364 case RGBRST:
365 #ifdef RGBLIGHT_ENABLE
366 if (record->event.pressed) {
367 eeconfig_update_rgblight_default();
368 rgblight_enable();
369 RGB_current_mode = rgblight_config.mode;
370 }
371 #endif
372 #ifdef RGB_MATRIX_ENABLE
373 if (record->event.pressed) {
374 eeconfig_update_rgb_matrix_default();
375 rgb_matrix_enable();
376 }
377 #endif
378 break;
379 }
380 return true;
381 }
382
383 #ifdef RGB_MATRIX_ENABLE
384
385 void suspend_power_down_keymap(void) {
386 rgb_matrix_set_suspend_state(true);
387 }
388
389 void suspend_wakeup_init_keymap(void) {
390 rgb_matrix_set_suspend_state(false);
391 }
392
393 #endif