configs/corne_keymap.c
corne_keymap.cRaw
1/*
2Copyright 2019 @foostan
3Copyright 2020 Drashna Jaelre <@drashna>
4
5This program is free software: you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation, either version 2 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19// INSTRUCTIONS
20// install qmk: python3 -m pip install --user qmk (https://docs.qmk.fm/#/newbs_getting_started)
21// clone repo https://github.com/qmk/qmk_firmware into ~/qmk_firmware
22// copy this file into ~/qmk_firmware/keyboards/crkbd/keymaps/default/keymap.c
23// copy qmk.ini into ~/
24//
25// compile the keymap:
26// > qmk compile -kb crkbd -km default
27//
28// once keyboard connected, execute:
29// > qmk flash
30//
31// or if previous doesn't work, use:
32// > qmk flash -kb crkbd -km default
33//
34// and lately it needs the '-bl dfu' too:
35// > qmk flash -bl dfu -kb crkbd -km default
36//
37// If the right side does not work or acts as it were the left side, in
38// keyboards/crkbd/keymaps/default/config.h add:
39// #define SPLIT_USB_DETECT
40
41#include QMK_KEYBOARD_H
42
43const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
44 [0] = LAYOUT_split_3x6_3(
45 //,-----------------------------------------------------. ,-----------------------------------------------------.
46 KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
47 //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
48 KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
49 //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
50 KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT,
51 //|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
52 KC_LGUI, MO(1), KC_SPC, KC_ENT, MO(2), KC_RALT
53 //`--------------------------' `--------------------------'
54
55 ),
56
57 [1] = LAYOUT_split_3x6_3(
58 //,-----------------------------------------------------. ,-----------------------------------------------------.
59 KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL,
60 //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
61 KC_LCTL,KC_MUTE,KC_VOLD,KC_VOLU, XXXXXXX, XXXXXXX, KC_LEFT, KC_DOWN, KC_UP,KC_RIGHT, XXXXXXX, XXXXXXX,
62 //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
63 KC_LSFT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
64 //|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
65 KC_LGUI, _______, KC_SPC, KC_ENT, MO(3), KC_RALT
66 //`--------------------------' `--------------------------'
67 ),
68
69 [2] = LAYOUT_split_3x6_3(
70 //,-----------------------------------------------------. ,-----------------------------------------------------.
71 KC_ESC, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_DEL,
72 //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
73 KC_LCTL, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS, KC_GRV,
74 //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
75 KC_LSFT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE, KC_TILD,
76 //|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
77 KC_LGUI, MO(3), KC_SPC, KC_ENT, _______, KC_RALT
78 //`--------------------------' `--------------------------'
79 ),
80
81 [3] = LAYOUT_split_3x6_3(
82 //,-----------------------------------------------------. ,-----------------------------------------------------.
83 QK_RBT, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11,
84 //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
85 RGB_TOG, RGB_HUI, RGB_SAI, RGB_VAI, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_F12,
86 //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
87 RGB_MOD, RGB_HUD, RGB_SAD, RGB_VAD, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
88 //|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
89 KC_LGUI, _______, KC_SPC, KC_ENT, _______, KC_RALT
90 //`--------------------------' `--------------------------'
91 )
92};
93
94#ifdef OLED_DRIVER_ENABLE
95oled_rotation_t oled_init_user(oled_rotation_t rotation) {
96 if (!is_master) {
97 return OLED_ROTATION_180; // flips the display 180 degrees if offhand
98 }
99 return rotation;
100}
101
102#define L_BASE 0
103#define L_LOWER 2
104#define L_RAISE 4
105#define L_ADJUST 8
106
107void oled_render_layer_state(void) {
108 oled_write_P(PSTR("Layer: "), false);
109 switch (layer_state) {
110 case L_BASE:
111 oled_write_ln_P(PSTR("Default"), false);
112 break;
113 case L_LOWER:
114 oled_write_ln_P(PSTR("Lower"), false);
115 break;
116 case L_RAISE:
117 oled_write_ln_P(PSTR("Raise"), false);
118 break;
119 case L_ADJUST:
120 case L_ADJUST|L_LOWER:
121 case L_ADJUST|L_RAISE:
122 case L_ADJUST|L_LOWER|L_RAISE:
123 oled_write_ln_P(PSTR("Adjust"), false);
124 break;
125 }
126}
127
128
129char keylog_str[24] = {};
130
131const char code_to_name[60] = {
132 ' ', ' ', ' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f',
133 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
134 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
135 '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
136 'R', 'E', 'B', 'T', '_', '-', '=', '[', ']', '\\',
137 '#', ';', '\'', '`', ',', '.', '/', ' ', ' ', ' '};
138
139void set_keylog(uint16_t keycode, keyrecord_t *record) {
140 char name = ' ';
141 if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) ||
142 (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) { keycode = keycode & 0xFF; }
143 if (keycode < 60) {
144 name = code_to_name[keycode];
145 }
146
147 // update keylog
148 snprintf(keylog_str, sizeof(keylog_str), "%dx%d, k%2d : %c",
149 record->event.key.row, record->event.key.col,
150 keycode, name);
151}
152
153void oled_render_keylog(void) {
154 oled_write(keylog_str, false);
155}
156
157void render_bootmagic_status(bool status) {
158 /* Show Ctrl-Gui Swap options */
159 static const char PROGMEM logo[][2][3] = {
160 {{0x97, 0x98, 0}, {0xb7, 0xb8, 0}},
161 {{0x95, 0x96, 0}, {0xb5, 0xb6, 0}},
162 };
163 if (status) {
164 oled_write_ln_P(logo[0][0], false);
165 oled_write_ln_P(logo[0][1], false);
166 } else {
167 oled_write_ln_P(logo[1][0], false);
168 oled_write_ln_P(logo[1][1], false);
169 }
170}
171
172void oled_render_logo(void) {
173 static const char PROGMEM crkbd_logo[] = {
174 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94,
175 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4,
176 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4,
177 0};
178 oled_write_P(crkbd_logo, false);
179}
180
181void oled_task_user(void) {
182 if (is_master) {
183 oled_render_layer_state();
184 oled_render_keylog();
185 } else {
186 oled_render_logo();
187 }
188}
189
190bool process_record_user(uint16_t keycode, keyrecord_t *record) {
191 if (record->event.pressed) {
192 set_keylog(keycode, record);
193 }
194 return true;
195}
196#endif // OLED_DRIVER_ENABLE