aboutsummaryrefslogtreecommitdiff
path: root/keyboards/crkbd/keymaps/oled_sample/keymap.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/crkbd/keymaps/oled_sample/keymap.c')
-rw-r--r--keyboards/crkbd/keymaps/oled_sample/keymap.c209
1 files changed, 209 insertions, 0 deletions
diff --git a/keyboards/crkbd/keymaps/oled_sample/keymap.c b/keyboards/crkbd/keymaps/oled_sample/keymap.c
new file mode 100644
index 000000000..9daae9607
--- /dev/null
+++ b/keyboards/crkbd/keymaps/oled_sample/keymap.c
@@ -0,0 +1,209 @@
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#include QMK_KEYBOARD_H
20
21
22// Each layer gets a name for readability, which is then used in the keymap matrix below.
23// The underscores don't mean anything - you can have a layer called STUFF or any other name.
24// Layer names don't all need to be of the same length, obviously, and you can also skip them
25// entirely and just use numbers.
26enum crkbd_layers {
27 _QWERTY,
28 _LOWER,
29 _RAISE,
30 _ADJUST,
31};
32
33
34#define RAISE MO(_RAISE)
35#define LOWER MO(_LOWER)
36#define CTLTB CTL_T(KC_TAB)
37#define GUIEI GUI_T(KC_LANG2)
38#define ALTKN ALT_T(KC_LANG1)
39
40const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
41 [_QWERTY] = LAYOUT_split_3x6_3(
42 KC_ESC, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
43 CTLTB, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
44 KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT,
45 GUIEI, LOWER, KC_SPC, KC_ENT, RAISE, ALTKN
46 ),
47
48 [_LOWER] = LAYOUT_split_3x6_3(
49 KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC,
50 CTLTB, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, XXXXXXX,
51 KC_LSFT, KC_F11, KC_F12, KC_F13, KC_F14, KC_F15, KC_F16, KC_F17, KC_F18, KC_F19, KC_F20, XXXXXXX,
52 GUIEI, LOWER, KC_SPC, KC_ENT, RAISE, ALTKN
53 ),
54
55 [_RAISE] = LAYOUT_split_3x6_3(
56 KC_ESC, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC,
57 CTLTB, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_MINS, KC_EQL, KC_LCBR, KC_RCBR, KC_PIPE, KC_GRV,
58 KC_LSFT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_UNDS, KC_PLUS, KC_LBRC, KC_RBRC, KC_BSLS, KC_TILD,
59 GUIEI, LOWER, KC_SPC, KC_ENT, RAISE, ALTKN
60
61 ),
62
63 [_ADJUST] = LAYOUT_split_3x6_3(
64 RESET, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
65 RGB_TOG, RGB_HUI, RGB_SAI, RGB_VAI, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
66 RGB_MOD, RGB_HUD, RGB_SAD, RGB_VAD, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
67 GUIEI, LOWER, KC_SPC, KC_ENT, RAISE, ALTKN
68 )
69};
70
71layer_state_t layer_state_set_user(layer_state_t state) {
72 state = update_tri_layer_state(state, _RAISE, _LOWER, _ADJUST);
73 return state;
74}
75
76
77#ifdef OLED_ENABLE
78oled_rotation_t oled_init_user(oled_rotation_t rotation) {
79 if (is_keyboard_master()) {
80 return OLED_ROTATION_270;
81 } else {
82 return rotation;
83 }
84}
85
86void render_crkbd_logo(void) {
87 static const char PROGMEM crkbd_logo[] = {
88 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94,
89 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4,
90 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4,
91 0};
92 oled_write_P(crkbd_logo, false);
93}
94
95# define KEYLOG_LEN 5
96char keylog_str[KEYLOG_LEN] = {};
97uint8_t keylogs_str_idx = 0;
98uint16_t log_timer = 0;
99
100const char code_to_name[60] = {
101 ' ', ' ', ' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f',
102 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
103 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
104 '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
105 'R', 'E', 'B', 'T', '_', '-', '=', '[', ']', '\\',
106 '#', ';', '\'', '`', ',', '.', '/', ' ', ' ', ' '};
107
108void add_keylog(uint16_t keycode) {
109 if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) {
110 keycode = keycode & 0xFF;
111 }
112
113 for (uint8_t i = KEYLOG_LEN - 1; i > 0; i--) {
114 keylog_str[i] = keylog_str[i - 1];
115 }
116 if (keycode < 60) {
117 keylog_str[0] = code_to_name[keycode];
118 }
119 keylog_str[KEYLOG_LEN - 1] = 0;
120
121 log_timer = timer_read();
122}
123
124void update_log(void) {
125 if (timer_elapsed(log_timer) > 750) {
126 add_keylog(0);
127 }
128}
129
130void render_keylogger_status(void) {
131 oled_write_P(PSTR("KLogr"), false);
132 oled_write(keylog_str, false);
133}
134
135void render_default_layer_state(void) {
136 oled_write_P(PSTR("Lyout"), false);
137 switch (get_highest_layer(default_layer_state)) {
138 case _QWERTY:
139 oled_write_P(PSTR(" QRTY"), false);
140 break;
141 }
142}
143
144void render_layer_state(void) {
145 oled_write_P(PSTR("LAYER"), false);
146 oled_write_P(PSTR("Lower"), layer_state_is(_LOWER));
147 oled_write_P(PSTR("Raise"), layer_state_is(_RAISE));
148}
149
150void render_keylock_status(uint8_t led_usb_state) {
151 oled_write_P(PSTR("Lock:"), false);
152 oled_write_P(PSTR(" "), false);
153 oled_write_P(PSTR("N"), led_usb_state & (1 << USB_LED_NUM_LOCK));
154 oled_write_P(PSTR("C"), led_usb_state & (1 << USB_LED_CAPS_LOCK));
155 oled_write_ln_P(PSTR("S"), led_usb_state & (1 << USB_LED_SCROLL_LOCK));
156}
157
158void render_mod_status(uint8_t modifiers) {
159 oled_write_P(PSTR("Mods:"), false);
160 oled_write_P(PSTR(" "), false);
161 oled_write_P(PSTR("S"), (modifiers & MOD_MASK_SHIFT));
162 oled_write_P(PSTR("C"), (modifiers & MOD_MASK_CTRL));
163 oled_write_P(PSTR("A"), (modifiers & MOD_MASK_ALT));
164 oled_write_P(PSTR("G"), (modifiers & MOD_MASK_GUI));
165}
166
167void render_bootmagic_status(void) {
168 /* Show Ctrl-Gui Swap options */
169 static const char PROGMEM logo[][2][3] = {
170 {{0x97, 0x98, 0}, {0xb7, 0xb8, 0}},
171 {{0x95, 0x96, 0}, {0xb5, 0xb6, 0}},
172 };
173 oled_write_P(PSTR("BTMGK"), false);
174 oled_write_P(PSTR(" "), false);
175 oled_write_P(logo[0][0], !keymap_config.swap_lctl_lgui);
176 oled_write_P(logo[1][0], keymap_config.swap_lctl_lgui);
177 oled_write_P(PSTR(" "), false);
178 oled_write_P(logo[0][1], !keymap_config.swap_lctl_lgui);
179 oled_write_P(logo[1][1], keymap_config.swap_lctl_lgui);
180 oled_write_P(PSTR(" NKRO"), keymap_config.nkro);
181}
182
183void render_status_main(void) {
184 /* Show Keyboard Layout */
185 render_default_layer_state();
186 render_keylock_status(host_keyboard_leds());
187 render_mod_status(get_mods());
188 render_bootmagic_status();
189
190 render_keylogger_status();
191}
192
193bool oled_task_user(void) {
194 update_log();
195 if (is_keyboard_master()) {
196 render_status_main(); // Renders the current keyboard state (layer, lock, caps, scroll, etc)
197 } else {
198 render_crkbd_logo();
199 }
200 return false;
201}
202
203bool process_record_user(uint16_t keycode, keyrecord_t *record) {
204 if (record->event.pressed) {
205 add_keylog(keycode);
206 }
207 return true;
208}
209#endif