keymap.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* Copyright 2019 Brandon Schlack
  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. #include "brandonschlack.h"
  18. // LEDs
  19. #define TOP_LED B1
  20. #define MIDDLE_LED B2
  21. #define BOTTOM_LED B3
  22. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  23. [_BASE] = LAYOUT( \
  24. KC_HOME, KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSLS, KC_GRV, \
  25. KC_PGUP, KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSPC, \
  26. KC_PGDN, HY_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, \
  27. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, PLY_FN1, \
  28. KC_LOPT, KC_LCMD, SPC_RAI, KC_LCTL, SPC_RAI, KC_RCMD, KC_ROPT \
  29. ),
  30. [_FN1] = LAYOUT( \
  31. KC_MUTE, QM_MAKE, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, MC_LHPD, MC_SLPD, \
  32. KC_VOLU, RGB_MOD, RGB_HUI, RGB_SAI, RGB_VAI, RGB_SPI, _______, _______, _______, _______, _______, KC_HOME, KC_UP, KC_END, KC_DELT, \
  33. KC_VOLD, RGB_TOG, RGB_HUD, RGB_SAD, RGB_VAD, RGB_SPD, _______, _______, _______, KC_MPRV, KC_MNXT, KC_PGDN, KC_UP, KC_MPLY, \
  34. _______, RGB_LYR, RGB_THM, _______, _______, _______, _______, _______, _______, _______, KC_LEFT, KC_DOWN, RGT_SFT, _______, \
  35. _______, _______, _______, _______, _______, _______, _______ \
  36. ),
  37. [_FN2] = LAYOUT( \
  38. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
  39. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
  40. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
  41. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
  42. _______, _______, _______, _______, _______, _______, _______ \
  43. ),
  44. [_ADJUST] = LAYOUT( \
  45. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
  46. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
  47. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
  48. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
  49. _______, _______, _______, _______, _______, _______, _______ \
  50. )
  51. /*
  52. [_BLANK] = LAYOUT( \
  53. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
  54. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
  55. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
  56. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
  57. _______, _______, _______, _______, _______, _______, _______ \
  58. )
  59. */
  60. };
  61. #ifdef STOPLIGHT_LED
  62. bool is_led_stoplight_active = false;
  63. uint8_t led_stoplight_index = 0;
  64. uint16_t led_stoplight_timer = 0;
  65. void matrix_scan_led_stoplight(void);
  66. void led_stoplight_start(void) {
  67. writePinHigh(TOP_LED);
  68. writePinHigh(MIDDLE_LED);
  69. writePinHigh(BOTTOM_LED);
  70. is_led_stoplight_active = true;
  71. led_stoplight_timer = timer_read();
  72. };
  73. void led_stoplight_set(pin_t pin) {
  74. writePinLow(pin);
  75. };
  76. void led_stoplight_end(void) {
  77. // Reset timer and status variables
  78. led_stoplight_index = 0;
  79. is_led_stoplight_active = false;
  80. led_stoplight_timer = 0;
  81. led_update_kb(host_keyboard_led_state());
  82. };
  83. void matrix_scan_led_stoplight(void) {
  84. if (is_led_stoplight_active) {
  85. if (timer_elapsed(led_stoplight_timer) > (1000 * (led_stoplight_index + 1))) {
  86. switch (led_stoplight_index){
  87. case 0:
  88. led_stoplight_set(TOP_LED);
  89. led_stoplight_index++;
  90. break;
  91. case 1:
  92. led_stoplight_set(MIDDLE_LED);
  93. led_stoplight_index++;
  94. break;
  95. case 2:
  96. led_stoplight_set(BOTTOM_LED);
  97. led_stoplight_index++;
  98. break;
  99. default:
  100. led_stoplight_index = 0;
  101. is_led_stoplight_active = false;
  102. led_stoplight_timer = 0;
  103. led_update_kb(host_keyboard_led_state());
  104. break;
  105. }
  106. }
  107. }
  108. };
  109. #endif
  110. void keyboard_post_init_keymap(void) {
  111. #ifdef STOPLIGHT_LED
  112. led_stoplight_start();
  113. #endif
  114. };
  115. void matrix_scan_keymap(void) {
  116. #ifdef STOPLIGHT_LED
  117. matrix_scan_led_stoplight();
  118. #endif
  119. };
  120. #ifdef USE_LEDS_FOR_LAYERS
  121. // example of how to use LEDs as layer indicators
  122. static uint8_t top = 0;
  123. static uint8_t middle = 0;
  124. layer_state_t layer_state_set_keymap(layer_state_t state) {
  125. top = middle = 0;
  126. state = update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
  127. switch (get_highest_layer(state)) {
  128. case _FN1:
  129. top = 1;
  130. break;
  131. case _FN2:
  132. middle = 1;
  133. break;
  134. case _ADJUST:
  135. top = 1;
  136. middle = 1;
  137. break;
  138. default: // for any other layers, or the default layer
  139. break;
  140. }
  141. return state;
  142. }
  143. // override kb level function
  144. bool led_update_user(led_t usb_led) {
  145. if (!is_led_stoplight_active) {
  146. writePin(TOP_LED, !top);
  147. writePin(MIDDLE_LED, !middle);
  148. writePin(BOTTOM_LED, !usb_led.caps_lock); // still use bottom for Caps Lock
  149. };
  150. return false; // we are using LEDs for something else override kb
  151. }
  152. #endif