logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

helix.c (12917B)


  1. /* Copyright 2023 splitkb.com <support@splitkb.com>
  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 "quantum.h"
  17. // The first four layers gets a name for readability, which is then used in the OLED below.
  18. enum layers {
  19. _DEFAULT,
  20. _LOWER,
  21. _RAISE,
  22. _ADJUST
  23. };
  24. #ifdef OLED_ENABLE
  25. // NOTE: Most of the OLED code was originally written by Soundmonster for the Corne,
  26. // and has been copied directly from `crkbd/soundmonster/keymap.c`
  27. oled_rotation_t oled_init_kb(oled_rotation_t rotation) {
  28. return OLED_ROTATION_270;
  29. }
  30. void render_mod_status_gui_alt(uint8_t modifiers) {
  31. static const char PROGMEM gui_off_1[] = {0x85, 0x86, 0};
  32. static const char PROGMEM gui_off_2[] = {0xa5, 0xa6, 0};
  33. static const char PROGMEM gui_on_1[] = {0x8d, 0x8e, 0};
  34. static const char PROGMEM gui_on_2[] = {0xad, 0xae, 0};
  35. static const char PROGMEM alt_off_1[] = {0x87, 0x88, 0};
  36. static const char PROGMEM alt_off_2[] = {0xa7, 0xa8, 0};
  37. static const char PROGMEM alt_on_1[] = {0x8f, 0x90, 0};
  38. static const char PROGMEM alt_on_2[] = {0xaf, 0xb0, 0};
  39. // fillers between the modifier icons bleed into the icon frames
  40. static const char PROGMEM off_off_1[] = {0xc5, 0};
  41. static const char PROGMEM off_off_2[] = {0xc6, 0};
  42. static const char PROGMEM on_off_1[] = {0xc7, 0};
  43. static const char PROGMEM on_off_2[] = {0xc8, 0};
  44. static const char PROGMEM off_on_1[] = {0xc9, 0};
  45. static const char PROGMEM off_on_2[] = {0xca, 0};
  46. static const char PROGMEM on_on_1[] = {0xcb, 0};
  47. static const char PROGMEM on_on_2[] = {0xcc, 0};
  48. if(modifiers & MOD_MASK_GUI) {
  49. oled_write_P(gui_on_1, false);
  50. } else {
  51. oled_write_P(gui_off_1, false);
  52. }
  53. if ((modifiers & MOD_MASK_GUI) && (modifiers & MOD_MASK_ALT)) {
  54. oled_write_P(on_on_1, false);
  55. } else if(modifiers & MOD_MASK_GUI) {
  56. oled_write_P(on_off_1, false);
  57. } else if(modifiers & MOD_MASK_ALT) {
  58. oled_write_P(off_on_1, false);
  59. } else {
  60. oled_write_P(off_off_1, false);
  61. }
  62. if(modifiers & MOD_MASK_ALT) {
  63. oled_write_P(alt_on_1, false);
  64. } else {
  65. oled_write_P(alt_off_1, false);
  66. }
  67. if(modifiers & MOD_MASK_GUI) {
  68. oled_write_P(gui_on_2, false);
  69. } else {
  70. oled_write_P(gui_off_2, false);
  71. }
  72. if ((modifiers & MOD_MASK_GUI) && (modifiers & MOD_MASK_ALT)) {
  73. oled_write_P(on_on_2, false);
  74. } else if(modifiers & MOD_MASK_GUI) {
  75. oled_write_P(on_off_2, false);
  76. } else if(modifiers & MOD_MASK_ALT) {
  77. oled_write_P(off_on_2, false);
  78. } else {
  79. oled_write_P(off_off_2, false);
  80. }
  81. if(modifiers & MOD_MASK_ALT) {
  82. oled_write_P(alt_on_2, false);
  83. } else {
  84. oled_write_P(alt_off_2, false);
  85. }
  86. }
  87. void render_mod_status_ctrl_shift(uint8_t modifiers) {
  88. static const char PROGMEM ctrl_off_1[] = {0x89, 0x8a, 0};
  89. static const char PROGMEM ctrl_off_2[] = {0xa9, 0xaa, 0};
  90. static const char PROGMEM ctrl_on_1[] = {0x91, 0x92, 0};
  91. static const char PROGMEM ctrl_on_2[] = {0xb1, 0xb2, 0};
  92. static const char PROGMEM shift_off_1[] = {0x8b, 0x8c, 0};
  93. static const char PROGMEM shift_off_2[] = {0xab, 0xac, 0};
  94. static const char PROGMEM shift_on_1[] = {0xcd, 0xce, 0};
  95. static const char PROGMEM shift_on_2[] = {0xcf, 0xd0, 0};
  96. // fillers between the modifier icons bleed into the icon frames
  97. static const char PROGMEM off_off_1[] = {0xc5, 0};
  98. static const char PROGMEM off_off_2[] = {0xc6, 0};
  99. static const char PROGMEM on_off_1[] = {0xc7, 0};
  100. static const char PROGMEM on_off_2[] = {0xc8, 0};
  101. static const char PROGMEM off_on_1[] = {0xc9, 0};
  102. static const char PROGMEM off_on_2[] = {0xca, 0};
  103. static const char PROGMEM on_on_1[] = {0xcb, 0};
  104. static const char PROGMEM on_on_2[] = {0xcc, 0};
  105. if(modifiers & MOD_MASK_CTRL) {
  106. oled_write_P(ctrl_on_1, false);
  107. } else {
  108. oled_write_P(ctrl_off_1, false);
  109. }
  110. if ((modifiers & MOD_MASK_CTRL) && (modifiers & MOD_MASK_SHIFT)) {
  111. oled_write_P(on_on_1, false);
  112. } else if(modifiers & MOD_MASK_CTRL) {
  113. oled_write_P(on_off_1, false);
  114. } else if(modifiers & MOD_MASK_SHIFT) {
  115. oled_write_P(off_on_1, false);
  116. } else {
  117. oled_write_P(off_off_1, false);
  118. }
  119. if(modifiers & MOD_MASK_SHIFT) {
  120. oled_write_P(shift_on_1, false);
  121. } else {
  122. oled_write_P(shift_off_1, false);
  123. }
  124. if(modifiers & MOD_MASK_CTRL) {
  125. oled_write_P(ctrl_on_2, false);
  126. } else {
  127. oled_write_P(ctrl_off_2, false);
  128. }
  129. if ((modifiers & MOD_MASK_CTRL) && (modifiers & MOD_MASK_SHIFT)) {
  130. oled_write_P(on_on_2, false);
  131. } else if(modifiers & MOD_MASK_CTRL) {
  132. oled_write_P(on_off_2, false);
  133. } else if(modifiers & MOD_MASK_SHIFT) {
  134. oled_write_P(off_on_2, false);
  135. } else {
  136. oled_write_P(off_off_2, false);
  137. }
  138. if(modifiers & MOD_MASK_SHIFT) {
  139. oled_write_P(shift_on_2, false);
  140. } else {
  141. oled_write_P(shift_off_2, false);
  142. }
  143. }
  144. void render_logo(void) {
  145. static const char PROGMEM aurora_logo[] = {
  146. 0x00, 0x00, 0x00, 0xe0, 0x00, 0xf8, 0xc0, 0xf8, 0xe0, 0xc0, 0xfc, 0x00, 0x7e, 0x18, 0x00, 0x80,
  147. 0x00, 0x02, 0x80, 0xf0, 0x00, 0xc0, 0x80, 0xf8, 0xc0, 0xe0, 0x70, 0x60, 0x3c, 0x38, 0x3c, 0x1c,
  148. 0x00, 0x3f, 0x0c, 0x0f, 0x1f, 0x03, 0x07, 0x01, 0xc3, 0x00, 0xe0, 0x80, 0x00, 0xe0, 0x80, 0xf8,
  149. 0x80, 0xc0, 0xf7, 0xc7, 0x6f, 0x7b, 0x39, 0x30, 0x00, 0x80, 0x00, 0xc0, 0x00, 0xc0, 0xc2, 0xe0,
  150. 0x00, 0x40, 0x38, 0x30, 0x38, 0x1e, 0x18, 0x1e, 0x0f, 0x0c, 0x07, 0x07, 0x07, 0x03, 0x03, 0x21,
  151. 0x21, 0x31, 0x30, 0x18, 0x18, 0x1c, 0x08, 0x0c, 0x0e, 0x07, 0x06, 0x07, 0x03, 0xc3, 0x03, 0x01,
  152. 0x4c, 0xcc, 0xc2, 0xc2, 0x41, 0x49, 0x09, 0x2b, 0x2a, 0x6a, 0x6e, 0x24, 0x24, 0x04, 0x92, 0x92,
  153. 0xb1, 0xf1, 0xf1, 0xf2, 0xe6, 0xa4, 0xa4, 0x04, 0x04, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28
  154. };
  155. oled_write_raw_P(aurora_logo, sizeof(aurora_logo));
  156. oled_set_cursor(0, 4);
  157. }
  158. void render_logo_text(void) {
  159. oled_write_P(PSTR("helix"), false);
  160. }
  161. void render_kb_LED_state(void) {
  162. // Host Keyboard LED Status
  163. led_t led_state = host_keyboard_led_state();
  164. oled_write_P(led_state.num_lock ? PSTR("N ") : PSTR(" "), false);
  165. oled_write_P(led_state.caps_lock ? PSTR("C ") : PSTR(" "), false);
  166. oled_write_P(led_state.scroll_lock ? PSTR("S ") : PSTR(" "), false);
  167. }
  168. void render_layer_state(void) {
  169. static const char PROGMEM default_layer[] = {
  170. 0x20, 0x94, 0x95, 0x96, 0x20,
  171. 0x20, 0xb4, 0xb5, 0xb6, 0x20,
  172. 0x20, 0xd4, 0xd5, 0xd6, 0x20, 0};
  173. static const char PROGMEM raise_layer[] = {
  174. 0x20, 0x97, 0x98, 0x99, 0x20,
  175. 0x20, 0xb7, 0xb8, 0xb9, 0x20,
  176. 0x20, 0xd7, 0xd8, 0xd9, 0x20, 0};
  177. static const char PROGMEM lower_layer[] = {
  178. 0x20, 0x9a, 0x9b, 0x9c, 0x20,
  179. 0x20, 0xba, 0xbb, 0xbc, 0x20,
  180. 0x20, 0xda, 0xdb, 0xdc, 0x20, 0};
  181. static const char PROGMEM adjust_layer[] = {
  182. 0x20, 0x9d, 0x9e, 0x9f, 0x20,
  183. 0x20, 0xbd, 0xbe, 0xbf, 0x20,
  184. 0x20, 0xdd, 0xde, 0xdf, 0x20, 0};
  185. switch (get_highest_layer(layer_state | default_layer_state)) {
  186. case _LOWER:
  187. oled_write_P(lower_layer, false);
  188. break;
  189. case _RAISE:
  190. oled_write_P(raise_layer, false);
  191. break;
  192. case _ADJUST:
  193. oled_write_P(adjust_layer, false);
  194. break;
  195. default:
  196. oled_write_P(default_layer, false);
  197. }
  198. }
  199. bool oled_task_kb(void) {
  200. if (!oled_task_user()) {
  201. return false;
  202. }
  203. if (is_keyboard_master()) {
  204. // Renders the current keyboard state (layers and mods)
  205. render_logo();
  206. render_logo_text();
  207. oled_advance_page(false);
  208. render_layer_state();
  209. oled_advance_page(false);
  210. render_mod_status_gui_alt(get_mods()|get_oneshot_mods());
  211. render_mod_status_ctrl_shift(get_mods()|get_oneshot_mods());
  212. render_kb_LED_state();
  213. } else {
  214. // clang-format off
  215. static const char PROGMEM aurora_art[] = {
  216. 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x1c, 0x08, 0x00, 0x00,
  217. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
  218. 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x40,
  219. 0xe0, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0x80,
  220. 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x80, 0x00, 0xf0, 0x00, 0x00, 0xc0,
  221. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
  222. 0x81, 0x00, 0xc0, 0x00, 0xfe, 0x00, 0xfc, 0x00, 0xff, 0x20, 0xff, 0xf0, 0x0f, 0xf0, 0x00, 0xff,
  223. 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x00, 0xf8, 0x00, 0x00, 0xf8,
  224. 0xff, 0x10, 0xff, 0x84, 0xff, 0x60, 0xff, 0x36, 0xff, 0x0f, 0xff, 0x3f, 0x00, 0x5f, 0x00, 0x05,
  225. 0x80, 0x00, 0x80, 0x00, 0xc0, 0x38, 0x00, 0xec, 0xf0, 0x00, 0xfb, 0x80, 0xff, 0xf0, 0xff, 0xef,
  226. 0xff, 0xe8, 0xff, 0x03, 0xff, 0x0c, 0xff, 0x00, 0xff, 0x00, 0x03, 0x00, 0x00, 0xf8, 0x00, 0x80,
  227. 0xff, 0x20, 0xff, 0xd0, 0xff, 0xe0, 0xfe, 0xf8, 0xff, 0xfc, 0xff, 0xff, 0x0f, 0xff, 0x01, 0x3f,
  228. 0xff, 0x00, 0x0f, 0x00, 0x01, 0x00, 0x03, 0x00, 0xfe, 0x80, 0xfe, 0x00, 0xc0, 0xff, 0xc4, 0xfb,
  229. 0xff, 0xfe, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0x07, 0xff, 0x03, 0x3f, 0x00, 0x0f, 0xc0, 0x00,
  230. 0x00, 0x00, 0xb8, 0x00, 0xff, 0x40, 0xbe, 0xf0, 0xff, 0xf1, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff,
  231. 0x1f, 0xff, 0x67, 0x00, 0xef, 0x00, 0x1f, 0x00, 0x00, 0x07, 0x00, 0x00, 0xe0, 0x00, 0xff, 0xf0,
  232. 0xff, 0x88, 0xff, 0xc4, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8f, 0x7f, 0x0f, 0xff,
  233. 0x00, 0x07, 0xfe, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xc0, 0x3f, 0xf8, 0xe7, 0xff,
  234. 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, 0x1f, 0x3f, 0x01, 0xff, 0x0b, 0x00, 0xff, 0x00, 0x00, 0x05,
  235. 0x00, 0x00, 0x00, 0xe0, 0x00, 0xf8, 0x60, 0x80, 0xfe, 0xe3, 0xfc, 0xff, 0x1e, 0xff, 0xff, 0x23,
  236. 0xff, 0x09, 0xff, 0x20, 0x00, 0x3f, 0x02, 0x00, 0x00, 0x0f, 0x00, 0x40, 0x00, 0xc0, 0x00, 0xfc,
  237. 0xe0, 0xfc, 0xf0, 0xff, 0xff, 0x7f, 0xfc, 0xff, 0x0f, 0xff, 0x07, 0x1f, 0x00, 0x01, 0x0f, 0x00,
  238. 0x0f, 0x00, 0x81, 0x70, 0x0c, 0xf0, 0x80, 0x00, 0x00, 0xe4, 0xf8, 0xe6, 0x70, 0x3f, 0xcf, 0xff,
  239. 0x1f, 0xff, 0x48, 0xff, 0x0f, 0x00, 0x07, 0x00, 0x00, 0x43, 0x60, 0xf8, 0xf0, 0xfe, 0x38, 0xfe,
  240. 0x00, 0xfc, 0x03, 0x00, 0xc8, 0x72, 0xcf, 0xfc, 0x00, 0x03, 0x0f, 0x01, 0xe0, 0x1c, 0xe0, 0x03,
  241. 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x06, 0xf9, 0x00, 0x03, 0x00, 0x07,
  242. 0xff, 0x00, 0x10, 0x12, 0xc9, 0xf0, 0xcf, 0xb4, 0x7f, 0x80, 0xe0, 0x1e, 0x01, 0x40, 0x65, 0x5e,
  243. 0xe0, 0x00, 0x00, 0xf0, 0x0c, 0xf0, 0x00, 0x80, 0x7e, 0x01, 0x80, 0x93, 0xfc, 0xc0, 0x00, 0x00,
  244. 0x00, 0x00, 0x00, 0x00, 0x89, 0x18, 0x2c, 0x46, 0x00, 0x07, 0x21, 0x10, 0x10, 0x80, 0x09, 0x13,
  245. 0x31, 0xbf, 0xff, 0x00, 0x08, 0x1a, 0xf7, 0x0f, 0x00, 0x00, 0x44, 0x45, 0x34, 0xbf, 0xb8, 0x00,
  246. 0x10, 0xf0, 0x08, 0xf4, 0x18, 0x11, 0xfc, 0x18, 0xfb, 0x0e, 0x10, 0xf8, 0x04, 0xf8, 0x10, 0x20,
  247. 0x18, 0x09, 0xff, 0x0c, 0xea, 0x1f, 0x28, 0x60, 0x30, 0xf8, 0x20, 0xc0, 0x42, 0x33, 0x21, 0x00
  248. };
  249. // clang-format on
  250. oled_write_raw_P(aurora_art, sizeof(aurora_art));
  251. }
  252. return false;
  253. }
  254. #endif
  255. #ifdef ENCODER_ENABLE
  256. bool encoder_update_kb(uint8_t index, bool clockwise) {
  257. if (!encoder_update_user(index, clockwise)) {
  258. return false;
  259. }
  260. // 0 is left-half encoder,
  261. // 1 is right-half encoder
  262. if (index == 0) {
  263. // Volume control
  264. if (clockwise) {
  265. tap_code(KC_VOLU);
  266. } else {
  267. tap_code(KC_VOLD);
  268. }
  269. } else if (index == 1) {
  270. // Page up/Page down
  271. if (clockwise) {
  272. tap_code(KC_PGDN);
  273. } else {
  274. tap_code(KC_PGUP);
  275. }
  276. }
  277. return true;
  278. }
  279. #endif