qmk_firmware

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

keychron_common.c (3444B)


      1 /* Copyright 2022 @ 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 "keychron_common.h"
     18 #include "sync_timer.h"
     19 
     20 bool is_siri_active = false;
     21 uint32_t siri_timer = 0;
     22 
     23 key_combination_t key_comb_list[4] = {
     24     {2, {KC_LWIN, KC_TAB}},
     25     {2, {KC_LWIN, KC_E}},
     26     {3, {KC_LSFT, KC_LCMD, KC_4}},
     27     {2, {KC_LWIN, KC_C}}
     28 };
     29 
     30 static uint8_t mac_keycode[4] = { KC_LOPT, KC_ROPT, KC_LCMD, KC_RCMD };
     31 
     32 void housekeeping_task_keychron(void) {
     33     if (is_siri_active) {
     34         if (sync_timer_elapsed32(siri_timer) >= 500) {
     35             unregister_code(KC_LCMD);
     36             unregister_code(KC_SPACE);
     37             is_siri_active = false;
     38         }
     39     }
     40 }
     41 
     42 bool process_record_keychron(uint16_t keycode, keyrecord_t *record) {
     43     switch (keycode) {
     44         case QK_KB_0:
     45             if (record->event.pressed) {
     46                 register_code(KC_MISSION_CONTROL);
     47             } else {
     48                 unregister_code(KC_MISSION_CONTROL);
     49             }
     50             return false;  // Skip all further processing of this key
     51         case QK_KB_1:
     52             if (record->event.pressed) {
     53                 register_code(KC_LAUNCHPAD);
     54             } else {
     55                 unregister_code(KC_LAUNCHPAD);
     56             }
     57             return false;  // Skip all further processing of this key
     58         case KC_LOPTN:
     59         case KC_ROPTN:
     60         case KC_LCMMD:
     61         case KC_RCMMD:
     62             if (record->event.pressed) {
     63                 register_code(mac_keycode[keycode - KC_LOPTN]);
     64             } else {
     65                 unregister_code(mac_keycode[keycode - KC_LOPTN]);
     66             }
     67             return false;  // Skip all further processing of this key
     68         case KC_SIRI:
     69             if (record->event.pressed) {
     70                 if (!is_siri_active) {
     71                     is_siri_active = true;
     72                     register_code(KC_LCMD);
     73                     register_code(KC_SPACE);
     74                 }
     75                 siri_timer = sync_timer_read32();
     76             } else {
     77                 // Do something else when release
     78             }
     79             return false;  // Skip all further processing of this key
     80         case KC_TASK:
     81         case KC_FLXP:
     82         case KC_SNAP:
     83         case KC_CRTA:
     84             if (record->event.pressed) {
     85                 for (uint8_t i = 0; i < key_comb_list[keycode - KC_TASK].len; i++) {
     86                     register_code(key_comb_list[keycode - KC_TASK].keycode[i]);
     87                 }
     88             } else {
     89                 for (uint8_t i = 0; i < key_comb_list[keycode - KC_TASK].len; i++) {
     90                     unregister_code(key_comb_list[keycode - KC_TASK].keycode[i]);
     91                 }
     92             }
     93             return false;  // Skip all further processing of this key
     94         default:
     95             return true;  // Process all other keycodes normally
     96     }
     97 }