summaryrefslogtreecommitdiffstats
path: root/keyboards/keychron/c2_pro/c2_pro.c
blob: 2cd58ab4d796f4d252431742074f8b979501f0ba (plain)
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
/* Copyright 2023 @ Keychron (https://www.keychron.com)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "quantum.h"

// clang-format off
const matrix_row_t matrix_mask[] = {
    0b11111111111111111111,
    0b11111111111111111111,
    0b11111111111111111111,
    0b11111111111111111111,
    0b11111111111111111111,
    0b11111111111111101111,
};

// clang-format on

#ifdef DIP_SWITCH_ENABLE

bool dip_switch_update_kb(uint8_t index, bool active) {
    if (!dip_switch_update_user(index, active)) {
        return false;
    }
    if (index == 0) {
        default_layer_set(1UL << (active ? 2 : 0));
    }
    return true;
}

#endif // DIP_SWITCH_ENABLE

#    ifdef RGB_MATRIX_ENABLE
#        define LED_SET_FLAGS rgb_matrix_set_flags
#        define LED_GET_FLAGS rgb_matrix_get_flags
#        define LED_SET_ALL_OFF rgb_matrix_set_color_all(COLOR_BLACK)
#        define LED_IS_ENABLED rgb_matrix_is_enabled
#        define LED_ENABLE rgb_matrix_enable
#        define LED_MATRIX_INDICATORS_KB rgb_matrix_indicators_kb
#        define LED_MATRIX_INDICATORS_USER rgb_matrix_indicators_user
#        define LED_MATRIX_SET_COLOR rgb_matrix_set_color
#        define LED_MATRIX_UPDATE_PWN_BUFFERS rgb_matrix_update_pwm_buffers
#        define LED_MATRIX_INDICATORS_NONE_KB rgb_matrix_indicators_none_kb
#        define LED_MATRIX_IS_ENABLED rgb_matrix_is_enabled
#        define COLOR_WHITE 255, 255, 255
#        define COLOR_BLACK 0, 0, 0
#    endif

#    ifdef LED_MATRIX_ENABLE
#        define LED_SET_FLAGS led_matrix_set_flags
#        define LED_GET_FLAGS led_matrix_get_flags
#        define LED_SET_ALL_OFF led_matrix_set_value_all(COLOR_BLACK)
#        define LED_IS_ENABLED led_matrix_is_enabled
#        define LED_ENABLE led_matrix_enable
#        define LED_MATRIX_INDICATORS_KB led_matrix_indicators_kb
#        define LED_MATRIX_INDICATORS_USER led_matrix_indicators_user
#        define LED_MATRIX_SET_COLOR led_matrix_set_value
#        define LED_MATRIX_UPDATE_PWN_BUFFERS led_matrix_update_pwm_buffers
#        define LED_MATRIX_INDICATORS_NONE_KB led_matrix_indicators_none_kb
#        define LED_MATRIX_IS_ENABLED led_matrix_is_enabled
#        define COLOR_WHITE 255
#        define COLOR_BLACK 0

bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
    if (!process_record_user(keycode, record)) {
        return false;
    }
    switch (keycode) {
        case RGB_TOG:
            if (record->event.pressed) {
                switch (LED_GET_FLAGS()) {
                    case LED_FLAG_ALL: {
                        LED_SET_FLAGS(LED_FLAG_NONE);
                        LED_SET_ALL_OFF;
                    } break;
                    default: {
                        LED_SET_FLAGS(LED_FLAG_ALL);
                    } break;
                }
            }
            if (!LED_IS_ENABLED()) {
                LED_SET_FLAGS(LED_FLAG_ALL);
                LED_ENABLE();
            }
            return false;
    }
    return true;
}

bool LED_MATRIX_INDICATORS_KB(void) {
    if (!LED_MATRIX_INDICATORS_USER()) {
        return false;
    }
    if (host_keyboard_led_state().caps_lock) {
        LED_MATRIX_SET_COLOR(CAPS_LED_INDEX, COLOR_WHITE);
    } else {
        LED_MATRIX_SET_COLOR(CAPS_LED_INDEX, COLOR_BLACK);
    }
    if (host_keyboard_led_state().num_lock) {
        LED_MATRIX_SET_COLOR(NUM_LED_INDEX, COLOR_WHITE);
    } else {
        LED_MATRIX_SET_COLOR(NUM_LED_INDEX, COLOR_BLACK);
    }
    if (default_layer_state == (1 << 0)) {
        LED_MATRIX_SET_COLOR(MAC_LED_INDEX, COLOR_WHITE);
    } else {
        LED_MATRIX_SET_COLOR(MAC_LED_INDEX, COLOR_BLACK);
    }
    if (default_layer_state == (1 << 2)) {
        LED_MATRIX_SET_COLOR(WIN_LED_INDEX, COLOR_WHITE);
    } else {
        LED_MATRIX_SET_COLOR(WIN_LED_INDEX, COLOR_BLACK);
    }
    return true;
}

#endif