/* Copyright 2019 @foostan Copyright 2020 Drashna Jaelre <@drashna> This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include QMK_KEYBOARD_H #include "oneshot.h" enum tap_dance{ GUI_ALT }; qk_tap_dance_action_t tap_dance_actions[] = { [GUI_ALT] = ACTION_TAP_DANCE_DOUBLE(KC_LGUI, KC_LALT) }; enum keycodes { DL_COLE = SAFE_RANGE, DL_QWER, DL_GAME, OS_GUI, OS_CTRL, OS_ALT, OS_SHFT, }; enum layers { COLE, QWER, G0, G1, L1, L2, L3, }; const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [COLE] = LAYOUT_split_3x6_3( //,-----------------------------------------------------. ,-----------------------------------------------------. KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC, //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------| KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT, //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------| KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, //|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------| KC_LGUI, LCTL_T(KC_ENT), MO(L1), MO(L2), KC_SPC, KC_RGUI //`--------------------------' `--------------------------' ), [QWER] = LAYOUT_split_3x6_3( //,-----------------------------------------------------. ,-----------------------------------------------------. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC, //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------| KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------| KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, //|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------| KC_LGUI, LCTL_T(KC_ENT), MO(L1), MO(L2), KC_SPC, KC_RGUI //`--------------------------' `--------------------------' ), /* * Gaming Layers */ [G0] = LAYOUT_split_3x6_3( //,-----------------------------------------------------. ,-----------------------------------------------------. KC_TAB, KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC, //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------| KC_ESC, KC_LCTL, KC_A, KC_R, KC_S, KC_T, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT, //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------| KC_LSFT, KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, //|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------| KC_LGUI, KC_SPC, MO(G1), MO(L2), KC_SPC, KC_RGUI //`--------------------------' `--------------------------' ), [G1] = LAYOUT_split_3x6_3( //,-----------------------------------------------------. ,-----------------------------------------------------. _______, KC_0, KC_1, _______, KC_2, KC_3, _______, _______, _______, _______, _______, _______, //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------| KC_ESC, _______, _______, _______, _______, KC_4, _______, _______, _______, _______, _______, _______, //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------| _______, _______, _______, _______, _______, KC_5, _______, _______, _______, _______, _______, _______, //|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------| _______, _______, _______, MO(L3), _______, _______ //`--------------------------' `--------------------------' ), /* * Symbol layer. */ [L1] = LAYOUT_split_3x6_3( //,-----------------------------------------------------. ,-----------------------------------------------------. KC_ESC, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_GRV, KC_TILD, _______, //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------| _______, KC_UNDS, KC_LBRC, KC_LCBR, KC_LPRN,KC_MINUS, KC_PLUS, KC_RPRN, KC_RCBR, KC_RBRC, KC_EQL, KC_DEL, //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------| _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_PIPE, KC_BSLS, _______, //|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------| _______, _______, _______, MO(L3), OS_CTRL, OS_ALT //`--------------------------' `--------------------------' ), /* * Navigation layer. */ [L2] = LAYOUT_split_3x6_3( //,-----------------------------------------------------. ,-----------------------------------------------------. _______, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, _______, //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------| _______, KC_CAPS, KC_HOME, KC_PGUP, KC_PGDN, KC_END, KC_LEFT, KC_DOWN, KC_UP,KC_RIGHT, XXXXXXX, KC_DEL, //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------| _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_INS, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, _______, //|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------| OS_ALT, OS_CTRL, MO(L3), _______, _______, _______ //`--------------------------' `--------------------------' ), [L3] = LAYOUT_split_3x6_3( //,-----------------------------------------------------. ,-----------------------------------------------------. RESET, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, XXXXXXX, //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------| XXXXXXX, DL_COLE, DL_QWER, DL_GAME, XXXXXXX, KC_F11, KC_F12, KC_PSCR, KC_SLCK, KC_PAUS, XXXXXXX, XXXXXXX, //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------| XXXXXXX, XXXXXXX, OS_CTRL, OS_ALT, OS_SHFT, XXXXXXX, XXXXXXX, OS_SHFT, OS_ALT, OS_CTRL, XXXXXXX, XXXXXXX, //|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------| _______, _______, _______, _______, _______, _______ //`--------------------------' `--------------------------' ) }; // Callum's one shot functionality bool is_oneshot_cancel_key(uint16_t keycode) { switch (keycode) { case KC_ESC : return true; default: return false; } } bool is_oneshot_ignored_key(uint16_t keycode) { switch (keycode) { case MO(L1): case MO(L2): case KC_LSFT: case KC_RSFT: case OS_SHFT: case OS_CTRL: case OS_ALT: case OS_GUI: return true; default: return false; } } // one shot states oneshot_state os_shft_state = os_up_unqueued; oneshot_state os_ctrl_state = os_up_unqueued; oneshot_state os_alt_state = os_up_unqueued; oneshot_state os_cmd_state = os_up_unqueued; // function prototype void set_keylog(uint16_t keycode, keyrecord_t *record); bool process_record_user(uint16_t keycode, keyrecord_t *record) { update_oneshot( &os_shft_state, KC_LSFT, OS_SHFT, keycode, record ); update_oneshot( &os_ctrl_state, KC_LCTL, OS_CTRL, keycode, record ); update_oneshot( &os_alt_state, KC_LALT, OS_ALT, keycode, record ); update_oneshot( &os_cmd_state, KC_LGUI, OS_GUI, keycode, record ); switch (keycode) { case DL_COLE: if (record->event.pressed) { set_single_persistent_default_layer(COLE); } return false; break; case DL_QWER: if (record->event.pressed) { set_single_persistent_default_layer(QWER); } return false; break; case DL_GAME: if (record->event.pressed) { set_single_persistent_default_layer(G0); } return false; break; default: if (record->event.pressed) { set_keylog(keycode, record); // This is calles a stub unless OLED_DRIVER_ENABLE is true } return true; } } #ifdef OLED_DRIVER_ENABLE oled_rotation_t oled_init_user(oled_rotation_t rotation) { if (!is_master) { return OLED_ROTATION_180; // flips the display 180 degrees if offhand } return rotation; } #define L_BASE 0 #define L_LOWER 2 #define L_RAISE 4 #define L_ADJUST 8 void oled_render_layer_state(void) { oled_write_P(PSTR("Layer: "), false); switch (layer_state) { case L_BASE: oled_write_ln_P(PSTR("Default"), false); break; case L_LOWER: oled_write_ln_P(PSTR("Lower"), false); break; case L_RAISE: oled_write_ln_P(PSTR("Raise"), false); break; case L_ADJUST: case L_ADJUST|L_LOWER: case L_ADJUST|L_RAISE: case L_ADJUST|L_LOWER|L_RAISE: oled_write_ln_P(PSTR("Adjust"), false); break; } } char keylog_str[24] = {}; const 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', '_', '-', '=', '[', ']', '\\', '#', ';', '\'', '`', ',', '.', '/', ' ', ' ', ' '}; void set_keylog(uint16_t keycode, keyrecord_t *record) { char name = ' '; if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) { keycode = keycode & 0xFF; } if (keycode < 60) { name = code_to_name[keycode]; } // update keylog snprintf(keylog_str, sizeof(keylog_str), "%dx%d, k%2d : %c", record->event.key.row, record->event.key.col, keycode, name); } void oled_render_keylog(void) { oled_write(keylog_str, false); } void render_bootmagic_status(bool status) { /* Show Ctrl-Gui Swap options */ static const char PROGMEM logo[][2][3] = { {{0x97, 0x98, 0}, {0xb7, 0xb8, 0}}, {{0x95, 0x96, 0}, {0xb5, 0xb6, 0}}, }; if (status) { oled_write_ln_P(logo[0][0], false); oled_write_ln_P(logo[0][1], false); } else { oled_write_ln_P(logo[1][0], false); oled_write_ln_P(logo[1][1], false); } } void oled_render_logo(void) { static const char PROGMEM crkbd_logo[] = { 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0}; oled_write_P(crkbd_logo, false); } void oled_task_user(void) { if (is_master) { oled_render_layer_state(); oled_render_keylog(); } else { oled_render_logo(); } } #else // stub so process_record_user() works without enabling OLED_DRIVER_ENABLE void set_keylog(uint16_t keycode, keyrecord_t *record) { return; } #endif // OLED_DRIVER_ENABLE