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.

197 lines
9.6 KiB

  1. /*
  2. Copyright 2021 0xCB - Conor Burns
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include QMK_KEYBOARD_H
  15. // clang-format off
  16. enum layer_names {
  17. _HOME,
  18. _FN2,
  19. _FN3,
  20. _FN4
  21. };
  22. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  23. [_HOME] = LAYOUT_all(
  24. KC_MPLY,
  25. KC_GESC, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
  26. KC_TAB, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_ENT,
  27. KC_LSPO, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_RSPC,
  28. KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_SPC, KC_SPC, KC_RALT, MO(1), MO(2)
  29. ),
  30. [_FN2] = LAYOUT_all(
  31. RESET,
  32. KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL,
  33. KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, _______,
  34. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  35. _______, _______, _______, _______, _______, _______, _______, _______, _______
  36. ),
  37. [_FN3] = LAYOUT_all(
  38. EEP_RST,
  39. _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_LBRC, KC_RBRC, KC_BSLS,
  40. _______, _______, _______, _______, _______, _______, _______, _______, KC_SCLN, KC_QUOT, _______,
  41. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_SLSH,
  42. _______, _______, _______, _______, _______, _______, _______, _______, _______
  43. ),
  44. [_FN4] = LAYOUT_all(
  45. _______,
  46. _______, KC_MUTE, KC_VOLD, KC_VOLU, KC_MPRV, KC_MNXT, KC_MSTP, KC_INS, KC_HOME, KC_DEL, KC_END, _______,
  47. _______, _______, KC_BRID, KC_BRIU, _______, _______, _______, KC_PGUP, KC_UP, KC_PGDN, _______,
  48. _______, _______, _______, _______, _______, _______, _______, KC_LEFT, KC_DOWN, KC_RGHT, _______,
  49. _______, _______, _______, _______, _______, _______, _______, _______, _______
  50. ),
  51. };
  52. // clang-format on
  53. /*layer switcher */
  54. layer_state_t layer_state_set_user(layer_state_t state) {
  55. state = update_tri_layer_state(state, _FN2, _FN3, _FN4);
  56. return state;
  57. }
  58. /* rotary encoder (MX12) - add different functions for layers here */
  59. #ifdef ENCODER_ENABLE
  60. bool encoder_update_user(uint8_t index, bool clockwise) {
  61. if (IS_LAYER_ON(_FN4)) {
  62. if (clockwise) {
  63. tap_code(KC_VOLU);
  64. } else {
  65. tap_code(KC_VOLD);
  66. }
  67. } else if (IS_LAYER_ON(_FN3)) {
  68. if (clockwise) {
  69. tap_code(KC_VOLU);
  70. } else {
  71. tap_code(KC_VOLD);
  72. }
  73. } else if (IS_LAYER_ON(_FN2)) {
  74. if (clockwise) {
  75. tap_code(KC_VOLU);
  76. } else {
  77. tap_code(KC_VOLD);
  78. }
  79. } else {
  80. if (clockwise) {
  81. tap_code(KC_VOLU);
  82. } else {
  83. tap_code(KC_VOLD);
  84. }
  85. }
  86. return true;
  87. }
  88. #endif
  89. /* oled stuff :) */
  90. #ifdef OLED_ENABLE
  91. uint16_t startup_timer = 0;
  92. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  93. startup_timer = timer_read();
  94. return rotation;
  95. }
  96. static void render_logo(void) {
  97. static const char PROGMEM raw_logo[] = {
  98. 0, 8, 0,192,194,192,192, 60, 60, 44, 60,188, 60, 60, 60, 60, 44, 61, 60,192,192,192,208, 1, 0,252,252,180,252, 60, 60, 44, 60,252,253,252,252, 60, 60, 44, 60,244,220,252,252, 0, 0, 16, 0, 0, 0,192,192, 65,192, 60, 60, 52, 60,192,193,192,192, 16, 0, 0,144, 4, 0,252,125,244, 60, 60, 60, 60, 61,252,252,244,252, 60, 60, 60, 61,248,108,252, 0, 0, 61, 60,188, 60, 52,252,252,220,252, 61, 60, 60, 52, 0, 0,192,210, 64,192, 60, 60, 44, 61, 60, 60, 60, 61, 52, 60, 60, 60,192,192, 64,196, 0, 4, 0,
  99. 0, 16, 0, 61, 63, 55, 63,192, 64,192,196,192,192,192,200,192,196,192,192, 3, 3, 2, 11, 0, 0, 35, 3, 3, 3, 0, 64, 2, 0,255,255,253,247, 0, 0, 0, 32, 1, 0, 1, 65, 8, 0,189,244,252,236, 3,130, 3, 1, 0, 68, 0, 0, 3, 34,131, 3,252,252,236,252, 0, 32, 17, 1, 1, 0, 0, 32, 0, 2,255,255,127,247, 0, 1, 0, 8, 1, 1, 1, 0, 0, 0, 16, 0, 64, 0,255,191,255,251, 0,129, 0, 2, 32, 0,255,255,239,255, 0, 0, 2, 0, 0, 0, 8, 64, 0, 1, 0, 0, 3, 35, 3, 3, 0, 8, 0,
  100. 1, 16, 0,192, 64,194,192, 3, 67, 3, 3, 9, 3, 3, 3, 3, 2, 83, 3,252,252,188,244, 0, 2, 32, 0, 0, 2, 0,144, 0, 0,255,255,237,255, 0, 16, 0, 0, 0, 64, 2, 0,128, 0,255,123,255,255, 60, 52, 60, 60, 60, 60, 60, 60, 44, 60, 56, 60,239,255,126,255, 0, 2, 32, 0, 0, 34, 0, 0, 16, 0,255,255,255,223, 0, 0, 4, 0, 0, 0, 33, 0, 0, 17, 0, 0, 0, 0,255,255,239,255, 0,128, 0, 0, 72, 0,255,253,247,255, 0, 0, 1, 0,144, 0, 4, 0, 32, 0, 0, 2,192,192,192,200, 0, 16, 0,
  101. 64, 4, 0, 3, 7, 3, 3, 60, 60, 52,188, 60, 61, 60, 60, 60, 60, 44, 60, 67, 3, 3, 3, 0, 0, 64, 0, 0, 4, 0, 0, 16, 0, 47, 63, 62, 63, 0, 0,132, 0, 0, 0, 0,128, 8, 0,255,255,111,127, 0, 0, 0, 2,128, 0, 0, 0, 64, 4, 0,128,127,127,107,127, 0, 32, 0, 0, 0, 66, 0, 0, 0,136, 55, 63, 61, 63, 0, 0, 0, 2, 0, 64, 0,136, 0, 0, 60, 44,189, 60, 63, 63, 63, 59, 60, 60,172, 60, 0, 64, 3, 2, 3,131, 60, 44, 60, 60, 60, 60,188, 60, 56, 44, 60, 60, 3, 3,131, 2, 0, 32, 2,
  102. };
  103. oled_write_raw_P(raw_logo, sizeof(raw_logo));
  104. }
  105. /* Shows the name of the current layer and locks for the host (CAPS etc.) */
  106. static void render_layer(void) {
  107. led_t led_state = host_keyboard_led_state();
  108. // clang-format off
  109. static const char PROGMEM logo[][3][7] = {
  110. {{0x97, 0x98, 0x99, 0x9A, 0}, {0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0}, {0x9B, 0x9C, 0x9D, 0x9E, 0x9F, 0}}, /* l num CB */
  111. {{0xB7, 0xB8, 0xB9, 0xBA, 0}, {0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0}, {0xBB, 0xBC, 0xBD, 0xBE, 0xBF, 0}}, /* 1 num CB */
  112. {{0xD7, 0xD8, 0xD9, 0xDA, 0}, {0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0}, {0xDB, 0xDC, 0xDD, 0xDE, 0xDF, 0}}, /* 1 cap CB */
  113. {{0xF7, 0xF8, 0xF9, 0xFA, 0}, {0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0}, {0xFB, 0xFC, 0xFD, 0xFE, 0xFF, 0}}, /* l cap CB */
  114. {{0xB7, 0xC0, 0xC1, 0xBA, 0}, {0xB7, 0xC2, 0xC3, 0xBA, 0}, {0xB7, 0xC4, 0xC5, 0xBA, 0}}, /* 2 3 4 */
  115. {{0xD7, 0xE0, 0xE1, 0xDA, 0}, {0xD7, 0xE2, 0xE3, 0xDA, 0}, {0xD7, 0xE4, 0xE5, 0xDA, 0}}, /* 2 3 4 */
  116. };
  117. // clang-format on
  118. oled_set_cursor(0, 0);
  119. oled_write_P(logo[0][0], false);
  120. oled_set_cursor(0, 3);
  121. oled_write_P(logo[3][0], false);
  122. switch (get_highest_layer(layer_state)) {
  123. case _HOME:
  124. oled_set_cursor(0, 1);
  125. oled_write_P(logo[1][0], false);
  126. oled_set_cursor(0, 2);
  127. oled_write_P(logo[2][0], false);
  128. break;
  129. case _FN2:
  130. oled_set_cursor(0, 1);
  131. oled_write_P(logo[4][0], false);
  132. oled_set_cursor(0, 2);
  133. oled_write_P(logo[5][0], false);
  134. break;
  135. case _FN3:
  136. oled_set_cursor(0, 1);
  137. oled_write_P(logo[4][1], false);
  138. oled_set_cursor(0, 2);
  139. oled_write_P(logo[5][1], false);
  140. break;
  141. case _FN4:
  142. oled_set_cursor(0, 1);
  143. oled_write_P(logo[4][2], false);
  144. oled_set_cursor(0, 2);
  145. oled_write_P(logo[5][2], false);
  146. break;
  147. default:
  148. oled_set_cursor(0, 1);
  149. oled_write_P(PSTR(" "), false);
  150. oled_set_cursor(0, 2);
  151. oled_write_P(PSTR(" "), false);
  152. }
  153. oled_set_cursor(8, 0);
  154. oled_write_P(led_state.num_lock ? logo[0][1] : PSTR(" "), false);
  155. oled_set_cursor(8, 1);
  156. oled_write_P(led_state.num_lock ? logo[1][1] : PSTR(" "), false);
  157. oled_set_cursor(8, 2);
  158. oled_write_P(led_state.caps_lock ? logo[2][1] : PSTR(" "), false);
  159. oled_set_cursor(8, 3);
  160. oled_write_P(led_state.caps_lock ? logo[3][1] : PSTR(" "), false);
  161. oled_set_cursor(16, 0);
  162. oled_write_P(logo[0][2], false);
  163. oled_set_cursor(16, 1);
  164. oled_write_P(logo[1][2], false);
  165. oled_set_cursor(16, 2);
  166. oled_write_P(logo[2][2], false);
  167. oled_set_cursor(16, 3);
  168. oled_write_P(logo[3][2], false);
  169. }
  170. void oled_task_user(void) {
  171. static bool finished_timer = false;
  172. if (!finished_timer && (timer_elapsed(startup_timer) < 3000)) {
  173. render_logo();
  174. } else {
  175. if (!finished_timer) {
  176. oled_clear();
  177. finished_timer = true;
  178. }
  179. render_layer();
  180. }
  181. }
  182. #endif
  183. /* Resets via on eep reset - thank you drashna! */
  184. void eeconfig_init_kb(void) {
  185. via_eeprom_set_valid(false);
  186. via_init();
  187. eeconfig_init_user();
  188. }