]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboards/helix/rev2/keymaps/five_rows_jis/keymap.c
Merge pull request #3229 from qmk/hf/shinydox
[qmk_firmware.git] / keyboards / helix / rev2 / keymaps / five_rows_jis / keymap.c
1 #include "helix.h"
2 #include "bootloader.h"
3 #include "action_layer.h"
4 #include "eeconfig.h"
5 #ifdef PROTOCOL_LUFA
6 #include "lufa.h"
7 #include "split_util.h"
8 #endif
9 #include "LUFA/Drivers/Peripheral/TWI.h"
10 #ifdef AUDIO_ENABLE
11   #include "audio.h"
12 #endif
13 #ifdef SSD1306OLED
14   #include "ssd1306.h"
15 #endif
16
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
19
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
22
23 extern keymap_config_t keymap_config;
24
25 #ifdef RGBLIGHT_ENABLE
26 //Following line allows macro to read current RGB settings
27 extern rgblight_config_t rgblight_config;
28 #endif
29
30 extern uint8_t is_master;
31
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.
36 enum layer_number {
37   _BASE = 0,
38   _BAS_E,
39   _LOWER,
40   _LOW_E,
41   _RAISE,
42   _RAI_E,
43   _ADJUST,
44 };
45
46 enum custom_keycodes {
47   BASE = SAFE_RANGE,
48   BAS_E,
49   LOWER,
50   LOW_E,
51   RAISE,
52   RAI_E,
53   ADJUST,
54   EISU,
55   #ifdef KANA_ENABLE
56   KANA,
57   #endif
58   RGBRST
59 };
60
61 // JIS key aliases
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
69
70 // Fillers to make layering more clear
71 #define _______ KC_TRNS
72 #define XXXXXXX KC_NO
73
74 #if HELIX_ROWS == 5
75 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
76   /* Qwerty JIS Normal
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    * `-------------------------------------------------------------------------------------------------'
88    */
89   [_BASE] = LAYOUT( \
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  \
95     ),
96
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    * `-------------------------------------------------------------------------------------------------'
109    */
110   [_BAS_E] = LAYOUT( \
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 \
116     ),
117
118   /* Lower JIS Normal
119    * ,-----------------------------------------.             ,-----------------------------------------.
120    * |      |      |      |      |      |      |             |      |      |      |  -=  |  ^~  |  \|  |
121    * |------+------+------+------+------+------|             |------+------+------+------+------+------|
122    * |      |      |      |      |      |      |             |      |      |      |      |  @`  |  [{  |
123    * |------+------+------+------+------+------|             |------+------+------+------+------+------|
124    * |      |      |      |      |      |      |             |      |      |      |  ;+  |  :*  |  ]}  |
125    * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
126    * |      |      |      |      |      |      |      |      |      |      |  ,<  |  .>  |  /?  |  \_  |
127    * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
128    * |      |      |      |      |      |      | Del  |      |      |      |      |      |      |      |
129    * `-------------------------------------------------------------------------------------------------'
130    */
131   [_LOWER] = LAYOUT( \
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  \
137     ),
138
139   /* Lower JIS Exchange L and R
140    * ,-----------------------------------------.             ,-----------------------------------------.
141    * |      |      |      |  -=  |  ^~  |  \|  |             |      |      |      |      |      |      |
142    * |------+------+------+------+------+------|             |------+------+------+------+------+------|
143    * |      |      |      |      |  @`  |  [{  |             |      |      |      |      |      |      |
144    * |------+------+------+------+------+------|             |------+------+------+------+------+------|
145    * |      |      |      |  ;+  |  :*  |  ]}  |             |      |      |      |      |      |      |
146    * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
147    * |      |  ,<  |  .>  |  /?  |  \_  |PageUp|      |      |      |      |      |      |      |      |
148    * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
149    * |      |      |      |      | Home |PageDn| End  |      |      |      |      |      |      | Del  |
150    * `-------------------------------------------------------------------------------------------------'
151    */
152   [_LOW_E] = LAYOUT( \
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   \
158     ),
159
160   /* Raise JIS Normal
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    * `-------------------------------------------------------------------------------------------------'
172    */
173   [_RAISE] = LAYOUT( \
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  \
179     ),
180
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    * `-------------------------------------------------------------------------------------------------'
193    */
194   [_RAI_E] = LAYOUT( \
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  \
200     ),
201
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    * `-------------------------------------------------------------------------------------------------'
214    */
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     _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______  \
221     ),
222 };
223
224 #elif HELIX_ROWS == 4
225
226 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
227         // Do it yourself :)
228 };
229
230 #else
231 #error "undefined keymaps"
232 #endif
233
234
235 #ifdef AUDIO_ENABLE
236 float tone_qwerty[][2]     = SONG(QWERTY_SOUND);
237 float music_scale[][2]     = SONG(MUSIC_SCALE_SOUND);
238 #endif
239
240 // define variables for reactive RGB
241 bool TOG_STATUS = false;
242 int RGB_current_mode;
243
244 void persistent_default_layer_set(uint16_t default_layer) {
245   eeconfig_update_default_layer(default_layer);
246   default_layer_set(default_layer);
247 }
248
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);
255     #endif
256     layer_on(layer3);
257    } else {
258     layer_off(layer3);
259   }
260 }
261 #endif
262
263 void toggle_lower_raise_layer(bool pressed, uint16_t dist_layer, uint16_t lower_layer, uint16_t raise_layer) {
264   if (pressed) {
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) {
271           rgblight_mode(16);
272         } else {
273           rgblight_mode(15);
274         }
275       #endif
276     }
277
278     layer_on(dist_layer);
279     #ifdef ADJUST_MACRO_ENABLE
280       update_tri_layer_RGB(lower_layer, raise_layer, _ADJUST);
281     #endif
282   } else {
283     #ifdef RGBLIGHT_ENABLE
284       rgblight_mode(RGB_current_mode);   // revert RGB to initial mode prior to RGB mode change
285     #endif
286     TOG_STATUS = false;
287     layer_off(dist_layer);
288     #ifdef ADJUST_MACRO_ENABLE
289       update_tri_layer_RGB(lower_layer, raise_layer, _ADJUST);
290     #endif
291   }
292 }
293
294 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
295   switch (keycode) {
296     case BASE:
297       if (record->event.pressed) {
298         #ifdef AUDIO_ENABLE
299           PLAY_SONG(tone_qwerty);
300         #endif
301         persistent_default_layer_set(1UL<<_BASE);
302       }
303       return false;
304       break;
305     case BAS_E:
306       if (record->event.pressed) {
307         #ifdef AUDIO_ENABLE
308           PLAY_SONG(tone_qwerty);
309         #endif
310         persistent_default_layer_set(1UL<<_BAS_E);
311       }
312       return false;
313       break;
314     case LOWER:
315       toggle_lower_raise_layer(record->event.pressed, _LOWER, _LOWER, _RAISE);
316       return false;
317       break;
318     case LOW_E:
319       toggle_lower_raise_layer(record->event.pressed, _LOW_E, _LOW_E, _RAI_E);
320       return false;
321       break;
322     case RAISE:
323       toggle_lower_raise_layer(record->event.pressed, _RAISE, _LOWER, _RAISE);
324       return false;
325       break;
326     case RAI_E:
327       toggle_lower_raise_layer(record->event.pressed, _RAI_E, _LOW_E, _RAI_E);
328       return false;
329       break;
330     case ADJUST:
331         if (record->event.pressed) {
332           #ifdef RGBLIGHT_ENABLE
333             rgblight_mode(14);
334           #endif
335           layer_on(_ADJUST);
336         } else {
337           #ifdef RGBLIGHT_ENABLE
338             rgblight_mode(RGB_current_mode);
339           #endif
340           layer_off(_ADJUST);
341         }
342         return false;
343         break;
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
345     case RGB_MOD:
346       #ifdef RGBLIGHT_ENABLE
347         if (record->event.pressed) {
348           rgblight_mode(RGB_current_mode);
349           rgblight_step();
350           RGB_current_mode = rgblight_config.mode;
351         }
352       #endif
353       return false;
354       break;
355     case EISU:
356       if (record->event.pressed) {
357         if (keymap_config.swap_lalt_lgui==false) {
358           register_code(KC_LANG2);
359         } else {
360           SEND_STRING(SS_LALT("`"));
361         }
362       } else {
363         unregister_code(KC_LANG2);
364       }
365       return false;
366       break;
367     #ifdef KANA_ENABLE
368     case KANA:
369       if (record->event.pressed) {
370         if(keymap_config.swap_lalt_lgui==false){
371           register_code(KC_LANG1);
372         }else{
373           SEND_STRING(SS_LALT("`"));
374         }
375       } else {
376         unregister_code(KC_LANG1);
377       }
378       return false;
379       break;
380     #endif
381     case RGBRST:
382       #ifdef RGBLIGHT_ENABLE
383         if (record->event.pressed) {
384           eeconfig_update_rgblight_default();
385           rgblight_enable();
386           RGB_current_mode = rgblight_config.mode;
387         }
388       #endif
389       break;
390   }
391
392   return true;
393   // return process_layer_control(keycode, record, false) ? process_layer_control(keycode, record, true) : true;
394 }
395
396 void matrix_init_user(void) {
397   #ifdef AUDIO_ENABLE
398     startup_user();
399   #endif
400   #ifdef RGBLIGHT_ENABLE
401     RGB_current_mode = rgblight_config.mode;
402   #endif
403   //SSD1306 OLED init, make sure to add #define SSD1306OLED in config.h
404   #ifdef SSD1306OLED
405     TWI_Init(TWI_BIT_PRESCALE_1, TWI_BITLENGTH_FROM_FREQ(1, 800000));
406     iota_gfx_init(!has_usb());   // turns on the display
407   #endif
408 }
409
410
411 #ifdef AUDIO_ENABLE
412
413 void startup_user()
414 {
415   _delay_ms(20); // gets rid of tick
416 }
417
418 void shutdown_user()
419 {
420   _delay_ms(150);
421   stop_all_notes();
422 }
423
424 void music_on_user(void)
425 {
426   music_scale_user();
427 }
428
429 void music_scale_user(void)
430 {
431   PLAY_SONG(music_scale);
432 }
433
434 #endif
435
436
437 //SSD1306 OLED update loop, make sure to add #define SSD1306OLED in config.h
438 #ifdef SSD1306OLED
439
440 void matrix_scan_user(void) {
441   iota_gfx_task();  // this is what updates the display continuously
442 }
443
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));
448     dest->dirty = true;
449   }
450 }
451
452 //assign the right code to your layers for OLED display
453 #define L_BASE _BASE
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)
461
462 static void render_logo(struct CharacterMatrix *matrix) {
463
464   static char logo[]={
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,
468     0};
469   matrix_write(matrix, logo);
470   //matrix_write_P(&matrix, PSTR(" Split keyboard kit"));
471 }
472
473
474
475 void render_status(struct CharacterMatrix *matrix) {
476
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]);
483   } else {
484     matrix_write(matrix, logo[1][0]);
485     matrix_write_P(matrix, PSTR("\n"));
486     matrix_write(matrix, logo[1][1]);
487   }
488
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
490   char buf[16];
491   matrix_write_P(matrix, PSTR("\nLayer: "));
492     switch (layer_state) {
493       case L_BASE:
494         if (default_layer_state == (1UL<<_BAS_E)) {
495           matrix_write_P(matrix, PSTR("Base_Ex"));
496         } else {
497           matrix_write_P(matrix, PSTR("Base"));
498         }
499         break;
500       case L_RAISE:
501         matrix_write_P(matrix, PSTR("Raise"));
502         break;
503       case L_RAI_E:
504         matrix_write_P(matrix, PSTR("Raise_Ex"));
505         break;
506       case L_LOWER:
507         matrix_write_P(matrix, PSTR("Lower"));
508         break;
509       case L_LOW_E:
510         matrix_write_P(matrix, PSTR("Lower_Ex"));
511         break;
512       case L_ADJUST:
513       case L_ADJUST_TRI:
514       case L_ADJUST_TRIE:
515         matrix_write_P(matrix, PSTR("Adjust"));
516         break;
517       default:
518         snprintf(buf, sizeof(buf), "Undef-%d", (short)layer_state);
519         matrix_write(matrix, buf);
520     }
521
522   // Host Keyboard LED Status
523   char led[32];
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);
529 }
530
531
532 void iota_gfx_task_user(void) {
533   struct CharacterMatrix matrix;
534
535 #if DEBUG_TO_SCREEN
536   if (debug_enable) {
537     return;
538   }
539 #endif
540
541   matrix_clear(&matrix);
542   if (is_master) {
543     render_status(&matrix);
544   } else {
545     render_logo(&matrix);
546   }
547
548   matrix_update(&display, &matrix);
549 }
550
551 #endif