You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
3.7 KiB

2 years ago
  1. /* Copyright 2022 imchipwood && deveth0
  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 "v3x.h"
  17. #ifdef RGB_MATRIX_ENABLE
  18. led_config_t g_led_config = {{// Key Matrix to LED Index
  19. {NO_LED, 0, 1, 2, 3},
  20. {NO_LED, 7, 6, 5, 4},
  21. {NO_LED, 8, 9, 10, 11},
  22. {NO_LED, 15, 14, 13, 12}},
  23. {// LED Index to Physical Position
  24. {0, 0},
  25. {75, 0},
  26. {149, 0},
  27. {224, 0},
  28. {224, 21},
  29. {149, 21},
  30. {75, 21},
  31. {0, 21},
  32. {0, 43},
  33. {75, 43},
  34. {149, 43},
  35. {224, 43},
  36. {224, 64},
  37. {149, 64},
  38. {75, 64},
  39. {0, 64}},
  40. {// LED Index to Flag
  41. 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4}};
  42. #endif
  43. void keyboard_pre_init_kb(void) {
  44. // Set LED IO as outputs
  45. setPinOutput(LED_00);
  46. setPinOutput(LED_01);
  47. setPinOutput(LED_02);
  48. keyboard_pre_init_user();
  49. }
  50. void shutdown_user() {
  51. // Shutdown LEDs
  52. writePinLow(LED_00);
  53. writePinLow(LED_01);
  54. writePinLow(LED_02);
  55. }
  56. layer_state_t layer_state_set_kb(layer_state_t state) {
  57. // Layer LEDs act as binary indication of current layer
  58. uint8_t layer = get_highest_layer(state);
  59. writePin(LED_00, layer & 0b1);
  60. writePin(LED_01, (layer >> 1) & 0b1);
  61. uprintf("%d string", layer);
  62. return layer_state_set_user(state);
  63. }
  64. // Optional override functions below.
  65. // You can leave any or all of these undefined.
  66. // These are only required if you want to perform custom actions.
  67. void matrix_init_kb(void) {
  68. // put your keyboard start-up code here
  69. // runs once when the firmware starts up
  70. uint8_t led_delay_ms = 80;
  71. for (int i = 0; i < 2; i++) {
  72. writePinHigh(LED_00);
  73. writePinHigh(LED_01);
  74. writePinHigh(LED_02);
  75. wait_ms(led_delay_ms);
  76. writePinLow(LED_00);
  77. writePinLow(LED_01);
  78. writePinLow(LED_02);
  79. if (i < 1) {
  80. wait_ms(led_delay_ms);
  81. }
  82. }
  83. matrix_init_user();
  84. }
  85. bool led_update_kb(led_t led_state) {
  86. if (!led_update_user(led_state)) return false;
  87. // put your keyboard LED indicator (ex: Caps Lock LED) toggling code here
  88. writePin(LED_02, !led_state.num_lock);
  89. return true;
  90. }
  91. #ifdef ENCODER_ENABLE
  92. bool encoder_update_kb(uint8_t index, bool clockwise) {
  93. if (!encoder_update_user(index, clockwise)) {
  94. return false;
  95. }
  96. switch (get_highest_layer(layer_state)) {
  97. case 0:
  98. // main layer, volume
  99. if (clockwise) {
  100. tap_code(KC_VOLU);
  101. } else {
  102. tap_code(KC_VOLD);
  103. }
  104. break;
  105. }
  106. return true;
  107. }
  108. #endif