You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

206 lines
9.0 KiB

  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. #include <stdio.h>
  17. enum layer_names {
  18. _DVORAK,
  19. _LOWER,
  20. _RAISE,
  21. _ADJUST
  22. };
  23. enum planck_keycodes {
  24. DVORAK = SAFE_RANGE,
  25. LOWER,
  26. RAISE,
  27. ADJUST
  28. };
  29. // Adding macros to make the keymaps below much easier to read.
  30. #define DELGUI GUI_T(KC_DEL)
  31. #define ALTENT ALT_T(KC_ENT)
  32. #define SCLNCTL CTL_T(KC_SCLN)
  33. #define QUEALT ALT_T(KC_Q)
  34. #define VEEALT ALT_T(KC_V)
  35. #define ZEDCTL CTL_T(KC_Z)
  36. #define ADJUST MO(_ADJUST)
  37. #define LOWER MO(_LOWER)
  38. #define RAISE MO(_RAISE)
  39. #define MACLOCK LGUI(LCTL(KC_Q))
  40. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  41. [_DVORAK] = LAYOUT_split_3x6_3(
  42. //,-----------------------------------------------------. ,-----------------------------------------------------.
  43. KC_TAB, KC_SCLN, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_SLSH,
  44. //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
  45. KC_ESC, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_MINS,
  46. //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
  47. KC_LSFT, SCLNCTL, QUEALT, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, VEEALT, ZEDCTL, KC_RSFT,
  48. //|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
  49. LOWER, KC_BSPC, DELGUI, KC_ENT, KC_SPC, RAISE
  50. //`--------------------------' `--------------------------'
  51. ),
  52. [_LOWER] = LAYOUT_split_3x6_3(
  53. //,-----------------------------------------------------. ,-----------------------------------------------------.
  54. KC_GRV, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSLS,
  55. //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
  56. XXXXXXX, XXXXXXX, XXXXXXX, KC_UP, XXXXXXX, KC_HOME, KC_PGUP, XXXXXXX, KC_PLUS, KC_LCBR, KC_RCBR, XXXXXXX,
  57. //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
  58. XXXXXXX, XXXXXXX, KC_LEFT, KC_DOWN, KC_RGHT, KC_END, KC_PGDN, KC_MUTE, KC_VOLD, KC_VOLU, XXXXXXX, XXXXXXX,
  59. //|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
  60. _______, KC_DEL, MACLOCK, _______, KC_INS, _______
  61. //`--------------------------' `--------------------------'
  62. ),
  63. [_RAISE] = LAYOUT_split_3x6_3(
  64. //,-----------------------------------------------------. ,-----------------------------------------------------.
  65. KC_TILD, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_PIPE,
  66. //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
  67. XXXXXXX, XXXXXXX, XXXXXXX, KC_UP, XXXXXXX, KC_HOME, KC_PGUP, XXXXXXX, KC_EQL, KC_LBRC, KC_RBRC, XXXXXXX,
  68. //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
  69. XXXXXXX, XXXXXXX, KC_LEFT, KC_DOWN, KC_RGHT, KC_END, KC_PGDN, KC_MPRV, KC_MPLY, KC_MNXT, XXXXXXX, XXXXXXX,
  70. //|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
  71. _______, KC_DEL, MACLOCK, _______, KC_INS, _______
  72. //`--------------------------' `--------------------------'
  73. ),
  74. [_ADJUST] = LAYOUT_split_3x6_3(
  75. //,-----------------------------------------------------. ,-----------------------------------------------------.
  76. KC_F11, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F12,
  77. //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
  78. RGB_TOG, RGB_HUI, RGB_SAI, RGB_VAI, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
  79. //|--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------|
  80. RGB_MOD, RGB_HUD, RGB_SAD, RGB_VAD, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, RESET,
  81. //|--------+--------+--------+--------+--------+--------+--------| |--------+--------+--------+--------+--------+--------+--------|
  82. _______, _______, _______, _______, _______, _______
  83. //`--------------------------' `--------------------------'
  84. )
  85. };
  86. layer_state_t layer_state_set_user(layer_state_t state) {
  87. return update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
  88. }
  89. #ifdef OLED_ENABLE
  90. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  91. if (!is_keyboard_master()) {
  92. return OLED_ROTATION_180; // flips the display 180 degrees if offhand
  93. }
  94. return rotation;
  95. }
  96. #define L_BASE 0
  97. #define L_LOWER 2
  98. #define L_RAISE 4
  99. #define L_ADJUST 8
  100. void oled_render_layer_state(void) {
  101. oled_write_P(PSTR("Layer: "), false);
  102. switch (layer_state) {
  103. case L_BASE:
  104. oled_write_ln_P(PSTR("Default"), false);
  105. break;
  106. case L_LOWER:
  107. oled_write_ln_P(PSTR("Lower"), false);
  108. break;
  109. case L_RAISE:
  110. oled_write_ln_P(PSTR("Raise"), false);
  111. break;
  112. case L_ADJUST:
  113. case L_ADJUST|L_LOWER:
  114. case L_ADJUST|L_RAISE:
  115. case L_ADJUST|L_LOWER|L_RAISE:
  116. oled_write_ln_P(PSTR("Adjust"), false);
  117. break;
  118. }
  119. }
  120. char keylog_str[24] = {};
  121. const char code_to_name[60] = {
  122. ' ', ' ', ' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f',
  123. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
  124. 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  125. '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
  126. 'R', 'E', 'B', 'T', '_', '-', '=', '[', ']', '\\',
  127. '#', ';', '\'', '`', ',', '.', '/', ' ', ' ', ' '};
  128. void set_keylog(uint16_t keycode, keyrecord_t *record) {
  129. char name = ' ';
  130. if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) ||
  131. (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) { keycode = keycode & 0xFF; }
  132. if (keycode < 60) {
  133. name = code_to_name[keycode];
  134. }
  135. // update keylog
  136. snprintf(keylog_str, sizeof(keylog_str), "%dx%d, k%2d : %c",
  137. record->event.key.row, record->event.key.col,
  138. keycode, name);
  139. }
  140. void oled_render_keylog(void) {
  141. oled_write(keylog_str, false);
  142. }
  143. void render_bootmagic_status(bool status) {
  144. /* Show Ctrl-Gui Swap options */
  145. static const char PROGMEM logo[][2][3] = {
  146. {{0x97, 0x98, 0}, {0xb7, 0xb8, 0}},
  147. {{0x95, 0x96, 0}, {0xb5, 0xb6, 0}},
  148. };
  149. if (status) {
  150. oled_write_ln_P(logo[0][0], false);
  151. oled_write_ln_P(logo[0][1], false);
  152. } else {
  153. oled_write_ln_P(logo[1][0], false);
  154. oled_write_ln_P(logo[1][1], false);
  155. }
  156. }
  157. void oled_render_logo(void) {
  158. static const char PROGMEM crkbd_logo[] = {
  159. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94,
  160. 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4,
  161. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4,
  162. 0};
  163. oled_write_P(crkbd_logo, false);
  164. }
  165. bool oled_task_user(void) {
  166. if (is_keyboard_master()) {
  167. oled_render_layer_state();
  168. oled_render_keylog();
  169. } else {
  170. oled_render_logo();
  171. }
  172. return false;
  173. }
  174. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  175. if (record->event.pressed) {
  176. set_keylog(keycode, record);
  177. }
  178. return true;
  179. }
  180. #endif // OLED_ENABLE