keymap.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /* Copyright 2019 imchipwood
  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. #define _BASE 0
  18. #define _SUB 1
  19. #define _DBG 2
  20. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  21. /*
  22. BASE LAYER
  23. /-----------------------------------------------------`
  24. | | 7 | 8 | 9 | Bkspc |
  25. | |---------|---------|---------|---------|
  26. | | 4 | 5 | 6 | + |
  27. | |---------|---------|---------|---------|
  28. | | 1 | 2 | 3 | * |
  29. |-------------|---------|---------|---------|---------|
  30. | Play/Pause | TT(SUB) | 0 | . | Enter |
  31. \-----------------------------------------------------'
  32. */
  33. [_BASE] = LAYOUT(
  34. KC_P7, KC_P8, KC_P9, KC_BSPC,
  35. KC_P4, KC_P5, KC_P6, KC_KP_PLUS,
  36. KC_P1, KC_P2, KC_P3, KC_KP_ASTERISK,
  37. KC_MPLY, TT(_SUB), KC_P0, KC_PDOT, KC_KP_ENTER
  38. ),
  39. /*
  40. SUB LAYER
  41. /-----------------------------------------------------`
  42. | | | | | Numlock |
  43. | |---------|---------|---------|---------|
  44. | | | | | - |
  45. | |---------|---------|---------|---------|
  46. | | | | | / |
  47. |-------------|---------|---------|---------|---------|
  48. | MO(_DBG) | | | | = |
  49. \-----------------------------------------------------'
  50. */
  51. [_SUB] = LAYOUT(
  52. _______, _______, _______, KC_NLCK,
  53. _______, _______, _______, KC_KP_MINUS,
  54. _______, _______, _______, KC_KP_SLASH,
  55. MO(_DBG), _______, _______, _______, KC_KP_EQUAL
  56. ),
  57. /*
  58. DEBUG LAYER
  59. /-----------------------------------------------------`
  60. | | | | | Reset |
  61. | |---------|---------|---------|---------|
  62. | | | | | |
  63. | |---------|---------|---------|---------|
  64. | | | | | |
  65. |-------------|---------|---------|---------|---------|
  66. | | | | | |
  67. \-----------------------------------------------------'
  68. */
  69. [_DBG] = LAYOUT(
  70. _______, _______, _______, RESET,
  71. _______, _______, _______, _______,
  72. _______, _______, _______, _______,
  73. _______, _______, _______, _______, _______
  74. ),
  75. };
  76. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  77. // If console is enabled, it will print the matrix position and status of each key pressed
  78. /*
  79. #ifdef CONSOLE_ENABLE
  80. uprintf("KL: kc: %u, col: %u, row: %u, pressed: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed);
  81. #endif
  82. */
  83. return true;
  84. }
  85. void keyboard_post_init_user(void) {
  86. // Customise these values to desired behaviour
  87. //debug_enable = true;
  88. //debug_matrix = true;
  89. //debug_keyboard = true;
  90. //debug_mouse = true;
  91. }
  92. void matrix_init_user(void) {
  93. }
  94. void matrix_scan_user(void) {
  95. }
  96. void led_set_user(uint8_t usb_led) {
  97. }
  98. void encoder_update_user(uint8_t index, bool clockwise) {
  99. /* Custom encoder control - handles CW/CCW turning of encoder
  100. * Cusotom behavior:
  101. * main layer:
  102. * CW: volume up
  103. * CCW: volume down
  104. * sub layer:
  105. * CW: next media track
  106. * CCW: prev media track
  107. * debug layer:
  108. * CW: brightness up
  109. * CCW: brightness down
  110. */
  111. if (index == 0) {
  112. switch (biton32(layer_state)) {
  113. case _BASE:
  114. // main layer - volume up (CW) and down (CCW)
  115. if (clockwise) {
  116. tap_code(KC_VOLU);
  117. } else {
  118. tap_code(KC_VOLD);
  119. }
  120. break;
  121. case _SUB:
  122. // sub layer - next track (CW) and previous track (CCW)
  123. if (clockwise) {
  124. tap_code(KC_MNXT);
  125. } else {
  126. tap_code(KC_MPRV);
  127. }
  128. break;
  129. case _DBG:
  130. // debug layer - brightness up (CW) and brightness down (CCW)
  131. if (clockwise) {
  132. tap_code(KC_BRIU);
  133. } else {
  134. tap_code(KC_BRID);
  135. }
  136. break;
  137. default:
  138. // any other layer (shouldn't exist..) - volume up (CW) and down (CCW)
  139. if (clockwise) {
  140. tap_code(KC_VOLU);
  141. } else {
  142. tap_code(KC_VOLD);
  143. }
  144. break;
  145. }
  146. }
  147. }