From ecca9c54594adf0117421f90c2c2d636fbfea884 Mon Sep 17 00:00:00 2001 From: lalalademaxiya1 <66767061+lalalademaxiya1@users.noreply.github.com> Date: Wed, 21 Jun 2023 11:05:07 +0800 Subject: Add Keychron C2 Pro (#20701) Co-authored-by: Drashna Jaelre Co-authored-by: adophoxia <100170946+adophoxia@users.noreply.github.com> Co-authored-by: jack <0x6a73@protonmail.com> --- keyboards/keychron/c2_pro/c2_pro.c | 129 +++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 keyboards/keychron/c2_pro/c2_pro.c (limited to 'keyboards/keychron/c2_pro/c2_pro.c') 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 . + */ + +#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 -- cgit v1.2.3