2 #include "bootloader.h"
3 #include "action_layer.h"
5 #include "LUFA/Drivers/Peripheral/TWI.h"
15 extern keymap_config_t keymap_config;
17 //Following line allows macro to read current RGB settings
18 extern rgblight_config_t rgblight_config;
20 // Each layer gets a name for readability, which is then used in the keymap matrix below.
21 // The underscores don't mean anything - you can have a layer called STUFF or any other name.
22 // Layer names don't all need to be of the same length, obviously, and you can also skip them
23 // entirely and just use numbers.
29 #define _MOUSECURSOR 8
32 enum preonic_keycodes {
53 // Fillers to make layering more clear
54 #define _______ KC_TRNS
57 #define CTL_ESC CTL_T(KC_ESC) // Tap for Esc, hold for Ctrl
58 #define CTL_TTAB CTL_T(KC_TAB) // Tap for Esc, hold for Ctrl
59 #define CTL_ENT CTL_T(KC_ENT) // Tap for Enter, hold for Ctrl
60 #define SFT_ENT SFT_T(KC_ENT) // Tap for Enter, hold for Shift
61 // Requires KC_TRNS/_______ for the trigger key in the destination layer
62 #define LT_FN(kc) LT(_FNLAYER, kc) // L-ayer T-ap Function Layer
63 #define LT_MC(kc) LT(_MOUSECURSOR, kc) // L-ayer T-ap M-ouse C-ursor
64 #define LT_RAI(kc) LT(_RAISE, kc) // L-ayer T-ap to Raise
65 #define TG_NUMLAY TG(_NUMLAY) //Toggle for layer _NUMLAY
66 #define DEMOMACRO M(KC_DEMOMACRO) // My login macros
69 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
72 * ,------+------+------+------+------+------------------------------------------------.
73 * | Esc | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - |
74 * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
75 * | Tab | Q | W | E | R | T | Y | U | I | O | P | Bksp | 7 | 8 | 9 |
76 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
77 * | CAPS | A | S | D | F | G | H | J | K | L | ; |Enter | 4 | 5 | 6 |
78 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
79 * | Shift| Z | X | C | V | B | N | M | , | . | / | = | 1 | 2 | 3 |
80 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
81 * | ~ | Ctrl | Alt | GUI |Lower |Space |Space |Raise | RAlt | Ins | Del |NumLay| 0 | . | ENT |
82 * `--------------------------------------------------------------------------------------------------------'
85 KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS,\
86 KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC, KC_P7, KC_P8, KC_P9, \
87 KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, LT_MC(KC_SCLN), CTL_ENT, KC_P4, KC_P5, KC_P6, \
88 KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_EQL, KC_P1, KC_P2, KC_P3, \
89 KC_GRV, KC_RCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_RALT, KC_INS, KC_DEL, TG_NUMLAY, KC_P0, KC_PDOT, KC_PENT \
93 * ,-----------------------------------------------------------------------------------.
94 * | | | | | | | | | | | | |
95 * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
96 * | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | ~ | \ | | | |
97 * |------+------+------+------+------+-------------+------+------+------+------+------+------+------+------|
98 * | CAPS | F1 | F2 | F3 | F4 | F5 | F6 | _ | + | { | } | | | | | |
99 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
100 * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO ~ |ISO | | [ | ] | | | | |
101 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
102 * | | | | | | | | | Next | Vol- | Vol+ | Play | | | |
103 * `--------------------------------------------------------------------------------------------------------'
106 KC_ESC, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, \
107 KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_GRV, KC_BSLS, _______, _______, _______, \
108 KC_CAPS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_EQL, KC_LBRC, KC_RBRC, KC_PIPE, _______, _______, _______, \
109 _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, S(KC_NUHS), S(KC_NUBS), KC_LCBR, KC_RCBR, _______, _______, _______, _______, \
110 _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY, _______, _______, _______\
114 * ,-----------------------------------------------------------------------------------.
115 * | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 |
116 * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
117 * | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | ~ | \ | | | |
118 * |------+------+------+------+------+-------------+------+------+------+------+------+------+------+------|
119 * | | A | Up | D | PrSc | | 4 | 5 | 6 | * | : | ' | | | |
120 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
121 * | | Lt | Dn | Rt | Mute | | 1 | 2 | 3 | Up | / | | | | |
122 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
123 * | | | | | |Space | 0 | | Left | Down | Right| | | | |
124 * `--------------------------------------------------------------------------------------------------------'
127 KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, \
128 KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_PLUS, KC_BSLS, _______, _______, _______, \
129 _______, KC_A, KC_UP, KC_D, KC_PSCR, _______, KC_4, KC_5, KC_6, KC_PAST, KC_COLN, KC_QUOT, _______, _______, _______, \
130 _______, KC_LEFT, KC_DOWN, KC_RIGHT, KC__MUTE, _______, KC_1, KC_2, KC_3, KC_UP, KC_SLSH, _______, _______, _______, _______, \
131 _______, _______, _______, _______, _______, KC_SPC, KC_0, _______, KC_LEFT, KC_DOWN, KC_RIGHT, _______, _______, _______, _______ \
134 /* FN layer on Esc key
135 * ,-----------------------------------------------------------------------------------.
136 * | | | | | | | | | | | | |
137 * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
138 * | | ! | @ | # | $ | % | ^ | & | * | ( | ) | + | | | |
139 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
140 * | | F1 | F2 | F3 | F4 | F5 | F6 | _ | = | [ | ] | ' | | | |
141 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
142 * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO ~ |ISO | | { | } | | | | |
143 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
144 * | | | | | | | | | Next | Vol- | Vol+ | Play | | | |
145 * `--------------------------------------------------------------------------------------------------------'
148 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,\
149 _______, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_PLUS, _______, _______, _______, \
150 _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_EQL, KC_LBRC, KC_RBRC, KC_QUOT, _______, _______, _______, \
151 _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12,S(KC_NUHS), S(KC_NUBS), KC_LCBR, KC_RCBR, _______, _______, _______, _______, \
152 _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY, _______, _______, _______ \
156 * ,-----------------------------------------------------------------------------------.
157 * | | | | | | | | | | | | |
158 * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
159 * | | | | | | | | | | | | | F7 | F8 | F9 |
160 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
161 * | | | | | | | | | | | | | F4 | F5 | F6 |
162 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
163 * | | | | | | | | | | | | | | Up | |
164 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
165 * | | | | | | | | | | | | Exit | Left | Down | Rght |
166 * `--------------------------------------------------------------------------------------------------------'
169 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,\
170 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_INS, KC_HOME, KC_PGUP, \
171 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL, KC_END, KC_PGDN, \
172 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_PMNS, KC_UP, KC_PPLS, \
173 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_LEFT, KC_DOWN, KC_RIGHT \
176 /* Mouse Layer (semi-col)
177 * ,-----------------------------------------------------------------------------------.
178 * | |ACCL0| ACCL1| ACCL2 | | | | | | | | |
179 * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
180 * | | | | | | Home | Wh_Up| WHL_L| M_Up | WHL_R| | | | | |
181 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
182 * | | | | | | End | Wh_Dn| M_Lft| M_Dn | M_Rt | | | | | |
183 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
184 * | | | | | | | BTN2 | BTN3 | BTN4 | BTN5 | | | | | |
185 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
186 * | | | | | | BTN1 | | | | BTN1 | | | | | |
187 * `--------------------------------------------------------------------------------------------------------'
190 [_MOUSECURSOR] = KEYMAP(
191 _______, KC_ACL0, KC_ACL1, KC_ACL2, _______, _______, _______, _______, _______, _______, _______, _______,\
192 _______, _______, _______, _______, _______, KC_HOME, KC_PGUP, KC_WH_L, KC_MS_U, KC_WH_R, DEMOMACRO, _______, _______, _______, _______, \
193 _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_END , KC_PGDN, KC_MS_L, KC_MS_D, KC_MS_R, _______, _______, _______, _______, _______, \
194 _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, _______, KC_BTN2, KC_BTN3, KC_BTN4, KC_BTN5, _______, _______, _______, _______, _______, \
195 _______, _______, _______, _______, _______, KC_BTN1, KC_BTN1, _______, _______, _______, _______, _______, _______, _______, _______ \
198 /* Adjust (Lower + Raise)
200 * ,-----------------------------------------------------------------------------------.
201 * | Reset| | | | | | | | | VolD | VolU | Mute |
202 * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
203 * | |RGB TG|RGB ST|RGBH -|RGBH +|RGBS -|RGBS +|RGBV -|RGBV +| | | Del | | | |
204 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
205 * | | | |Aud on|Audoff|AGnorm|AGswap|Qwerty| | | | | | | |
206 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
207 * | |Voice-|Voice+|Mus on|Musoff|MIDIon|MIDIof| | BL + |BL ST |BLSTEP| BL TG| | | |
208 * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
209 * | | | | | | | | | | | | | | | |
210 * `--------------------------------------------------------------------------------------------------------'
213 RESET, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_VOLD, KC_VOLU, KC_MUTE, \
214 _______, RGB_TOG, RGB_MOD, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, RGB_VAI, RGB_VAD, _______, _______, KC_DEL, _______, _______, _______, \
215 _______, _______, _______, AU_ON, AU_OFF, AG_NORM, AG_SWAP, QWERTY, _______, _______, _______, _______, _______, _______, _______, \
216 _______, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, _______, BL_DEC, BL_INC, BL_STEP, BL_TOGG, _______, _______, _______, \
217 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ \
227 float tone_startup[][2] = SONG(STARTUP_SOUND);
228 float tone_qwerty[][2] = SONG(QWERTY_SOUND);
229 float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
230 float tone_goodbye[][2] = SONG(GOODBYE_SOUND);
233 // define variables for reactive RGB
234 bool RGB_INIT = false;
235 bool TOG_STATUS = false;
236 bool NUMLAY_STATUS = false;
237 int RGB_current_mode;
241 void persistant_default_layer_set(uint16_t default_layer) {
242 eeconfig_update_default_layer(default_layer);
243 default_layer_set(default_layer);
246 void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
247 if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
248 rgblight_mode(RGB_current_mode);
255 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
258 if (record->event.pressed) {
260 PLAY_NOTE_ARRAY(tone_qwerty, false, 0);
262 persistant_default_layer_set(1UL<<_QWERTY);
267 if (record->event.pressed) {
268 //not sure how to have keyboard check mode and set it to a variable, so my work around
269 //uses another variable that would be set to true after the first time a reactive key is pressed.
270 if (RGB_INIT) {} else {
271 RGB_current_mode = rgblight_config.mode;
274 if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
276 TOG_STATUS = !TOG_STATUS;
280 update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
282 rgblight_mode(RGB_current_mode); // revert RGB to initial mode prior to RGB mode change
285 update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
290 if (record->event.pressed) {
291 //not sure how to have keyboard check mode and set it to a variable, so my work around
292 //uses another variable that would be set to true after the first time a reactive key is pressed.
293 if (RGB_INIT) {} else {
294 RGB_current_mode = rgblight_config.mode;
297 if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
299 TOG_STATUS = !TOG_STATUS;
303 update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
305 rgblight_mode(RGB_current_mode); // revert RGB to initial mode prior to RGB mode change
308 update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
313 if (record->event.pressed) {
314 register_code(KC_RSFT);
315 #ifdef BACKLIGHT_ENABLE
319 unregister_code(KC_RSFT);
323 //my attempt for RGB layer lock indication via changing the mode, still have to figure out how to not have other keypress not override this mode
325 if (record->event.pressed) {
326 if (RGB_INIT) {} else {
327 RGB_current_mode = rgblight_config.mode;
330 NUMLAY_STATUS = !NUMLAY_STATUS;
335 rgblight_mode(RGB_current_mode);
336 layer_off(_NUMLAY); }
341 //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
342 if (record->event.pressed) {
343 rgblight_mode(RGB_current_mode);
345 RGB_current_mode = rgblight_config.mode;
353 void matrix_init_user(void) {
357 // calls code for the SSD1306 OLED
359 TWI_Init(TWI_BIT_PRESCALE_1, TWI_BITLENGTH_FROM_FREQ(1, 800000));
360 iota_gfx_init(); // turns on the display
368 void matrix_scan_user(void) {
370 iota_gfx_task(); // this is what updates the display continuously
378 _delay_ms(20); // gets rid of tick
379 PLAY_NOTE_ARRAY(tone_startup, false, 0);
384 PLAY_NOTE_ARRAY(tone_goodbye, false, 0);
389 void music_on_user(void)
394 void music_scale_user(void)
396 PLAY_NOTE_ARRAY(music_scale, false, 0);
404 const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
406 if (!eeconfig_is_enabled()) {
412 if (record->event.pressed){
413 return MACRO (I(1), T(H),T(E),T(L), T(L), T(O), T(SPACE), T(W), T(O), T(R), T(L), T(D), END);
420 void matrix_update(struct CharacterMatrix *dest,
421 const struct CharacterMatrix *source) {
422 if (memcmp(dest->display, source->display, sizeof(dest->display))) {
423 memcpy(dest->display, source->display, sizeof(dest->display));
428 //assign the right code to your layers for OLED display
435 #define L_NFNLAYER 192
436 #define L_MOUSECURSOR 256
437 #define L_ADJUST 65560
439 void iota_gfx_task_user(void) {
446 struct CharacterMatrix matrix;
448 matrix_clear(&matrix);
449 matrix_write_P(&matrix, PSTR("USB: "));
451 switch (USB_DeviceState) {
452 case DEVICE_STATE_Unattached:
453 matrix_write_P(&matrix, PSTR("Unattached"));
455 case DEVICE_STATE_Suspended:
456 matrix_write_P(&matrix, PSTR("Suspended"));
458 case DEVICE_STATE_Configured:
459 matrix_write_P(&matrix, PSTR("Connected"));
461 case DEVICE_STATE_Powered:
462 matrix_write_P(&matrix, PSTR("Powered"));
464 case DEVICE_STATE_Default:
465 matrix_write_P(&matrix, PSTR("Default"));
467 case DEVICE_STATE_Addressed:
468 matrix_write_P(&matrix, PSTR("Addressed"));
471 matrix_write_P(&matrix, PSTR("Invalid"));
475 // 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
478 snprintf(buf,sizeof(buf), "Undef-%ld", layer_state);
479 matrix_write_P(&matrix, PSTR("\n\nLayer: "));
480 switch (layer_state) {
482 matrix_write_P(&matrix, PSTR("Default"));
485 matrix_write_P(&matrix, PSTR("Raise"));
488 matrix_write_P(&matrix, PSTR("Lower"));
491 matrix_write_P(&matrix, PSTR("ADJUST"));
494 matrix_write(&matrix, buf);
497 // Host Keyboard LED Status
499 snprintf(led, sizeof(led), "\n%s %s %s",
500 (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) ? "NUMLOCK" : " ",
501 (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) ? "CAPS" : " ",
502 (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) ? "SCLK" : " ");
503 matrix_write(&matrix, led);
504 matrix_update(&display, &matrix);