rev2.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /* Copyright 2020 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 "rev2.h"
  17. #ifdef RGB_MATRIX_ENABLE
  18. const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
  19. /* Refer to IS31 manual for these locations
  20. * driver
  21. * | R location
  22. * | | G location
  23. * | | | B location
  24. * | | | | */
  25. // left CA
  26. {0, C1_1, C3_2, C4_2}, //D9-0-0
  27. {0, C5_2, C6_2, C7_2}, //D59-1-1
  28. {0, C2_1, C3_1, C4_1}, //D68-2-2
  29. {0, C5_1, C6_1, C7_1}, //D76-3-3
  30. {0, C1_2, C2_2, C4_3}, //D10-15-4
  31. {0, C5_3, C6_3, C7_3}, //D60-16-5
  32. {0, C1_3, C2_3, C3_3}, //D72-17-6
  33. {0, C5_4, C6_4, C7_4}, //D77-18-7
  34. {0, C1_4, C2_4, C3_4}, //D46-30-8
  35. {0, C4_4, C6_5, C7_5}, //D61-31-9
  36. {0, C1_5, C2_5, C3_5}, //D73-32-10
  37. {0, C4_5, C5_5, C7_6}, //D78-33-11
  38. {0, C1_6, C2_6, C3_6}, //D126-44-12
  39. {0, C4_6, C5_6, C6_6}, //D51-45-13
  40. {0, C1_7, C2_7, C3_7}, //D63-46-14
  41. {0, C4_7, C5_7, C6_7}, //D74-47-15
  42. {0, C1_8, C2_8, C3_8}, //D56-60-16
  43. {0, C4_8, C5_8, C6_8}, //D67-61-17
  44. // left CB
  45. {0, C2_9, C3_9, C4_9}, //D80-4-18
  46. {0, C5_9, C6_9, C7_9}, //D84-5-19
  47. {0, C1_9, C3_10, C4_10}, //D89-6-20
  48. {0, C5_10, C6_10, C7_10}, //D94-7-21
  49. {0, C1_10, C2_10, C4_11}, //D81-19-22
  50. {0, C5_11, C6_11, C7_11}, //D85-20-23
  51. {0, C1_11, C2_11, C3_11}, //D90-21-24
  52. {0, C5_12, C6_12, C7_12}, //D95-22-25
  53. {0, C1_12, C2_12, C3_12}, //D82-34-26
  54. {0, C4_12, C6_13, C7_13}, //D86-35-27
  55. {0, C1_13, C2_13, C3_13}, //D91-36-28
  56. {0, C4_13, C5_13, C7_14}, //D96-37-29
  57. {0, C1_14, C2_14, C3_14}, //D79-48-30
  58. {0, C4_14, C5_14, C6_14}, //D83-49-31
  59. {0, C1_15, C2_15, C3_15}, //D87-50-32
  60. {0, C4_15, C5_15, C6_15}, //D92-51-33
  61. {0, C1_16, C2_16, C3_16}, //D75-62-34
  62. {0, C4_16, C5_16, C6_16}, //D93-63-35
  63. // right CA
  64. {1, C2_1, C3_1, C4_1}, //D98-8-36
  65. {1, C5_1, C6_1, C7_1}, //D102-9-37
  66. {1, C1_1, C3_2, C4_2}, //D106-10-38
  67. {1, C5_2, C6_2, C7_2}, //D111-11-39
  68. {1, C2_9, C3_9, C4_9}, //D116-12-40
  69. {1, C5_9, C6_9, C7_9}, //D130-13-41
  70. {1, C1_13, C2_13, C3_13}, //D121-14-42
  71. {1, C1_2, C2_2, C4_3}, //D99-23-43
  72. {1, C5_3, C6_3, C7_3}, //D103-24-44
  73. {1, C1_3, C2_3, C3_3}, //D107-25-45
  74. {1, C5_4, C6_4, C7_4}, //D112-26-46
  75. {1, C1_9, C3_10, C4_10}, //D117-27-47
  76. {1, C5_10, C6_10, C7_10}, //D129-28-48
  77. {1, C4_13, C5_13, C7_14}, //D122-29-49
  78. {1, C1_4, C2_4, C3_4}, //D100-38-50
  79. {1, C4_4, C6_5, C7_5}, //D104-39-51
  80. {1, C1_5, C2_5, C3_5}, //D108-40-52
  81. {1, C4_5, C5_5, C7_6}, //D113-41-53
  82. // right CB
  83. {1, C1_10, C2_10, C4_11}, //D118-42-54
  84. {1, C5_11, C6_11, C7_11}, //D123-43-55
  85. {1, C1_6, C2_6, C3_6}, //D97-52-56
  86. {1, C4_6, C5_6, C6_6}, //D101-53-57
  87. {1, C1_7, C2_7, C3_7}, //D105-54-58
  88. {1, C4_7, C5_7, C6_7}, //D109-55-59
  89. {1, C1_11, C2_11, C3_11}, //D114-56-60
  90. {1, C5_12, C6_12, C7_12}, //D128-57-61
  91. {1, C1_14, C2_14, C3_14}, //D119-58-62
  92. {1, C4_14, C5_14, C6_14}, //D124-59-63
  93. {1, C1_8, C2_8, C3_8}, //D127-64-64
  94. {1, C4_8, C5_8, C6_8}, //D110-65-65
  95. {1, C1_12, C2_12, C3_12}, //D115-66-66
  96. {1, C4_12, C6_13, C7_13}, //D120-67-67
  97. {1, C1_15, C2_15, C3_15}, //D125-68-68
  98. {1, C4_15, C5_15, C6_15}, //D140-69-69
  99. {0, C8_7, C7_7, C7_8}, //INDICATOR LED-70
  100. {0, C8_8, C8_1, C8_2}, //INDICATOR LED-71
  101. {0, C9_7, C8_6, C9_6}, //INDICATOR LED-72
  102. {0, C9_8, C8_4, C8_5},//INDICATOR LED-73
  103. {0, C8_15, C9_1, C9_2},//INDICATOR LED-74
  104. {0, C8_16, C8_3, C9_3},//INDICATOR LED-75
  105. {0, C9_15, C9_9, C9_10},//INDICATOR LED-76
  106. {0, C9_16, C9_11, C7_12},//INDICATOR LED-77
  107. };
  108. led_config_t g_led_config = { {
  109. // Key Matrix to LED Index
  110. {0, 1, 2, 3, 18, 19, 20, 21, 36, 37, 38, 39, 40, 41},
  111. {4, 5, 6, 7, 22, 23, 24, 25, 43, 44, 45, 46, 47, 69},
  112. {8, 9, 10, 11, 26, 27, 28, 29, 50, 51, 52, 53, 54, 55},
  113. {13, 14, 15, 30, 31, 32, 33, 56, 57, 58, 59, 60, 62, 63},
  114. {16, 17, 34, NO_LED, NO_LED, NO_LED, 35, NO_LED, NO_LED, NO_LED, 65, 66, 67, 68},
  115. },
  116. {
  117. //LED Index to Physical Positon
  118. { 0, 0}, { 16, 0}, { 32, 0 }, { 48, 0}, //9-59-68-76
  119. { 0, 16}, { 16, 16}, { 32, 16}, { 48, 16}, //10-60-72-77
  120. { 0, 32}, { 16, 32}, { 32, 32}, { 48, 32}, //46-61-73-78
  121. { 0, 48}, { 0, 48}, { 12, 48}, { 16, 48}, //126-51-63-74
  122. { 0, 64}, { 16, 64}, //56-67
  123. { 64, 0}, { 80, 0}, { 96, 0}, { 112, 0}, //80-84-89-94
  124. { 64, 16}, { 80, 16}, { 96,16}, { 112,16}, //81-85-90-95
  125. { 64, 32}, { 80, 32}, { 96,32}, { 112,32}, //82-86-91-96
  126. { 32, 48}, { 48, 48}, { 64,48}, { 80,48}, //79-83-87-92
  127. { 32, 64}, { 80, 64}, //75-93
  128. { 128, 0}, { 144, 0}, { 160, 0}, { 176, 0}, {192, 0}, {220, 0}, {210, 0}, //98-102-106-111-116-121-130
  129. { 128,16}, {144,16}, {160,16}, {176, 16}, {192, 16}, {220, 16}, {220,16}, //99-103-107-112-117-129-122
  130. { 128,32}, { 144,32}, { 160,32}, { 176,32}, {192, 32}, {220, 32}, //100-104-108-113-118-123
  131. { 96,48}, {112,48}, {128, 48}, {144, 48}, {160, 48}, {200, 48}, {220,48}, {220,48}, //97-101-105-109-114-119-128-124
  132. { 96,64}, {144,64}, {160,64}, {176,64}, {220, 64}, //127-110-115-120-125
  133. { 220, 0}, //140
  134. }, {
  135. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  136. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  137. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  138. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  139. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  140. } };
  141. __attribute__((weak)) void rgb_matrix_indicators_user(void) {
  142. if (host_keyboard_led_state().caps_lock) {
  143. rgb_matrix_set_color(8, 255, 255, 255);
  144. rgb_matrix_set_color(70, 255, 0, 0);
  145. } else {
  146. rgb_matrix_set_color(70, 0, 0, 0);
  147. }
  148. if (host_keyboard_led_state().num_lock) {
  149. rgb_matrix_set_color(71, 255, 0, 0);
  150. } else {
  151. rgb_matrix_set_color(71, 0, 0, 0);
  152. }
  153. if (host_keyboard_led_state().scroll_lock) {
  154. rgb_matrix_set_color(72, 255, 0, 0);
  155. } else {
  156. rgb_matrix_set_color(72, 0, 0, 0);
  157. }
  158. }
  159. __attribute__((weak))
  160. layer_state_t layer_state_set_user(layer_state_t state) {
  161. // if on layer 1, turn on L1 LED, otherwise off.
  162. if (get_highest_layer(state) == 0) {
  163. rgb_matrix_set_color(73, 255, 0, 0);
  164. } else {
  165. rgb_matrix_set_color(73, 0, 0, 0);
  166. }
  167. // if on layer 2, turn on L2 LED, otherwise off.
  168. if (get_highest_layer(state) == 1) {
  169. rgb_matrix_set_color(74, 255, 0, 0);
  170. } else {
  171. rgb_matrix_set_color(74, 0, 0, 0);
  172. }
  173. // if on layer 3, turn on L3 LED, otherwise off.
  174. if (get_highest_layer(state) == 2) {
  175. rgb_matrix_set_color(75, 255, 0, 0);
  176. } else {
  177. rgb_matrix_set_color(75, 0, 0, 0);
  178. }
  179. // if on layer 4, turn on L4 LED, otherwise off.
  180. if (get_highest_layer(state) == 3) {
  181. rgb_matrix_set_color(76, 255, 0, 0);
  182. } else {
  183. rgb_matrix_set_color(76, 0, 0, 0);
  184. }
  185. // if on layer 5, turn on L5 LED, otherwise off.
  186. if (get_highest_layer(state) == 4) {
  187. rgb_matrix_set_color(77, 255, 0, 0);
  188. } else {
  189. rgb_matrix_set_color(77, 0, 0, 0);
  190. }
  191. return state;
  192. }
  193. #endif
  194. bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
  195. if (record->event.pressed) {
  196. switch(keycode) {
  197. #ifdef RGB_MATRIX_DISABLE_KEYCODES
  198. case KC_F13: // toggle rgb matrix
  199. rgb_matrix_toggle();
  200. return false;
  201. case KC_F14:
  202. rgb_matrix_step();
  203. return false;
  204. case KC_F15:
  205. rgb_matrix_increase_speed();
  206. return false;
  207. case KC_F16:
  208. rgb_matrix_decrease_speed();
  209. return false;
  210. case KC_F17:
  211. rgb_matrix_increase_hue();
  212. return false;
  213. case KC_F18:
  214. rgb_matrix_decrease_hue();
  215. return false;
  216. case KC_F19:
  217. rgb_matrix_increase_sat();
  218. return false;
  219. case KC_F20:
  220. rgb_matrix_decrease_sat();
  221. return false;
  222. case KC_F21:
  223. rgb_matrix_increase_val();
  224. return false;
  225. case KC_F22:
  226. rgb_matrix_decrease_val();
  227. return false;
  228. #endif
  229. default:
  230. break;
  231. }
  232. }
  233. return true;
  234. }