1 #include QMK_KEYBOARD_H
2 #include "bootloader.h"
5 #include "split_util.h"
14 extern keymap_config_t keymap_config;
16 #ifdef RGBLIGHT_ENABLE
17 //Following line allows macro to read current RGB settings
18 extern rgblight_config_t rgblight_config;
21 extern uint8_t is_master;
23 // Each layer gets a name for readability, which is then used in the keymap matrix below.
24 // The underscores don't mean anything - you can have a layer called STUFF or any other name.
25 // Layer names don't all need to be of the same length, obviously, and you can also skip them
26 // entirely and just use numbers.
36 enum custom_keycodes {
54 // Fillers to make layering more clear
55 #define _______ KC_TRNS
58 #define M_SAMPLE M(KC_SAMPLEMACRO)
60 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
63 * ,-----------------------------------------. ,-----------------------------------------.
64 * | Tab | Q | W | E | R | T | | Y | U | I | O | P | Bksp |
65 * |------+------+------+------+------+------| |------+------+------+------+------+------|
66 * | Ctrl | A | S | D | F | G | | H | J | K | L | ; | ' |
67 * |------+------+------+------+------+------| |------+------+------+------+------+------|
68 * | Shift| Z | X | C | V | B | | N | M | , | . | / |Enter |
69 * |------+------+------+------+------+------+-------------+------+------+------+------+------+------|
70 * |Adjust| Esc | Alt | GUI | EISU |Lower |Space |Space |Raise | KANA | Left | Down | Up |Right |
71 * `-------------------------------------------------------------------------------------------------'
75 KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC, \
76 KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, \
77 KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT , \
78 ADJUST, KC_ESC, KC_LALT, KC_LGUI, EISU, LOWER, KC_SPC, KC_SPC, RAISE, KANA, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT \
81 * ,-----------------------------------------. ,-----------------------------------------.
82 * | Tab | Q | W | F | P | G | | J | L | U | Y | ; | Bksp |
83 * |------+------+------+------+------+------| |------+------+------+------+------+------|
84 * | Ctrl | A | R | S | T | D | | H | N | E | I | O | ' |
85 * |------+------+------+------+------+------| |------+------+------+------+------+------|
86 * | Shift| Z | X | C | V | B | | K | M | , | . | / |Enter |
87 * |------+------+------+------+------+------+-------------+------+------+------+------+------+------|
88 * |Adjust| Esc | Alt | GUI | EISU |Lower |Space |Space |Raise | KANA | Left | Down | Up |Right |
89 * `-------------------------------------------------------------------------------------------------'
91 [_COLEMAK] = LAYOUT( \
92 KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC, \
93 KC_LCTL, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT, \
94 KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT , \
95 ADJUST, KC_ESC, KC_LALT, KC_LGUI, EISU, LOWER, KC_SPC, KC_SPC, RAISE, KANA, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT \
99 * ,-----------------------------------------. ,-----------------------------------------.
100 * | Tab | ' | , | . | P | Y | | F | G | C | R | L | Bksp |
101 * |------+------+------+------+------+------| |------+------+------+------+------+------|
102 * | Ctrl | A | O | E | U | I | | D | H | T | N | S | / |
103 * |------+------+------+------+------+------| |------+------+------+------+------+------|
104 * | Shift| ; | Q | J | K | X | | B | M | W | V | Z |Enter |
105 * |------+------+------+------+------+------+-------------+------+------+------+------+------+------|
106 * |Adjust| Esc | Alt | GUI | EISU |Lower |Space |Space |Raise | KANA | Left | Down | Up |Right |
107 * `-------------------------------------------------------------------------------------------------'
109 [_DVORAK] = LAYOUT( \
110 KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_BSPC, \
111 KC_LCTL, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH, \
112 KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_ENT , \
113 ADJUST, KC_ESC, KC_LALT, KC_LGUI, EISU, LOWER, KC_SPC, KC_SPC, RAISE, KANA, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT \
117 * ,-----------------------------------------. ,-----------------------------------------.
118 * | ~ | ! | @ | # | $ | % | | ^ | & | * | ( | ) | Del |
119 * |------+------+------+------+------+------| |------+------+------+------+------+------|
120 * | | F1 | F2 | F3 | F4 | F5 | | F6 | _ | + | { | } | | |
121 * |------+------+------+------+------+------| |------+------+------+------+------+------|
122 * | | F7 | F8 | F9 | F10 | F11 | | F12 | | PrSc | Home | End | |
123 * |------+------+------+------+------+------+-------------+------+------+------+------+------+------|
124 * | | | | | | | | | | | Next | Vol- | Vol+ | Play |
125 * `-------------------------------------------------------------------------------------------------'
128 KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_DEL, \
129 _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE, \
130 _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, KC_PSCR, KC_HOME, KC_END, _______, \
131 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY \
135 * ,-----------------------------------------. ,-----------------------------------------.
136 * | ` | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | Del |
137 * |------+------+------+------+------+------| |------+------+------+------+------+------|
138 * | | F1 | F2 | F3 | F4 | F5 | | F6 | - | = | [ | ] | \ |
139 * |------+------+------+------+------+------| |------+------+------+------+------+------|
140 * | | F7 | F8 | F9 | F10 | F11 | | F12 | | PrSc |PageDn|PageUp| |
141 * |------+------+------+------+------+------+-------------+------+------+------+------+------+------|
142 * | | | | | | | | | | | Next | Vol- | Vol+ | Play |
143 * `-------------------------------------------------------------------------------------------------'
146 KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL, \
147 _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS, \
148 _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, KC_PSCR, KC_PGDN, KC_PGUP, _______, \
149 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY \
152 /* Adjust (Lower + Raise)
153 * ,-----------------------------------------. ,-----------------------------------------.
154 * | | Reset| | | | | | | | | | | |
155 * |------+------+------+------+------+------| |------+------+------+------+------+------|
156 * | |Aud on|Audoff|MU TOG|MU MOD| Mac | | Win |Qwerty|Colemk|Dvorak| | |
157 * |------+------+------+------+------+------| |------+------+------+------+------+------|
158 * | |CK TOG|CK RST| CK UP|CK DWN| | | | |RGB ON| HUE+ | SAT+ | VAL+ |
159 * |------+------+------+------+------+------+-------------+------+------+------+------+------+------|
160 * | | | | | | | | | | | MODE | HUE- | SAT- | VAL- |
161 * `-------------------------------------------------------------------------------------------------'
163 [_ADJUST] = LAYOUT( \
164 _______, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
165 _______, AU_ON, AU_OFF, MU_TOG, MU_MOD, AG_NORM, AG_SWAP, QWERTY, COLEMAK, DVORAK, _______, _______, \
166 _______, CK_TOGG, CK_RST, CK_UP, CK_DOWN, _______, _______, _______, RGB_TOG, RGB_HUI, RGB_SAI, RGB_VAI, \
167 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RGB_MOD, RGB_HUD, RGB_SAD, RGB_VAD \
175 float tone_qwerty[][2] = SONG(QWERTY_SOUND);
176 float tone_dvorak[][2] = SONG(DVORAK_SOUND);
177 float tone_colemak[][2] = SONG(COLEMAK_SOUND);
178 float tone_plover[][2] = SONG(PLOVER_SOUND);
179 float tone_plover_gb[][2] = SONG(PLOVER_GOODBYE_SOUND);
180 float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
183 // define variables for reactive RGB
184 bool TOG_STATUS = false;
185 int RGB_current_mode;
187 void persistent_default_layer_set(uint16_t default_layer) {
188 eeconfig_update_default_layer(default_layer);
189 default_layer_set(default_layer);
192 // Setting ADJUST layer RGB back to default
193 void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
194 if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
195 #ifdef RGBLIGHT_ENABLE
196 //rgblight_mode(RGB_current_mode);
204 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
207 if (record->event.pressed) {
209 PLAY_SONG(tone_qwerty);
211 persistent_default_layer_set(1UL<<_QWERTY);
216 if (record->event.pressed) {
218 PLAY_SONG(tone_colemak);
220 persistent_default_layer_set(1UL<<_COLEMAK);
225 if (record->event.pressed) {
227 PLAY_SONG(tone_dvorak);
229 persistent_default_layer_set(1UL<<_DVORAK);
234 if (record->event.pressed) {
235 //not sure how to have keyboard check mode and set it to a variable, so my work around
236 //uses another variable that would be set to true after the first time a reactive key is pressed.
237 if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
239 TOG_STATUS = !TOG_STATUS;
240 #ifdef RGBLIGHT_ENABLE
241 //rgblight_mode(RGBLIGHT_MODE_SNAKE + 1);
245 update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
247 #ifdef RGBLIGHT_ENABLE
248 //rgblight_mode(RGB_current_mode); // revert RGB to initial mode prior to RGB mode change
252 update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
257 if (record->event.pressed) {
258 //not sure how to have keyboard check mode and set it to a variable, so my work around
259 //uses another variable that would be set to true after the first time a reactive key is pressed.
260 if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
262 TOG_STATUS = !TOG_STATUS;
263 #ifdef RGBLIGHT_ENABLE
264 //rgblight_mode(RGBLIGHT_MODE_SNAKE);
268 update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
270 #ifdef RGBLIGHT_ENABLE
271 //rgblight_mode(RGB_current_mode); // revert RGB to initial mode prior to RGB mode change
275 update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
280 if (record->event.pressed) {
287 //led operations - RGB mode change now updates the RGB_current_mode to allow the right RGB mode to be set after reactive keys are released
289 #ifdef RGBLIGHT_ENABLE
290 if (record->event.pressed) {
291 rgblight_mode(RGB_current_mode);
293 RGB_current_mode = rgblight_config.mode;
299 if (record->event.pressed) {
300 if(keymap_config.swap_lalt_lgui==false){
301 register_code(KC_LANG2);
303 SEND_STRING(SS_LALT("`"));
306 unregister_code(KC_LANG2);
311 if (record->event.pressed) {
312 if(keymap_config.swap_lalt_lgui==false){
313 register_code(KC_LANG1);
315 SEND_STRING(SS_LALT("`"));
318 unregister_code(KC_LANG1);
323 #ifdef RGBLIGHT_ENABLE
324 if (record->event.pressed) {
325 eeconfig_update_rgblight_default();
327 RGB_current_mode = rgblight_config.mode;
335 void matrix_init_user(void) {
339 #ifdef RGBLIGHT_ENABLE
340 RGB_current_mode = rgblight_config.mode;
342 //SSD1306 OLED init, make sure to add #define SSD1306OLED in config.h
344 iota_gfx_init(!has_usb()); // turns on the display
353 _delay_ms(50); // gets rid of tick
362 void music_on_user(void)
367 void music_scale_user(void)
369 PLAY_SONG(music_scale);
375 //SSD1306 OLED update loop, make sure to add #define SSD1306OLED in config.h
378 void matrix_scan_user(void) {
379 iota_gfx_task(); // this is what updates the display continuously
382 void matrix_update(struct CharacterMatrix *dest,
383 const struct CharacterMatrix *source) {
384 if (memcmp(dest->display, source->display, sizeof(dest->display))) {
385 memcpy(dest->display, source->display, sizeof(dest->display));
390 //assign the right code to your layers for OLED display
392 #define L_LOWER (1<<_LOWER)
393 #define L_RAISE (1<<_RAISE)
394 #define L_ADJUST (1<<_ADJUST)
395 #define L_ADJUST_TRI (L_ADJUST|L_RAISE|L_LOWER)
397 static void render_logo(struct CharacterMatrix *matrix) {
400 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,
401 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,
402 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,
404 matrix_write(matrix, logo);
405 //matrix_write_P(&matrix, PSTR(" Split keyboard kit"));
410 void render_status(struct CharacterMatrix *matrix) {
412 // Render to mode icon
413 static char logo[][2][3]={{{0x95,0x96,0},{0xb5,0xb6,0}},{{0x97,0x98,0},{0xb7,0xb8,0}}};
414 if(keymap_config.swap_lalt_lgui==false){
415 matrix_write(matrix, logo[0][0]);
416 matrix_write_P(matrix, PSTR("\n"));
417 matrix_write(matrix, logo[0][1]);
419 matrix_write(matrix, logo[1][0]);
420 matrix_write_P(matrix, PSTR("\n"));
421 matrix_write(matrix, logo[1][1]);
424 // Define layers here, Have not worked out how to have text displayed for each layer. Copy down the number you see and add a case for it below
426 snprintf(buf,sizeof(buf), "Undef-%ld", layer_state);
427 matrix_write_P(matrix, PSTR("\nLayer: "));
428 switch (layer_state) {
430 matrix_write_P(matrix, PSTR("Default"));
433 matrix_write_P(matrix, PSTR("Raise"));
436 matrix_write_P(matrix, PSTR("Lower"));
440 matrix_write_P(matrix, PSTR("Adjust"));
443 matrix_write(matrix, buf);
446 // Host Keyboard LED Status
448 snprintf(led, sizeof(led), "\n%s %s %s",
449 (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) ? "NUMLOCK" : " ",
450 (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) ? "CAPS" : " ",
451 (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) ? "SCLK" : " ");
452 matrix_write(matrix, led);
456 void iota_gfx_task_user(void) {
457 struct CharacterMatrix matrix;
465 matrix_clear(&matrix);
467 render_status(&matrix);
469 render_logo(&matrix);
471 matrix_update(&display, &matrix);