You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

742 lines
24 KiB

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