logo

qmk_firmware

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

corne.c (13069B)


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