keymap.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* Copyright 2018 Holten Campbell
  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 BLINK_DURATION 512
  18. #define CAPS_LED_PIN B1
  19. #define NUM_LED_PIN B2
  20. #define SCROLL_LED_PIN B3
  21. uint8_t CAPS;
  22. uint16_t BLINK_TIMER = 0;
  23. uint8_t CAPS_LED_STATE = 0;
  24. // Init togg_indicator so the compiler doesn't complain when I declare it last.
  25. static void togg_indicator(uint8_t *state, uint8_t pin);
  26. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  27. [0] = LAYOUT(
  28. KC_ESC, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC, KC_BSPC,
  29. LT(2, KC_TAB), KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, LT(2, KC_ENT),
  30. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, LT(3, KC_B), KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT,
  31. KC_LCTL, KC_LGUI, KC_LALT, LT(1, KC_SPC), LT(1, KC_SPC), KC_RALT, KC_RGUI, KC_RCTL
  32. ),
  33. [1] = LAYOUT(
  34. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL, KC_DEL,
  35. KC_TRNS, KC_MINS, KC_EQL, KC_SCLN, KC_QUOT, KC_TRNS, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, KC_QUOT, KC_TRNS,
  36. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_LBRC, KC_RBRC, KC_BSLS, KC_TRNS,
  37. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS
  38. ),
  39. [2] = LAYOUT(
  40. KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_DEL, KC_TRNS,
  41. KC_TRNS, KC_UNDS, KC_PLUS, KC_COLN, KC_DQUO, KC_TRNS, KC_HOME, KC_PGDN, KC_PGUP, KC_END, KC_DQUO, KC_TRNS,
  42. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_LCBR, KC_RCBR, KC_PIPE, KC_TRNS,
  43. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS
  44. ),
  45. [3] = LAYOUT(
  46. KC_TRNS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12,
  47. KC_CAPS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
  48. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
  49. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS
  50. )
  51. };
  52. void matrix_init_user(void) {
  53. // set CapsLock LED to output and low
  54. setPinOutput(CAPS_LED_PIN);
  55. writePinLow(CAPS_LED_PIN);
  56. // set NumLock LED to output and low
  57. setPinOutput(NUM_LED_PIN);
  58. writePinLow(NUM_LED_PIN);
  59. // set ScrollLock LED to output and low
  60. setPinOutput(SCROLL_LED_PIN);
  61. writePinLow(SCROLL_LED_PIN);
  62. }
  63. void matrix_scan_user(void) {
  64. if (CAPS == 1) {
  65. // Blink the first led when capslock is active
  66. if (BLINK_TIMER >= BLINK_DURATION) {
  67. togg_indicator(&CAPS_LED_STATE, CAPS_LED_PIN);
  68. BLINK_TIMER = 0;
  69. }
  70. BLINK_TIMER++;
  71. }
  72. }
  73. //function for layer indicator LED
  74. layer_state_t layer_state_set_user(layer_state_t state) {
  75. if (layer_state_cmp(state, 1)) {
  76. writePinHigh(CAPS_LED_PIN);
  77. } else {
  78. writePinLow(CAPS_LED_PIN);
  79. }
  80. if (layer_state_cmp(state, 2)) {
  81. writePinHigh(NUM_LED_PIN);
  82. } else {
  83. writePinLow(NUM_LED_PIN);
  84. }
  85. if (layer_state_cmp(state, 3)) {
  86. writePinHigh(SCROLL_LED_PIN);
  87. } else {
  88. writePinLow(SCROLL_LED_PIN);
  89. }
  90. return state;
  91. }
  92. void led_set_user(uint8_t usb_led) {
  93. if (IS_LED_ON(usb_led, USB_LED_CAPS_LOCK)) {
  94. CAPS = 1;
  95. }
  96. else {
  97. CAPS = 0;
  98. }
  99. }
  100. void togg_indicator(uint8_t *state, uint8_t pin) {
  101. // Toggles a pin based on the current state
  102. if (*state == 0){
  103. *state = 1;
  104. writePinHigh(pin);
  105. }
  106. else if (*state == 1){
  107. *state = 0;
  108. writePinLow(pin);
  109. }
  110. }