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