logo

qmk_firmware

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

nz67v2.c (4326B)


  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. led_config_t g_led_config = {
  25. {
  26. {54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68},
  27. {53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39},
  28. {25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, NO_LED, 37, 38},
  29. {24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, NO_LED, 13, 12, 11},
  30. {0, 1, 2, 3, NO_LED, 4, NO_LED, 5, NO_LED, 6, 7, NO_LED, 8, 9, 10}
  31. },
  32. {
  33. {0,64},{16,64},{32,64},{48,64}, {80,64}, {112,64}, {144,64},{160,64}, {192,64},{208,64},{224,64},
  34. {224,48},{208,48},{192,48}, {160,48},{144,48},{128,48},{112,48},{96,48},{80,48},{64,48},{48,48},{32,48},{16,48},{0,48},
  35. {0,32},{16,32},{32,32},{48,32},{64,32},{80,32},{96,32},{112,32},{128,32},{144,32},{160,32},{176,32}, {208,32},{224,32},
  36. {224,16},{208,16},{192,16},{176,16},{160,16},{144,16},{128,16},{112,16},{96,16},{80,16},{64,16},{48,16},{32,16},{16,16},{0,16},
  37. {0,0},{16,0},{32,0},{48,0},{64,0},{80,0},{96,0},{112,0},{128,0},{144,0},{160,0},{176,0},{192,0},{208,0},{224,0},
  38. {224,0},{196,0},{168,0},{140,0},{112,0},{84,0},{56,0},{28,0},{0,0},
  39. {224,64},{196,64},{168,64},{140,64},{112,64},{84,64},{56,64},{28,64}
  40. },
  41. {
  42. 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  43. 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  44. 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  45. 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  46. 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  47. 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  48. 4, 4, 4, 4, 4, 4, 4, 4, 4,
  49. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  50. 2, 2, 2, 2, 2, 2, 2
  51. }
  52. };
  53. bool rgb_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max) {
  54. if (!rgb_matrix_indicators_advanced_user(led_min, led_max)) {
  55. return false;
  56. }
  57. if (rgb_matrix_is_enabled()) {
  58. if (kb_cums.underground_rgb_sw == 1) {
  59. for (uint8_t i = led_min; i < led_max; ++i) {
  60. if ((g_led_config.flags[i] == 4)) {
  61. rgb_matrix_set_color(i, 0, 0, 0);
  62. }
  63. }
  64. } else if (kb_cums.underground_rgb_sw == 2) {
  65. for (uint8_t i = led_min; i < led_max; ++i) {
  66. if ((g_led_config.flags[i] == 2)) {
  67. rgb_matrix_set_color(i, 0, 0, 0);
  68. }
  69. }
  70. }
  71. } else {
  72. rgb_matrix_set_color_all(0,0,0);
  73. }
  74. if (host_keyboard_led_state().caps_lock) {
  75. RGB_MATRIX_INDICATOR_SET_COLOR(25, rgblight_get_val(), rgblight_get_val(), rgblight_get_val());
  76. }
  77. return true;
  78. }
  79. void eeconfig_init_kb(void) {
  80. kb_cums.raw = 0;
  81. eeconfig_update_kb(kb_cums.raw);
  82. eeconfig_init_user();
  83. }
  84. void keyboard_post_init_kb(void) {
  85. kb_cums.underground_rgb_sw = eeconfig_read_kb();
  86. keyboard_post_init_user();
  87. }
  88. #endif
  89. bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
  90. if (!process_record_user(keycode, record)) { return false; }
  91. switch(keycode) {
  92. #ifdef RGB_MATRIX_ENABLE
  93. case URGB_K:
  94. if (rgb_matrix_config.enable && record->event.pressed) {
  95. kb_cums.underground_rgb_sw += 1;
  96. kb_cums.underground_rgb_sw %= 3;
  97. }
  98. eeconfig_update_kb(kb_cums.raw);
  99. return false;
  100. #endif
  101. default:
  102. break;
  103. }
  104. return true;
  105. }
  106. void board_init(void) {
  107. AFIO->MAPR |= AFIO_MAPR_TIM3_REMAP_PARTIALREMAP;
  108. }