rev6a.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. Copyright 2021 Danny Nguyen <danny@keeb.io>
  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. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include "rev6a.h"
  15. #ifdef RGB_MATRIX_ENABLE
  16. led_config_t g_led_config = { {
  17. // Key Matrix to LED Index
  18. // Left Half
  19. { 0, 1, 2, 3, 4, 5 },
  20. { 11, 10, 9, 8, 7, 6 },
  21. { 12, 13, 14, 15, 16, 17 },
  22. { 23, 22, 21, 20, 19, 18 },
  23. { NO_LED, NO_LED, 24, 25, 26, 27 },
  24. // Right Half
  25. { 34, 35, 36, 37, 38, 39 },
  26. { 45, 44, 43, 42, 41, 40 },
  27. { 46, 47, 48, 49, 50, 51 },
  28. { 57, 56, 55, 54, 53, 52 },
  29. { NO_LED, NO_LED, 58, 59, 60, 61 }
  30. }, {
  31. // LED Index to Physical Position
  32. // Left Half
  33. { 0, 5 }, { 16, 5 }, { 32, 2 }, { 48, 0 }, { 64, 2 }, { 80, 3 },
  34. { 80, 17 }, { 64, 15 }, { 48, 13 }, { 32, 15 }, { 16, 18 }, { 0, 18 },
  35. { 0, 32 }, { 16, 32 }, { 32, 28 }, { 48, 27 }, { 64, 28 }, { 80, 30 },
  36. { 80, 43 }, { 64, 42 }, { 48, 40 }, { 32, 42 }, { 16, 45 }, { 0, 45 },
  37. { 56, 47 }, { 72, 58 }, { 90, 64 }, { 98, 52 },
  38. { 80, 58 }, { 40, 50 }, { 8, 43 }, { 8, 5 }, { 40, 1 }, { 72, 3 },
  39. // Right Half
  40. { 224, 5 }, { 208, 5 }, { 192, 2 }, { 176, 0 }, { 160, 2 }, { 144, 3 },
  41. { 144, 18 }, { 160, 18 }, { 176, 15 }, { 192, 13 }, { 208, 15 }, { 224, 17 },
  42. { 224, 32 }, { 208, 32 }, { 192, 28 }, { 176, 27 }, { 160, 28 }, { 144, 30 },
  43. { 144, 45 }, { 160, 45 }, { 176, 42 }, { 192, 40 }, { 208, 42 }, { 224, 43 },
  44. { 168, 47 }, { 152, 58 }, { 134, 64 }, { 126, 52 },
  45. { 144, 58 }, { 184, 50 }, { 216, 43 }, { 216, 5 }, { 184, 1 }, { 152, 3 }
  46. }, {
  47. // LED Index to Flag
  48. // Left Half
  49. 4, 4, 4, 4, 4, 4,
  50. 4, 4, 4, 4, 4, 4,
  51. 4, 4, 4, 4, 4, 4,
  52. 4, 4, 4, 4, 4, 4,
  53. 4, 4, 4, 4,
  54. 2, 2, 2, 2, 2, 2,
  55. // Right Half
  56. 4, 4, 4, 4, 4, 4,
  57. 4, 4, 4, 4, 4, 4,
  58. 4, 4, 4, 4, 4, 4,
  59. 4, 4, 4, 4, 4, 4,
  60. 4, 4, 4, 4,
  61. 2, 2, 2, 2, 2, 2
  62. } };
  63. # if defined(VIA_ENABLE) && defined(VIA_CUSTOM_LIGHTING_ENABLE)
  64. // VIA supports only 4 discrete values for effect speed; map these to some
  65. // useful speed values for RGB Matrix.
  66. enum speed_values {
  67. RGBLIGHT_SPEED_0 = UINT8_MAX / 16, // not 0 to avoid really slow effects
  68. RGBLIGHT_SPEED_1 = UINT8_MAX / 4,
  69. RGBLIGHT_SPEED_2 = UINT8_MAX / 2, // matches the default value
  70. RGBLIGHT_SPEED_3 = UINT8_MAX / 4 * 3, // UINT8_MAX is really fast
  71. };
  72. static uint8_t speed_from_rgblight(uint8_t rgblight_speed) {
  73. switch (rgblight_speed) {
  74. case 0:
  75. return RGBLIGHT_SPEED_0;
  76. case 1:
  77. return RGBLIGHT_SPEED_1;
  78. case 2:
  79. default:
  80. return RGBLIGHT_SPEED_2;
  81. case 3:
  82. return RGBLIGHT_SPEED_3;
  83. }
  84. }
  85. static uint8_t speed_to_rgblight(uint8_t rgb_matrix_speed) {
  86. if (rgb_matrix_speed < ((RGBLIGHT_SPEED_0 + RGBLIGHT_SPEED_1) / 2)) {
  87. return 0;
  88. } else if (rgb_matrix_speed < ((RGBLIGHT_SPEED_1 + RGBLIGHT_SPEED_2) / 2)) {
  89. return 1;
  90. } else if (rgb_matrix_speed < ((RGBLIGHT_SPEED_2 + RGBLIGHT_SPEED_3) / 2)) {
  91. return 2;
  92. } else {
  93. return 3;
  94. }
  95. }
  96. void raw_hid_receive_kb(uint8_t *data, uint8_t length) {
  97. switch (data[0]) {
  98. case id_lighting_get_value:
  99. if (data[1] == id_qmk_rgblight_effect_speed) {
  100. data[2] = speed_to_rgblight(rgb_matrix_get_speed());
  101. }
  102. break;
  103. case id_lighting_set_value:
  104. if (data[1] == id_qmk_rgblight_effect_speed) {
  105. rgb_matrix_set_speed_noeeprom(speed_from_rgblight(data[2]));
  106. }
  107. break;
  108. }
  109. }
  110. # endif // defined(VIA_ENABLE) && defined(VIA_CUSTOM_LIGHTING_ENABLE)
  111. #endif
  112. #ifdef ENCODER_ENABLE
  113. bool encoder_update_kb(uint8_t index, bool clockwise) {
  114. if (!encoder_update_user(index, clockwise)) { return false; }
  115. if (index == 0) {
  116. if (clockwise) {
  117. tap_code(KC_VOLU);
  118. } else {
  119. tap_code(KC_VOLD);
  120. }
  121. } else if (index == 1) {
  122. if (clockwise) {
  123. tap_code(KC_PGDN);
  124. } else {
  125. tap_code(KC_PGUP);
  126. }
  127. }
  128. return false;
  129. }
  130. #endif