2
0

keymap.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  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. #define DELAY_TIME 75
  20. static uint16_t key_timer;
  21. static uint16_t tap_timer;
  22. static uint16_t delay_registered_code;
  23. static uint8_t delay_mat_row;
  24. static uint8_t delay_mat_col;
  25. static bool delay_key_stat;
  26. static bool delay_key_pressed;
  27. static bool tapping_key;
  28. // Each layer gets a name for readability, which is then used in the keymap matrix below.
  29. // The underscores don't mean anything - you can have a layer called STUFF or any other name.
  30. // Layer names don't all need to be of the same length, obviously, and you can also skip them
  31. // entirely and just use numbers.
  32. #define _BASE 0
  33. #define _OPT 1
  34. #define _FUNC 2
  35. #define _SYM 3
  36. #define _NUM 4
  37. bool RGBAnimation = false; //Flag for LED Layer color Refresh.
  38. enum custom_keycodes {
  39. QWERTY = SAFE_RANGE,
  40. EISU,
  41. KANA,
  42. RGBRST,
  43. RGBOFF,
  44. RGB1,
  45. RGB2,
  46. RGB3,
  47. OPT_TAP_SP,
  48. DESKTOP,
  49. MAC,
  50. WIN,
  51. };
  52. enum macro_keycodes {
  53. KC_SAMPLEMACRO,
  54. };
  55. // Fillers to make layering more clear
  56. #define _______ KC_TRNS
  57. #define XXXXXXX KC_NO
  58. //Macros
  59. #define M_SAMPLE M(KC_SAMPLEMACRO)
  60. #if HELIX_ROWS == 5
  61. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  62. /* Base
  63. * ,-----------------------------------------. ,-----------------------------------------.
  64. * | C+z | ; | [ | ( | < | { | | | | | | | |
  65. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  66. * | KANA | P | K | R | A | F | | | | | | | |
  67. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  68. * | BS | D | T | H | E | O | | | | | | | |
  69. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  70. * | Shift| Y | S | N | I | U |Space | | | | | | | |
  71. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  72. * | Ctrl | Alt | Gui | Sym | Num | OPT | Ent | | | | | | | |
  73. * `-------------------------------------------------------------------------------------------------'
  74. */
  75. [_BASE] = LAYOUT( \
  76. LCTL(KC_Z), KC_SCLN, KC_LBRC, KC_LPRN, KC_LT, KC_LCBR, _______, _______, _______, _______, _______, _______, \
  77. KANA, KC_P, KC_K, KC_R, KC_A, KC_F, _______, _______, _______, _______, _______, _______, \
  78. KC_BSPC, KC_D, KC_T, KC_H, KC_E, KC_O, _______, _______, _______, _______, _______, _______, \
  79. OSM(MOD_LSFT), KC_Y, KC_S, KC_N, KC_I, KC_U, KC_SPC, _______, _______, _______, _______, _______, _______, _______, \
  80. OSM(MOD_LCTL), OSM(MOD_LALT), OSM(MOD_LGUI), MO(_SYM), MO(_NUM), OPT_TAP_SP, KC_ENT, _______, _______, _______, _______, _______, _______, _______ \
  81. ),
  82. /* Opt
  83. * ,-----------------------------------------. ,-----------------------------------------.
  84. * | Esc | : | ] | ) | > | } | | | | | | | |
  85. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  86. * | EISU| J | M | B | ' | Tab | | | | | | | |
  87. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  88. * | . | V | C | L | Z | Q | | | | | | | |
  89. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  90. * | | X | G | W | - | Del | Esc | | | | | | | |
  91. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  92. * | | | | , | DTOP | | | | | | | | | |
  93. * `-------------------------------------------------------------------------------------------------'
  94. */
  95. [_OPT] = LAYOUT( \
  96. KC_ESC, KC_COLN,KC_RBRC, KC_RPRN,KC_GT, KC_RCBR, _______, _______, _______, _______, _______, _______, \
  97. EISU, KC_J, KC_M, KC_B, KC_QUOT, KC_TAB, _______, _______, _______, _______, _______, _______, \
  98. KC_DOT, KC_V, KC_C, KC_L, KC_Z, KC_Q, _______, _______, _______, _______, _______, _______, \
  99. _______, KC_X, KC_G, KC_W, KC_MINUS, KC_DEL, KC_ESC, _______, _______, _______, _______, _______, _______, _______, \
  100. _______, _______,_______, KC_COMM,DESKTOP, _______, _______, _______, _______, _______, _______, _______, _______, _______ \
  101. ),
  102. /* Func
  103. * ,-----------------------------------------. ,-----------------------------------------.
  104. * |RGBRST| Hue | | RST | Mac | Win | | | | | | | |
  105. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  106. * | RGB1 | VAL+ | F7 | F8 | F9 | | | | | | | | |
  107. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  108. * | RGB2 | VAL- | F4 | F5 | F6 | F12 | | | | | | | |
  109. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  110. * | RGB3 | F10 | F1 | F2 | F3 | F11 | | | | | | | | |
  111. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  112. * |RGBOFF| | | | | | | | | | | | | |
  113. * `-------------------------------------------------------------------------------------------------'
  114. */
  115. [_FUNC] = LAYOUT( \
  116. RGBRST,RGB_HUI, _______, RESET, MAC, WIN, _______, _______, _______, _______, _______, _______, \
  117. RGB1, RGB_VAI, KC_F7, KC_F8, KC_F9, _______, _______, _______, _______, _______, _______, _______, \
  118. RGB2, RGB_VAD, KC_F4, KC_F5, KC_F6, KC_F12, _______, _______, _______, _______, _______, _______, \
  119. RGB3, KC_F10, KC_F1, KC_F2, KC_F3, KC_F11, _______, _______, _______, _______, _______, _______, _______, _______, \
  120. RGBOFF,_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ \
  121. ),
  122. /* Sym
  123. * ,-----------------------------------------. ,-----------------------------------------.
  124. * | Ins | GRV | | PU | PD | ^ | | | | | | | |
  125. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  126. * | | \ | # | = | ? | % | | | | | | | |
  127. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  128. * | | $ | upA | @ | ! | | | | | | | | | |
  129. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  130. * | CL | <- | dwA | -> | _ | & | | | | | | | | |
  131. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  132. * | | | PS | | ~ | | | | | | | | | |
  133. * `-------------------------------------------------------------------------------------------------'
  134. */
  135. [_SYM] = LAYOUT( \
  136. KC_INS, KC_GRV, _______, KC_PGUP, KC_PGDN, KC_CIRC, _______, _______, _______, _______, _______, _______, \
  137. _______, KC_BSLS, KC_HASH, KC_EQL, KC_QUES, KC_PERC, _______, _______, _______, _______, _______, _______, \
  138. _______, KC_DLR, KC_UP, KC_AT, KC_EXLM, KC_PIPE, _______, _______, _______, _______, _______, _______, \
  139. KC_CAPS, KC_LEFT, KC_DOWN, KC_RIGHT,KC_UNDS, KC_AMPR, _______, _______, _______, _______, _______, _______, _______, _______, \
  140. _______, _______, KC_PSCR, _______, KC_TILD, _______, _______, _______, _______, _______, _______, _______, _______, _______ \
  141. ),
  142. /* Raise
  143. * ,-----------------------------------------. ,-----------------------------------------.
  144. * | | | Func | home | End | | | | | | | | |
  145. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  146. * | | * | 7 | 8 | 9 | - | | | | | | | |
  147. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  148. * | . | / | 4 | 5 | 6 | + | | | | | | | |
  149. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  150. * | LN | 0 | 1 | 2 | 3 |C+S+F1| | | | | | | | |
  151. * |------+------+------+------+------+------+------+------+------+------+------+------+------+------|
  152. * | | | | , | | | | | | | | | | |
  153. * `-------------------------------------------------------------------------------------------------'
  154. */
  155. [_NUM] = LAYOUT( \
  156. _______, _______, OSL(_FUNC), KC_HOME, KC_END, _______, _______, _______, _______, _______, _______, _______, \
  157. _______, KC_ASTR, KC_P7, KC_P8, KC_P9, KC_MINS, _______, _______, _______, _______, _______, _______, \
  158. KC_PDOT, KC_SLSH, KC_P4, KC_P5, KC_P6, KC_PLUS, _______, _______, _______, _______, _______, _______, \
  159. KC_NLCK, KC_P0, KC_P1, KC_P2, KC_P3, LCTL(S(KC_F1)), _______, _______, _______, _______, _______, _______, _______, _______, \
  160. _______, _______, KC_PDOT, KC_COMM, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ \
  161. )
  162. };
  163. #else
  164. #error "undefined keymaps"
  165. #endif
  166. #ifdef AUDIO_ENABLE
  167. float tone_qwerty[][2] = SONG(QWERTY_SOUND);
  168. float tone_dvorak[][2] = SONG(DVORAK_SOUND);
  169. float tone_colemak[][2] = SONG(COLEMAK_SOUND);
  170. float tone_plover[][2] = SONG(PLOVER_SOUND);
  171. float tone_plover_gb[][2] = SONG(PLOVER_GOODBYE_SOUND);
  172. float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
  173. #endif
  174. // define variables for reactive RGB
  175. //bool TOG_STATUS = false;
  176. int RGB_current_mode;
  177. void persistent_default_layer_set(uint16_t default_layer) {
  178. eeconfig_update_default_layer(default_layer);
  179. default_layer_set(default_layer);
  180. }
  181. bool find_mairix(uint16_t keycode, uint8_t *row, uint8_t *col){
  182. for(uint8_t i=0; i<MATRIX_ROWS; i++){
  183. for(uint8_t j=0; j<MATRIX_COLS; j++){
  184. if( pgm_read_word(&(keymaps[_BASE][i][j]))==keycode){
  185. *row = i;
  186. *col = j;
  187. return true;
  188. }
  189. }
  190. }
  191. return false;
  192. }
  193. void unregister_delay_code(void){
  194. if(delay_registered_code){
  195. unregister_code(delay_registered_code);
  196. if (delay_registered_code & QK_LSFT){
  197. unregister_code(KC_LSFT);
  198. }
  199. if (delay_registered_code & QK_LCTL){
  200. unregister_code(KC_LCTL);
  201. }
  202. if (delay_registered_code & QK_LALT){
  203. unregister_code(KC_LALT);
  204. }
  205. if (delay_registered_code & QK_LGUI){
  206. unregister_code(KC_LGUI);
  207. }
  208. delay_registered_code=0;
  209. }
  210. }
  211. void register_delay_code(uint8_t layer){
  212. if(delay_key_stat){
  213. unregister_delay_code();
  214. uint16_t code = pgm_read_word(&(keymaps[layer][delay_mat_row][delay_mat_col]));
  215. if (code & QK_LSFT){
  216. register_code(KC_LSFT);
  217. }
  218. if (code & QK_LCTL){
  219. register_code(KC_LCTL);
  220. }
  221. if (code & QK_LALT){
  222. register_code(KC_LALT);
  223. }
  224. if (code & QK_LGUI){
  225. register_code(KC_LGUI);
  226. }
  227. register_code(code);
  228. delay_registered_code = code;
  229. delay_key_stat = false;
  230. tapping_key = true;
  231. }
  232. }
  233. #ifdef RGBLIGHT_ENABLE
  234. struct keybuf {
  235. char col, row;
  236. char frame;
  237. };
  238. struct keybuf keybufs[256];
  239. unsigned char keybuf_begin, keybuf_end;
  240. int col, row;
  241. #endif
  242. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  243. #ifdef RGBLIGHT_ENABLE
  244. col = record->event.key.col;
  245. row = record->event.key.row;
  246. if (record->event.pressed && ((row < 5 && is_master) || (row >= 5 && !is_master))) {
  247. int end = keybuf_end;
  248. keybufs[end].col = col;
  249. keybufs[end].row = row % 5;
  250. keybufs[end].frame = 0;
  251. keybuf_end ++;
  252. }
  253. #endif
  254. if(tap_timer&&keycode!=OPT_TAP_SP){
  255. tapping_key = true;
  256. }
  257. if(keycode==delay_registered_code){
  258. if (!record->event.pressed){
  259. unregister_delay_code();
  260. }
  261. }
  262. switch (keycode) {
  263. case KC_SCLN:
  264. case KC_LBRC:
  265. case KC_LPRN:
  266. case KC_LT:
  267. case KC_LCBR:
  268. case KC_P:
  269. case KC_K:
  270. case KC_R:
  271. case KC_A:
  272. case KC_F:
  273. case KC_BSPC:
  274. case KC_D:
  275. case KC_T:
  276. case KC_H:
  277. case KC_E:
  278. case KC_O:
  279. case KC_Y:
  280. case KC_S:
  281. case KC_N:
  282. case KC_I:
  283. case KC_U:
  284. case LCTL(KC_Z):
  285. case KC_SPC:
  286. if (record->event.pressed) {
  287. register_delay_code(_BASE);
  288. if(find_mairix(keycode, &delay_mat_row, &delay_mat_col)){
  289. key_timer = timer_read();
  290. delay_key_stat = true;
  291. delay_key_pressed = true;
  292. }
  293. }else{
  294. delay_key_pressed = false;
  295. }
  296. return false;
  297. break;
  298. case OPT_TAP_SP:
  299. if (record->event.pressed) {
  300. tapping_key = false;
  301. register_delay_code(_OPT);
  302. layer_on(_OPT);
  303. tap_timer = timer_read();
  304. }else{
  305. layer_off(_OPT);
  306. if(tapping_key==false && timer_elapsed(tap_timer) < TAPPING_TERM){
  307. SEND_STRING(" ");
  308. }
  309. tap_timer = 0;
  310. }
  311. return false;
  312. break;
  313. case EISU:
  314. if (record->event.pressed) {
  315. if(keymap_config.swap_lalt_lgui==false){
  316. register_code(KC_LANG2);
  317. }else{
  318. SEND_STRING(SS_LALT("`"));
  319. }
  320. } else {
  321. unregister_code(KC_LANG2);
  322. }
  323. return false;
  324. break;
  325. case KANA:
  326. if (record->event.pressed) {
  327. if(keymap_config.swap_lalt_lgui==false){
  328. register_code(KC_LANG1);
  329. }else{
  330. SEND_STRING(SS_LALT("`"));
  331. }
  332. } else {
  333. unregister_code(KC_LANG1);
  334. }
  335. return false;
  336. break;
  337. case DESKTOP:
  338. if (record->event.pressed) {
  339. if(keymap_config.swap_lalt_lgui==false){
  340. register_code(KC_F11);
  341. }else{
  342. SEND_STRING(SS_LGUI("d"));
  343. }
  344. } else {
  345. unregister_code(KC_F11);
  346. }
  347. return false;
  348. break;
  349. case RGBRST:
  350. #ifdef RGBLIGHT_ENABLE
  351. if (record->event.pressed) {
  352. eeconfig_update_rgblight_default();
  353. rgblight_enable();
  354. RGB_current_mode = rgblight_config.mode;
  355. RGBAnimation = false;
  356. }
  357. #endif
  358. break;
  359. case RGBOFF:
  360. #ifdef RGBLIGHT_ENABLE
  361. if (record->event.pressed) {
  362. rgblight_disable();
  363. }
  364. #endif
  365. break;
  366. case RGB1:
  367. #ifdef RGBLIGHT_ENABLE
  368. if (record->event.pressed) {
  369. RGBAnimation = true;
  370. rgblight_mode(RGBLIGHT_MODE_RAINBOW_MOOD);
  371. RGB_current_mode = rgblight_config.mode;
  372. }
  373. #endif
  374. break;
  375. case RGB2:
  376. #ifdef RGBLIGHT_ENABLE
  377. if (record->event.pressed) {
  378. RGBAnimation = true;
  379. rgblight_mode(RGBLIGHT_MODE_RAINBOW_SWIRL + 1);
  380. RGB_current_mode = rgblight_config.mode;
  381. }
  382. #endif
  383. break;
  384. case RGB3:
  385. #ifdef RGBLIGHT_ENABLE
  386. if (record->event.pressed) {
  387. RGBAnimation = true;
  388. rgblight_mode(RGBLIGHT_MODE_KNIGHT);
  389. RGB_current_mode = rgblight_config.mode;
  390. }
  391. #endif
  392. break;
  393. case MAC:
  394. if (record->event.pressed) {
  395. keymap_config.swap_lalt_lgui = false;
  396. keymap_config.swap_ralt_rgui = false;
  397. #ifdef AUDIO_ENABLE
  398. PLAY_SONG(ag_norm_song);
  399. #endif
  400. }
  401. break;
  402. case WIN:
  403. if (record->event.pressed) {
  404. keymap_config.swap_lalt_lgui = true;
  405. keymap_config.swap_ralt_rgui = true;
  406. #ifdef AUDIO_ENABLE
  407. PLAY_SONG(ag_swap_song);
  408. #endif
  409. }
  410. break;
  411. }
  412. return true;
  413. }
  414. //keyboard start-up code. Runs once when the firmware starts up.
  415. void matrix_init_user(void) {
  416. #ifdef AUDIO_ENABLE
  417. startup_user();
  418. #endif
  419. #ifdef RGBLIGHT_ENABLE
  420. RGB_current_mode = rgblight_config.mode;
  421. #endif
  422. //SSD1306 OLED init, make sure to add #define SSD1306OLED in config.h
  423. #ifdef SSD1306OLED
  424. iota_gfx_init(!has_usb()); // turns on the display
  425. #endif
  426. }
  427. #ifdef AUDIO_ENABLE
  428. void startup_user()
  429. {
  430. _delay_ms(20); // gets rid of tick
  431. }
  432. void shutdown_user()
  433. {
  434. _delay_ms(150);
  435. stop_all_notes();
  436. }
  437. void music_on_user(void)
  438. {
  439. music_scale_user();
  440. }
  441. void music_scale_user(void)
  442. {
  443. PLAY_SONG(music_scale);
  444. }
  445. #endif
  446. //assign the right code to your layers for OLED display
  447. #define L_BASE 0
  448. #define L_OPT 2
  449. #define L_FUNC 4
  450. #define L_SYM 8
  451. #define L_NUM 16
  452. #define L_FNLAYER 64
  453. #define L_NUMLAY 128
  454. #define L_NLOWER 136
  455. #define L_NFNLAYER 192
  456. #define L_MOUSECURSOR 256
  457. // LED Effect
  458. #ifdef RGBLIGHT_ENABLE
  459. unsigned char rgb[7][5][3];
  460. void led_ripple_effect(char r, char g, char b) {
  461. static int scan_count = -10;
  462. static int keys[] = { 6, 6, 6, 7, 7 };
  463. static int keys_sum[] = { 0, 6, 12, 18, 25 };
  464. if (scan_count == -1) {
  465. rgblight_enable_noeeprom();
  466. rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT);
  467. } else if (scan_count >= 0 && scan_count < 5) {
  468. for (unsigned char c=keybuf_begin; c!=keybuf_end; c++) {
  469. int i = c;
  470. // FIXME:
  471. int y = scan_count;
  472. int dist_y = abs(y - keybufs[i].row);
  473. for (int x=0; x<keys[y]; x++) {
  474. int dist = abs(x - keybufs[i].col) + dist_y;
  475. if (dist <= keybufs[i].frame) {
  476. int elevation = MAX(0, (8 + dist - keybufs[i].frame)) << 2;
  477. if (elevation) {
  478. if ((rgb[x][y][0] != 255) && r) { rgb[x][y][0] = MIN(255, elevation + rgb[x][y][0]); }
  479. if ((rgb[x][y][1] != 255) && g) { rgb[x][y][1] = MIN(255, elevation + rgb[x][y][1]); }
  480. if ((rgb[x][y][2] != 255) && b) { rgb[x][y][2] = MIN(255, elevation + rgb[x][y][2]); }
  481. }
  482. }
  483. }
  484. }
  485. } else if (scan_count == 5) {
  486. for (unsigned char c=keybuf_begin; c!=keybuf_end; c++) {
  487. int i = c;
  488. if (keybufs[i].frame < 18) {
  489. keybufs[i].frame ++;
  490. } else {
  491. keybuf_begin ++;
  492. }
  493. }
  494. } else if (scan_count >= 6 && scan_count <= 10) {
  495. int y = scan_count - 6;
  496. for (int x=0; x<keys[y]; x++) {
  497. int at = keys_sum[y] + ((y & 1) ? x : (keys[y] - x - 1));
  498. led[at].r = rgb[x][y][0];
  499. led[at].g = rgb[x][y][1];
  500. led[at].b = rgb[x][y][2];
  501. }
  502. rgblight_set();
  503. } else if (scan_count == 11) {
  504. memset(rgb, 0, sizeof(rgb));
  505. }
  506. scan_count++;
  507. if (scan_count >= 12) { scan_count = 0; }
  508. }
  509. #endif
  510. uint8_t layer_state_old;
  511. //runs every scan cycle (a lot)
  512. void matrix_scan_user(void) {
  513. #ifdef SSD1306OLED
  514. iota_gfx_task(); // this is what updates the display continuously
  515. #endif
  516. if(delay_key_stat && (timer_elapsed(key_timer) > DELAY_TIME)){
  517. register_delay_code(_BASE);
  518. if(!delay_key_pressed){
  519. unregister_delay_code();
  520. }
  521. }
  522. if(layer_state_old != layer_state){
  523. switch (layer_state) {
  524. case L_BASE:
  525. break;
  526. case L_OPT:
  527. register_delay_code(_OPT);
  528. break;
  529. case L_NUM:
  530. register_delay_code(_NUM);
  531. break;
  532. case L_SYM:
  533. register_delay_code(_SYM);
  534. break;
  535. case L_FUNC:
  536. register_delay_code(_FUNC);
  537. break;
  538. }
  539. layer_state_old = layer_state;
  540. }
  541. #ifdef RGBLIGHT_ENABLE
  542. if(!RGBAnimation){
  543. switch (layer_state) {
  544. case L_BASE:
  545. #ifdef RGBLED_BACK
  546. led_ripple_effect(0,112,127);
  547. #else
  548. rgblight_setrgb(0,112,127);
  549. #endif
  550. break;
  551. case L_OPT:
  552. #ifdef RGBLED_BACK
  553. led_ripple_effect(127,0,100);
  554. #else
  555. rgblight_setrgb(127,0,100);
  556. #endif
  557. break;
  558. case L_NUM:
  559. #ifdef RGBLED_BACK
  560. led_ripple_effect(127,23,0);
  561. #else
  562. rgblight_setrgb(127,23,0);
  563. #endif
  564. break;
  565. case L_SYM:
  566. #ifdef RGBLED_BACK
  567. led_ripple_effect(0,127,0);
  568. #else
  569. rgblight_setrgb(0,127,0);
  570. #endif
  571. break;
  572. case L_FUNC:
  573. #ifdef RGBLED_BACK
  574. led_ripple_effect(127,0,61);
  575. #else
  576. rgblight_setrgb(127,0,61);
  577. #endif
  578. break;
  579. }
  580. }
  581. #endif
  582. }
  583. //SSD1306 OLED update loop, make sure to add #define SSD1306OLED in config.h
  584. #ifdef SSD1306OLED
  585. void matrix_update(struct CharacterMatrix *dest,
  586. const struct CharacterMatrix *source) {
  587. if (memcmp(dest->display, source->display, sizeof(dest->display))) {
  588. memcpy(dest->display, source->display, sizeof(dest->display));
  589. dest->dirty = true;
  590. }
  591. }
  592. // Render to OLED
  593. void render_status(struct CharacterMatrix *matrix) {
  594. // froggy logo
  595. static char logo[4][1][17]=
  596. {
  597. {
  598. {0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0x73,0x74,0}
  599. },
  600. {
  601. {0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,0}
  602. },
  603. {
  604. {0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,0}
  605. },
  606. {
  607. {0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0}
  608. }
  609. };
  610. static char indctr[8][2][4]=
  611. {
  612. // white icon
  613. {
  614. {0x60,0x61,0x62,0},
  615. {0x63,0x64,0}
  616. },
  617. {
  618. {0x80,0x81,0x82,0},
  619. {0x83,0x84,0}
  620. },
  621. {
  622. {0xa0,0xa1,0xa2,0},
  623. {0xa3,0xa4,0}
  624. },
  625. {
  626. {0xc0,0xc1,0xc2,0},
  627. {0xc3,0xc4,0}
  628. },
  629. // Black icon
  630. {
  631. {0x75,0x76,0x77,0},
  632. {0x78,0x79,0}
  633. },
  634. {
  635. {0x95,0x96,0x97,0},
  636. {0x98,0x99,0}
  637. },
  638. {
  639. {0xb5,0xb6,0xb7,0},
  640. {0xb8,0xb9,0}
  641. },
  642. {
  643. {0xd5,0xd6,0xd7,0},
  644. {0xd8,0xd9,0}
  645. },
  646. };
  647. int rown = 0;
  648. int rowf = 0;
  649. int rowa = 0;
  650. int rows = 0;
  651. //Set Indicator icon
  652. if (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) { rown = 4; } else { rown = 0; }
  653. if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) { rowa = 4; } else { rowa = 0; }
  654. if (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) { rows = 4; } else { rows = 0; }
  655. if (layer_state == L_FUNC) { rowf = 4; }
  656. matrix_write(matrix, indctr[rown] [0]);
  657. matrix_write(matrix, indctr[rowf] [1]);
  658. matrix_write(matrix, logo [0] [0]);
  659. matrix_write(matrix, indctr[rown+1][0]);
  660. matrix_write(matrix, indctr[rowf+1][1]);
  661. matrix_write(matrix, logo [1] [0]);
  662. matrix_write(matrix, indctr[rowa+2][0]);
  663. matrix_write(matrix, indctr[rows+2][1]);
  664. matrix_write(matrix, logo [2] [0]);
  665. matrix_write(matrix, indctr[rowa+3][0]);
  666. matrix_write(matrix, indctr[rows+3][1]);
  667. matrix_write(matrix, logo [3] [0]);
  668. }
  669. void iota_gfx_task_user(void) {
  670. struct CharacterMatrix matrix;
  671. #if DEBUG_TO_SCREEN
  672. if (debug_enable) {
  673. return;
  674. }
  675. #endif
  676. matrix_clear(&matrix);
  677. if(is_master){
  678. render_status(&matrix);
  679. }
  680. matrix_update(&display, &matrix);
  681. }
  682. #endif