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.

454 lines
24 KiB

  1. /* Copyright 2021 adpenrose
  2. *
  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. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include QMK_KEYBOARD_H
  17. /* Base layout:
  18. * ,---------------------------------------------------------------------|
  19. * |` |1 |2 |3 |4 |5 |6 |7 |8 |9 |0 |- |= |Backspace| OLED|
  20. * |--------------------------------------------------------------- |
  21. * |Tab |Q |W |E |R |T |Y |U |I |O |P |[ | ] | \ OLED|
  22. * |---------------------------------------------------------------------|
  23. * |Caps |A |S |D |F |G |H |J |K |L |; |' | Enter | ENC |
  24. * |---------------------------------------------------------------------|
  25. * |Shft |Z |X |C |V |B |N |M |, |. |/ |Shift |Up| M1 |
  26. * |---------------------------------------------------------------------|
  27. * |Ctrl|GUI |Alt | Space |MO(2) |MO(3)| |Lt |Dn |Rt |
  28. * `---------------------------------------------------------------------|'
  29. */
  30. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  31. /* Base */
  32. [0] = LAYOUT_65_ansi_blocker(
  33. KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC,
  34. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS,
  35. KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_MUTE,
  36. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_DEL,
  37. KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, MO(2), MO(3), KC_LEFT, KC_DOWN, KC_RIGHT
  38. ),
  39. [1] = LAYOUT_65_ansi_blocker(
  40. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  41. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  42. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  43. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  44. _______, _______, _______, _______, _______, _______, _______, _______, _______
  45. ),
  46. [2] = LAYOUT_65_ansi_blocker(
  47. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  48. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  49. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  50. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  51. _______, _______, _______, _______, _______, _______, _______, _______, _______
  52. ),
  53. [3] = LAYOUT_65_ansi_blocker(
  54. _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______,
  55. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  56. QK_BOOT, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_MPLY,
  57. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  58. _______, _______, _______, _______, _______, _______, _______, _______, _______
  59. ),
  60. };
  61. /* Encoder */
  62. #ifdef ENCODER_ENABLE
  63. bool encoder_update_user(uint8_t index, bool clockwise) {
  64. /* Used to change the layer using the encoder. */
  65. static int8_t selected_layer = 0;
  66. if (clockwise){
  67. /* Check if left shift is pressed: */
  68. if (selected_layer < 4 && get_mods() & MOD_BIT(KC_LSFT)){
  69. selected_layer ++;
  70. /* If already on the last layer, jumps back to the first layer: */
  71. if (selected_layer == 4) {
  72. selected_layer = 0;
  73. }
  74. /* Move to the selected layer. */
  75. layer_move(selected_layer);
  76. } else if (get_mods() & MOD_BIT(KC_RSFT)){ /* Check if right shift is pressed: */
  77. switch (get_highest_layer(layer_state)){
  78. default:
  79. /* Go to the next track. */
  80. tap_code(KC_MNXT);
  81. break;
  82. }
  83. } else {
  84. /* If shift isn't pressed, encoder will do this stuff: */
  85. switch (get_highest_layer(layer_state)){
  86. default:
  87. /* Turn up the volume of the system. */
  88. tap_code(KC_VOLU);
  89. break;
  90. }
  91. }
  92. } else {
  93. /* Check if left shift is pressed: */
  94. if (selected_layer > -1 && get_mods() & MOD_BIT(KC_LSFT)){
  95. selected_layer --;
  96. /* If already on the first layer, jumps up to the last layer: */
  97. if (selected_layer == -1) {
  98. selected_layer = 3;
  99. }
  100. /* Move to the selected layer. */
  101. layer_move(selected_layer);
  102. } else if (get_mods() & MOD_BIT(KC_RSFT)){ /* Check if right shift is pressed: */
  103. switch (get_highest_layer(layer_state)){
  104. default:
  105. /* Go to the previous track. */
  106. tap_code(KC_MPRV);
  107. break;
  108. }
  109. } else {
  110. /* If shift isn't pressed, encoder will do this stuff: */
  111. switch (get_highest_layer(layer_state)){
  112. default:
  113. /* Turn down the volume of the system. */
  114. tap_code(KC_VOLD);
  115. break;
  116. }
  117. }
  118. }
  119. return false;
  120. }
  121. #endif
  122. #ifdef OLED_ENABLE
  123. /*=========================================== OLED CONFIGURATION ===========================================*/
  124. bool oled_horizontal = true; // OLED rotation (true = horizontal, false = vertical)
  125. bool graph_direction = false; // Graph movement (true = right to left, false = left to right)
  126. float graph_top_wpm = 100.0; // Minimum WPM required to reach the top of the graph
  127. int graph_refresh = 1000; // In milliseconds, determines the graph-line frequency
  128. int icon_med_wpm = 50; // WPM required to display the medium snail
  129. int icon_fast_wpm = 72; // WPM required to display the fast snail
  130. // Layer names: Should be exactly 5 characters in length if vertical display, or 6 characters if horizontal
  131. #define MA_LAYER_NAME "QWRTY" // Layer 0 name
  132. #define L1_LAYER_NAME "KICAD" // Layer 1 name
  133. #define L2_LAYER_NAME "NMPAD" // Layer 2 name
  134. #define L3_LAYER_NAME "FUNCT" // Layer 3 name
  135. // Constants required for the background render, the graph render and the WPM counter. THESE VALUES SHOULD NOT BE CHANGED.
  136. bool first_loop = true;
  137. int timer = 0;
  138. int wpm_limit = 20;
  139. int max_wpm = -1;
  140. int wpm_icon = -1;
  141. int graph_lines[65];
  142. /*================================================================================================================*/
  143. /* Rotation of the OLED: */
  144. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  145. if (oled_horizontal) {
  146. return OLED_ROTATION_180;
  147. } else {
  148. return OLED_ROTATION_270;
  149. }
  150. }
  151. // Toggles pixel on/off, converts horizontal coordinates to vertical equivalent if necessary
  152. static void write_pixel(int x, int y, bool onoff) {
  153. if (oled_horizontal) {
  154. oled_write_pixel(x, y, onoff);
  155. } else {
  156. oled_write_pixel(y, 127 - x, onoff);
  157. }
  158. }
  159. /*====================================== BASE KEYBOARD MATRIX IMAGES =======================================*/
  160. // Draw static background image to OLED (keyboard with no bottom row)
  161. static void render_background(void) {
  162. if (oled_horizontal) {
  163. static const char PROGMEM oled_keymap_horizontal[] = {
  164. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  165. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  166. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  167. 0x84, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x00, 0x80, 0x04,
  168. 0x00, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x00, 0x80, 0x04, 0x00,
  169. 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00,
  170. 0x00, 0x80, 0x04, 0x00, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x00,
  171. 0x80, 0x04, 0x04, 0x04, 0x04, 0x84, 0x84, 0x84, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  172. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  173. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  174. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  175. 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10,
  176. 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
  177. 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
  178. 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
  179. 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
  180. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  181. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  182. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  183. 0x42, 0x42, 0x02, 0x02, 0x02, 0x02, 0x42, 0x42, 0x00, 0x00, 0x00, 0x00, 0x42, 0x40, 0x00, 0x00,
  184. 0x00, 0x02, 0x40, 0x40, 0x40, 0x40, 0x42, 0x40, 0x40, 0x40, 0x40, 0x42, 0x40, 0x40, 0x40, 0x40,
  185. 0x42, 0x40, 0x40, 0x40, 0x40, 0x42, 0x40, 0x40, 0x40, 0x40, 0x42, 0x40, 0x40, 0x40, 0x40, 0x42,
  186. 0x40, 0x40, 0x40, 0x00, 0x02, 0x00, 0x00, 0x40, 0x40, 0x02, 0x00, 0x00, 0x00, 0x40, 0x42, 0x02,
  187. 0x02, 0x02, 0x02, 0x42, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00,
  188. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  189. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  190. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  191. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  192. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  193. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  194. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  195. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  196. };
  197. oled_write_raw_P(oled_keymap_horizontal, sizeof(oled_keymap_horizontal));
  198. } else {
  199. static const char PROGMEM oled_keymap_vertical[] = {
  200. 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00,
  201. 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  202. 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x87, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00,
  203. 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  204. 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
  205. 0x00, 0x43, 0x00, 0x00, 0x00, 0x00, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  206. 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00,
  207. 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0xe1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  208. 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00,
  209. 0x00, 0x21, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  210. 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
  211. 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  212. 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00,
  213. 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  214. 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
  215. 0x00, 0x42, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  216. 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00,
  217. 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  218. 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00,
  219. 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  220. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  221. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  222. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  223. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  224. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  225. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  226. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  227. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  228. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  229. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  230. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  231. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  232. };
  233. oled_write_raw_P(oled_keymap_vertical, sizeof(oled_keymap_vertical));
  234. }
  235. }
  236. /*================================================================================================================*/
  237. /*=============================== PIXEL'S COORDINATES FOR EACH PHYSICAL KEY ================================*/
  238. // Location of OLED keyboard's top left pixel, relative to the display
  239. static const int keymap_template[2] = {46, 0};
  240. // Location of key highlights top left pixels, relative to keymap_template {X, Y, Key length in px}
  241. static int keymap_coords[MATRIX_ROWS][MATRIX_COLS][3] = {
  242. { {0, 0, 1}, {5, 0, 1}, {10, 0, 1}, {15, 0, 1}, {20, 0, 1}, {25, 0, 1}, {30, 0, 1} },
  243. { {0, 5, 5}, {9, 5, 1}, {14, 5, 1}, {19, 5, 1}, {24, 5, 1}, {29, 5, 1}, {34, 5, 1} },
  244. { {0, 10, 6}, {10, 10, 1}, {15, 10, 1}, {20, 10, 1}, {25, 10, 1}, {30, 10, 1}, {35, 10, 1} },
  245. { {0, 15, 8}, {12, 15, 1}, {17, 15, 1}, {22, 15, 1}, {27, 15, 1}, {32, 15, 1}, {37, 15, 1} },
  246. { {0, 20, 2}, {6, 20, 2}, {12, 20, 2}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {18, 20, 33} },
  247. { {35, 0, 1}, {40, 0, 1}, {45, 0, 1}, {50, 0, 1}, {55, 0, 1}, {60, 0, 1}, {65, 0, 8} },
  248. { {39, 5, 1}, {44, 5, 1}, {49, 5, 1}, {54, 5, 1}, {59, 5, 1}, {64, 5, 1}, {69, 5, 4} },
  249. { {40, 10, 1}, {45, 10, 1}, {50, 10, 1}, {55, 10, 1}, {60, 10, 1}, {65, 10, 8}, {77, 10, 1} },
  250. { {42, 15, 1}, {47, 15, 1}, {52, 15, 1}, {57, 15, 1}, {62, 15, 6}, {72, 15, 1}, {77, 15, 1} },
  251. { {0, 0, 0}, {0, 0, 0}, {55, 20, 2}, {61, 20, 2}, {67, 20, 1}, {72, 20, 1}, {77, 20, 1} },
  252. };
  253. // Toggles pixels surrounding key
  254. static void render_keymap(uint8_t key_row, uint8_t key_col, bool onoff) {
  255. int length = keymap_coords[key_row][key_col][2] + 4;
  256. int left = keymap_coords[key_row][key_col][0] + keymap_template[0];
  257. int top = keymap_coords[key_row][key_col][1] + keymap_template[1];
  258. int right = left + length - 1;
  259. int bottom = top + 4;
  260. // Draw top and bottom walls (horizontal for <length>px)
  261. for (int x = 0; x < length; x++) {
  262. write_pixel(left + x, top, onoff);
  263. write_pixel(left + x, bottom, onoff);
  264. }
  265. // Draw left and right walls (vertical for 5px)
  266. for (int y = 0; y < 5; y++) {
  267. write_pixel(left, top + y, onoff);
  268. write_pixel(right, top + y, onoff);
  269. }
  270. }
  271. /*================================================================================================================*/
  272. /*============================================= LAYER'S NAME ===============================================*/
  273. // Write active layer name
  274. static void render_layer_state(void) {
  275. if (oled_horizontal) {
  276. oled_set_cursor(0, 0);
  277. } else {
  278. oled_set_cursor(0, 15);
  279. }
  280. switch (get_highest_layer(layer_state)) {
  281. case 0:
  282. oled_write_P(PSTR(MA_LAYER_NAME), false);
  283. break;
  284. case 1:
  285. oled_write_P(PSTR(L1_LAYER_NAME), false);
  286. break;
  287. case 2:
  288. oled_write_P(PSTR(L2_LAYER_NAME), false);
  289. break;
  290. case 3:
  291. oled_write_P(PSTR(L3_LAYER_NAME), false);
  292. break;
  293. default:
  294. oled_write("ERROR", false);
  295. break;
  296. }
  297. }
  298. /*================================================================================================================*/
  299. /*==================================== WPM COUNTERS (CURRENT AND MAX) ======================================*/
  300. // Update WPM counters
  301. static void render_wpm_counters(int current_wpm) {
  302. int cursorposition_cur = 2;
  303. int cursorposition_max = 1;
  304. if (oled_horizontal == false) {
  305. cursorposition_cur = 13;
  306. cursorposition_max = 14;
  307. }
  308. oled_set_cursor(0, cursorposition_cur);
  309. oled_write(get_u8_str(get_current_wpm(), '0'), false);
  310. char wpm_counter[4];
  311. wpm_counter[3] = '\0';
  312. wpm_counter[2] = '0' + current_wpm % 10;
  313. wpm_counter[1] = '0' + (current_wpm / 10) % 10;
  314. wpm_counter[0] = '0' + (current_wpm / 100) % 10;
  315. if (current_wpm > max_wpm) {
  316. max_wpm = current_wpm;
  317. wpm_limit = max_wpm + 20;
  318. oled_set_cursor(0, cursorposition_max);
  319. oled_write(wpm_counter, false);
  320. }
  321. }
  322. /*================================================================================================================*/
  323. /*============================================== WPM GRAPH =================================================*/
  324. // Update WPM graph
  325. static void render_wpm_graph(int current_wpm) {
  326. int line_height = ((current_wpm / graph_top_wpm) * 7);
  327. if (line_height > 7) {
  328. line_height = 7;
  329. }
  330. // Count graph line pixels, return if nothing to draw
  331. int pixel_count = line_height;
  332. for (int i = 0; i < 64; i++) {
  333. pixel_count += graph_lines[i];
  334. }
  335. if (pixel_count == 0) {
  336. return;
  337. }
  338. // Shift array elements left or right depending on graph_direction, append new graph line
  339. if (graph_direction) {
  340. for (int i = 0; i < 64; i++) {
  341. graph_lines[i] = graph_lines[i + 1];
  342. }
  343. graph_lines[64] = line_height;
  344. } else {
  345. for (int i = 64; i > 0; i--) {
  346. graph_lines[i] = graph_lines[i - 1];
  347. }
  348. graph_lines[0] = line_height;
  349. }
  350. // Draw all graph lines (left to right, bottom to top)
  351. int draw_count, arrpos;
  352. for (int x = 1; x <= 127; x += 2) {
  353. arrpos = x / 2;
  354. draw_count = graph_lines[arrpos];
  355. for (int y = 31; y >= 25; y--) {
  356. if (draw_count > 0) {
  357. write_pixel(x, y, true);
  358. draw_count--;
  359. } else {
  360. write_pixel(x, y, false);
  361. }
  362. }
  363. }
  364. }
  365. /*================================================================================================================*/
  366. /*======================================== WPM BASED SNAIL ICON ============================================*/
  367. // Update WPM snail icon
  368. static void render_wpm_icon(int current_wpm) {
  369. // wpm_icon is used to prevent unnecessary redraw
  370. if ((current_wpm < icon_med_wpm) && (wpm_icon != 0)) {
  371. wpm_icon = 0;
  372. } else if ((current_wpm >= icon_med_wpm) && (current_wpm < icon_fast_wpm) && (wpm_icon != 1)) {
  373. wpm_icon = 1;
  374. } else if ((current_wpm >= icon_fast_wpm) && (wpm_icon != 2)) {
  375. wpm_icon = 2;
  376. } else {
  377. return;
  378. }
  379. static const char PROGMEM snails[][2][24] = {
  380. {{0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x20, 0xA0, 0x20, 0x40, 0x40, 0x80, 0x00, 0x00, 0x00, 0x80, 0x40, 0x20, 0x50, 0x88, 0x04, 0x00, 0x00},
  381. {0x40, 0x60, 0x50, 0x4E, 0x51, 0x64, 0x4A, 0x51, 0x54, 0x49, 0x41, 0x62, 0x54, 0x49, 0x46, 0x41, 0x40, 0x30, 0x09, 0x04, 0x02, 0x01, 0x00, 0x00}},
  382. {{0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x40, 0x40, 0x40, 0x40, 0x80, 0x80, 0x00, 0x00, 0x00, 0x04, 0x98, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00},
  383. {0x60, 0x50, 0x54, 0x4A, 0x51, 0x64, 0x4A, 0x51, 0x55, 0x49, 0x41, 0x62, 0x54, 0x49, 0x46, 0x41, 0x21, 0x10, 0x0A, 0x08, 0x05, 0x02, 0x00, 0x00}},
  384. {{0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x40, 0x40, 0x40, 0x80, 0x80, 0x10, 0x10, 0x10, 0x20, 0x40, 0x40, 0xC0, 0x80, 0x80, 0x00, 0x00, 0x00},
  385. {0x60, 0x58, 0x54, 0x62, 0x49, 0x54, 0x52, 0x51, 0x55, 0x49, 0x62, 0x52, 0x4D, 0x45, 0x46, 0x22, 0x21, 0x11, 0x10, 0x0A, 0x08, 0x05, 0x02, 0x00}}
  386. };
  387. if (oled_horizontal) {
  388. oled_set_cursor(3, 1);
  389. oled_write_raw_P(snails[wpm_icon][0], sizeof(snails[wpm_icon][0]));
  390. oled_set_cursor(3, 2);
  391. oled_write_raw_P(snails[wpm_icon][1], sizeof(snails[wpm_icon][1]));
  392. } else {
  393. oled_set_cursor(0, 11);
  394. oled_write_raw_P(snails[wpm_icon][0], sizeof(snails[wpm_icon][0]));
  395. oled_set_cursor(0, 12);
  396. oled_write_raw_P(snails[wpm_icon][1], sizeof(snails[wpm_icon][1]));
  397. }
  398. }
  399. /*================================================================================================================*/
  400. /* Function that renders stuff on the oled */
  401. bool oled_task_user(void) {
  402. // Draw OLED keyboard, preventing redraw.
  403. if (first_loop) {
  404. render_background();
  405. first_loop = false;
  406. }
  407. // Get current WPM
  408. int current_wpm = get_current_wpm();
  409. // Write active layer name to display
  410. render_layer_state();
  411. // Update WPM counters
  412. render_wpm_counters(current_wpm);
  413. // Update WPM snail icon
  414. render_wpm_icon(current_wpm);
  415. // Update WPM graph every graph_refresh milliseconds
  416. if (timer_elapsed(timer) > graph_refresh) {
  417. render_wpm_graph(current_wpm);
  418. timer = timer_read();
  419. }
  420. return false;
  421. }
  422. #endif
  423. // Called by QMK during key processing
  424. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  425. #ifdef OLED_ENABLE
  426. // Toggle pixels surrounding key
  427. render_keymap(record->event.key.row, record->event.key.col, record->event.pressed);
  428. #endif
  429. return true;
  430. }