2 #include "bootloader.h"
3 #include "action_layer.h"
7 #include "split_util.h"
9 #include "LUFA/Drivers/Peripheral/TWI.h"
17 extern keymap_config_t keymap_config;
19 #ifdef RGBLIGHT_ENABLE
20 //Following line allows macro to read current RGB settings
21 extern rgblight_config_t rgblight_config;
24 extern uint8_t is_master;
27 static uint16_t key_timer;
28 static uint16_t tap_timer;
29 static uint16_t delay_registered_code;
30 static uint8_t delay_mat_row;
31 static uint8_t delay_mat_col;
32 static bool delay_key_stat;
33 static bool delay_key_pressed;
34 static bool tapping_key;
36 // Each layer gets a name for readability, which is then used in the keymap matrix below.
37 // The underscores don't mean anything - you can have a layer called STUFF or any other name.
38 // Layer names don't all need to be of the same length, obviously, and you can also skip them
39 // entirely and just use numbers.
46 bool RGBAnimation = false; //Flag for LED Layer color Refresh.
48 enum custom_keycodes {
68 // Fillers to make layering more clear
69 #define _______ KC_TRNS
72 #define M_SAMPLE M(KC_SAMPLEMACRO)
75 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
78 * ,-----------------------------------------. ,-----------------------------------------.
79 * | C+z | ; | [ | ( | < | { | | | | | | | |
80 * |------+------+------+------+------+------| |------+------+------+------+------+------|
81 * | KANA | P | K | R | A | F | | | | | | | |
82 * |------+------+------+------+------+------| |------+------+------+------+------+------|
83 * | BS | D | T | H | E | O | | | | | | | |
84 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
85 * | Shift| Y | S | N | I | U |Space | | | | | | | |
86 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
87 * | Ctrl | Alt | win | Sym | Num | OPT | Ent | | | | | | | |
88 * `-------------------------------------------------------------------------------------------------'
91 LCTL(KC_Z), KC_SCLN, KC_LBRC, KC_LPRN, KC_LT, KC_LCBR, _______, _______, _______, _______, _______, _______, \
92 KANA, KC_P, KC_K, KC_R, KC_A, KC_F, _______, _______, _______, _______, _______, _______, \
93 KC_BSPC, KC_D, KC_T, KC_H, KC_E, KC_O, _______, _______, _______, _______, _______, _______, \
94 OSM(MOD_LSFT), KC_Y, KC_S, KC_N, KC_I, KC_U, KC_SPC, _______, _______, _______, _______, _______, _______, _______, \
95 OSM(MOD_LCTL), OSM(MOD_LALT), OSM(MOD_LGUI), MO(_SYM), MO(_NUM), OPT_TAP_SP, KC_ENT, _______, _______, _______, _______, _______, _______, _______ \
99 * ,-----------------------------------------. ,-----------------------------------------.
100 * | Esc | : | ] | ) | > | } | | | | | | | |
101 * |------+------+------+------+------+------| |------+------+------+------+------+------|
102 * | EISU| J | M | B | ' | Tab | | | | | | | |
103 * |------+------+------+------+------+------| |------+------+------+------+------+------|
104 * | . | V | C | L | Z | Q | | | | | | | |
105 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
106 * | | X | G | W | - | Del | Esc | | | | | | | |
107 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
108 * | | | | , | DTOP | | | | | | | | | |
109 * `-------------------------------------------------------------------------------------------------'
112 KC_ESC, KC_COLN,KC_RBRC, KC_RPRN,KC_GT, KC_RCBR, _______, _______, _______, _______, _______, _______, \
113 EISU, KC_J, KC_M, KC_B, KC_QUOT, KC_TAB, _______, _______, _______, _______, _______, _______, \
114 KC_DOT, KC_V, KC_C, KC_L, KC_Z, KC_Q, _______, _______, _______, _______, _______, _______, \
115 _______, KC_X, KC_G, KC_W, KC_MINUS, KC_DEL, KC_ESC, _______, _______, _______, _______, _______, _______, _______, \
116 _______, _______,_______, KC_COMM,DESKTOP, _______, _______, _______, _______, _______, _______, _______, _______, _______ \
120 * ,-----------------------------------------. ,-----------------------------------------.
121 * |RGBRST| Hue | | RST | Mac | Win | | | | | | | |
122 * |------+------+------+------+------+------| |------+------+------+------+------+------|
123 * | RGB1 | VAL+ | F7 | F8 | F9 | | | | | | | | |
124 * |------+------+------+------+------+------| |------+------+------+------+------+------|
125 * | RGB2 | VAL- | F4 | F5 | F6 | F12 | | | | | | | |
126 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
127 * | RGB3 | F10 | F1 | F2 | F3 | F11 | | | | | | | | |
128 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
129 * |RGBOFF| | | | | | | | | | | | | |
130 * `-------------------------------------------------------------------------------------------------'
133 RGBRST,RGB_HUI, _______, RESET, MAC, WIN, _______, _______, _______, _______, _______, _______, \
134 RGB1, RGB_VAI, KC_F7, KC_F8, KC_F9, _______, _______, _______, _______, _______, _______, _______, \
135 RGB2, RGB_VAD, KC_F4, KC_F5, KC_F6, KC_F12, _______, _______, _______, _______, _______, _______, \
136 RGB3, KC_F10, KC_F1, KC_F2, KC_F3, KC_F11, _______, _______, _______, _______, _______, _______, _______, _______, \
137 RGBOFF,_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ \
141 * ,-----------------------------------------. ,-----------------------------------------.
142 * | Ins | GRV | | PU | PD | ^ | | | | | | | |
143 * |------+------+------+------+------+------| |------+------+------+------+------+------|
144 * | | \ | # | = | ? | % | | | | | | | |
145 * |------+------+------+------+------+------| |------+------+------+------+------+------|
146 * | | $ | upA | @ | ! | | | | | | | | | |
147 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
148 * | CL | <- | dwA | -> | _ | & | | | | | | | | |
149 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
150 * | | | PS | | ~ | | | | | | | | | |
151 * `-------------------------------------------------------------------------------------------------'
154 KC_INS, KC_GRV, _______, KC_PGUP, KC_PGDN, KC_CIRC, _______, _______, _______, _______, _______, _______, \
155 _______, KC_BSLS, KC_HASH, KC_EQL, KC_QUES, KC_PERC, _______, _______, _______, _______, _______, _______, \
156 _______, KC_DLR, KC_UP, KC_AT, KC_EXLM, KC_PIPE, _______, _______, _______, _______, _______, _______, \
157 KC_CAPS, KC_LEFT, KC_DOWN, KC_RIGHT,KC_UNDS, KC_AMPR, _______, _______, _______, _______, _______, _______, _______, _______, \
158 _______, _______, KC_PSCR, _______, KC_TILD, _______, _______, _______, _______, _______, _______, _______, _______, _______ \
162 * ,-----------------------------------------. ,-----------------------------------------.
163 * | | | Func | home | End | | | | | | | | |
164 * |------+------+------+------+------+------| |------+------+------+------+------+------|
165 * | | * | 7 | 8 | 9 | - | | | | | | | |
166 * |------+------+------+------+------+------| |------+------+------+------+------+------|
167 * | . | / | 4 | 5 | 6 | + | | | | | | | |
168 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
169 * | LN | 0 | 1 | 2 | 3 |C+S+F1| | | | | | | | |
170 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
171 * | | | | , | | | | | | | | | | |
172 * `-------------------------------------------------------------------------------------------------'
175 _______, _______, OSL(_FUNC), KC_HOME, KC_END, _______, _______, _______, _______, _______, _______, _______, \
176 _______, KC_ASTR, KC_P7, KC_P8, KC_P9, KC_MINS, _______, _______, _______, _______, _______, _______, \
177 KC_PDOT, KC_SLSH, KC_P4, KC_P5, KC_P6, KC_PLUS, _______, _______, _______, _______, _______, _______, \
178 KC_NLCK, KC_P0, KC_P1, KC_P2, KC_P3, LCTL(S(KC_F1)), _______, _______, _______, _______, _______, _______, _______, _______, \
179 _______, _______, KC_PDOT, KC_COMM, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ \
183 #error "undefined keymaps"
189 float tone_qwerty[][2] = SONG(QWERTY_SOUND);
190 float tone_dvorak[][2] = SONG(DVORAK_SOUND);
191 float tone_colemak[][2] = SONG(COLEMAK_SOUND);
192 float tone_plover[][2] = SONG(PLOVER_SOUND);
193 float tone_plover_gb[][2] = SONG(PLOVER_GOODBYE_SOUND);
194 float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
197 // define variables for reactive RGB
198 //bool TOG_STATUS = false;
199 int RGB_current_mode;
201 void persistent_default_layer_set(uint16_t default_layer) {
202 eeconfig_update_default_layer(default_layer);
203 default_layer_set(default_layer);
206 bool find_mairix(uint16_t keycode, uint8_t *row, uint8_t *col){
207 for(uint8_t i=0; i<MATRIX_ROWS; i++){
208 for(uint8_t j=0; j<MATRIX_COLS; j++){
209 if( pgm_read_word(&(keymaps[_BASE][i][j]))==keycode){
219 void unregister_delay_code(void){
220 if(delay_registered_code){
221 unregister_code(delay_registered_code);
222 if (delay_registered_code & QK_LSFT){
223 unregister_code(KC_LSFT);
225 if (delay_registered_code & QK_LCTL){
226 unregister_code(KC_LCTL);
228 if (delay_registered_code & QK_LALT){
229 unregister_code(KC_LALT);
231 if (delay_registered_code & QK_LGUI){
232 unregister_code(KC_LGUI);
234 delay_registered_code=0;
238 void register_delay_code(uint8_t layer){
240 unregister_delay_code();
242 uint16_t code = pgm_read_word(&(keymaps[layer][delay_mat_row][delay_mat_col]));
244 register_code(KC_LSFT);
247 register_code(KC_LCTL);
250 register_code(KC_LALT);
253 register_code(KC_LGUI);
256 delay_registered_code = code;
257 delay_key_stat = false;
262 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
264 if(tap_timer&&keycode!=OPT_TAP_SP){
268 if(keycode==delay_registered_code){
269 if (!record->event.pressed){
270 unregister_delay_code();
298 if (record->event.pressed) {
299 register_delay_code(_BASE);
300 if(find_mairix(keycode, &delay_mat_row, &delay_mat_col)){
301 key_timer = timer_read();
302 delay_key_stat = true;
303 delay_key_pressed = true;
306 delay_key_pressed = false;
311 if (record->event.pressed) {
313 register_delay_code(_OPT);
315 tap_timer = timer_read();
318 if(tapping_key==false && timer_elapsed(tap_timer) < TAPPING_TERM){
326 if (record->event.pressed) {
327 if(keymap_config.swap_lalt_lgui==false){
328 register_code(KC_LANG2);
330 SEND_STRING(SS_LALT("`"));
333 unregister_code(KC_LANG2);
338 if (record->event.pressed) {
339 if(keymap_config.swap_lalt_lgui==false){
340 register_code(KC_LANG1);
342 SEND_STRING(SS_LALT("`"));
345 unregister_code(KC_LANG1);
350 if (record->event.pressed) {
351 if(keymap_config.swap_lalt_lgui==false){
352 register_code(KC_F11);
354 SEND_STRING(SS_LGUI("d"));
357 unregister_code(KC_F11);
362 #ifdef RGBLIGHT_ENABLE
363 if (record->event.pressed) {
364 eeconfig_update_rgblight_default();
366 RGB_current_mode = rgblight_config.mode;
367 RGBAnimation = false;
372 #ifdef RGBLIGHT_ENABLE
373 if (record->event.pressed) {
379 #ifdef RGBLIGHT_ENABLE
380 if (record->event.pressed) {
383 RGB_current_mode = rgblight_config.mode;
388 #ifdef RGBLIGHT_ENABLE
389 if (record->event.pressed) {
392 RGB_current_mode = rgblight_config.mode;
397 #ifdef RGBLIGHT_ENABLE
398 if (record->event.pressed) {
401 RGB_current_mode = rgblight_config.mode;
406 if (record->event.pressed) {
407 keymap_config.swap_lalt_lgui = false;
408 keymap_config.swap_ralt_rgui = false;
410 PLAY_SONG(ag_norm_song);
415 if (record->event.pressed) {
416 keymap_config.swap_lalt_lgui = true;
417 keymap_config.swap_ralt_rgui = true;
419 PLAY_SONG(ag_swap_song);
428 //keyboard start-up code. Runs once when the firmware starts up.
429 void matrix_init_user(void) {
433 #ifdef RGBLIGHT_ENABLE
434 RGB_current_mode = rgblight_config.mode;
436 //SSD1306 OLED init, make sure to add #define SSD1306OLED in config.h
438 TWI_Init(TWI_BIT_PRESCALE_1, TWI_BITLENGTH_FROM_FREQ(1, 800000));
439 iota_gfx_init(!has_usb()); // turns on the display
448 _delay_ms(20); // gets rid of tick
457 void music_on_user(void)
462 void music_scale_user(void)
464 PLAY_SONG(music_scale);
470 //assign the right code to your layers for OLED display
479 #define L_NFNLAYER 192
480 #define L_MOUSECURSOR 256
483 uint8_t layer_state_old;
485 //runs every scan cycle (a lot)
486 void matrix_scan_user(void) {
488 iota_gfx_task(); // this is what updates the display continuously
491 if(delay_key_stat && (timer_elapsed(key_timer) > DELAY_TIME)){
492 register_delay_code(_BASE);
493 if(!delay_key_pressed){
494 unregister_delay_code();
498 if(layer_state_old != layer_state){
499 switch (layer_state) {
501 #ifdef RGBLIGHT_ENABLE
503 rgblight_sethsv(187,255,255);
506 rgblight_mode(RGB_current_mode);
511 register_delay_code(_OPT);
514 register_delay_code(_NUM);
515 #ifdef RGBLIGHT_ENABLE
516 rgblight_sethsv(25,255,255);
521 register_delay_code(_SYM);
522 #ifdef RGBLIGHT_ENABLE
523 rgblight_sethsv(96,255,255);
528 register_delay_code(_FUNC);
529 #ifdef RGBLIGHT_ENABLE
530 rgblight_sethsv(331,255,255);
535 layer_state_old = layer_state;
539 //SSD1306 OLED update loop, make sure to add #define SSD1306OLED in config.h
542 void matrix_update(struct CharacterMatrix *dest,
543 const struct CharacterMatrix *source) {
544 if (memcmp(dest->display, source->display, sizeof(dest->display))) {
545 memcpy(dest->display, source->display, sizeof(dest->display));
551 void render_status(struct CharacterMatrix *matrix) {
554 static char logo[4][1][17]=
557 {0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0x73,0x74,0}
560 {0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,0}
563 {0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,0}
566 {0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0}
570 static char indctr[8][2][4]=
614 if (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) { rown = 4; } else { rown = 0; }
615 if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) { rowa = 4; } else { rowa = 0; }
616 if (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) { rows = 4; } else { rows = 0; }
617 if (layer_state == L_FUNC) { rowf = 4; }
619 matrix_write(matrix, indctr[rown] [0]);
620 matrix_write(matrix, indctr[rowf] [1]);
621 matrix_write(matrix, logo [0] [0]);
622 matrix_write(matrix, indctr[rown+1][0]);
623 matrix_write(matrix, indctr[rowf+1][1]);
624 matrix_write(matrix, logo [1] [0]);
625 matrix_write(matrix, indctr[rowa+2][0]);
626 matrix_write(matrix, indctr[rows+2][1]);
627 matrix_write(matrix, logo [2] [0]);
628 matrix_write(matrix, indctr[rowa+3][0]);
629 matrix_write(matrix, indctr[rows+3][1]);
630 matrix_write(matrix, logo [3] [0]);
634 void iota_gfx_task_user(void) {
635 struct CharacterMatrix matrix;
643 matrix_clear(&matrix);
645 render_status(&matrix);
647 matrix_update(&display, &matrix);