keymap.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* Copyright 2021 Valdydesu_
  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. _1,
  19. _2,
  20. _3,
  21. _4
  22. };
  23. enum planck_keycodes {
  24. L1 = SAFE_RANGE,
  25. L2,
  26. L3
  27. };
  28. #define LOWER MO(_4)
  29. #define IND_1 D4
  30. #define IND_2 C6
  31. #define IND_3 D7
  32. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  33. [_1] = LAYOUT(
  34. KC_ESC, KC_F1, KC_F2,
  35. LOWER, KC_Z, KC_X),
  36. [_2] = LAYOUT(
  37. LALT(KC_TAB), LGUI(KC_TAB), LCTL(KC_S),
  38. LOWER, LCTL(KC_C), LCTL(KC_V)),
  39. [_3] = LAYOUT(
  40. KC_TRNS, KC_TRNS, KC_TRNS,
  41. KC_TRNS, KC_TRNS, KC_TRNS),
  42. [_4] = LAYOUT(
  43. L1, L2, L3,
  44. _______, _______, _______),
  45. };
  46. layer_state_t layer_state_set_user(layer_state_t state) {
  47. state = update_tri_layer_state(state, _4, X_PAUSE, X_PAUSE);
  48. gpio_write_pin(IND_1, layer_state_cmp(state, 1));
  49. gpio_write_pin(IND_2, layer_state_cmp(state, 2));
  50. gpio_write_pin(IND_3, layer_state_cmp(state, 3));
  51. return state;
  52. }
  53. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  54. switch (keycode) {
  55. case L1:
  56. if (record->event.pressed) {
  57. set_single_persistent_default_layer(_1);
  58. }
  59. return false;
  60. case L2:
  61. if (record->event.pressed) {
  62. set_single_persistent_default_layer(_2);
  63. }
  64. return false;
  65. case L3:
  66. if (record->event.pressed) {
  67. set_single_persistent_default_layer(_3);
  68. }
  69. return false;
  70. }
  71. return true;
  72. }
  73. void matrix_init_user(void) {
  74. //init the Pro Micro on-board LEDs
  75. gpio_set_pin_output(IND_1);
  76. gpio_set_pin_output(IND_2);
  77. gpio_set_pin_output(IND_3);
  78. //set to off
  79. gpio_write_pin_high(IND_1);
  80. gpio_write_pin_high(IND_2);
  81. gpio_write_pin_high(IND_3);
  82. }
  83. bool encoder_update_user(uint8_t index, bool clockwise) {
  84. if (layer_state_is(_1)) {
  85. if (clockwise) {
  86. tap_code(KC_UP);
  87. } else {
  88. tap_code(KC_DOWN);
  89. }
  90. } else if (layer_state_is(_2)) {
  91. if (clockwise) {
  92. tap_code(KC_RGHT);
  93. } else {
  94. tap_code(KC_LEFT);
  95. }
  96. } else if (layer_state_is(_3)) {
  97. if (clockwise) {
  98. tap_code(KC_VOLU);
  99. } else {
  100. tap_code(KC_VOLD);
  101. }
  102. }
  103. return true;
  104. }