2
0

keymap.c 24 KB

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