noah.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /**
  2. * noah.c
  3. */
  4. #include "noah.h"
  5. #ifdef RGBLIGHT_ENABLE
  6. #include <string.h>
  7. #include "rgblight.h"
  8. #include "ws2812.h"
  9. extern rgblight_config_t rgblight_config;
  10. // led 0 for caps lock, led 1 for scroll lock, led 3 for num lock
  11. // led 4 for layer 1, led 5 for layer 2, led 6 for layer 3, led 7 for layer 4
  12. #if RGBLED_NUM < 7
  13. #error "MUST set the RGBLED_NUM bigger than 7"
  14. #endif
  15. LED_TYPE noah_leds[RGBLED_NUM];
  16. static bool noah_led_mode = false;
  17. void rgblight_set(void) {
  18. memset(&noah_leds[0], 0, sizeof(noah_leds));
  19. if (!rgblight_config.enable) {
  20. for (uint8_t i = 0; i < RGBLED_NUM; i++) {
  21. led[i].r = 0;
  22. led[i].g = 0;
  23. led[i].b = 0;
  24. }
  25. }
  26. if (noah_led_mode) {
  27. uint8_t ind_led = host_keyboard_leds();
  28. if (IS_LED_ON(ind_led, USB_LED_CAPS_LOCK)) {
  29. noah_leds[0] = led[0];
  30. }
  31. if (IS_LED_ON(ind_led, USB_LED_SCROLL_LOCK)) {
  32. noah_leds[1] = led[1];
  33. }
  34. if (IS_LED_ON(ind_led, USB_LED_NUM_LOCK)) {
  35. noah_leds[2] = led[2];
  36. }
  37. for (int32_t i = 0; i < 4; i++) {
  38. if(layer_state_is(i+1)) {
  39. noah_leds[i + 3] = led[i + 3];
  40. }
  41. }
  42. } else {
  43. memcpy(&noah_leds[0], &led[0], sizeof(noah_leds));
  44. }
  45. ws2812_setleds(noah_leds, RGBLED_NUM);
  46. }
  47. #endif
  48. void matrix_scan_kb(void) {
  49. #ifdef RGBLIGHT_ENABLE
  50. rgblight_task();
  51. #endif
  52. matrix_scan_user();
  53. }
  54. #ifdef RGB_MATRIX_ENABLE
  55. const is31_led __flash g_is31_leds[DRIVER_LED_TOTAL] = {
  56. /* Refer to IS31 manual for these locations
  57. * driver
  58. * | R location
  59. * | | G location
  60. * | | | B location
  61. * | | | | */
  62. // left CB
  63. {0, C1_9, C3_10, C4_10},
  64. {0, C1_10, C2_10, C4_11},
  65. {0, C1_11, C2_11, C3_11},
  66. {0, C1_12, C2_12, C3_12},
  67. {0, C1_13, C2_13, C3_13},
  68. {0, C1_14, C2_14, C3_14},
  69. {0, C1_15, C2_15, C3_15},
  70. {0, C1_16, C2_16, C3_16},
  71. {0, C5_9, C4_9, C6_9},
  72. {0, C5_16, C4_16, C6_16},
  73. {0, C9_9, C8_9, C7_9},
  74. {0, C9_10, C8_10, C7_10},
  75. {0, C9_11, C8_11, C7_11},
  76. {0, C9_12, C8_12, C7_12},
  77. {0, C9_13, C8_13, C7_13},
  78. {0, C9_14, C8_14, C7_14},
  79. {0, C9_15, C8_15, C6_14},
  80. {0, C9_16, C7_15, C6_15},
  81. // left CA
  82. {0, C1_1, C3_2, C4_2},
  83. {0, C1_2, C2_2, C4_3},
  84. {0, C1_3, C2_3, C3_3},
  85. {0, C1_4, C2_4, C3_4},
  86. {0, C1_5, C2_5, C3_5},
  87. {0, C1_6, C2_6, C3_6},
  88. {0, C1_7, C2_7, C3_7},
  89. {0, C1_8, C2_8, C3_8},
  90. {0, C5_1, C4_1, C6_1},
  91. {0, C5_8, C4_8, C6_8},
  92. {0, C9_1, C8_1, C7_1},
  93. {0, C9_2, C8_2, C7_2},
  94. {0, C9_3, C8_3, C7_3},
  95. {0, C9_4, C8_4, C7_4},
  96. {0, C9_5, C8_5, C7_5},
  97. {0, C9_6, C8_6, C7_6},
  98. {0, C9_7, C8_7, C6_6},
  99. {0, C9_8, C7_7, C6_7},
  100. // right CA
  101. {1, C1_1, C3_2, C4_2},
  102. {1, C1_2, C2_2, C4_3},
  103. {1, C1_3, C2_3, C3_3},
  104. {1, C1_4, C2_4, C3_4},
  105. {1, C1_5, C2_5, C3_5},
  106. {1, C1_6, C2_6, C3_6},
  107. {1, C1_7, C2_7, C3_7},
  108. {1, C1_8, C2_8, C3_8},
  109. {1, C5_1, C4_1, C6_1},
  110. {1, C5_8, C4_8, C6_8},
  111. {1, C9_1, C8_1, C7_1},
  112. {1, C9_2, C8_2, C7_2},
  113. {1, C9_3, C8_3, C7_3},
  114. {1, C9_4, C8_4, C7_4},
  115. {1, C9_5, C8_5, C7_5},
  116. {1, C9_6, C8_6, C7_6},
  117. {1, C9_7, C8_7, C6_6},
  118. {1, C9_8, C7_7, C6_7},
  119. // right CB
  120. {1, C1_9, C3_10, C4_10},
  121. {1, C1_10, C2_10, C4_11},
  122. {1, C1_11, C2_11, C3_11},
  123. {1, C1_12, C2_12, C3_12},
  124. {1, C1_13, C2_13, C3_13},
  125. {1, C1_14, C2_14, C3_14},
  126. {1, C1_15, C2_15, C3_15},
  127. {1, C1_16, C2_16, C3_16},
  128. {1, C5_9, C4_9, C6_9},
  129. {1, C5_16, C4_16, C6_16},
  130. {1, C9_9, C8_9, C7_9},
  131. {1, C9_10, C8_10, C7_10},
  132. {1, C9_11, C8_11, C7_11},
  133. {1, C9_12, C8_12, C7_12},
  134. {1, C9_13, C8_13, C7_13},
  135. {1, C9_14, C8_14, C7_14},
  136. {1, C9_15, C8_15, C6_14},
  137. {1, C9_16, C7_15, C6_15},
  138. };
  139. led_config_t g_led_config = {
  140. {
  141. { 1, 2, 3, 4, 5, 6, 7, 36, 37, 38, 39, 40, NO_LED, 41},
  142. { 0, 8, 10, 11, 12, 13, 14, 44, 46, 47, 48, 49, 50, 51},
  143. { 30, 18, 26, 9, 19, 15, 16, 17, 55, 56, 57, 58, 59, 60},
  144. { 29, 31, 32, 33, 20, 21, 23, 22, 54, 62, 64, 65, 66, 63},
  145. { 34, 35, 27, 25, 67, 68, 69, 70, 71, 61, 53, 45, 42, 43},
  146. },
  147. {
  148. { 0, 16},{ 0, 0},{ 15, 0},{ 30, 0},{ 45, 0},{ 60, 0},{ 75, 0},{ 90, 0},
  149. { 20, 16},{ 42, 32},
  150. { 45, 16},{ 50, 16},{ 65, 16},{ 80, 16},{ 95, 16},{ 70, 32},{ 84, 32},{ 98, 32},
  151. { 14, 32},{ 56, 32},{ 65, 48},{ 80, 48},{110, 48},{ 95, 48},{112, 64},{100, 64},
  152. { 42, 32},{ 38, 64},
  153. { 0, 32},{ 10, 48},{ 0, 48},{ 20, 48},{ 35, 48},{ 50, 48},{ 0, 64},{ 19, 64},
  154. {105, 0},{120, 0},{135, 0},{150, 0},{165, 0},{180, 0},{202, 0},{224, 0},
  155. {110, 16},{224, 16},
  156. {125, 16},{140, 16},{155, 16},{172, 16},{187, 16},{202, 16},{210, 32},{224, 32},
  157. {125, 48},{112, 32},{126, 32},{140, 32},{154, 32},{168, 32},{182, 32},{224, 48},
  158. {140, 48},{200, 48},
  159. {155, 48},{170, 48},{185, 48},{150, 64},{173, 64},{195, 64},{210, 64},{224, 64}
  160. },
  161. {
  162. 1, 1, 4, 4, 4, 4, 4, 4,
  163. 4, 4,
  164. 4, 4, 4, 4, 4, 4, 4, 4,
  165. 4, 4, 4, 4, 4, 4, 4, 4,
  166. 4, 4,
  167. 1, 1, 1, 4, 4, 4, 1, 1,
  168. 4, 4, 4, 4, 4, 4, 1, 1,
  169. 4, 1,
  170. 4, 4, 4, 4, 4, 4, 4, 1,
  171. 4, 4, 4, 4, 4, 4, 4, 1,
  172. 4, 4,
  173. 4, 4, 4, 1, 1, 1, 1, 1,
  174. }
  175. };
  176. #endif
  177. bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
  178. if (record->event.pressed) {
  179. switch(keycode) {
  180. #ifdef RGBLIGHT_ENABLE
  181. case KC_F24: // switch the led mode on or off
  182. noah_led_mode = !noah_led_mode;
  183. return false;
  184. #ifdef RGB_MATRIX_ENABLE
  185. case KC_F13: // toggle rgb matrix
  186. rgb_matrix_toggle();
  187. return false;
  188. case KC_F14:
  189. rgb_matrix_step();
  190. return false;
  191. #endif
  192. #endif
  193. default:
  194. break;
  195. }
  196. }
  197. return process_record_user(keycode, record);
  198. }