aboutsummaryrefslogtreecommitdiff
path: root/keyboards/crkbd/keymaps/drashna/keymap.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/crkbd/keymaps/drashna/keymap.c')
-rw-r--r--keyboards/crkbd/keymaps/drashna/keymap.c289
1 files changed, 171 insertions, 118 deletions
diff --git a/keyboards/crkbd/keymaps/drashna/keymap.c b/keyboards/crkbd/keymaps/drashna/keymap.c
index af0bc0d9a..693c53b16 100644
--- a/keyboards/crkbd/keymaps/drashna/keymap.c
+++ b/keyboards/crkbd/keymaps/drashna/keymap.c
@@ -2,17 +2,16 @@
2#include "drashna.h" 2#include "drashna.h"
3 3
4extern keymap_config_t keymap_config; 4extern keymap_config_t keymap_config;
5extern uint8_t is_master; 5extern uint8_t is_master;
6 6
7#ifdef RGBLIGHT_ENABLE 7#ifdef RGBLIGHT_ENABLE
8//Following line allows macro to read current RGB settings 8// Following line allows macro to read current RGB settings
9extern rgblight_config_t rgblight_config; 9extern rgblight_config_t rgblight_config;
10#endif 10#endif
11 11
12enum crkbd_keycodes { 12enum crkbd_keycodes { RGBRST = NEW_SAFE_RANGE };
13 RGBRST = NEW_SAFE_RANGE
14};
15 13
14// clang-format off
16#define LAYOUT_crkbd_base( \ 15#define LAYOUT_crkbd_base( \
17 K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, \ 16 K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, \
18 K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, \ 17 K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, \
@@ -103,60 +102,30 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
103 _______, KC_NUKE, _______, _______, TG_MODS, _______ 102 _______, KC_NUKE, _______, _______, TG_MODS, _______
104 ) 103 )
105}; 104};
106 105// clang-format on
107void matrix_init_keymap(void) {
108#ifndef CONVERT_TO_PROTON_C
109 setPinOutput(D5);
110 writePinHigh(D5);
111
112 setPinOutput(B0);
113 writePinHigh(B0);
114#endif
115}
116
117 106
118#ifdef OLED_DRIVER_ENABLE 107#ifdef OLED_DRIVER_ENABLE
119oled_rotation_t oled_init_user(oled_rotation_t rotation) { 108oled_rotation_t oled_init_user(oled_rotation_t rotation) { return OLED_ROTATION_270; }
120 if (is_master) { 109uint16_t oled_timer;
121 return OLED_ROTATION_270;
122 } else {
123 return rotation;
124 }
125}
126
127void render_crkbd_logo(void) {
128 static const char PROGMEM crkbd_logo[] = {
129 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94,
130 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4,
131 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4,
132 0};
133 oled_write_P(crkbd_logo, false);
134}
135 110
136#define KEYLOG_LEN (int)(32 / OLED_FONT_WIDTH) 111char keylog_str[5] = {};
137char keylog_str[KEYLOG_LEN] = {}; 112uint8_t keylogs_str_idx = 0;
138uint8_t keylogs_str_idx = 0; 113uint16_t log_timer = 0;
139uint16_t log_timer = 0;
140 114
141const char code_to_name[60] = { 115const char code_to_name[60] = {' ', ' ', ' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'R', 'E', 'B', 'T', '_', '-', '=', '[', ']', '\\', '#', ';', '\'', '`', ',', '.', '/', ' ', ' ', ' '};
142 ' ', ' ', ' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f',
143 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
144 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
145 '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
146 'R', 'E', 'B', 'T', '_', '-', '=', '[', ']', '\\',
147 '#', ';', '\'', '`', ',', '.', '/', ' ', ' ', ' '};
148 116
149void add_keylog(uint16_t keycode) { 117void add_keylog(uint16_t keycode) {
150 if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || 118 if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) {
151 (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) { keycode = keycode & 0xFF; } 119 keycode = keycode & 0xFF;
120 }
152 121
153 for (uint8_t i = KEYLOG_LEN - 1; i > 0; i--) { 122 for (uint8_t i = 4; i > 0; i--) {
154 keylog_str[i] = keylog_str[i - 1]; 123 keylog_str[i] = keylog_str[i - 1];
155 } 124 }
156 if (keycode < 60) { 125 if (keycode < 60) {
157 keylog_str[0] = code_to_name[keycode]; 126 keylog_str[0] = code_to_name[keycode];
158 } 127 }
159 keylog_str[KEYLOG_LEN] = 0; 128 keylog_str[5] = 0;
160 129
161 log_timer = timer_read(); 130 log_timer = timer_read();
162} 131}
@@ -167,94 +136,153 @@ void update_log(void) {
167 } 136 }
168} 137}
169 138
170
171bool process_record_keymap(uint16_t keycode, keyrecord_t *record) { 139bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
172 if (record->event.pressed) { add_keylog(keycode); } 140 if (record->event.pressed) {
141 add_keylog(keycode);
142 oled_timer = timer_read();
143 }
173 return true; 144 return true;
174} 145}
175 146
176void render_status(void) { 147void render_rgb_status(void) {
148 oled_write_ln("RGB:", false);
149 static char temp[20] = {0};
150 snprintf(temp, sizeof(temp) + 1, "M:%3dH:%3dS:%3dV:%3d", rgb_matrix_config.mode, rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v);
151 oled_write(temp, false);
152}
177 153
178 oled_write_P(PSTR("Layer"), false); 154void render_status_main(void) {
179 switch (biton32(layer_state)) { 155 /* Show Keyboard Layout */
180 case 0: 156 oled_write("Lyout", false);
181 oled_write_P(PSTR("Base "), false); 157 switch (biton32(default_layer_state)) {
158 case _QWERTY:
159 oled_write(" QRTY", false);
182 break; 160 break;
183 case _RAISE: 161 case _COLEMAK:
184 oled_write_P(PSTR("Raise"), false); 162 oled_write(" COLE", false);
185 break; 163 break;
186 case _LOWER: 164 case _DVORAK:
187 oled_write_P(PSTR("Lower"), false); 165 oled_write(" DVRK", false);
188 break; 166 break;
189 case _ADJUST: 167 case _WORKMAN:
190 oled_write_P(PSTR("Adjst"), false); 168 oled_write(" WKMN", false);
191 break; 169 break;
192 default: 170 case _NORMAN:
193 oled_write_P(PSTR("Unkn "), false); 171 oled_write(" NORM", false);
172 break;
173 case _MALTRON:
174 oled_write(" MLTN", false);
175 break;
176 case _EUCALYN:
177 oled_write(" ECLN", false);
178 break;
179 case _CARPLAX:
180 oled_write(" CRPX", false);
194 break; 181 break;
195 } 182 }
196 oled_write_P(PSTR("Lyout"), false); 183
184 /* Show Lock Status (only work on master side) */
185 uint8_t led_usb_state = host_keyboard_leds();
186 oled_write("Lock:", false);
187 oled_write(" ", false);
188 oled_write_ln("NUM", led_usb_state & (1 << USB_LED_NUM_LOCK));
189 oled_write(" ", false);
190 oled_write("CAPS", led_usb_state & (1 << USB_LED_CAPS_LOCK));
191 oled_write(" ", false);
192 oled_write("SCRL", led_usb_state & (1 << USB_LED_SCROLL_LOCK));
193
194 /* Show Alt-Gui Swap options */
195 oled_write("BTMGK", false);
196 oled_write(" ", false);
197 oled_write_ln("Win", !keymap_config.swap_lalt_lgui);
198 oled_write(" ", false);
199 oled_write_ln("Mac", keymap_config.swap_lalt_lgui);
200
201# if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
202 /* Show RGB Options */
203 render_rgb_status();
204# endif
205
206 oled_write(keylog_str, false);
207}
208
209void render_status_secondary(void) {
210 /* Show Keyboard Layout */
211 oled_write("Lyout", false);
197 switch (biton32(default_layer_state)) { 212 switch (biton32(default_layer_state)) {
198 case _QWERTY: 213 case _QWERTY:
199 oled_write_P(PSTR("QWRTY"), false); 214 oled_write(" QRTY", false);
200 break; 215 break;
201 case _COLEMAK: 216 case _COLEMAK:
202 oled_write_P(PSTR("COLMK"), false); 217 oled_write(" COLE", false);
203 break; 218 break;
204 case _DVORAK: 219 case _DVORAK:
205 oled_write_P(PSTR("DVRAK"), false); 220 oled_write(" DVRK", false);
206 break; 221 break;
207 case _WORKMAN: 222 case _WORKMAN:
208 oled_write_P(PSTR("WRKMN"), false); 223 oled_write(" WKMN", false);
209 break; 224 break;
210 case _NORMAN: 225 case _NORMAN:
211 oled_write_P(PSTR("NORMN"), false); 226 oled_write(" NORM", false);
212 break; 227 break;
213 case _MALTRON: 228 case _MALTRON:
214 oled_write_P(PSTR("MLTRN"), false); 229 oled_write(" MLTN", false);
215 break; 230 break;
216 case _EUCALYN: 231 case _EUCALYN:
217 oled_write_P(PSTR("ECLYN"), false); 232 oled_write(" ECLN", false);
218 break; 233 break;
219 case _CARPLAX: 234 case _CARPLAX:
220 oled_write_P(PSTR("CRPLX"), false); 235 oled_write(" CRPX", false);
221 break; 236 break;
222 } 237 }
223 238
224 uint8_t modifiers = get_mods(); 239 /* Show Activate layer */
225 uint8_t one_shot = get_oneshot_mods(); 240 oled_write("Layer", false);
226 241 switch (biton32(layer_state)) {
227 oled_write_P(PSTR("Mods:"), false); 242 case _RAISE:
228 oled_write_P( (modifiers & MOD_MASK_SHIFT || one_shot & MOD_MASK_SHIFT) ? PSTR(" SFT ") : PSTR(" "), false); 243 oled_write("Raise", false);
229 oled_write_P( (modifiers & MOD_MASK_CTRL || one_shot & MOD_MASK_CTRL ) ? PSTR(" CTL ") : PSTR(" "), false); 244 break;
230 oled_write_P( (modifiers & MOD_MASK_ALT || one_shot & MOD_MASK_ALT ) ? PSTR(" ALT ") : PSTR(" "), false); 245 case _LOWER:
231 oled_write_P( (modifiers & MOD_MASK_GUI || one_shot & MOD_MASK_GUI ) ? PSTR(" GUI ") : PSTR(" "), false); 246 oled_write("Lower", false);
232 247 break;
248 case _ADJUST:
249 oled_write("Adjst", false);
250 break;
251 default:
252 oled_write("Dflt ", false);
253 break;
254 }
233 255
234 oled_write_P(PSTR("BTMGK"), false); 256 /* Show Mod */
257 uint8_t modifiers = get_mods() | get_oneshot_mods();
235 258
236 if (keymap_config.swap_lalt_lgui) { 259 oled_write("Mods:", false);
237 oled_write_P(PSTR(" Mac "), false); 260 oled_write(" ", false);
238 } else { 261 oled_write_ln("SFT", (modifiers & MOD_MASK_SHIFT));
239 oled_write_P(PSTR(" Win "), false); 262 oled_write(" ", false);
240 } 263 oled_write_ln("CTL", (modifiers & MOD_MASK_CTRL));
264 oled_write(" ", false);
265 oled_write_ln("ALT", (modifiers & MOD_MASK_ALT));
266 oled_write(" ", false);
267 oled_write_ln("GUI", (modifiers & MOD_MASK_GUI));
241 268
242 uint8_t led_usb_state = host_keyboard_leds(); 269# if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
243 oled_write_P(PSTR("Lock:"), false); 270 render_rgb_status();
244 oled_write_P(led_usb_state & (1<<USB_LED_NUM_LOCK) ? PSTR(" NUM ") : PSTR(" "), false); 271# endif
245 oled_write_P(led_usb_state & (1<<USB_LED_CAPS_LOCK) ? PSTR(" CAPS") : PSTR(" "), false);
246 oled_write_P(led_usb_state & (1<<USB_LED_SCROLL_LOCK) ? PSTR(" SCRL") : PSTR(" "), false);
247 272
273 /* Show logged Keys */
248 oled_write(keylog_str, false); 274 oled_write(keylog_str, false);
249} 275}
250 276
251
252void oled_task_user(void) { 277void oled_task_user(void) {
278 if (timer_elapsed(oled_timer) > 60000) {
279 oled_off();
280 return;
281 }
253 if (is_master) { 282 if (is_master) {
254 render_status(); // Renders the current keyboard state (layer, lock, caps, scroll, etc) 283 render_status_main(); // Renders the current keyboard state (layer, lock, caps, scroll, etc)
255 } else { 284 } else {
256 render_crkbd_logo(); 285 render_status_secondary();
257 oled_scroll_left(); // Turns on scrolling
258 } 286 }
259} 287}
260 288
@@ -272,57 +300,82 @@ uint16_t get_tapping_term(uint16_t keycode) {
272 300
273#ifdef RGB_MATRIX_ENABLE 301#ifdef RGB_MATRIX_ENABLE
274 302
303static bool is_suspended;
304static bool rgb_matrix_enabled;
305
275void suspend_power_down_keymap(void) { 306void suspend_power_down_keymap(void) {
276 rgb_matrix_set_suspend_state(true); 307 rgb_matrix_set_suspend_state(true);
308 if (!is_suspended) {
309 is_suspended = true;
310 rgb_matrix_enabled = (bool)rgb_matrix_config.enable;
311 rgb_matrix_disable_noeeprom();
312 }
277} 313}
278 314
279void suspend_wakeup_init_keymap(void) { 315void suspend_wakeup_init_keymap(void) {
280 rgb_matrix_set_suspend_state(false); 316 rgb_matrix_set_suspend_state(false);
317 is_suspended = false;
318 if (rgb_matrix_enabled) {
319 rgb_matrix_enable_noeeprom();
320 }
281} 321}
282
283void rgb_matrix_indicators_user(void) { 322void rgb_matrix_indicators_user(void) {
284 if ( userspace_config.rgb_layer_change && 323 if (userspace_config.rgb_layer_change &&
285#ifdef RGB_DISABLE_WHEN_USB_SUSPENDED 324# ifdef RGB_DISABLE_WHEN_USB_SUSPENDED
286 !g_suspend_state && 325 !g_suspend_state &&
287#endif 326# endif
288#if defined(RGBLIGHT_ENABLE) 327# if defined(RGBLIGHT_ENABLE)
289 (!rgblight_config.enable && rgb_matrix_config.enable) 328 (!rgblight_config.enable && rgb_matrix_config.enable)
290#else 329# else
291 rgb_matrix_config.enable 330 rgb_matrix_config.enable
292#endif 331# endif
293 ) { 332 ) {
294 switch (biton32(layer_state)) { 333 switch (biton32(layer_state)) {
295 case _MODS:
296 rgb_matrix_layer_helper(0xFF, 0xFF, 0x00, LED_FLAG_UNDERGLOW); break;
297 case _GAMEPAD: 334 case _GAMEPAD:
298 rgb_matrix_layer_helper(0xFF, 0x80, 0x00, LED_FLAG_UNDERGLOW); break; 335 rgb_matrix_layer_helper(HSV_ORANGE, 1, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW);
336 break;
299 case _DIABLO: 337 case _DIABLO:
300 rgb_matrix_layer_helper(0xFF, 0x00, 0x00, LED_FLAG_UNDERGLOW); break; 338 rgb_matrix_layer_helper(HSV_RED, 1, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW);
339 break;
301 case _RAISE: 340 case _RAISE:
302 rgb_matrix_layer_helper(0xFF, 0xFF, 0x00, LED_FLAG_UNDERGLOW); break; 341 rgb_matrix_layer_helper(HSV_YELLOW, 1, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW);
342 break;
303 case _LOWER: 343 case _LOWER:
304 rgb_matrix_layer_helper(0x00, 0xFF, 0x00, LED_FLAG_UNDERGLOW); break; 344 rgb_matrix_layer_helper(HSV_GREEN, 1, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW);
345 break;
305 case _ADJUST: 346 case _ADJUST:
306 rgb_matrix_layer_helper(0xFF, 0x00, 0x00, LED_FLAG_UNDERGLOW); break; 347 rgb_matrix_layer_helper(HSV_RED, 1, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW);
307 default: 348 break;
349 default: {
350 bool mods_enabled = IS_LAYER_ON(_MODS);
308 switch (biton32(default_layer_state)) { 351 switch (biton32(default_layer_state)) {
309 case _QWERTY: 352 case _QWERTY:
310 rgb_matrix_layer_helper(0x00, 0xFF, 0xFF, LED_FLAG_UNDERGLOW); break; 353 rgb_matrix_layer_helper(HSV_CYAN, mods_enabled, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW);
354 break;
311 case _COLEMAK: 355 case _COLEMAK:
312 rgb_matrix_layer_helper(0xFF, 0x00, 0xFF, LED_FLAG_UNDERGLOW); break; 356 rgb_matrix_layer_helper(HSV_MAGENTA, mods_enabled, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW);
357 break;
313 case _DVORAK: 358 case _DVORAK:
314 rgb_matrix_layer_helper(0x00, 0xFF, 0x00, LED_FLAG_UNDERGLOW); break; 359 rgb_matrix_layer_helper(HSV_SPRINGGREEN, mods_enabled, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW);
360 break;
315 case _WORKMAN: 361 case _WORKMAN:
316 rgb_matrix_layer_helper(0xD9, 0xA5, 0x21, LED_FLAG_UNDERGLOW); break; 362 rgb_matrix_layer_helper(HSV_GOLDENROD, mods_enabled, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW);
363 break;
317 case _NORMAN: 364 case _NORMAN:
318 rgb_matrix_layer_helper(0xFF, 0x7C, 0x4D, LED_FLAG_UNDERGLOW); break; 365 rgb_matrix_layer_helper(HSV_CORAL, mods_enabled, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW);
366 break;
319 case _MALTRON: 367 case _MALTRON:
320 rgb_matrix_layer_helper(0xFF, 0xFF, 0x00, LED_FLAG_UNDERGLOW); break; 368 rgb_matrix_layer_helper(HSV_YELLOW, mods_enabled, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW);
369 break;
321 case _EUCALYN: 370 case _EUCALYN:
322 rgb_matrix_layer_helper(0xFF, 0x80, 0xBF, LED_FLAG_UNDERGLOW); break; 371 rgb_matrix_layer_helper(HSV_PINK, mods_enabled, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW);
372 break;
323 case _CARPLAX: 373 case _CARPLAX:
324 rgb_matrix_layer_helper(0x00, 0x00, 0xFF, LED_FLAG_UNDERGLOW); break; 374 rgb_matrix_layer_helper(HSV_BLUE, mods_enabled, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW);
375 break;
325 } 376 }
377 break;
378 }
326 } 379 }
327 } 380 }
328} 381}