keymap.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /*
  2. Copyright 2019 @foostan
  3. Copyright 2020 Drashna Jaelre <@drashna>
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 2 of the License, or
  7. (at your option) any later version.
  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. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #include QMK_KEYBOARD_H
  16. #define ALT_ESC ALT_T(KC_ESC)
  17. #define CTL_ESC CTL_T(KC_ESC)
  18. #define GUI_ESC GUI_T(KC_ESC)
  19. #define HYPER LGUI(LSFT(KC_LALT))
  20. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  21. // 0 - Base Mac
  22. [0] = LAYOUT_split_3x6_3(
  23. //,-----------------------------------------------------. ,-----------------------------------------------------.
  24. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
  25. //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
  26. CTL_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
  27. //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
  28. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT,
  29. //|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
  30. MO(3), ALT_ESC, KC_LGUI, KC_SPC, MO(2), HYPER
  31. //`--------------------------' `--------------------------'
  32. ),
  33. // 1 - Base Linux
  34. [1] = LAYOUT_split_3x6_3(
  35. //,-----------------------------------------------------. ,-----------------------------------------------------.
  36. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
  37. //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
  38. ALT_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
  39. //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
  40. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT,
  41. //|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
  42. MO(4), GUI_ESC, KC_LCTL, KC_SPC, MO(2), HYPER
  43. //`--------------------------' `--------------------------'
  44. ),
  45. // 2 - Symbols
  46. [2] = LAYOUT_split_3x6_3(
  47. //,-----------------------------------------------------. ,-----------------------------------------------------.
  48. _______, KC_BSLS, KC_SLSH, KC_LBRC, KC_RBRC, KC_TILD, KC_PIPE, KC_EQL, KC_PLUS, KC_MINS, KC_UNDS, _______,
  49. //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
  50. _______, KC_LCBR, KC_RCBR, KC_LPRN, KC_RPRN, KC_GRV, KC_LEFT, KC_DOWN, KC_UP,KC_RIGHT, _______, _______,
  51. //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
  52. _______, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, _______,
  53. //|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
  54. MO(5), _______, _______, _______, KC_TRNS, _______
  55. //`--------------------------' `--------------------------'
  56. ),
  57. // 3 - MAN Mac
  58. [3] = LAYOUT_split_3x6_3(
  59. //,-----------------------------------------------------. ,-----------------------------------------------------.
  60. _______, _______, KC_BRMD, KC_VOLU, KC_BRMU, _______, _______, KC_7, KC_8, KC_9, KC_ASTR, _______,
  61. //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
  62. _______, KC_MUTE, KC_MRWD, KC_MPLY, KC_MFFD, _______, _______, KC_4, KC_5, KC_6, KC_PLUS, _______,
  63. //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
  64. _______, _______, _______, KC_VOLD, _______, _______, _______, KC_1, KC_2, KC_3, KC_BSLS, _______,
  65. //|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
  66. KC_TRNS, _______, _______, KC_0, MO(5), _______
  67. //`--------------------------' `--------------------------'
  68. ),
  69. // 4 - MAN Linux
  70. [4] = LAYOUT_split_3x6_3(
  71. //,-----------------------------------------------------. ,-----------------------------------------------------.
  72. _______, _______, KC_BRID, KC_VOLU, KC_BRIU, _______, _______, KC_7, KC_8, KC_9, KC_ASTR, _______,
  73. //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
  74. _______, KC_MUTE, KC_MPRV, KC_MPLY, KC_MNXT, _______, _______, KC_4, KC_5, KC_6, KC_PLUS, _______,
  75. //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
  76. _______, _______, _______, KC_VOLD, _______, _______, _______, KC_1, KC_2, KC_3, KC_BSLS, _______,
  77. //|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
  78. KC_TRNS, _______, _______, KC_0, MO(5), _______
  79. //`--------------------------' `--------------------------'
  80. ),
  81. // 5 - Extra
  82. [5] = LAYOUT_split_3x6_3(
  83. //,-----------------------------------------------------. ,-----------------------------------------------------.
  84. _______, DF(0), DF(1), _______, _______, _______, _______, _______, _______, _______, _______, _______,
  85. //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
  86. _______, _______, _______, _______, _______, _______, KC_HOME, KC_PGDN, KC_PGUP, KC_END, _______, _______,
  87. //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
  88. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  89. //|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
  90. KC_TRNS, _______, _______, _______, KC_TRNS, _______
  91. //`--------------------------' `--------------------------'
  92. )
  93. };
  94. #ifdef OLED_DRIVER_ENABLE
  95. # include <stdio.h>
  96. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  97. if (!is_keyboard_master()) {
  98. return OLED_ROTATION_180; // flips the display 180 degrees if offhand
  99. }
  100. return rotation;
  101. }
  102. #define L_BASE_MAC 0
  103. #define L_BASE_LINUX 2
  104. #define L_SYMBOLS 4
  105. #define L_MAN_MAC 8
  106. #define L_MAN_LINUX 16
  107. #define L_EXTRA 32
  108. void oled_render_layer_state(void) {
  109. oled_write_P(PSTR("L: "), false);
  110. switch (layer_state) {
  111. case L_BASE_MAC:
  112. case L_BASE_LINUX:
  113. oled_write_ln_P(PSTR("Base"), false);
  114. break;
  115. case L_SYMBOLS:
  116. oled_write_ln_P(PSTR("Symbols"), false);
  117. break;
  118. case L_MAN_MAC:
  119. oled_write_ln_P(PSTR("Media/Num (Mac)"), false);
  120. break;
  121. case L_MAN_LINUX:
  122. oled_write_ln_P(PSTR("Media/Num (Linux)"), false);
  123. break;
  124. case L_EXTRA:
  125. case L_EXTRA|L_SYMBOLS:
  126. case L_EXTRA|L_MAN_MAC:
  127. case L_EXTRA|L_MAN_LINUX:
  128. case L_EXTRA|L_SYMBOLS|L_MAN_MAC:
  129. case L_EXTRA|L_SYMBOLS|L_MAN_LINUX:
  130. oled_write_ln_P(PSTR("Extra"), false);
  131. break;
  132. default:
  133. oled_write_ln_P(PSTR("Unhandled!"), false);
  134. break;
  135. }
  136. }
  137. char keylog_str[24] = {};
  138. const char code_to_name[60] = {
  139. ' ', ' ', ' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f',
  140. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
  141. 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  142. '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
  143. 'R', 'E', 'B', 'T', '_', '-', '=', '[', ']', '\\',
  144. '#', ';', '\'', '`', ',', '.', '/', ' ', ' ', ' '};
  145. void set_keylog(uint16_t keycode, keyrecord_t *record) {
  146. char name = ' ';
  147. if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) ||
  148. (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) { keycode = keycode & 0xFF; }
  149. if (keycode < 60) {
  150. name = code_to_name[keycode];
  151. }
  152. // update keylog
  153. snprintf(keylog_str, sizeof(keylog_str), "%dx%d, k%2d : %c",
  154. record->event.key.row, record->event.key.col,
  155. keycode, name);
  156. }
  157. void oled_render_keylog(void) {
  158. oled_write(keylog_str, false);
  159. }
  160. void render_bootmagic_status(bool status) {
  161. /* Show Ctrl-Gui Swap options */
  162. static const char PROGMEM logo[][2][3] = {
  163. {{0x97, 0x98, 0}, {0xb7, 0xb8, 0}},
  164. {{0x95, 0x96, 0}, {0xb5, 0xb6, 0}},
  165. };
  166. if (status) {
  167. oled_write_ln_P(logo[0][0], false);
  168. oled_write_ln_P(logo[0][1], false);
  169. } else {
  170. oled_write_ln_P(logo[1][0], false);
  171. oled_write_ln_P(logo[1][1], false);
  172. }
  173. }
  174. void oled_render_logo(void) {
  175. static const char PROGMEM crkbd_logo[] = {
  176. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94,
  177. 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4,
  178. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4,
  179. 0};
  180. oled_write_P(crkbd_logo, false);
  181. }
  182. void oled_task_user(void) {
  183. if (is_keyboard_master()) {
  184. oled_render_layer_state();
  185. oled_render_keylog();
  186. } else {
  187. oled_render_logo();
  188. }
  189. }
  190. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  191. if (record->event.pressed) {
  192. set_keylog(keycode, record);
  193. }
  194. return true;
  195. }
  196. #endif // OLED_DRIVER_ENABLE