summaryrefslogtreecommitdiff
path: root/keyboards/keychron/c2_pro/c2_pro.c
diff options
context:
space:
mode:
authorlalalademaxiya1 <66767061+lalalademaxiya1@users.noreply.github.com>2023-06-21 11:05:07 +0800
committerGitHub <noreply@github.com>2023-06-20 21:05:07 -0600
commitecca9c54594adf0117421f90c2c2d636fbfea884 (patch)
treef40773b0ba3bf122a2a5f4c43d4954baa2968e00 /keyboards/keychron/c2_pro/c2_pro.c
parent595d393fd82d7cde0216667e64809c1923cb337c (diff)
Add Keychron C2 Pro (#20701)
Co-authored-by: Drashna Jaelre <drashna@live.com> Co-authored-by: adophoxia <100170946+adophoxia@users.noreply.github.com> Co-authored-by: jack <0x6a73@protonmail.com>
Diffstat (limited to 'keyboards/keychron/c2_pro/c2_pro.c')
-rw-r--r--keyboards/keychron/c2_pro/c2_pro.c129
1 files changed, 129 insertions, 0 deletions
diff --git a/keyboards/keychron/c2_pro/c2_pro.c b/keyboards/keychron/c2_pro/c2_pro.c
new file mode 100644
index 0000000000..2cd58ab4d7
--- /dev/null
+++ b/keyboards/keychron/c2_pro/c2_pro.c
@@ -0,0 +1,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