keymap.c 14 KB

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