keymap.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. #include QMK_KEYBOARD_H
  2. #include "bootloader.h"
  3. #ifdef PROTOCOL_LUFA
  4. #include "lufa.h"
  5. #include "split_util.h"
  6. #endif
  7. #ifdef AUDIO_ENABLE
  8. #include "audio.h"
  9. #endif
  10. #ifdef SSD1306OLED
  11. #include "ssd1306.h"
  12. #endif
  13. extern keymap_config_t keymap_config;
  14. #ifdef RGBLIGHT_ENABLE
  15. //Following line allows macro to read current RGB settings
  16. extern rgblight_config_t rgblight_config;
  17. #endif
  18. extern uint8_t is_master;
  19. // Each layer gets a name for readability, which is then used in the keymap matrix below.
  20. // The underscores don't mean anything - you can have a layer called STUFF or any other name.
  21. // Layer names don't all need to be of the same length, obviously, and you can also skip them
  22. // entirely and just use numbers.
  23. enum layer_number {
  24. _QWERTY = 0,
  25. _LOWER,
  26. _RAISE,
  27. _FUNC,
  28. _ADJUST
  29. };
  30. enum custom_keycodes {
  31. QWERTY = SAFE_RANGE,
  32. LOWER,
  33. RAISE,
  34. FUNC,
  35. ADJUST,
  36. EISU,
  37. KANA
  38. };
  39. enum macro_keycodes {
  40. KC_SAMPLEMACRO,
  41. };
  42. // Fillers to make layering more clear
  43. #define _______ KC_TRNS
  44. #define XXXXXXX KC_NO
  45. //Macros
  46. #define M_SAMPLE M(KC_SAMPLEMACRO)
  47. #if HELIX_ROWS == 5
  48. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  49. /* Qwerty
  50. * ,-----------------------------------------. ,-----------------------------------------.
  51. * | ` | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | = |
  52. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  53. * | Tab | Q | W | E | R | T | | Y | U | I | O | P | - |
  54. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  55. * | ESC | A | S | D | F | G | | H | J | K | L | ; | ' |
  56. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  57. * |Shift | Z | X | C | V | B | Fn | Fn | N | M | , | . | / |Shift |
  58. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  59. * | EISU | Ctrl | Alt | GUI |Lower |Space | Bksp |Enter |Space |Raise | GUI | Alt | Ctrl | KANA |
  60. * `-------------------------------------------------------------------------------------------------'
  61. */
  62. [_QWERTY] = LAYOUT( \
  63. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_EQL, \
  64. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_MINS, \
  65. KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, \
  66. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, FUNC, FUNC, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT , \
  67. EISU, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_BSPC, KC_ENT, KC_SPC, RAISE, KC_RGUI, KC_RALT, KC_RCTL, KANA \
  68. ),
  69. /* Lower
  70. * ,-----------------------------------------. ,-----------------------------------------.
  71. * | ~ | ! | @ | # | $ | % | | ^ | & | * | ( | ) | |
  72. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  73. * | ~ | ! | @ | # | $ | % | | ^ | & | * | ( | ) | |
  74. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  75. * | Del | F1 | F2 | F3 | F4 | F5 | | F6 | _ | + | { | } | | |
  76. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  77. * | | F7 | F8 | F9 | F10 | F11 | | | F12 | | | | | |
  78. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  79. * | | | | | | | | | | | Next | Vol- | Vol+ | Play |
  80. * `-------------------------------------------------------------------------------------------------'
  81. */
  82. [_LOWER] = LAYOUT( \
  83. KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, _______, \
  84. KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, _______, \
  85. KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE, \
  86. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, _______, _______, KC_F12, _______, _______, _______, _______, _______, \
  87. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY \
  88. ),
  89. /* Raise
  90. * ,-----------------------------------------. ,-----------------------------------------.
  91. * | ` | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | Bksp |
  92. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  93. * | ` | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | Del |
  94. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  95. * | Del | F1 | F2 | F3 | F4 | F5 | | F6 | - | = | [ | ] | \ |
  96. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  97. * | | F7 | F8 | F9 | F10 | F11 | | | F12 | | | | | |
  98. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  99. * | | | | | | | | | | | Next | Vol- | Vol+ | Play |
  100. * `-------------------------------------------------------------------------------------------------'
  101. */
  102. [_RAISE] = LAYOUT( \
  103. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC, \
  104. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL, \
  105. KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS, \
  106. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, _______, _______, KC_F12, _______, _______, _______, _______, _______, \
  107. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY \
  108. ),
  109. /* Func
  110. * ,-----------------------------------------. ,-----------------------------------------.
  111. * | ` | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | Bksp |
  112. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  113. * | ` | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | Del |
  114. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  115. * | | | | | | | | LEFT | DOWN | UP |RIGHT | PGUP | |
  116. * |------+------+------+------+------+------|------+------|------+------+------+------+------+------|
  117. * | | | | | | | | | HOME | END |Alt+← |Alt+→ | PGDN | |
  118. * |------+------+------+------+------+------+-------------+------+------+------+------+------+------|
  119. * | | | | | | | | | | | Next | Vol- | Vol+ | Play |
  120. * `-------------------------------------------------------------------------------------------------'
  121. */
  122. [_FUNC] = LAYOUT( \
  123. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC, \
  124. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL, \
  125. _______, _______, _______, _______, _______, _______, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, KC_PGUP, _______, \
  126. _______, _______, _______, _______, _______, _______, _______, _______, KC_HOME, KC_END, LALT(KC_LEFT), LALT(KC_RGHT), KC_PGDN, _______, \
  127. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY \
  128. ),
  129. /* Adjust (Lower + Raise)
  130. * ,-----------------------------------------. ,-----------------------------------------.
  131. * | F1 | F2 | F3 | F4 | F5 | F6 | | F7 | F8 | F9 | F10 | F11 | F12 |
  132. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  133. * | | Reset| | | | | | | | | | | Del |
  134. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  135. * | | | |Aud on|Audoff| Mac | | Win |Qwerty| | | | |
  136. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  137. * | | | | | | | | | | |RGB ON| HUE+ | SAT+ | VAL+ |
  138. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  139. * | | | | | | | | | | | MODE | HUE- | SAT- | VAL- |
  140. * `-------------------------------------------------------------------------------------------------'
  141. */
  142. [_ADJUST] = LAYOUT( \
  143. KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, \
  144. _______, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL, \
  145. _______, _______, _______, AU_ON, AU_OFF, AG_NORM, AG_SWAP, QWERTY, _______, _______, _______, _______, \
  146. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RGB_TOG, RGB_HUI, RGB_SAI, RGB_VAI, \
  147. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RGB_MOD, RGB_HUD, RGB_SAD, RGB_VAD \
  148. )
  149. };
  150. #elif HELIX_ROWS == 4
  151. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  152. /* Qwerty
  153. * ,-----------------------------------------. ,-----------------------------------------.
  154. * | = | Q | W | E | R | T | | Y | U | I | O | P | - |
  155. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  156. * | Esc | A | S | D | F | G | | H | J | K | L | ; | ' |
  157. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  158. * | Shift| Z | X | C | V | B | | N | M | , | . | / |Enter |
  159. * |------+------+------+------+------+------+-------------+------+------+------+------+------+------|
  160. * | EISU | Ctrl | Alt | GUI |ESC/Lower | Func | Bksp |Enter |Space |Raise | GUI | Alt | Ctrl | KANA |
  161. * `-------------------------------------------------------------------------------------------------'
  162. */
  163. [_QWERTY] = LAYOUT( \
  164. KC_EQL, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_MINS, \
  165. KC_TAB, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, \
  166. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT , \
  167. EISU, KC_LCTL, KC_LALT, KC_LGUI, LT(_LOWER, KC_ESC), FUNC, KC_BSPC, KC_ENT, KC_SPC, RAISE, KC_RGUI, KC_RALT, KC_RCTL, KANA \
  168. ),
  169. /* Lower
  170. * ,-----------------------------------------. ,-----------------------------------------.
  171. * | ~ | ! | @ | # | $ | % | | ^ | & | * | ( | ) | |
  172. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  173. * | Del | F1 | F2 | F3 | F4 | F5 | | F6 | _ | + | { | } | | |
  174. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  175. * | | F7 | F8 | F9 | F10 | F11 | | F12 | | | | | |
  176. * |------+------+------+------+------+------+-------------+------+------+------+------+------+------|
  177. * | | | | | | | | | | | Next | Vol- | Vol+ | Play |
  178. * `-------------------------------------------------------------------------------------------------'
  179. */
  180. [_LOWER] = LAYOUT( \
  181. KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, _______, \
  182. KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE, \
  183. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, _______, _______, _______, \
  184. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY \
  185. ),
  186. /* Raise
  187. * ,-----------------------------------------. ,-----------------------------------------.
  188. * | ` | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | |
  189. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  190. * | Del | F1 | F2 | F3 | F4 | F5 | | F6 | - | = | [ | ] | \ |
  191. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  192. * | | F7 | F8 | F9 | F10 | F11 | | F12 | | | | | |
  193. * |------+------+------+------+------+------+-------------+------+------+------+------+------+------|
  194. * | | | | | | | | | | | Next | Vol- | Vol+ | Play |
  195. * `-------------------------------------------------------------------------------------------------'
  196. */
  197. [_RAISE] = LAYOUT( \
  198. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, _______, \
  199. KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS, \
  200. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, _______, _______, _______, \
  201. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY \
  202. ),
  203. /* Func
  204. * ,-----------------------------------------. ,-----------------------------------------.
  205. * | ` | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | Del |
  206. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  207. * | | | | | | | | LEFT | DOWN | UP |RIGHT | PGUP | |
  208. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  209. * | | | | | | | | HOME | END |Alt+← |Alt+→ | PGDN | |
  210. * |------+------+------+------+------+------+-------------+------+------+------+------+------+------|
  211. * | | | | | | | | | | | Next | Vol- | Vol+ | Play |
  212. * `-------------------------------------------------------------------------------------------------'
  213. */
  214. [_FUNC] = LAYOUT( \
  215. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL, \
  216. _______, _______, _______, _______, _______, _______, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, KC_PGUP, _______, \
  217. _______, _______, _______, _______, _______, _______, KC_HOME, KC_END, LALT(KC_LEFT), LALT(KC_RGHT), KC_PGDN, _______, \
  218. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY \
  219. ),
  220. /* Adjust (Lower + Raise)
  221. * ,-----------------------------------------. ,-----------------------------------------.
  222. * | | Reset| | | | | | | | | | | Del |
  223. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  224. * | | | |Aud on|Audoff| Mac | | Win |Qwerty| | | | |
  225. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  226. * | | | | | | | | | |RGB ON| HUE+ | SAT+ | VAL+ |
  227. * |------+------+------+------+------+------+-------------+------+------+------+------+------+------|
  228. * | | | | | | | | | | | MODE | HUE- | SAT- | VAL- |
  229. * `-------------------------------------------------------------------------------------------------'
  230. */
  231. [_ADJUST] = LAYOUT( \
  232. _______, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL, \
  233. _______, _______, _______, AU_ON, AU_OFF, AG_NORM, AG_SWAP, QWERTY, _______, _______, _______, _______, \
  234. _______, _______, _______, _______, _______, _______, _______, _______, RGB_TOG, RGB_HUI, RGB_SAI, RGB_VAI, \
  235. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RGB_MOD, RGB_HUD, RGB_SAD, RGB_VAD \
  236. )
  237. };
  238. #else
  239. #error "undefined keymaps"
  240. #endif
  241. #ifdef AUDIO_ENABLE
  242. float tone_qwerty[][2] = SONG(QWERTY_SOUND);
  243. float tone_dvorak[][2] = SONG(DVORAK_SOUND);
  244. float tone_colemak[][2] = SONG(COLEMAK_SOUND);
  245. float tone_plover[][2] = SONG(PLOVER_SOUND);
  246. float tone_plover_gb[][2] = SONG(PLOVER_GOODBYE_SOUND);
  247. float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
  248. #endif
  249. // define variables for reactive RGB
  250. bool TOG_STATUS = false;
  251. int RGB_current_mode;
  252. void persistent_default_layer_set(uint16_t default_layer) {
  253. eeconfig_update_default_layer(default_layer);
  254. default_layer_set(default_layer);
  255. }
  256. // Setting ADJUST layer RGB back to default
  257. void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
  258. if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
  259. #ifdef RGBLIGHT_ENABLE
  260. //rgblight_mode(RGB_current_mode);
  261. #endif
  262. layer_on(layer3);
  263. } else {
  264. layer_off(layer3);
  265. }
  266. }
  267. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  268. switch (keycode) {
  269. case QWERTY:
  270. if (record->event.pressed) {
  271. #ifdef AUDIO_ENABLE
  272. PLAY_SONG(tone_qwerty);
  273. #endif
  274. persistent_default_layer_set(1UL<<_QWERTY);
  275. }
  276. return false;
  277. break;
  278. case LOWER:
  279. if (record->event.pressed) {
  280. //not sure how to have keyboard check mode and set it to a variable, so my work around
  281. //uses another variable that would be set to true after the first time a reactive key is pressed.
  282. if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
  283. } else {
  284. TOG_STATUS = !TOG_STATUS;
  285. #ifdef RGBLIGHT_ENABLE
  286. //rgblight_mode(RGBLIGHT_MODE_SNAKE + 1);
  287. #endif
  288. }
  289. layer_on(_LOWER);
  290. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  291. } else {
  292. #ifdef RGBLIGHT_ENABLE
  293. //rgblight_mode(RGB_current_mode); // revert RGB to initial mode prior to RGB mode change
  294. #endif
  295. TOG_STATUS = false;
  296. layer_off(_LOWER);
  297. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  298. }
  299. return false;
  300. break;
  301. case RAISE:
  302. if (record->event.pressed) {
  303. //not sure how to have keyboard check mode and set it to a variable, so my work around
  304. //uses another variable that would be set to true after the first time a reactive key is pressed.
  305. if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
  306. } else {
  307. TOG_STATUS = !TOG_STATUS;
  308. #ifdef RGBLIGHT_ENABLE
  309. //rgblight_mode(RGBLIGHT_MODE_SNAKE);
  310. #endif
  311. }
  312. layer_on(_RAISE);
  313. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  314. } else {
  315. #ifdef RGBLIGHT_ENABLE
  316. //rgblight_mode(RGB_current_mode); // revert RGB to initial mode prior to RGB mode change
  317. #endif
  318. layer_off(_RAISE);
  319. TOG_STATUS = false;
  320. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  321. }
  322. return false;
  323. break;
  324. case FUNC:
  325. if (record->event.pressed) {
  326. layer_on(_FUNC);
  327. } else {
  328. layer_off(_FUNC);
  329. }
  330. return false;
  331. break;
  332. case ADJUST:
  333. if (record->event.pressed) {
  334. layer_on(_ADJUST);
  335. } else {
  336. layer_off(_ADJUST);
  337. }
  338. return false;
  339. break;
  340. //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
  341. case RGB_MOD:
  342. #ifdef RGBLIGHT_ENABLE
  343. if (record->event.pressed) {
  344. rgblight_mode(RGB_current_mode);
  345. rgblight_step();
  346. RGB_current_mode = rgblight_config.mode;
  347. }
  348. #endif
  349. return false;
  350. break;
  351. case EISU:
  352. if (record->event.pressed) {
  353. if(keymap_config.swap_lalt_lgui==false){
  354. register_code(KC_LANG2);
  355. }else{
  356. SEND_STRING(SS_LALT("`"));
  357. }
  358. } else {
  359. unregister_code(KC_LANG2);
  360. }
  361. return false;
  362. break;
  363. case KANA:
  364. if (record->event.pressed) {
  365. if(keymap_config.swap_lalt_lgui==false){
  366. register_code(KC_LANG1);
  367. }else{
  368. SEND_STRING(SS_LALT("`"));
  369. }
  370. } else {
  371. unregister_code(KC_LANG1);
  372. }
  373. return false;
  374. break;
  375. }
  376. return true;
  377. }
  378. void matrix_init_user(void) {
  379. #ifdef AUDIO_ENABLE
  380. startup_user();
  381. #endif
  382. #ifdef RGBLIGHT_ENABLE
  383. RGB_current_mode = rgblight_config.mode;
  384. #endif
  385. //SSD1306 OLED init, make sure to add #define SSD1306OLED in config.h
  386. #ifdef SSD1306OLED
  387. iota_gfx_init(!has_usb()); // turns on the display
  388. #endif
  389. }
  390. #ifdef AUDIO_ENABLE
  391. void startup_user()
  392. {
  393. _delay_ms(20); // gets rid of tick
  394. }
  395. void shutdown_user()
  396. {
  397. _delay_ms(150);
  398. stop_all_notes();
  399. }
  400. void music_on_user(void)
  401. {
  402. music_scale_user();
  403. }
  404. void music_scale_user(void)
  405. {
  406. PLAY_SONG(music_scale);
  407. }
  408. #endif
  409. //SSD1306 OLED update loop, make sure to add #define SSD1306OLED in config.h
  410. #ifdef SSD1306OLED
  411. // hook point for 'led_test' keymap
  412. // 'default' keymap's led_test_init() is empty function, do nothing
  413. // 'led_test' keymap's led_test_init() force rgblight_mode_noeeprom(RGBLIGHT_MODE_RGB_TEST);
  414. __attribute__ ((weak))
  415. void led_test_init(void) {}
  416. void matrix_scan_user(void) {
  417. led_test_init();
  418. iota_gfx_task(); // this is what updates the display continuously
  419. }
  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));
  424. dest->dirty = true;
  425. }
  426. }
  427. //assign the right code to your layers for OLED display
  428. #define L_BASE 0
  429. #define L_LOWER (1<<_LOWER)
  430. #define L_RAISE (1<<_RAISE)
  431. #define L_FUNC (1<<_FUNC)
  432. #define L_ADJUST (1<<_ADJUST)
  433. #define L_ADJUST_TRI (L_ADJUST|L_RAISE|L_LOWER)
  434. static void render_logo(struct CharacterMatrix *matrix) {
  435. static char logo[]={
  436. 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,
  437. 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,
  438. 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,
  439. 0};
  440. matrix_write(matrix, logo);
  441. //matrix_write_P(&matrix, PSTR(" Split keyboard kit"));
  442. }
  443. void render_status(struct CharacterMatrix *matrix) {
  444. // Render to mode icon
  445. static char logo[][2][3]={{{0x95,0x96,0},{0xb5,0xb6,0}},{{0x97,0x98,0},{0xb7,0xb8,0}}};
  446. if(keymap_config.swap_lalt_lgui==false){
  447. matrix_write(matrix, logo[0][0]);
  448. matrix_write_P(matrix, PSTR("\n"));
  449. matrix_write(matrix, logo[0][1]);
  450. }else{
  451. matrix_write(matrix, logo[1][0]);
  452. matrix_write_P(matrix, PSTR("\n"));
  453. matrix_write(matrix, logo[1][1]);
  454. }
  455. // 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
  456. char buf[40];
  457. snprintf(buf,sizeof(buf), "Undef-%ld", layer_state);
  458. matrix_write_P(matrix, PSTR("\nLayer: "));
  459. switch (layer_state) {
  460. case L_BASE:
  461. matrix_write_P(matrix, PSTR("Default"));
  462. break;
  463. case L_RAISE:
  464. matrix_write_P(matrix, PSTR("Raise"));
  465. break;
  466. case L_LOWER:
  467. matrix_write_P(matrix, PSTR("Lower"));
  468. break;
  469. case L_FUNC:
  470. matrix_write_P(matrix, PSTR("Func"));
  471. break;
  472. case L_ADJUST:
  473. case L_ADJUST_TRI:
  474. matrix_write_P(matrix, PSTR("Adjust"));
  475. break;
  476. default:
  477. matrix_write(matrix, buf);
  478. }
  479. // Host Keyboard LED Status
  480. char led[40];
  481. snprintf(led, sizeof(led), "\n%s %s %s",
  482. (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) ? "NUMLOCK" : " ",
  483. (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) ? "CAPS" : " ",
  484. (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) ? "SCLK" : " ");
  485. matrix_write(matrix, led);
  486. }
  487. void iota_gfx_task_user(void) {
  488. struct CharacterMatrix matrix;
  489. #if DEBUG_TO_SCREEN
  490. if (debug_enable) {
  491. return;
  492. }
  493. #endif
  494. matrix_clear(&matrix);
  495. if(is_master){
  496. render_status(&matrix);
  497. }else{
  498. render_logo(&matrix);
  499. }
  500. matrix_update(&display, &matrix);
  501. }
  502. #endif