keymap.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /* Copyright 2020 Andrew Liaw
  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 QMK_KEYBOARD_H
  17. enum planck_layers {
  18. _BASE,
  19. _LOWER,
  20. _RAISE,
  21. _ADJUST,
  22. };
  23. enum planck_keycodes {
  24. L_RESET = SAFE_RANGE,
  25. };
  26. #ifdef AUDIO_ENABLE
  27. float planck_sound[][2] = SONG(PLANCK_SOUND);
  28. #endif
  29. #define LOWER MO(_LOWER)
  30. #define RAISE MO(_RAISE)
  31. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  32. /* Base
  33. * ,-----------------------------------------------------------------------------------.
  34. * | Tab | Q | W | E | R | T | Y | U | I | O | P | Bksp |
  35. * |------+------+------+------+------+------+------+------+------+------+------+------|
  36. * | Esc | A | S | D | F | G | H | J | K | L | ; | " |
  37. * |------+------+------+------+------+------+------+------+------+------+------+------|
  38. * | Shift| Z | X | C | V | B | N | M | , | . | / | Shift|
  39. * |------+------+------+------+------+------+------+------+------+------+------+------|
  40. * |Leader| Ctrl | Alt | GUI | Lower| Enter| Space| Raise| GUI | Alt | Ctrl | Del |
  41. * `-----------------------------------------------------------------------------------'
  42. */
  43. [_BASE] = LAYOUT_planck_grid(
  44. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
  45. KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
  46. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT,
  47. KC_LEAD, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_ENT, KC_SPC, RAISE, KC_RGUI, KC_RALT, KC_RCTL, KC_DEL
  48. ),
  49. /* Lower
  50. * ,-----------------------------------------------------------------------------------.
  51. * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | |
  52. * |------+------+------+------+------+-------------+------+------+------+------+------|
  53. * | Caps | | | | | | Left | Down | Up | Right| | \ |
  54. * |------+------+------+------+------+------|------+------+------+------+------+------|
  55. * | | | | | | | | Home | End | Pg Up| Pg Dn| |
  56. * |------+------+------+------+------+------+------+------+------+------+------+------|
  57. * | | | | | | | | | | | | |
  58. * `-----------------------------------------------------------------------------------'
  59. */
  60. [_LOWER] = LAYOUT_planck_grid(
  61. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, _______,
  62. KC_CAPS, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, XXXXXXX, KC_BSLS,
  63. _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_HOME, KC_END, KC_PGUP, KC_PGDN, _______,
  64. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  65. ),
  66. /* Raise
  67. * ,-----------------------------------------------------------------------------------.
  68. * | ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | |
  69. * |------+------+------+------+------+-------------+------+------+------+------+------|
  70. * | | F1 | F2 | F3 | F4 | F5 | F6 | - | = | [ | ] | | |
  71. * |------+------+------+------+------+------|------+------+------+------+------+------|
  72. * | | F7 | F8 | F9 | F10 | F11 | F12 | _ | + | { | } | |
  73. * |------+------+------+------+------+------+------+------+------+------+------+------|
  74. * | | | | | | | | | | | | |
  75. * `-----------------------------------------------------------------------------------'
  76. */
  77. [_RAISE] = LAYOUT_planck_grid(
  78. KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, _______,
  79. _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_PIPE,
  80. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, _______,
  81. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  82. ),
  83. /* Adjust (Lower + Raise)
  84. * ,-----------------------------------------------------------------------------------.
  85. * | | Reset| Debug| Clear| RGB | HUE+ | HUE- | SAT+ | SAT- |BRGTH+|BRGTH-| |
  86. * |------+------+------+------+------+------+------+------+------+------+------+------|
  87. * | | | |Aud on|Audoff| Swap | Norm | | | | | |
  88. * |------+------+------+------+------+------+------+------+------+------+------+------|
  89. * | | | |Mus on|Musoff| NKRO | 6KRO | | | | | |
  90. * |------+------+------+------+------+------+------+------+------+------+------+------|
  91. * | | | | | | | | | | | | |
  92. * `-----------------------------------------------------------------------------------'
  93. */
  94. [_ADJUST] = LAYOUT_planck_grid(
  95. _______, L_RESET, DEBUG, EEP_RST, RGB_TOG, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, RGB_VAI, RGB_VAD, _______,
  96. _______, XXXXXXX, XXXXXXX, AU_ON, AU_OFF, AG_SWAP, AG_NORM, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, _______,
  97. _______, XXXXXXX, XXXXXXX, MU_ON, MU_OFF, NK_ON, NK_OFF, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, _______,
  98. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  99. )
  100. };
  101. const rgblight_segment_t PROGMEM base_layer[] = RGBLIGHT_LAYER_SEGMENTS({0, 9, 0, 0, 0});
  102. const rgblight_segment_t PROGMEM lower_layer[] = RGBLIGHT_LAYER_SEGMENTS({0, 8, HSV_RED});
  103. const rgblight_segment_t PROGMEM raise_layer[] = RGBLIGHT_LAYER_SEGMENTS({0, 8, HSV_GREEN});
  104. const rgblight_segment_t PROGMEM adjust_layer[] = RGBLIGHT_LAYER_SEGMENTS({0, 8, HSV_BLUE});
  105. const rgblight_segment_t PROGMEM capslock_layer[] = RGBLIGHT_LAYER_SEGMENTS({4, 5, HSV_WHITE});
  106. // Later layers take precedence.
  107. const rgblight_segment_t* const PROGMEM rgb_layers[] = RGBLIGHT_LAYERS_LIST(
  108. base_layer,
  109. lower_layer,
  110. raise_layer,
  111. adjust_layer,
  112. capslock_layer
  113. );
  114. bool audio_disable = false;
  115. void keyboard_pre_init_user(void) {
  116. // If the audio is off during hardware init,
  117. // it causes problem when the audio is turn on later.
  118. // The workaround is to always set the audio on during hardware init,
  119. // then toggle audio back to the setting.
  120. #ifdef AUDIO_ENABLE
  121. if (!is_audio_on()) {
  122. audio_disable = true;
  123. audio_on();
  124. }
  125. #endif
  126. }
  127. void matrix_init_user(void) {
  128. // To fix a audio related problem. See comments in keyboard_pre_init_user().
  129. #ifdef AUDIO_ENABLE
  130. if (audio_disable) {
  131. audio_off();
  132. }
  133. #endif
  134. }
  135. void keyboard_post_init_user(void) {
  136. rgblight_layers = rgb_layers;
  137. rgblight_set_layer_state(0, true);
  138. }
  139. bool leader_found;
  140. LEADER_EXTERNS();
  141. void matrix_scan_user(void) {
  142. LEADER_DICTIONARY() {
  143. leading = false;
  144. leader_found = false;
  145. SEQ_ONE_KEY(L_RESET) {
  146. leader_found = true;
  147. reset_keyboard();
  148. }
  149. else
  150. SEQ_ONE_KEY(KC_DEL) {
  151. leader_found = true;
  152. layer_clear();
  153. }
  154. else
  155. SEQ_ONE_KEY(LOWER) {
  156. leader_found = true;
  157. layer_on(_LOWER);
  158. }
  159. else
  160. SEQ_ONE_KEY(RAISE) {
  161. leader_found = true;
  162. layer_on(_RAISE);
  163. }
  164. leader_end();
  165. }
  166. }
  167. void leader_end(void) {
  168. // Plays sound on if leader sequence found.
  169. if (leader_found) {
  170. #ifdef AUDIO_ENABLE
  171. PLAY_SONG(planck_sound);
  172. #endif
  173. }
  174. }
  175. bool led_update_user(led_t led_state) {
  176. // Turn on RBG for capslock.
  177. rgblight_set_layer_state(4, led_state.caps_lock);
  178. return true;
  179. }
  180. layer_state_t layer_state_set_user(layer_state_t state) {
  181. // Set RBG layer according to active keymap layer.
  182. rgblight_set_layer_state(1, layer_state_cmp(state, 1));
  183. rgblight_set_layer_state(2, layer_state_cmp(state, 2));
  184. rgblight_set_layer_state(3, layer_state_cmp(state, 1) && layer_state_cmp(state, 2));
  185. return update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
  186. }
  187. bool music_mask_user(uint16_t keycode) {
  188. switch (keycode) {
  189. case RAISE:
  190. case LOWER:
  191. return false;
  192. default:
  193. return true;
  194. }
  195. }