keymap.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. enum ilpse_layers {
  27. _QWERTY,
  28. _LOWER,
  29. _RAISE
  30. };
  31. #define LOWER MO(_LOWER)
  32. #define RAISE MO(_RAISE)
  33. #define GUBS RGUI_T(KC_BSPC)
  34. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  35. [_QWERTY] = LAYOUT(
  36. KC_GESC, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_MINS, KC_BSPC,
  37. KC_TAB, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_ENT,
  38. KC_LSPO, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSPC,
  39. KC_LCTL, KC_LALT, LOWER, GUBS, KC_SPC, RAISE, KC_RGUI, KC_RCTL
  40. ),
  41. [_LOWER] = LAYOUT(
  42. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_LBRC, KC_RBRC,
  43. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, KC_SCLN, KC_QUOT,
  44. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_BSLS, KC_TRNS,
  45. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS
  46. ),
  47. [_RAISE] = LAYOUT(
  48. KC_TILD, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_TRNS, KC_DEL,
  49. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MINS, KC_EQL, KC_LCBR, KC_RCBR, KC_PIPE, KC_ENT,
  50. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_UNDS, KC_PLUS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
  51. RESET, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS
  52. )
  53. };
  54. void matrix_init_user(void) {
  55. // set CapsLock LED to output and low
  56. setPinOutput(CAPS_LED_PIN);
  57. writePinLow(CAPS_LED_PIN);
  58. // set NumLock LED to output and low
  59. setPinOutput(NUM_LED_PIN);
  60. writePinLow(NUM_LED_PIN);
  61. // set ScrollLock LED to output and low
  62. setPinOutput(SCROLL_LED_PIN);
  63. writePinLow(SCROLL_LED_PIN);
  64. }
  65. void matrix_scan_user(void) {
  66. if (CAPS == 1) {
  67. // Blink the first led when capslock is active
  68. if (BLINK_TIMER >= BLINK_DURATION) {
  69. togg_indicator(&CAPS_LED_STATE, CAPS_LED_PIN);
  70. BLINK_TIMER = 0;
  71. }
  72. BLINK_TIMER++;
  73. }
  74. }
  75. //function for layer indicator LED
  76. layer_state_t layer_state_set_user(layer_state_t state) {
  77. writePin(CAPS_LED_PIN, layer_state_cmp(state, 0));
  78. writePin(NUM_LED_PIN, layer_state_cmp(state, 1));
  79. writePin(SCROLL_LED_PIN, layer_state_cmp(state, 2));
  80. return state;
  81. }
  82. void led_set_user(uint8_t usb_led) {
  83. CAPS = IS_LED_ON(usb_led, USB_LED_CAPS_LOCK);
  84. }
  85. void togg_indicator(uint8_t *state, uint8_t pin) {
  86. // Toggles a pin based on the current state
  87. if (*state == 0){
  88. *state = 1;
  89. writePinHigh(pin);
  90. }
  91. else if (*state == 1){
  92. *state = 0;
  93. writePinLow(pin);
  94. }
  95. }