nz67v2.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* Copyright 2022 JasonRen(biu)
  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 "nz67v2.h"
  17. #ifdef RGB_MATRIX_ENABLE
  18. /* globol var store in eeprom for key and underground rgb switch */
  19. typedef union {
  20. uint32_t raw;
  21. uint8_t underground_rgb_sw :8;
  22. } kb_cums_t;
  23. kb_cums_t kb_cums;
  24. bool rgb_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max) {
  25. if (!rgb_matrix_indicators_advanced_user(led_min, led_max)) {
  26. return false;
  27. }
  28. if (rgb_matrix_is_enabled()) {
  29. if (kb_cums.underground_rgb_sw == 1) {
  30. for (uint8_t i = led_min; i < led_max; ++i) {
  31. if ((g_led_config.flags[i] == 4)) {
  32. rgb_matrix_set_color(i, 0, 0, 0);
  33. }
  34. }
  35. } else if (kb_cums.underground_rgb_sw == 2) {
  36. for (uint8_t i = led_min; i < led_max; ++i) {
  37. if ((g_led_config.flags[i] == 2)) {
  38. rgb_matrix_set_color(i, 0, 0, 0);
  39. }
  40. }
  41. }
  42. } else {
  43. rgb_matrix_set_color_all(0,0,0);
  44. }
  45. if (host_keyboard_led_state().caps_lock) {
  46. RGB_MATRIX_INDICATOR_SET_COLOR(25, rgblight_get_val(), rgblight_get_val(), rgblight_get_val());
  47. }
  48. return true;
  49. }
  50. void eeconfig_init_kb(void) {
  51. kb_cums.raw = 0;
  52. eeconfig_update_kb(kb_cums.raw);
  53. eeconfig_init_user();
  54. }
  55. void keyboard_post_init_kb(void) {
  56. kb_cums.underground_rgb_sw = eeconfig_read_kb();
  57. keyboard_post_init_user();
  58. }
  59. #endif
  60. bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
  61. if (!process_record_user(keycode, record)) { return false; }
  62. switch(keycode) {
  63. #ifdef RGB_MATRIX_ENABLE
  64. case URGB_K:
  65. if (rgb_matrix_config.enable && record->event.pressed) {
  66. kb_cums.underground_rgb_sw += 1;
  67. kb_cums.underground_rgb_sw %= 3;
  68. }
  69. eeconfig_update_kb(kb_cums.raw);
  70. return false;
  71. #endif
  72. default:
  73. break;
  74. }
  75. return true;
  76. }
  77. void board_init(void) {
  78. AFIO->MAPR |= AFIO_MAPR_TIM3_REMAP_PARTIALREMAP;
  79. }