1 #include QMK_KEYBOARD_H
2 #include "LUFA/Drivers/Peripheral/TWI.h"
7 extern keymap_config_t keymap_config;
9 //Following line allows macro to read current RGB settings
10 extern rgblight_config_t rgblight_config;
13 // Each layer gets a name for readability, which is then used in the keymap matrix below.
14 // The underscores don't mean anything - you can have a layer called STUFF or any other name.
15 // Layer names don't all need to be of the same length, obviously, and you can also skip them
16 // entirely and just use numbers.
24 enum custom_keycodes {
43 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
46 * ,-----------------------------------------------------------------------------------.
47 * | Tab | Q | W | E | R | T | Y | U | I | O | P | Bksp |
48 * |------+------+------+------+------+-------------+------+------+------+------+------|
49 * | Esc | A | S | D | F | G | H | J | K | L | ; | " |
50 * |------+------+------+------+------+------|------+------+------+------+------+------|
51 * | Shift| Z | X | C | V | B | N | M | , | . | / |Enter |
52 * |------+------+------+------+------+------+------+------+------+------+------+------|
53 * |Adjust| Ctrl | Alt | GUI |Lower |Space |Space |Raise | Left | Down | Up |Right |
54 * `-----------------------------------------------------------------------------------'
57 KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC, \
58 KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, \
59 KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT , \
60 ADJUST, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT \
64 * ,-----------------------------------------------------------------------------------.
65 * | Tab | Q | W | F | P | G | J | L | U | Y | ; | Bksp |
66 * |------+------+------+------+------+-------------+------+------+------+------+------|
67 * | Esc | A | R | S | T | D | H | N | E | I | O | " |
68 * |------+------+------+------+------+------|------+------+------+------+------+------|
69 * | Shift| Z | X | C | V | B | K | M | , | . | / |Enter |
70 * |------+------+------+------+------+------+------+------+------+------+------+------|
71 * |Adjust| Ctrl | Alt | GUI |Lower |Space |Space |Raise | Left | Down | Up |Right |
72 * `-----------------------------------------------------------------------------------'
74 [_COLEMAK] = LAYOUT( \
75 KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC, \
76 KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT, \
77 KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT , \
78 ADJUST, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT \
82 * ,-----------------------------------------------------------------------------------.
83 * | Tab | " | , | . | P | Y | F | G | C | R | L | Bksp |
84 * |------+------+------+------+------+-------------+------+------+------+------+------|
85 * | Esc | A | O | E | U | I | D | H | T | N | S | / |
86 * |------+------+------+------+------+------|------+------+------+------+------+------|
87 * | Shift| ; | Q | J | K | X | B | M | W | V | Z |Enter |
88 * |------+------+------+------+------+------+------+------+------+------+------+------|
89 * |Adjust| Ctrl | Alt | GUI |Lower |Space |Space |Raise | Left | Down | Up |Right |
90 * `-----------------------------------------------------------------------------------'
93 KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_BSPC, \
94 KC_ESC, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH, \
95 KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_ENT , \
96 ADJUST, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT \
100 * ,-----------------------------------------------------------------------------------.
101 * | ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | Bksp |
102 * |------+------+------+------+------+-------------+------+------+------+------+------|
103 * | Del | F1 | F2 | F3 | F4 | F5 | F6 | _ | + | | \ | | |
104 * |------+------+------+------+------+------|------+------+------+------+------+------|
105 * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO ~ |ISO | | | |Enter |
106 * |------+------+------+------+------+------+------+------+------+------+------+------|
107 * | | | | | | | | Next | Vol- | Vol+ | Play |
108 * `-----------------------------------------------------------------------------------'
111 KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC, \
112 KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE, \
113 _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12,S(KC_NUHS),S(KC_NUBS),_______, _______, _______, \
114 _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY \
118 * ,-----------------------------------------------------------------------------------.
119 * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp |
120 * |------+------+------+------+------+-------------+------+------+------+------+------|
121 * | Del | F1 | F2 | F3 | F4 | F5 | F6 | - | = | [ | ] | \ |
122 * |------+------+------+------+------+------|------+------+------+------+------+------|
123 * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO # |ISO / | | |Enter |
124 * |------+------+------+------+------+------+------+------+------+------+------+------|
125 * | | | | | | | | Next | Vol- | Vol+ | Play |
126 * `-----------------------------------------------------------------------------------'
129 KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC, \
130 KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS, \
131 _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_NUHS, KC_NUBS, _______, _______, _______, \
132 _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY \
135 /* Adjust (Lower + Raise)
136 * ,-----------------------------------------------------------------------------------.
137 * | | Reset| | | | | | | | | | Del |
138 * |------+------+------+------+------+-------------+------+------+------+------+------|
139 * | | | |Aud on|Audoff|AGnorm|AGswap|Qwerty|Colemk|Dvorak| | |
140 * |------+------+------+------+------+------|------+------+------+------+------+------|
141 * | | | | | | | | | | | | |
142 * |------+------+------+------+------+------+------+------+------+------+------+------|
143 * | | | | | | | | | | | |
144 * `-----------------------------------------------------------------------------------'
146 [_ADJUST] = LAYOUT( \
147 _______, RESET, _______, M_SAMPLE, _______, _______, _______, _______, _______, _______, _______, KC_DEL, \
148 _______, _______, _______, AU_ON, AU_OFF, AG_NORM, AG_SWAP, QWERTY, COLEMAK, DVORAK, _______, _______, \
149 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
150 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ \
159 float tone_startup[][2] = SONG(STARTUP_SOUND);
160 float tone_qwerty[][2] = SONG(QWERTY_SOUND);
161 float tone_dvorak[][2] = SONG(DVORAK_SOUND);
162 float tone_colemak[][2] = SONG(COLEMAK_SOUND);
163 float tone_plover[][2] = SONG(PLOVER_SOUND);
164 float tone_plover_gb[][2] = SONG(PLOVER_GOODBYE_SOUND);
165 float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
166 float tone_goodbye[][2] = SONG(GOODBYE_SOUND);
169 // define variables for reactive RGB
170 bool TOG_STATUS = false;
171 int RGB_current_mode;
173 void persistent_default_layer_set(uint16_t default_layer) {
174 eeconfig_update_default_layer(default_layer);
175 default_layer_set(default_layer);
178 // Setting ADJUST layer RGB back to default
179 void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
180 if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
181 rgblight_mode(RGB_current_mode);
188 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
191 if (record->event.pressed) {
193 PLAY_SONG(tone_qwerty);
195 persistent_default_layer_set(1UL<<_QWERTY);
200 if (record->event.pressed) {
202 PLAY_SONG(tone_colemak);
204 persistent_default_layer_set(1UL<<_COLEMAK);
209 if (record->event.pressed) {
211 PLAY_SONG(tone_dvorak);
213 persistent_default_layer_set(1UL<<_DVORAK);
218 if (record->event.pressed) {
219 //not sure how to have keyboard check mode and set it to a variable, so my work around
220 //uses another variable that would be set to true after the first time a reactive key is pressed.
221 if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
223 TOG_STATUS = !TOG_STATUS;
227 update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
229 rgblight_mode(RGB_current_mode); // revert RGB to initial mode prior to RGB mode change
232 update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
237 if (record->event.pressed) {
238 //not sure how to have keyboard check mode and set it to a variable, so my work around
239 //uses another variable that would be set to true after the first time a reactive key is pressed.
240 if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
242 TOG_STATUS = !TOG_STATUS;
246 update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
248 rgblight_mode(RGB_current_mode); // revert RGB to initial mode prior to RGB mode change
251 update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
256 if (record->event.pressed) {
257 register_code(KC_RSFT);
258 #ifdef BACKLIGHT_ENABLE
262 unregister_code(KC_RSFT);
266 //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
268 if (record->event.pressed) {
269 rgblight_mode(RGB_current_mode);
271 RGB_current_mode = rgblight_config.mode;
276 if (record->event.pressed){
277 SEND_STRING("hello world");
284 void matrix_init_user(void) {
288 RGB_current_mode = rgblight_config.mode;
291 //SSD1306 OLED init and update loop, make sure to add #define SSD1306OLED in config.h
293 void matrix_master_OLED_init (void) {
294 TWI_Init(TWI_BIT_PRESCALE_1, TWI_BITLENGTH_FROM_FREQ(1, 800000));
295 iota_gfx_init(); // turns on the display
298 void matrix_scan_user(void) {
299 iota_gfx_task(); // this is what updates the display continuously
307 _delay_ms(20); // gets rid of tick
308 PLAY_SONG(tone_startup);
313 PLAY_SONG(tone_goodbye);
318 void music_on_user(void)
323 void music_scale_user(void)
325 PLAY_SONG(music_scale);
330 void matrix_update(struct CharacterMatrix *dest,
331 const struct CharacterMatrix *source) {
332 if (memcmp(dest->display, source->display, sizeof(dest->display))) {
333 memcpy(dest->display, source->display, sizeof(dest->display));
338 //assign the right code to your layers for OLED display
345 #define L_NFNLAYER 192
346 #define L_MOUSECURSOR 256
347 #define L_ADJUST 65560
349 void iota_gfx_task_user(void) {
356 struct CharacterMatrix matrix;
358 matrix_clear(&matrix);
359 matrix_write_P(&matrix, PSTR("USB: "));
361 switch (USB_DeviceState) {
362 case DEVICE_STATE_Unattached:
363 matrix_write_P(&matrix, PSTR("Unattached"));
365 case DEVICE_STATE_Suspended:
366 matrix_write_P(&matrix, PSTR("Suspended"));
368 case DEVICE_STATE_Configured:
369 matrix_write_P(&matrix, PSTR("Connected"));
371 case DEVICE_STATE_Powered:
372 matrix_write_P(&matrix, PSTR("Powered"));
374 case DEVICE_STATE_Default:
375 matrix_write_P(&matrix, PSTR("Default"));
377 case DEVICE_STATE_Addressed:
378 matrix_write_P(&matrix, PSTR("Addressed"));
381 matrix_write_P(&matrix, PSTR("Invalid"));
385 // 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
388 snprintf(buf,sizeof(buf), "Undef-%ld", layer_state);
389 matrix_write_P(&matrix, PSTR("\n\nLayer: "));
390 switch (layer_state) {
392 matrix_write_P(&matrix, PSTR("Default"));
395 matrix_write_P(&matrix, PSTR("Raise"));
398 matrix_write_P(&matrix, PSTR("Lower"));
401 matrix_write_P(&matrix, PSTR("ADJUST"));
404 matrix_write(&matrix, buf);
407 // Host Keyboard LED Status
409 snprintf(led, sizeof(led), "\n%s %s %s",
410 (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) ? "NUMLOCK" : " ",
411 (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) ? "CAPS" : " ",
412 (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) ? "SCLK" : " ");
413 matrix_write(&matrix, led);
414 matrix_update(&display, &matrix);