qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

c3_pro.c (3587B)


      1 /* Copyright 2024 @ Keychron (https://www.keychron.com)
      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 
     17 #include "c3_pro.h"
     18 
     19 void keyboard_post_init_kb(void) {
     20     gpio_set_pin_output_push_pull(LED_MAC_OS_PIN);
     21     gpio_set_pin_output_push_pull(LED_WIN_OS_PIN);
     22     gpio_write_pin(LED_MAC_OS_PIN, !LED_OS_PIN_ON_STATE);
     23     gpio_write_pin(LED_WIN_OS_PIN, !LED_OS_PIN_ON_STATE);
     24     
     25     keyboard_post_init_user();
     26 }
     27 
     28 void housekeeping_task_kb(void) {
     29     if (get_highest_layer(default_layer_state) == 0) {
     30         gpio_write_pin(LED_MAC_OS_PIN, LED_OS_PIN_ON_STATE);
     31         gpio_write_pin(LED_WIN_OS_PIN, !LED_OS_PIN_ON_STATE);
     32     }
     33     if (get_highest_layer(default_layer_state) == 2) {
     34         gpio_write_pin(LED_MAC_OS_PIN, !LED_OS_PIN_ON_STATE);
     35         gpio_write_pin(LED_WIN_OS_PIN, LED_OS_PIN_ON_STATE);
     36     }
     37 }
     38 
     39 bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
     40     if (!process_record_user(keycode, record)) {
     41         return false;
     42     }
     43     switch (keycode) {
     44 #ifdef RGB_MATRIX_ENABLE
     45         case QK_RGB_MATRIX_TOGGLE:
     46             if (record->event.pressed) {
     47                 switch (rgb_matrix_get_flags()) {
     48                     case LED_FLAG_ALL: {
     49                         rgb_matrix_set_flags(LED_FLAG_NONE);
     50                         rgb_matrix_set_color_all(0, 0, 0);
     51                     } break;
     52                     default: {
     53                         rgb_matrix_set_flags(LED_FLAG_ALL);
     54                     } break;
     55                 }
     56             }
     57             if (!rgb_matrix_is_enabled()) {
     58                 rgb_matrix_set_flags(LED_FLAG_ALL);
     59                 rgb_matrix_enable();
     60             }
     61             return false;
     62 #endif
     63 #ifdef LED_MATRIX_ENABLE
     64         case QK_LED_MATRIX_TOGGLE:
     65             if (record->event.pressed) {
     66                 switch (led_matrix_get_flags()) {
     67                     case LED_FLAG_ALL: {
     68                         led_matrix_set_flags(LED_FLAG_NONE);
     69                         led_matrix_set_value_all(0);
     70                     } break;
     71                     default: {
     72                         led_matrix_set_flags(LED_FLAG_ALL);
     73                     } break;
     74                 }
     75             }
     76             if (!led_matrix_is_enabled()) {
     77                 led_matrix_set_flags(LED_FLAG_ALL);
     78                 led_matrix_enable();
     79             }
     80             return false;
     81 #endif
     82         case KC_OSSW:
     83             if (record->event.pressed) {
     84                 // Switches default layer between `MAC_BASE` and `WIN_BASE` (0 and 2)
     85                 if (get_highest_layer(default_layer_state) == 2 ) {
     86                     set_single_persistent_default_layer(0);
     87                 } else {
     88                     set_single_persistent_default_layer(2);
     89                 }
     90             }
     91             return false;
     92         default:
     93             return true;
     94     }
     95 }
     96 
     97 void suspend_power_down_kb(void) {
     98     gpio_write_pin(LED_WIN_OS_PIN, !LED_OS_PIN_ON_STATE);
     99     gpio_write_pin(LED_MAC_OS_PIN, !LED_OS_PIN_ON_STATE);
    100     suspend_power_down_user();
    101 }