keymap.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. #include QMK_KEYBOARD_H
  2. extern keymap_config_t keymap_config;
  3. #ifdef RGBLIGHT_ENABLE
  4. //Following line allows macro to read current RGB settings
  5. extern rgblight_config_t rgblight_config;
  6. #endif
  7. #ifdef OLED_DRIVER_ENABLE
  8. static uint32_t oled_timer = 0;
  9. #endif
  10. // Each layer gets a name for readability, which is then used in the keymap matrix below.
  11. // The underscores don't mean anything - you can have a layer called STUFF or any other name.
  12. // Layer names don't all need to be of the same length, obviously, and you can also skip them
  13. // entirely and just use numbers.
  14. enum layers {
  15. _QWERTY,
  16. _LOWER,
  17. _RAISE,
  18. _ADJUST
  19. };
  20. // Custom keycodes for layer keys
  21. // Dual function escape with left command
  22. #define KC_LGESC LGUI_T(KC_ESC)
  23. enum custom_keycodes {
  24. QWERTY = SAFE_RANGE,
  25. LOWER,
  26. RAISE,
  27. ADJUST,
  28. RGBRST,
  29. KC_RACL // right alt / colon
  30. };
  31. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  32. [_QWERTY] = LAYOUT_split_3x6_3(
  33. //,-----------------------------------------. ,---------------------------------------------.
  34. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
  35. //|------+------+------+------+------+------| |------+------+-------+------+-------+--------|
  36. KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN,KC_QUOT,
  37. //|------+------+------+------+------+------| |------+------+-------+------+-------+--------|
  38. KC_LSPO, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M,KC_COMM,KC_DOT,KC_SLSH,KC_RSPC,
  39. //|------+------+------+------+------+------+------| |------+------+------+-------+------+-------+--------|
  40. KC_LGESC,LOWER, KC_SPC, RCTL_T(KC_ENT), RAISE, KC_RACL
  41. //`--------------------' `--------------------'
  42. ),
  43. [_LOWER] = LAYOUT_split_3x6_3(
  44. //,---------------------------------------------. ,-----------------------------------------.
  45. KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL,
  46. //|------+------+-------+-------+-------+-------| |------+------+------+------+------+------|
  47. KC_LCTL, KC_NO,KC_MS_L,KC_MS_D,KC_MS_U,KC_MS_R, KC_LEFT,KC_DOWN,KC_UP,KC_RIGHT,KC_NO,KC_NO,
  48. //|------+------+-------+-------+-------+-------| |------+------+------+------+------+------|
  49. KC_LSFT, KC_NO,KC_BTN2,KC_WH_D,KC_WH_U,KC_BTN1, KC_HOME,KC_PGDN,KC_PGUP,KC_END,KC_NO,KC_NO,
  50. //|------+------+-------+-------+-------+-------+------| |------+------+------+------+------+------+------|
  51. KC_LGUI, LOWER,KC_SPC, KC_ENT, RAISE,KC_RALT
  52. //`--------------------' `--------------------'
  53. ),
  54. [_RAISE] = LAYOUT_split_3x6_3(
  55. //,-----------------------------------------. ,-----------------------------------------.
  56. KC_ESC,KC_EXLM,KC_AT,KC_HASH,KC_DLR,KC_PERC, KC_CIRC,KC_AMPR,KC_ASTR,KC_LPRN,KC_RPRN,KC_BSPC,
  57. //|------+------+------+------+------+------| |------+------+------+------+------+------|
  58. KC_LCTL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_MINS,KC_EQL,KC_LCBR,KC_RCBR,KC_PIPE,KC_GRV,
  59. //|------+------+------+------+------+------| |------+------+------+------+------+------|
  60. KC_LSFT, KC_F6, KC_F7, KC_F8, KC_F9,KC_F10, KC_UNDS,KC_PLUS,KC_LBRC,KC_RBRC,KC_BSLS,KC_TILD,
  61. //|------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  62. KC_LGUI, LOWER,KC_SPC, KC_ENT, RAISE,KC_RALT
  63. //`--------------------' `--------------------'
  64. ),
  65. [_ADJUST] = LAYOUT_split_3x6_3(
  66. //,-----------------------------------------. ,-----------------------------------------.
  67. RESET,RGBRST, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,KC__MUTE, KC_NO, KC_NO, KC_NO, KC_NO,
  68. //|------+------+------+------+------+------| |------+------+------+------+------+------|
  69. RGB_TOG,RGB_HUI,RGB_SAI,RGB_VAI,RGB_SPI,KC_NO, KC_PAUSE,KC__VOLUP, KC_NO, KC_NO, KC_NO, KC_NO,
  70. //|------+------+------+------+------+------| |------+------+------+------+------+------|
  71. RGB_MOD,RGB_HUD,RGB_SAD,RGB_VAD,RGB_SPD,KC_NO, KC_SCROLLLOCK,KC__VOLDOWN, KC_NO, KC_NO, KC_NO, RGB_RMOD,
  72. //|------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  73. KC_LGUI, LOWER,KC_SPC, KC_ENT, RAISE,KC_RALT
  74. //`--------------------' `--------------------'
  75. )
  76. };
  77. int RGB_current_mode;
  78. // Setting ADJUST layer RGB back to default
  79. void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
  80. if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
  81. layer_on(layer3);
  82. } else {
  83. layer_off(layer3);
  84. }
  85. }
  86. void matrix_init_user(void) {
  87. #ifdef RGBLIGHT_ENABLE
  88. RGB_current_mode = rgblight_config.mode;
  89. #endif
  90. }
  91. #ifdef OLED_DRIVER_ENABLE
  92. oled_rotation_t oled_init_user(oled_rotation_t rotation) { return OLED_ROTATION_270; }
  93. void render_space(void) {
  94. oled_write_P(PSTR(" "), false);
  95. }
  96. void render_mod_status_gui_alt(uint8_t modifiers) {
  97. static const char PROGMEM gui_off_1[] = {0x85, 0x86, 0};
  98. static const char PROGMEM gui_off_2[] = {0xa5, 0xa6, 0};
  99. static const char PROGMEM gui_on_1[] = {0x8d, 0x8e, 0};
  100. static const char PROGMEM gui_on_2[] = {0xad, 0xae, 0};
  101. static const char PROGMEM alt_off_1[] = {0x87, 0x88, 0};
  102. static const char PROGMEM alt_off_2[] = {0xa7, 0xa8, 0};
  103. static const char PROGMEM alt_on_1[] = {0x8f, 0x90, 0};
  104. static const char PROGMEM alt_on_2[] = {0xaf, 0xb0, 0};
  105. // fillers between the modifier icons bleed into the icon frames
  106. static const char PROGMEM off_off_1[] = {0xc5, 0};
  107. static const char PROGMEM off_off_2[] = {0xc6, 0};
  108. static const char PROGMEM on_off_1[] = {0xc7, 0};
  109. static const char PROGMEM on_off_2[] = {0xc8, 0};
  110. static const char PROGMEM off_on_1[] = {0xc9, 0};
  111. static const char PROGMEM off_on_2[] = {0xca, 0};
  112. static const char PROGMEM on_on_1[] = {0xcb, 0};
  113. static const char PROGMEM on_on_2[] = {0xcc, 0};
  114. if(modifiers & MOD_MASK_GUI) {
  115. oled_write_P(gui_on_1, false);
  116. } else {
  117. oled_write_P(gui_off_1, false);
  118. }
  119. if ((modifiers & MOD_MASK_GUI) && (modifiers & MOD_MASK_ALT)) {
  120. oled_write_P(on_on_1, false);
  121. } else if(modifiers & MOD_MASK_GUI) {
  122. oled_write_P(on_off_1, false);
  123. } else if(modifiers & MOD_MASK_ALT) {
  124. oled_write_P(off_on_1, false);
  125. } else {
  126. oled_write_P(off_off_1, false);
  127. }
  128. if(modifiers & MOD_MASK_ALT) {
  129. oled_write_P(alt_on_1, false);
  130. } else {
  131. oled_write_P(alt_off_1, false);
  132. }
  133. if(modifiers & MOD_MASK_GUI) {
  134. oled_write_P(gui_on_2, false);
  135. } else {
  136. oled_write_P(gui_off_2, false);
  137. }
  138. if (modifiers & MOD_MASK_GUI & MOD_MASK_ALT) {
  139. oled_write_P(on_on_2, false);
  140. } else if(modifiers & MOD_MASK_GUI) {
  141. oled_write_P(on_off_2, false);
  142. } else if(modifiers & MOD_MASK_ALT) {
  143. oled_write_P(off_on_2, false);
  144. } else {
  145. oled_write_P(off_off_2, false);
  146. }
  147. if(modifiers & MOD_MASK_ALT) {
  148. oled_write_P(alt_on_2, false);
  149. } else {
  150. oled_write_P(alt_off_2, false);
  151. }
  152. }
  153. void render_mod_status_ctrl_shift(uint8_t modifiers) {
  154. static const char PROGMEM ctrl_off_1[] = {0x89, 0x8a, 0};
  155. static const char PROGMEM ctrl_off_2[] = {0xa9, 0xaa, 0};
  156. static const char PROGMEM ctrl_on_1[] = {0x91, 0x92, 0};
  157. static const char PROGMEM ctrl_on_2[] = {0xb1, 0xb2, 0};
  158. static const char PROGMEM shift_off_1[] = {0x8b, 0x8c, 0};
  159. static const char PROGMEM shift_off_2[] = {0xab, 0xac, 0};
  160. static const char PROGMEM shift_on_1[] = {0xcd, 0xce, 0};
  161. static const char PROGMEM shift_on_2[] = {0xcf, 0xd0, 0};
  162. // fillers between the modifier icons bleed into the icon frames
  163. static const char PROGMEM off_off_1[] = {0xc5, 0};
  164. static const char PROGMEM off_off_2[] = {0xc6, 0};
  165. static const char PROGMEM on_off_1[] = {0xc7, 0};
  166. static const char PROGMEM on_off_2[] = {0xc8, 0};
  167. static const char PROGMEM off_on_1[] = {0xc9, 0};
  168. static const char PROGMEM off_on_2[] = {0xca, 0};
  169. static const char PROGMEM on_on_1[] = {0xcb, 0};
  170. static const char PROGMEM on_on_2[] = {0xcc, 0};
  171. if(modifiers & MOD_MASK_CTRL) {
  172. oled_write_P(ctrl_on_1, false);
  173. } else {
  174. oled_write_P(ctrl_off_1, false);
  175. }
  176. if ((modifiers & MOD_MASK_CTRL) && (modifiers & MOD_MASK_SHIFT)) {
  177. oled_write_P(on_on_1, false);
  178. } else if(modifiers & MOD_MASK_CTRL) {
  179. oled_write_P(on_off_1, false);
  180. } else if(modifiers & MOD_MASK_SHIFT) {
  181. oled_write_P(off_on_1, false);
  182. } else {
  183. oled_write_P(off_off_1, false);
  184. }
  185. if(modifiers & MOD_MASK_SHIFT) {
  186. oled_write_P(shift_on_1, false);
  187. } else {
  188. oled_write_P(shift_off_1, false);
  189. }
  190. if(modifiers & MOD_MASK_CTRL) {
  191. oled_write_P(ctrl_on_2, false);
  192. } else {
  193. oled_write_P(ctrl_off_2, false);
  194. }
  195. if (modifiers & MOD_MASK_CTRL & MOD_MASK_SHIFT) {
  196. oled_write_P(on_on_2, false);
  197. } else if(modifiers & MOD_MASK_CTRL) {
  198. oled_write_P(on_off_2, false);
  199. } else if(modifiers & MOD_MASK_SHIFT) {
  200. oled_write_P(off_on_2, false);
  201. } else {
  202. oled_write_P(off_off_2, false);
  203. }
  204. if(modifiers & MOD_MASK_SHIFT) {
  205. oled_write_P(shift_on_2, false);
  206. } else {
  207. oled_write_P(shift_off_2, false);
  208. }
  209. }
  210. void render_logo(void) {
  211. static const char PROGMEM corne_logo[] = {
  212. 0x80, 0x81, 0x82, 0x83, 0x84,
  213. 0xa0, 0xa1, 0xa2, 0xa3, 0xa4,
  214. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0};
  215. oled_write_P(corne_logo, false);
  216. oled_write_P(PSTR("corne"), false);
  217. }
  218. void render_layer_state(void) {
  219. static const char PROGMEM default_layer[] = {
  220. 0x20, 0x94, 0x95, 0x96, 0x20,
  221. 0x20, 0xb4, 0xb5, 0xb6, 0x20,
  222. 0x20, 0xd4, 0xd5, 0xd6, 0x20, 0};
  223. static const char PROGMEM raise_layer[] = {
  224. 0x20, 0x97, 0x98, 0x99, 0x20,
  225. 0x20, 0xb7, 0xb8, 0xb9, 0x20,
  226. 0x20, 0xd7, 0xd8, 0xd9, 0x20, 0};
  227. static const char PROGMEM lower_layer[] = {
  228. 0x20, 0x9a, 0x9b, 0x9c, 0x20,
  229. 0x20, 0xba, 0xbb, 0xbc, 0x20,
  230. 0x20, 0xda, 0xdb, 0xdc, 0x20, 0};
  231. static const char PROGMEM adjust_layer[] = {
  232. 0x20, 0x9d, 0x9e, 0x9f, 0x20,
  233. 0x20, 0xbd, 0xbe, 0xbf, 0x20,
  234. 0x20, 0xdd, 0xde, 0xdf, 0x20, 0};
  235. if(layer_state_is(_ADJUST)) {
  236. oled_write_P(adjust_layer, false);
  237. } else if(layer_state_is(_LOWER)) {
  238. oled_write_P(lower_layer, false);
  239. } else if(layer_state_is(_RAISE)) {
  240. oled_write_P(raise_layer, false);
  241. } else {
  242. oled_write_P(default_layer, false);
  243. }
  244. }
  245. void render_status_main(void) {
  246. render_logo();
  247. render_space();
  248. render_layer_state();
  249. render_space();
  250. render_mod_status_gui_alt(get_mods()|get_oneshot_mods());
  251. render_mod_status_ctrl_shift(get_mods()|get_oneshot_mods());
  252. }
  253. void render_status_secondary(void) {
  254. render_logo();
  255. render_space();
  256. render_layer_state();
  257. render_space();
  258. render_mod_status_gui_alt(get_mods()|get_oneshot_mods());
  259. render_mod_status_ctrl_shift(get_mods()|get_oneshot_mods());
  260. }
  261. void suspend_power_down_user() {
  262. oled_off();
  263. }
  264. void oled_task_user(void) {
  265. if (timer_elapsed32(oled_timer) > 30000) {
  266. oled_off();
  267. return;
  268. }
  269. #ifndef SPLIT_KEYBOARD
  270. else { oled_on(); }
  271. #endif
  272. if (is_keyboard_master()) {
  273. render_status_main(); // Renders the current keyboard state (layer, lock, caps, scroll, etc)
  274. } else {
  275. render_status_secondary();
  276. }
  277. }
  278. #endif
  279. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  280. if (record->event.pressed) {
  281. #ifdef OLED_DRIVER_ENABLE
  282. oled_timer = timer_read32();
  283. #endif
  284. // set_timelog();
  285. }
  286. static uint16_t my_colon_timer;
  287. switch (keycode) {
  288. case LOWER:
  289. if (record->event.pressed) {
  290. layer_on(_LOWER);
  291. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  292. } else {
  293. layer_off(_LOWER);
  294. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  295. }
  296. return false;
  297. case RAISE:
  298. if (record->event.pressed) {
  299. layer_on(_RAISE);
  300. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  301. } else {
  302. layer_off(_RAISE);
  303. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  304. }
  305. return false;
  306. case ADJUST:
  307. if (record->event.pressed) {
  308. layer_on(_ADJUST);
  309. } else {
  310. layer_off(_ADJUST);
  311. }
  312. return false;
  313. case KC_RACL:
  314. if (record->event.pressed) {
  315. my_colon_timer = timer_read();
  316. register_code(KC_RALT);
  317. } else {
  318. unregister_code(KC_RALT);
  319. if (timer_elapsed(my_colon_timer) < TAPPING_TERM) {
  320. SEND_STRING(":"); // Change the character(s) to be sent on tap here
  321. }
  322. }
  323. return false;
  324. case RGBRST:
  325. #ifdef RGBLIGHT_ENABLE
  326. if (record->event.pressed) {
  327. eeconfig_update_rgblight_default();
  328. rgblight_enable();
  329. RGB_current_mode = rgblight_config.mode;
  330. }
  331. #endif
  332. #ifdef RGB_MATRIX_ENABLE
  333. if (record->event.pressed) {
  334. eeconfig_update_rgb_matrix_default();
  335. rgb_matrix_enable();
  336. }
  337. #endif
  338. break;
  339. }
  340. return true;
  341. }
  342. #ifdef RGB_MATRIX_ENABLE
  343. void suspend_power_down_keymap(void) {
  344. rgb_matrix_set_suspend_state(true);
  345. }
  346. void suspend_wakeup_init_keymap(void) {
  347. rgb_matrix_set_suspend_state(false);
  348. }
  349. #endif