-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathgalaxy100.c
More file actions
853 lines (710 loc) · 26.5 KB
/
galaxy100.c
File metadata and controls
853 lines (710 loc) · 26.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
// Copyright 2024 Epomaker (@Epomaker)
// SPDX-License-Identifier: GPL-2.0-or-later
#include QMK_KEYBOARD_H
#include "rgb_record/rgb_record.h"
typedef union {
uint32_t raw;
struct {
uint8_t flag : 1;
uint8_t devs : 3;
uint8_t record_channel : 4;
uint8_t record_last_mode;
uint8_t last_btdevs : 3;
};
} confinfo_t;
confinfo_t confinfo;
typedef struct {
bool active;
uint32_t timer;
uint32_t interval;
uint32_t times;
uint8_t index;
RGB rgb;
void (*blink_cb)(uint8_t);
} hs_rgb_indicator_t;
enum layers {
_BL = 0,
_FL,
_MBL,
_MFL,
_FBL,
};
hs_rgb_indicator_t hs_rgb_indicators[HS_RGB_INDICATOR_COUNT];
hs_rgb_indicator_t hs_rgb_bat[HS_RGB_BAT_COUNT];
void rgb_blink_dir(void);
void hs_reset_settings(void);
void rgb_matrix_hs_indicator(void);
void rgb_matrix_hs_indicator_set(uint8_t index, RGB rgb, uint32_t interval, uint8_t times);
void rgb_matrix_hs_set_remain_time(uint8_t index, uint8_t remain_time);
#define keymap_is_mac_system() ((get_highest_layer(default_layer_state) == _MBL) || (get_highest_layer(default_layer_state) == _MFL))
#define keymap_is_base_layer() ((get_highest_layer(default_layer_state) == _BL) || (get_highest_layer(default_layer_state) == _FL))
uint32_t post_init_timer = 0x00;
bool inqbat_flag = false;
bool mac_status = false;
bool charging_state = false;
bool bat_full_flag = false;
bool enable_bat_indicators = true;
uint32_t bat_indicator_cnt = true;
static uint32_t ee_clr_timer = 0;
static uint32_t rec_time;
static bool rec_filp;
bool test_white_light_flag = false;
HSV start_hsv;
bool no_record_fg;
bool lower_sleep = false;
uint8_t buff[] = {14, 8, 2, 1, 1, 1, 1, 1, 1, 1, 0};
void eeconfig_confinfo_update(uint32_t raw) {
eeconfig_update_kb(raw);
}
uint32_t eeconfig_confinfo_read(void) {
return eeconfig_read_kb();
}
void eeconfig_confinfo_default(void) {
confinfo.flag = true;
confinfo.record_channel = 0;
confinfo.record_last_mode = 0xff;
confinfo.last_btdevs = 1;
// #ifdef WIRELESS_ENABLE
// confinfo.devs = DEVS_USB;
// #endif
eeconfig_init_user_datablock();
eeconfig_confinfo_update(confinfo.raw);
#ifdef RGBLIGHT_ENABLE
rgblight_mode(buff[0]);
#endif
}
void eeconfig_confinfo_init(void) {
confinfo.raw = eeconfig_confinfo_read();
if (!confinfo.raw) {
eeconfig_confinfo_default();
}
}
void keyboard_post_init_kb(void) {
#ifdef CONSOLE_ENABLE
debug_enable = true;
#endif
eeconfig_confinfo_init();
#ifdef LED_POWER_EN_PIN
gpio_set_pin_output(LED_POWER_EN_PIN);
gpio_write_pin_high(LED_POWER_EN_PIN);
gpio_set_pin_output(A9);
gpio_write_pin_high(A9);
gpio_set_pin_output(HS_LED_BOOSTING_PIN);
gpio_write_pin_high(HS_LED_BOOSTING_PIN);
#endif
#ifdef MM_BT_DEF_PIN
setPinInputHigh(MM_BT_DEF_PIN);
#endif
#ifdef MM_2G4_DEF_PIN
setPinInputHigh(MM_2G4_DEF_PIN);
#endif
#ifdef USB_POWER_EN_PIN
gpio_write_pin_low(USB_POWER_EN_PIN);
gpio_set_pin_output(USB_POWER_EN_PIN);
#endif
#ifdef HS_BAT_CABLE_PIN
setPinInput(HS_BAT_CABLE_PIN);
#endif
#ifdef BAT_FULL_PIN
setPinInputHigh(BAT_FULL_PIN);
#endif
#ifdef WIRELESS_ENABLE
wireless_init();
// wireless_devs_change(!confinfo.devs, confinfo.devs, false);
post_init_timer = timer_read32();
#endif
keyboard_post_init_user();
rgbrec_init(confinfo.record_channel);
start_hsv = rgb_matrix_get_hsv();
}
#ifdef WIRELESS_ENABLE
void usb_power_connect(void) {
# ifdef USB_POWER_EN_PIN
gpio_write_pin_low(USB_POWER_EN_PIN);
# endif
}
void usb_power_disconnect(void) {
# ifdef USB_POWER_EN_PIN
gpio_write_pin_high(USB_POWER_EN_PIN);
# endif
}
void suspend_power_down_kb(void) {
# ifdef LED_POWER_EN_PIN
gpio_write_pin_low(LED_POWER_EN_PIN);
# endif
suspend_power_down_user();
}
void suspend_wakeup_init_kb(void) {
# ifdef LED_POWER_EN_PIN
gpio_write_pin_high(LED_POWER_EN_PIN);
# endif
wireless_devs_change(wireless_get_current_devs(), wireless_get_current_devs(), false);
suspend_wakeup_init_user();
hs_rgb_blink_set_timer(timer_read32());
}
bool lpwr_is_allow_timeout_hook(void) {
if (wireless_get_current_devs() == DEVS_USB) {
return false;
}
return true;
}
void wireless_post_task(void) {
// auto switching devs
if (post_init_timer && timer_elapsed32(post_init_timer) >= 100) {
md_send_devctrl(MD_SND_CMD_DEVCTRL_FW_VERSION); // get the module fw version.
md_send_devctrl(MD_SND_CMD_DEVCTRL_SLEEP_BT_EN); // timeout 30min to sleep in bt mode, enable
md_send_devctrl(MD_SND_CMD_DEVCTRL_SLEEP_2G4_EN); // timeout 30min to sleep in 2.4g mode, enable
wireless_devs_change(!confinfo.devs, confinfo.devs, false);
post_init_timer = 0x00;
}
hs_mode_scan(false, confinfo.devs, confinfo.last_btdevs);
}
uint32_t wls_process_long_press(uint32_t trigger_time, void *cb_arg) {
uint16_t keycode = *((uint16_t *)cb_arg);
switch (keycode) {
case KC_BT1: {
uint8_t mode = confinfo.devs;
hs_modeio_detection(true, &mode, confinfo.last_btdevs);
if ((mode == hs_bt) || (mode == hs_wireless) || (mode == hs_none)) {
wireless_devs_change(wireless_get_current_devs(), DEVS_BT1, true);
}
} break;
case KC_BT2: {
uint8_t mode = confinfo.devs;
hs_modeio_detection(true, &mode, confinfo.last_btdevs);
if ((mode == hs_bt) || (mode == hs_wireless) || (mode == hs_none)) {
wireless_devs_change(wireless_get_current_devs(), DEVS_BT2, true);
}
} break;
case KC_BT3: {
uint8_t mode = confinfo.devs;
hs_modeio_detection(true, &mode, confinfo.last_btdevs);
if ((mode == hs_bt) || (mode == hs_wireless) || (mode == hs_none)) {
wireless_devs_change(wireless_get_current_devs(), DEVS_BT3, true);
}
} break;
case KC_2G4: {
uint8_t mode = confinfo.devs;
hs_modeio_detection(true, &mode, confinfo.last_btdevs);
if ((mode == hs_2g4) || (mode == hs_wireless) || (mode == hs_none)) {
wireless_devs_change(wireless_get_current_devs(), DEVS_2G4, true);
}
} break;
case EE_CLR: {
} break;
default:
break;
}
return 0;
}
bool process_record_wls(uint16_t keycode, keyrecord_t *record) {
static uint16_t keycode_shadow = 0x00;
static deferred_token wls_process_long_press_token = INVALID_DEFERRED_TOKEN;
keycode_shadow = keycode;
# ifndef WLS_KEYCODE_PAIR_TIME
# define WLS_KEYCODE_PAIR_TIME 3000
# endif
# define WLS_KEYCODE_EXEC(wls_dev) \
do { \
if (record->event.pressed) { \
if (wireless_get_current_devs() != wls_dev) \
wireless_devs_change(wireless_get_current_devs(), wls_dev, false); \
if (wls_process_long_press_token == INVALID_DEFERRED_TOKEN) { \
wls_process_long_press_token = defer_exec(WLS_KEYCODE_PAIR_TIME, wls_process_long_press, &keycode_shadow); \
} \
} else { \
cancel_deferred_exec(wls_process_long_press_token); \
wls_process_long_press_token = INVALID_DEFERRED_TOKEN; \
} \
} while (false)
switch (keycode) {
case KC_BT1: {
uint8_t mode = confinfo.devs;
hs_modeio_detection(true, &mode, confinfo.last_btdevs);
if ((mode == hs_bt) || (mode == hs_wireless) || (mode == hs_none)) {
WLS_KEYCODE_EXEC(DEVS_BT1);
hs_rgb_blink_set_timer(timer_read32());
}
} break;
case KC_BT2: {
uint8_t mode = confinfo.devs;
hs_modeio_detection(true, &mode, confinfo.last_btdevs);
if ((mode == hs_bt) || (mode == hs_wireless) || (mode == hs_none)) {
WLS_KEYCODE_EXEC(DEVS_BT2);
hs_rgb_blink_set_timer(timer_read32());
}
} break;
case KC_BT3: {
uint8_t mode = confinfo.devs;
hs_modeio_detection(true, &mode, confinfo.last_btdevs);
if ((mode == hs_bt) || (mode == hs_wireless) || (mode == hs_none)) {
WLS_KEYCODE_EXEC(DEVS_BT3);
hs_rgb_blink_set_timer(timer_read32());
}
} break;
case KC_2G4: {
uint8_t mode = confinfo.devs;
hs_modeio_detection(true, &mode, confinfo.last_btdevs);
if ((mode == hs_2g4) || (mode == hs_wireless) || (mode == hs_none)) {
WLS_KEYCODE_EXEC(DEVS_2G4);
hs_rgb_blink_set_timer(timer_read32());
}
} break;
default:
return true;
}
return false;
}
#endif
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
if (test_white_light_flag && record->event.pressed) {
test_white_light_flag = false;
rgb_matrix_set_color_all(0x00, 0x00, 0x00);
}
switch (keycode) {
case MO(_FL):
case MO(_MFL): {
if (!record->event.pressed && rgbrec_is_started()) {
if (no_record_fg == true) {
no_record_fg = false;
rgbrec_register_record(keycode, record);
}
no_record_fg = true;
}
break;
}
case RP_END:
case RP_P0:
case RP_P1:
case RP_P2:
case RGB_MOD:
break;
default: {
if (rgbrec_is_started()) {
if (!IS_QK_MOMENTARY(keycode) && record->event.pressed) {
rgbrec_register_record(keycode, record);
return false;
}
}
} break;
}
if (rgbrec_is_started() && (!(keycode == RP_P0 || keycode == RP_P1 || keycode == RP_P2 || keycode == RP_END || keycode == RGB_MOD || keycode == MO(_FL) || keycode == MO(_MFL)))) {
return false;
}
return true;
}
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
if (process_record_user(keycode, record) != true) {
return false;
}
switch (keycode) {
case QK_BOOT: {
if (record->event.pressed) {
dprintf("into boot!!!\r\n");
eeconfig_disable();
bootloader_jump();
}
} break;
case NK_TOGG: {
if (rgbrec_is_started()) {
return false;
}
if (record->event.pressed) {
rgb_matrix_hs_indicator_set(0xFF, (RGB){0x00, 0x6E, 0x00}, 250, 1);
}
} break;
case EE_CLR: {
if (record->event.pressed) {
ee_clr_timer = timer_read32();
} else {
ee_clr_timer = 0;
}
return false;
} break;
case RGB_SPI: {
if (record->event.pressed) {
if (rgb_matrix_get_speed() >= (RGB_MATRIX_SPD_STEP * 5)) {
rgb_blink_dir();
}
}
} break;
case RGB_SPD: {
if (record->event.pressed) {
if (rgb_matrix_get_speed() <= RGB_MATRIX_SPD_STEP) {
rgb_blink_dir();
rgb_matrix_set_speed(RGB_MATRIX_SPD_STEP);
return false;
}
}
} break;
case RGB_VAI: {
if (record->event.pressed) {
if (rgb_matrix_get_val() >= (RGB_MATRIX_MAXIMUM_BRIGHTNESS - RGB_MATRIX_VAL_STEP)) {
rgb_blink_dir();
start_hsv.v = RGB_MATRIX_MAXIMUM_BRIGHTNESS;
} else {
start_hsv.v = rgb_matrix_get_val() + RGB_MATRIX_VAL_STEP;
}
}
} break;
case RGB_VAD: {
if (record->event.pressed) {
if (rgb_matrix_get_val() <= RGB_MATRIX_VAL_STEP) {
rgb_blink_dir();
rgb_matrix_set_color_all(0, 0, 0);
start_hsv.v = 0;
} else {
start_hsv.v = rgb_matrix_get_val() - RGB_MATRIX_VAL_STEP;
}
}
} break;
case TO(_BL): {
if (record->event.pressed) {
rgb_matrix_hs_set_remain_time(HS_RGB_BLINK_INDEX_MAC, 0);
rgb_matrix_hs_indicator_set(HS_RGB_BLINK_INDEX_WIN, (RGB){RGB_WHITE}, 250, 3);
if (keymap_is_mac_system()) {
set_single_persistent_default_layer(_BL);
layer_move(0);
}
}
return false;
} break;
case TO(_MBL): {
if (record->event.pressed) {
rgb_matrix_hs_set_remain_time(HS_RGB_BLINK_INDEX_WIN, 0);
rgb_matrix_hs_indicator_set(HS_RGB_BLINK_INDEX_MAC, (RGB){RGB_WHITE}, 250, 3);
if (!keymap_is_mac_system()) {
set_single_persistent_default_layer(_MBL);
layer_move(0);
}
}
return false;
} break;
case RP_P0: {
if (record->event.pressed) {
confinfo.record_channel = 0;
rgbrec_read_current_channel(confinfo.record_channel);
rgbrec_end(confinfo.record_channel);
eeconfig_confinfo_update(confinfo.raw);
rgbrec_show(confinfo.record_channel);
dprintf("confinfo.record_last_mode = %d\r\n", confinfo.record_last_mode);
}
return false;
} break;
case RP_P1: {
if (record->event.pressed) {
confinfo.record_channel = 1;
rgbrec_read_current_channel(confinfo.record_channel);
rgbrec_end(confinfo.record_channel);
eeconfig_confinfo_update(confinfo.raw);
rgbrec_show(confinfo.record_channel);
}
return false;
} break;
case RP_P2: {
if (record->event.pressed) {
confinfo.record_channel = 2;
rgbrec_read_current_channel(confinfo.record_channel);
rgbrec_end(confinfo.record_channel);
eeconfig_confinfo_update(confinfo.raw);
rgbrec_show(confinfo.record_channel);
}
return false;
} break;
case RP_END: {
if (record->event.pressed) {
if (rgb_matrix_get_mode() != RGB_MATRIX_CUSTOM_RGBR_PLAY) {
return false;
}
if (!rgbrec_is_started()) {
rgbrec_start(confinfo.record_channel);
no_record_fg = false;
rec_time = timer_read32();
rgbrec_set_close_all(HSV_BLACK);
} else {
rec_time = 0;
rgbrec_end(confinfo.record_channel);
}
dprintf("confinfo.record_last_mode = %d\r\n", confinfo.record_last_mode);
}
return false;
} break;
case RGB_MOD: {
if (record->event.pressed) {
if (rgb_matrix_get_mode() == RGB_MATRIX_CUSTOM_RGBR_PLAY) {
if (rgbrec_is_started()) {
rgbrec_read_current_channel(confinfo.record_channel);
rgbrec_end(confinfo.record_channel);
no_record_fg = false;
}
if (confinfo.record_last_mode != 0xFF)
rgb_matrix_mode(confinfo.record_last_mode);
else
rgb_matrix_mode(RGB_MATRIX_DEFAULT_MODE);
eeconfig_confinfo_update(confinfo.raw);
dprintf("confinfo.record_last_mode = %d\r\n", confinfo.record_last_mode);
start_hsv = rgb_matrix_get_hsv();
return false;
}
record_rgbmatrix_increase(&(confinfo.record_last_mode));
eeconfig_confinfo_update(confinfo.raw);
start_hsv = rgb_matrix_get_hsv();
}
return false;
} break;
case RGB_HUI: {
if (record->event.pressed) {
record_color_hsv(true);
start_hsv = rgb_matrix_get_hsv();
}
return false;
} break;
case KC_LCMD: {
if (keymap_is_mac_system()) {
if (keymap_config.no_gui && !rgbrec_is_started()) {
if (record->event.pressed) {
register_code16(KC_LCMD);
} else {
unregister_code16(KC_LCMD);
}
}
}
return true;
} break;
case KC_RCMD: {
if (keymap_is_mac_system()) {
if (keymap_config.no_gui && !rgbrec_is_started()) {
if (record->event.pressed) {
register_code16(KC_RCMD);
} else {
unregister_code16(KC_RCMD);
}
}
}
return true;
} break;
case USE_TASK:{
if (record->event.pressed){
register_code(KC_LCTL);
register_code(KC_LSFT);
register_code(KC_ESC);
}
else{
unregister_code(KC_LCTL);
unregister_code(KC_LSFT);
unregister_code(KC_ESC);
}
return false;
}break;
case USE_PRO:{
if (record->event.pressed){
register_code(KC_LCTL);
register_code(KC_LALT);
register_code(KC_TAB);
}
else{
unregister_code(KC_LCTL);
unregister_code(KC_LALT);
unregister_code(KC_TAB);
}
return false;
}break;
default:
break;
}
return true;
}
void housekeeping_task_user(void) {
charging_state = readPin(HS_BAT_CABLE_PIN);
}
#ifdef RGB_MATRIX_ENABLE
# ifdef WIRELESS_ENABLE
bool wls_rgb_indicator_reset = false;
uint32_t wls_rgb_indicator_timer = 0x00;
uint32_t wls_rgb_indicator_interval = 0;
uint32_t wls_rgb_indicator_times = 0;
uint32_t wls_rgb_indicator_index = 0;
RGB wls_rgb_indicator_rgb = {0};
void rgb_matrix_wls_indicator_set(uint8_t index, RGB rgb, uint32_t interval, uint8_t times) {
wls_rgb_indicator_timer = timer_read32();
wls_rgb_indicator_index = index;
wls_rgb_indicator_interval = interval;
wls_rgb_indicator_times = times * 2;
wls_rgb_indicator_rgb = rgb;
}
void rgb_matrix_wls_indicator(void) {
if (wls_rgb_indicator_timer) {
if (timer_elapsed32(wls_rgb_indicator_timer) >= wls_rgb_indicator_interval) {
wls_rgb_indicator_timer = timer_read32();
if (wls_rgb_indicator_times) {
wls_rgb_indicator_times--;
}
if (wls_rgb_indicator_times <= 0) {
wls_rgb_indicator_timer = 0x00;
if (rgb_matrix_wls_indicator_cb() != true) {
return;
}
}
}
if (wls_rgb_indicator_times % 2) {
rgb_matrix_set_color(wls_rgb_indicator_index, wls_rgb_indicator_rgb.r, wls_rgb_indicator_rgb.g, wls_rgb_indicator_rgb.b);
} else {
rgb_matrix_set_color(wls_rgb_indicator_index, 0x00, 0x00, 0x00);
}
}
}
void rgb_matrix_hs_bat_set(uint8_t index, RGB rgb, uint32_t interval, uint8_t times) {
for (int i = 0; i < HS_RGB_BAT_COUNT; i++) {
if (!hs_rgb_bat[i].active) {
hs_rgb_bat[i].active = true;
hs_rgb_bat[i].timer = timer_read32();
hs_rgb_bat[i].interval = interval;
hs_rgb_bat[i].times = times * 2;
hs_rgb_bat[i].index = index;
hs_rgb_bat[i].rgb = rgb;
break;
}
}
}
# endif
#endif
void rgb_blink_dir(void) {
rgb_matrix_hs_indicator_set(HS_RGB_BLINK_INDEX_VAI, (RGB){0x20, 0x20, 0x20}, 250, 3);
rgb_matrix_hs_indicator_set(HS_RGB_BLINK_INDEX_VAD, (RGB){0x20, 0x20, 0x20}, 250, 3);
rgb_matrix_hs_indicator_set(HS_RGB_BLINK_INDEX_SPI, (RGB){0x20, 0x20, 0x20}, 250, 3);
rgb_matrix_hs_indicator_set(HS_RGB_BLINK_INDEX_SPD, (RGB){0x20, 0x20, 0x20}, 250, 3);
}
bool hs_reset_settings_user(void) {
rgb_matrix_hs_indicator_set(0xFF, (RGB){0x10, 0x10, 0x10}, 250, 3);
return true;
}
void nkr_indicators_hook(uint8_t index) {
if ((hs_rgb_indicators[index].rgb.r == 0x6E) && (hs_rgb_indicators[index].rgb.g == 0x00) && (hs_rgb_indicators[index].rgb.b == 0x00)) {
rgb_matrix_hs_indicator_set(0xFF, (RGB){0x6E, 0x00, 0x00}, 250, 1);
} else if ((hs_rgb_indicators[index].rgb.r == 0x00) && (hs_rgb_indicators[index].rgb.g == 0x6E) && (hs_rgb_indicators[index].rgb.b == 0x00)) {
rgb_matrix_hs_indicator_set(0xFF, (RGB){0x00, 0x00, 0x6F}, 250, 1);
}
}
void rgb_matrix_hs_indicator_set(uint8_t index, RGB rgb, uint32_t interval, uint8_t times) {
for (int i = 0; i < HS_RGB_INDICATOR_COUNT; i++) {
if (!hs_rgb_indicators[i].active) {
hs_rgb_indicators[i].active = true;
hs_rgb_indicators[i].timer = timer_read32();
hs_rgb_indicators[i].interval = interval;
hs_rgb_indicators[i].times = times * 2;
hs_rgb_indicators[i].index = index;
hs_rgb_indicators[i].rgb = rgb;
if (index != 0xFF)
hs_rgb_indicators[i].blink_cb = NULL;
else {
hs_rgb_indicators[i].blink_cb = nkr_indicators_hook;
}
break;
}
}
}
void rgb_matrix_hs_set_remain_time(uint8_t index, uint8_t remain_time) {
for (int i = 0; i < HS_RGB_INDICATOR_COUNT; i++) {
if (hs_rgb_indicators[i].index == index) {
hs_rgb_indicators[i].times = 0;
hs_rgb_indicators[i].active = false;
break;
}
}
}
void rgb_matrix_hs_indicator(void) {
for (int i = 0; i < HS_RGB_INDICATOR_COUNT; i++) {
if (hs_rgb_indicators[i].active) {
if (timer_elapsed32(hs_rgb_indicators[i].timer) >= hs_rgb_indicators[i].interval) {
hs_rgb_indicators[i].timer = timer_read32();
if (hs_rgb_indicators[i].times) {
hs_rgb_indicators[i].times--;
}
if (hs_rgb_indicators[i].times <= 0) {
hs_rgb_indicators[i].active = false;
hs_rgb_indicators[i].timer = 0x00;
if (hs_rgb_indicators[i].blink_cb != NULL)
hs_rgb_indicators[i].blink_cb(i);
continue;
}
}
if ((hs_rgb_indicators[i].times % 2)) {
if (hs_rgb_indicators[i].index == 0xFF) {
rgb_matrix_set_color_all(hs_rgb_indicators[i].rgb.r, hs_rgb_indicators[i].rgb.g, hs_rgb_indicators[i].rgb.b);
} else {
rgb_matrix_set_color(hs_rgb_indicators[i].index, hs_rgb_indicators[i].rgb.r, hs_rgb_indicators[i].rgb.g, hs_rgb_indicators[i].rgb.b);
}
} else {
if (hs_rgb_indicators[i].index == 0xFF) {
rgb_matrix_set_color_all(0x00, 0x00, 0x00);
} else {
rgb_matrix_set_color(hs_rgb_indicators[i].index, 0x00, 0x00, 0x00);
}
}
}
}
}
void rgb_matrix_start_rec(void) {
if (rgbrec_is_started()) {
if (!rec_time || timer_elapsed32(rec_time) > 250) {
rec_time = timer_read32();
rec_filp = !rec_filp;
}
if (rec_filp) {
rgb_matrix_set_color(0, 0x20, 0x20, 0x20);
rgb_matrix_set_color(1, 0x20, 0x20, 0x20);
rgb_matrix_set_color(2, 0x20, 0x20, 0x20);
} else {
rgb_matrix_set_color(0, 0x00, 0x00, 0x00);
rgb_matrix_set_color(1, 0x00, 0x00, 0x00);
rgb_matrix_set_color(2, 0x00, 0x00, 0x00);
}
} else {
rec_time = 0;
rec_filp = false;
}
}
bool rgb_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max) {
if (test_white_light_flag) {
RGB rgb_test_open = hsv_to_rgb((HSV){.h = 0, .s = 0, .v = RGB_MATRIX_VAL_STEP * 5});
rgb_matrix_set_color_all(rgb_test_open.r, rgb_test_open.g, rgb_test_open.b);
return false;
}
if (ee_clr_timer && timer_elapsed32(ee_clr_timer) > 3000) {
hs_reset_settings();
ee_clr_timer = 0;
}
if (host_keyboard_led_state().caps_lock)
rgb_matrix_set_color(HS_RGB_INDEX_CAPS, 0x20, 0x20, 0x20);
else
rgb_matrix_set_color(HS_RGB_INDEX_CAPS, RGB_BLACK);
if (!keymap_is_mac_system() && keymap_config.no_gui)
rgb_matrix_set_color(HS_RGB_INDEX_WIN_LOCK, 0x20, 0x20, 0x20);
else
rgb_matrix_set_color(HS_RGB_INDEX_WIN_LOCK, RGB_BLACK);
rgb_matrix_hs_indicator();
rgb_matrix_start_rec();
return true;
}
void hs_reset_settings(void) {
enable_bat_indicators = false;
eeconfig_init();
eeconfig_update_rgb_matrix_default();
keymap_config.raw = eeconfig_read_keymap();
#if defined(NKRO_ENABLE) && defined(FORCE_NKRO)
keymap_config.nkro = 0;
eeconfig_update_keymap(keymap_config.raw);
#endif
// #if defined(WIRELESS_ENABLE)
// wireless_devs_change(wireless_get_current_devs(), DEVS_USB, false);
// #endif
if (hs_reset_settings_user() != true) {
return;
}
keyboard_post_init_kb();
}
void lpwr_wakeup_hook(void) {
gpio_write_pin_high(LED_POWER_EN_PIN);
gpio_write_pin_high(A9);
gpio_write_pin_high(HS_LED_BOOSTING_PIN);
}