logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

rgb_led.c (5074B)


  1. /* Copyright 2020 Team Mechlovin'
  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 "quantum.h"
  17. #ifdef RGB_MATRIX_ENABLE
  18. const is31fl3731_led_t PROGMEM g_is31fl3731_leds[IS31FL3731_LED_COUNT] = {
  19. // left CA
  20. {0, C5_2, C6_2, C7_2}, //D2-0
  21. {0, C1_1, C3_2, C4_2}, //D20-1
  22. {0, C5_1, C6_1, C7_1}, //D36-2
  23. {0, C2_1, C3_1, C4_1}, //D46-3
  24. {0, C5_4, C6_4, C7_4}, //D65-4
  25. {0, C1_3, C2_3, C3_3}, //D26-5
  26. {0, C5_3, C6_3, C7_3}, //D37-6
  27. {0, C1_2, C2_2, C4_3}, //D47-7
  28. {0, C4_5, C5_5, C7_6}, //D11-8
  29. {0, C1_5, C2_5, C3_5}, //D27-9
  30. {0, C4_4, C6_5, C7_5}, //D38-10
  31. {0, C1_4, C2_4, C3_4}, //D48-11
  32. // left CB
  33. {0, C2_9, C3_9, C4_9}, //D17-12
  34. {0, C5_9, C6_9, C7_9}, //D28-13
  35. {0, C1_9, C3_10, C4_10}, //D39-14
  36. {0, C5_10, C6_10, C7_10}, //D49-15
  37. {0, C1_10, C2_10, C4_11}, //D18-16
  38. {0, C5_11, C6_11, C7_11}, //D29-17
  39. {0, C1_11, C2_11, C3_11}, //D40-18
  40. {0, C5_12, C6_12, C7_12}, //D50-19
  41. {0, C1_12, C2_12, C3_12}, //D19-20
  42. {0, C1_13, C2_13, C3_13}, //D61-21
  43. {0, C4_13, C5_13, C7_14}, //D35-22
  44. {0, C1_14, C2_14, C3_14}, //D41-23
  45. {0, C4_14, C5_14, C6_14}, //D51-24
  46. };
  47. led_config_t g_led_config = { {
  48. // Key Matrix to LED Index
  49. {0, 1, 2, 3},
  50. {4, 5, 6, 7},
  51. {8, 9, 10, 11},
  52. {12, 13, 14, 15},
  53. {16, 17, 18, 19},
  54. {20, 22, 23, 24}
  55. },
  56. {
  57. //LED Index to Physical Positon
  58. { 0, 0}, { 75, 0}, {149, 0}, {224, 0},
  59. { 0, 13}, { 75, 13}, {149, 13}, {224, 13},
  60. { 0, 25}, { 75, 25}, {149, 25}, {224, 25},
  61. { 0, 38}, { 75, 38}, {149, 38}, {224, 38},
  62. { 0, 51}, { 75, 51}, {149, 51}, {224, 51},
  63. { 0, 64}, { 37, 64}, { 75, 64}, {149, 64}, {224, 64},
  64. }, {
  65. 4, 4, 4, 4,
  66. 4, 1, 1, 4,
  67. 4, 1, 1, 4,
  68. 4, 1, 1, 4,
  69. 4, 1, 1, 4,
  70. 4, 0, 1, 1, 4,
  71. } };
  72. bool rgb_matrix_indicators_kb(void) {
  73. if (!rgb_matrix_indicators_user()) {
  74. return false;
  75. }
  76. if (host_keyboard_led_state().num_lock) {
  77. rgb_matrix_set_color(4, 255, 255, 255);
  78. }
  79. return true;
  80. }
  81. __attribute__((weak))
  82. layer_state_t layer_state_set_user(layer_state_t state) {
  83. // if on layer 1, turn on L1 LED, otherwise off.
  84. if (get_highest_layer(state) == 0) {
  85. rgb_matrix_set_color(1, 255, 0, 0);
  86. } else {
  87. rgb_matrix_set_color(1, 0, 0, 0);
  88. }
  89. // if on layer 2, turn on L2 LED, otherwise off.
  90. if (get_highest_layer(state) == 1) {
  91. rgb_matrix_set_color(0, 255, 0, 0);
  92. } else {
  93. rgb_matrix_set_color(0, 0, 0, 0);
  94. }
  95. // if on layer 3, turn on L3 LED, otherwise off.
  96. if (get_highest_layer(state) == 2) {
  97. rgb_matrix_set_color(3, 255, 0, 0);
  98. } else {
  99. rgb_matrix_set_color(3, 0, 0, 0);
  100. }
  101. // if on layer 4, turn on L4 LED, otherwise off.
  102. if (get_highest_layer(state) == 3) {
  103. rgb_matrix_set_color(2, 255, 0, 0);
  104. } else {
  105. rgb_matrix_set_color(2, 0, 0, 0);
  106. }
  107. return state;
  108. }
  109. #endif
  110. bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
  111. if (!process_record_user(keycode, record)) { return false; }
  112. if (record->event.pressed) {
  113. switch(keycode) {
  114. #ifdef RGB_MATRIX_ENABLE
  115. case KC_F13: // toggle rgb matrix
  116. rgb_matrix_toggle();
  117. return false;
  118. case KC_F14:
  119. rgb_matrix_step();
  120. return false;
  121. case KC_F15:
  122. rgb_matrix_increase_speed();
  123. return false;
  124. case KC_F16:
  125. rgb_matrix_decrease_speed();
  126. return false;
  127. case KC_F17:
  128. rgb_matrix_increase_hue();
  129. return false;
  130. case KC_F18:
  131. rgb_matrix_decrease_hue();
  132. return false;
  133. case KC_F19:
  134. rgb_matrix_increase_sat();
  135. return false;
  136. case KC_F20:
  137. rgb_matrix_decrease_sat();
  138. return false;
  139. case KC_F21:
  140. rgb_matrix_increase_val();
  141. return false;
  142. case KC_F22:
  143. rgb_matrix_decrease_val();
  144. return false;
  145. #endif
  146. default:
  147. break;
  148. }
  149. }
  150. return true;
  151. }