2 #include "bootloader.h"
3 #include "action_layer.h"
7 #include "split_util.h"
9 #include "LUFA/Drivers/Peripheral/TWI.h"
17 // * If you want to recognize that you pressed the Adjust key with the Lower / Raise key you can enable this comment out. However, the binary size may be over. *
18 // #define ADJUST_MACRO_ENABLE
20 // * If you want to use the Kana key you can enable this comment out. However, the binary size may be over. *
21 // #define KANA_ENABLE
23 extern keymap_config_t keymap_config;
25 #ifdef RGBLIGHT_ENABLE
26 //Following line allows macro to read current RGB settings
27 extern rgblight_config_t rgblight_config;
30 extern uint8_t is_master;
32 // Each layer gets a name for readability, which is then used in the keymap matrix below.
33 // The underscores don't mean anything - you can have a layer called STUFF or any other name.
34 // Layer names don't all need to be of the same length, obviously, and you can also skip them
35 // entirely and just use numbers.
46 enum custom_keycodes {
62 #define JP_CFTD KC_EQL // ^ and ~ Circumflex (Hat) and Tilde
63 #define JP_ATBQ KC_LBRC // @ and ` Atmark and Back-quote
64 #define JP_CLAS KC_QUOT // : and * Colon and Asterisk
65 #define JP_BSVL KC_JYEN // \ and | Back slash and and Vertical-line)
66 #define JP_LBRC KC_RBRC // [ and { Left-bracket
67 #define JP_RBRC KC_BSLS // ] and } Right-bracket
68 #define JP_BSUS KC_RO // \ and _ Back slash and Under-score
70 // Fillers to make layering more clear
71 #define _______ KC_TRNS
75 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
77 * ,-----------------------------------------. ,-----------------------------------------.
78 * | Esc | 1! | 2" | 3# | 4$ | 5% | | 6& | 7' | 8( | 9) | 0 | -= |
79 * |------+------+------+------+------+------| |------+------+------+------+------+------|
80 * | KANJI| Q | W | E | R | T | | Y | U | I | O | P | @` |
81 * |------+------+------+------+------+------| |------+------+------+------+------+------|
82 * | Tab | A | S | D | F | G | | H | J | K | L | ;+ | :* |
83 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
84 * | Shift| Z | X | C | V | B | N | B | N | M | ,< | .> | Up |Enter |
85 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
86 * | Ctrl | GUI | Alt |Adjust|Lower |Space |Bksp |Space |Space |Raise | APP | Left | Down |Right |
87 * `-------------------------------------------------------------------------------------------------'
90 KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, \
91 EISU, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, JP_ATBQ, \
92 KC_TAB, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, JP_CLAS, \
93 KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_UP, KC_ENT, \
94 KC_LCTL, KC_LALT, KC_LGUI, ADJUST, LOWER, KC_SPC, KC_BSPC, KC_SPC, KC_SPC, RAISE, KC_APP, KC_LEFT, KC_DOWN, KC_RGHT \
97 /* Qwerty JIS Exchange L and R
98 * ,-----------------------------------------. ,-----------------------------------------.
99 * | 6& | 7' | 8( | 9) | 0 | -= | | Esc | 1! | 2" | 3# | 4$ | 5% |
100 * |------+------+------+------+------+------| |------+------+------+------+------+------|
101 * | Y | U | I | O | P | @` | | Tab | Q | W | E | R | T |
102 * |------+------+------+------+------+------| |------+------+------+------+------+------|
103 * | H | J | K | L | ;+ | :* | | | A | S | D | F | G |
104 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
105 * | N | M | ,< | .> | /? | Up |Enter |KANJI | Shift| Z | X | C | V | B |
106 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
107 * |Space |Raise | }] | APP | Left | Down |Right |Adjust| Ctrl | GUI | Alt | [{ |Lower | Bksp |
108 * `-------------------------------------------------------------------------------------------------'
111 KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, \
112 KC_Y, KC_U, KC_I, KC_O, KC_P, JP_ATBQ, KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, \
113 KC_H, KC_J, KC_K, KC_L, KC_SCLN, JP_CLAS, XXXXXXX, KC_A, KC_S, KC_D, KC_F, KC_G, \
114 KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_UP, KC_ENT, EISU, KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, \
115 KC_SPC, RAI_E, JP_RBRC, KC_APP, KC_LEFT, KC_DOWN, KC_RGHT, ADJUST, KC_LCTL, KC_LALT, KC_LGUI, JP_LBRC, LOW_E, KC_BSPC \
119 * ,-----------------------------------------. ,-----------------------------------------.
120 * | | | | | | | | | | | -= | ^~ | \| |
121 * |------+------+------+------+------+------| |------+------+------+------+------+------|
122 * | | | | | | | | | | | | @` | [{ |
123 * |------+------+------+------+------+------| |------+------+------+------+------+------|
124 * | | | | | | | | | | | ;+ | :* | ]} |
125 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
126 * | | | | | | | | | | | ,< | .> | /? | \_ |
127 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
128 * | | | | | | | Del | | | | | | | |
129 * `-------------------------------------------------------------------------------------------------'
132 _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_MINS, JP_CFTD, JP_BSVL, \
133 _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, JP_ATBQ, JP_LBRC, \
134 _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_SCLN, JP_CLAS, JP_RBRC, \
135 _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_COMM, KC_DOT, KC_SLSH, JP_BSUS, \
136 _______, _______, _______, _______, XXXXXXX, XXXXXXX, KC_DEL, _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX \
139 /* Lower JIS Exchange L and R
140 * ,-----------------------------------------. ,-----------------------------------------.
141 * | | | | -= | ^~ | \| | | | | | | | |
142 * |------+------+------+------+------+------| |------+------+------+------+------+------|
143 * | | | | | @` | [{ | | | | | | | |
144 * |------+------+------+------+------+------| |------+------+------+------+------+------|
145 * | | | | ;+ | :* | ]} | | | | | | | |
146 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
147 * | | ,< | .> | /? | \_ |PageUp| | | | | | | | |
148 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
149 * | | | | | Home |PageDn| End | | | | | | | Del |
150 * `-------------------------------------------------------------------------------------------------'
153 _______, XXXXXXX, XXXXXXX, KC_MINS, JP_CFTD, JP_BSVL, _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, \
154 _______, XXXXXXX, XXXXXXX, XXXXXXX, JP_ATBQ, JP_LBRC, _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, \
155 _______, XXXXXXX, XXXXXXX, KC_SCLN, JP_CLAS, JP_RBRC, _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, \
156 _______, KC_COMM, KC_DOT, KC_SLSH, JP_BSUS, KC_PGUP, XXXXXXX, XXXXXXX, _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, \
157 _______, _______, XXXXXXX, _______, KC_HOME, KC_PGDN, KC_END, _______, _______, _______, _______, XXXXXXX, _______, KC_DEL \
161 * ,-----------------------------------------. ,-----------------------------------------.
162 * | F1 | F2 | F3 | F4 | F5 | F6 | | F7 | F8 | F9 | F10 | F11 | F12 |
163 * |------+------+------+------+------+------| |------+------+------+------+------+------|
164 * | | | | | | | | | | | | Home |PageUp|
165 * |------+------+------+------+------+------| |------+------+------+------+------+------|
166 * | | | | | | | | | | | | End |PageDn|
167 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
168 * | |MsBtn1|MsBtn2| | | | | | | | | | MsUp | |
169 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
170 * | | | | | | | | | | | |MsLeft|MsDown|MsRght|
171 * `-------------------------------------------------------------------------------------------------'
174 KC_F1 , KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, \
175 _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_HOME, KC_PGUP, \
176 _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_END, KC_PGDN, \
177 _______, KC_BTN1, KC_BTN2, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_MS_U, XXXXXXX, \
178 _______, _______, _______, _______, XXXXXXX, XXXXXXX, _______, _______, XXXXXXX, XXXXXXX, XXXXXXX, KC_MS_L, KC_MS_D, KC_MS_R \
181 /* Raise JIS Exchange L and R
182 * ,-----------------------------------------. ,-----------------------------------------.
183 * | F7 | F8 | F9 | F10 | F11 | F12 | | F1 | F2 | F3 | F4 | F5 | F6 |
184 * |------+------+------+------+------+------| |------+------+------+------+------+------|
185 * | | | | | | | | | | | | | |
186 * |------+------+------+------+------+------| |------+------+------+------+------+------|
187 * | | | | | | | | | | | | | |
188 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
189 * | | | | | | MsUp | | | |MsBtn1|MsBtn2| | | |
190 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
191 * | | | | |MsLeft|MsDown|MsRght| | | | | | | |
192 * `-------------------------------------------------------------------------------------------------'
195 KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_F1 , KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, \
196 XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, \
197 XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, \
198 XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_MS_U, XXXXXXX, XXXXXXX, _______, KC_BTN1, KC_BTN2, XXXXXXX, XXXXXXX, XXXXXXX, \
199 _______, _______, XXXXXXX, _______, KC_MS_L, KC_MS_D, KC_MS_R, _______, _______, _______, _______, XXXXXXX, _______, XXXXXXX \
202 /* Adjust (Lower + Raise) Common map for Normal and Exchange
203 * ,-----------------------------------------. ,-----------------------------------------.
204 * | | Reset|RGBRST|Aud on|Audoff| | | | Reset|RGBRST|Aud on|Audoff| |
205 * |------+------+------+------+------+------| |------+------+------+------+------+------|
206 * | |ModNrm|ModExc| Mac | Win | | | |ModNrm|ModExc| Mac | Win | |
207 * |------+------+------+------+------+------| |------+------+------+------+------|------+
208 * | |RGB ON| HUE+ | SAT+ | VAL+ | | | |RGB ON| HUE+ | SAT+ | VAL+ | |
209 * |------+------+------+------+------+------+------+------+------+------+------+------+------|------+
210 * | | MODE | HUE- | SAT- | VAL- | | | | | MODE | HUE- | SAT- | VAL- | |
211 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
212 * | | | | | | | | | | | | | | |
213 * `-------------------------------------------------------------------------------------------------'
215 [_ADJUST] = LAYOUT( \
216 XXXXXXX, RESET, RGBRST, AU_ON, AU_OFF, XXXXXXX, XXXXXXX, RESET, RGBRST, AU_ON, AU_OFF, XXXXXXX, \
217 XXXXXXX, BASE, BAS_E, AG_NORM, AG_SWAP, XXXXXXX, XXXXXXX, BASE, BAS_E, AG_NORM, AG_SWAP, XXXXXXX, \
218 XXXXXXX, RGB_TOG, RGB_HUI, RGB_SAI, RGB_VAI, XXXXXXX, XXXXXXX, RGB_TOG, RGB_HUI, RGB_SAI, RGB_VAI, XXXXXXX, \
219 XXXXXXX, RGB_SMOD,RGB_HUD, RGB_SAD, RGB_VAD, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, RGB_SMOD,RGB_HUD, RGB_SAD, RGB_VAD, XXXXXXX, \
220 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ \
224 #elif HELIX_ROWS == 4
226 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
231 #error "undefined keymaps"
236 float tone_qwerty[][2] = SONG(QWERTY_SOUND);
237 float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
240 // define variables for reactive RGB
241 bool TOG_STATUS = false;
242 int RGB_current_mode;
244 void persistent_default_layer_set(uint16_t default_layer) {
245 eeconfig_update_default_layer(default_layer);
246 default_layer_set(default_layer);
249 #ifdef ADJUST_MACRO_ENABLE
250 // Setting ADJUST layer RGB back to default
251 void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
252 if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
253 #ifdef RGBLIGHT_ENABLE
254 rgblight_mode(RGB_current_mode);
263 void toggle_lower_raise_layer(bool pressed, uint16_t dist_layer, uint16_t lower_layer, uint16_t raise_layer) {
265 //not sure how to have keyboard check mode and set it to a variable, so my work around
266 //uses another variable that would be set to true after the first time a reactive key is pressed.
267 if (!TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
268 TOG_STATUS = !TOG_STATUS;
269 #ifdef RGBLIGHT_ENABLE
270 if (dist_layer == _LOWER || dist_layer == _LOW_E) {
278 layer_on(dist_layer);
279 #ifdef ADJUST_MACRO_ENABLE
280 update_tri_layer_RGB(lower_layer, raise_layer, _ADJUST);
283 #ifdef RGBLIGHT_ENABLE
284 rgblight_mode(RGB_current_mode); // revert RGB to initial mode prior to RGB mode change
287 layer_off(dist_layer);
288 #ifdef ADJUST_MACRO_ENABLE
289 update_tri_layer_RGB(lower_layer, raise_layer, _ADJUST);
294 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
297 if (record->event.pressed) {
299 PLAY_SONG(tone_qwerty);
301 persistent_default_layer_set(1UL<<_BASE);
306 if (record->event.pressed) {
308 PLAY_SONG(tone_qwerty);
310 persistent_default_layer_set(1UL<<_BAS_E);
315 toggle_lower_raise_layer(record->event.pressed, _LOWER, _LOWER, _RAISE);
319 toggle_lower_raise_layer(record->event.pressed, _LOW_E, _LOW_E, _RAI_E);
323 toggle_lower_raise_layer(record->event.pressed, _RAISE, _LOWER, _RAISE);
327 toggle_lower_raise_layer(record->event.pressed, _RAI_E, _LOW_E, _RAI_E);
331 if (record->event.pressed) {
332 #ifdef RGBLIGHT_ENABLE
337 #ifdef RGBLIGHT_ENABLE
338 rgblight_mode(RGB_current_mode);
344 //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
346 #ifdef RGBLIGHT_ENABLE
347 if (record->event.pressed) {
348 rgblight_mode(RGB_current_mode);
350 RGB_current_mode = rgblight_config.mode;
356 if (record->event.pressed) {
357 if (keymap_config.swap_lalt_lgui==false) {
358 register_code(KC_LANG2);
360 SEND_STRING(SS_LALT("`"));
363 unregister_code(KC_LANG2);
369 if (record->event.pressed) {
370 if(keymap_config.swap_lalt_lgui==false){
371 register_code(KC_LANG1);
373 SEND_STRING(SS_LALT("`"));
376 unregister_code(KC_LANG1);
382 #ifdef RGBLIGHT_ENABLE
383 if (record->event.pressed) {
384 eeconfig_update_rgblight_default();
386 RGB_current_mode = rgblight_config.mode;
393 // return process_layer_control(keycode, record, false) ? process_layer_control(keycode, record, true) : true;
396 void matrix_init_user(void) {
400 #ifdef RGBLIGHT_ENABLE
401 RGB_current_mode = rgblight_config.mode;
403 //SSD1306 OLED init, make sure to add #define SSD1306OLED in config.h
405 TWI_Init(TWI_BIT_PRESCALE_1, TWI_BITLENGTH_FROM_FREQ(1, 800000));
406 iota_gfx_init(!has_usb()); // turns on the display
415 _delay_ms(20); // gets rid of tick
424 void music_on_user(void)
429 void music_scale_user(void)
431 PLAY_SONG(music_scale);
437 //SSD1306 OLED update loop, make sure to add #define SSD1306OLED in config.h
440 void matrix_scan_user(void) {
441 iota_gfx_task(); // this is what updates the display continuously
444 void matrix_update(struct CharacterMatrix *dest,
445 const struct CharacterMatrix *source) {
446 if (memcmp(dest->display, source->display, sizeof(dest->display))) {
447 memcpy(dest->display, source->display, sizeof(dest->display));
452 //assign the right code to your layers for OLED display
454 #define L_LOWER (1<<_LOWER)
455 #define L_RAISE (1<<_RAISE)
456 #define L_ADJUST (1<<_ADJUST)
457 #define L_ADJUST_TRI (L_ADJUST|L_RAISE|L_LOWER)
458 #define L_LOW_E (1<<_LOW_E)
459 #define L_RAI_E (1<<_RAI_E)
460 #define L_ADJUST_TRIE (L_ADJUST|L_RAI_E|L_LOW_E)
462 static void render_logo(struct CharacterMatrix *matrix) {
465 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,
466 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,
467 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,
469 matrix_write(matrix, logo);
470 //matrix_write_P(&matrix, PSTR(" Split keyboard kit"));
475 void render_status(struct CharacterMatrix *matrix) {
477 // Render to mode icon
478 static char logo[][2][3]={{{0x95,0x96,0},{0xb5,0xb6,0}},{{0x97,0x98,0},{0xb7,0xb8,0}}};
479 if(keymap_config.swap_lalt_lgui==false){
480 matrix_write(matrix, logo[0][0]);
481 matrix_write_P(matrix, PSTR("\n"));
482 matrix_write(matrix, logo[0][1]);
484 matrix_write(matrix, logo[1][0]);
485 matrix_write_P(matrix, PSTR("\n"));
486 matrix_write(matrix, logo[1][1]);
489 // 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
491 matrix_write_P(matrix, PSTR("\nLayer: "));
492 switch (layer_state) {
494 if (default_layer_state == (1UL<<_BAS_E)) {
495 matrix_write_P(matrix, PSTR("Base_Ex"));
497 matrix_write_P(matrix, PSTR("Base"));
501 matrix_write_P(matrix, PSTR("Raise"));
504 matrix_write_P(matrix, PSTR("Raise_Ex"));
507 matrix_write_P(matrix, PSTR("Lower"));
510 matrix_write_P(matrix, PSTR("Lower_Ex"));
515 matrix_write_P(matrix, PSTR("Adjust"));
518 snprintf(buf, sizeof(buf), "Undef-%d", (short)layer_state);
519 matrix_write(matrix, buf);
522 // Host Keyboard LED Status
524 snprintf(led, sizeof(led), "\n%s %s %s",
525 (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) ? "NUMLOCK" : " ",
526 (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) ? "CAPS" : " ",
527 (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) ? "SCLK" : " ");
528 matrix_write(matrix, led);
532 void iota_gfx_task_user(void) {
533 struct CharacterMatrix matrix;
541 matrix_clear(&matrix);
543 render_status(&matrix);
545 render_logo(&matrix);
548 matrix_update(&display, &matrix);