qmk_firmware

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

matrix.c (1927B)


      1 /* Copyright 2020 sekigon-gonnoc
      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 "grs_70ec.h"
     18 
     19 #include "ec_switch_matrix.h"
     20 #include "matrix.h"
     21 #include "debug.h"
     22 #include "split_util.h"
     23 #include "transport.h"
     24 #include "debounce.h"
     25 
     26 #ifndef LOW_THRESHOLD
     27 #    define LOW_THRESHOLD 200
     28 #endif
     29 
     30 #ifndef HIGH_THRESHOLD
     31 #    define HIGH_THRESHOLD 300
     32 #endif
     33 
     34 #define ERROR_DISCONNECT_COUNT 20
     35 
     36 #define ROWS_PER_HAND (MATRIX_ROWS / 2)
     37 
     38 /* matrix state(1:on, 0:off) */
     39 extern matrix_row_t raw_matrix[MATRIX_ROWS];  // raw values
     40 extern matrix_row_t matrix[MATRIX_ROWS];      // debounced values
     41 
     42 // row offsets for each hand
     43 static uint8_t thisHand, thatHand;
     44 
     45 // user-defined overridable functions
     46 __attribute__((weak)) void matrix_slave_scan_user(void) {}
     47 
     48 void matrix_init_custom(void) {
     49     split_pre_init();
     50 
     51     ecsm_config_t ecsm_config = {.low_threshold = LOW_THRESHOLD, .high_threshold = HIGH_THRESHOLD};
     52 
     53     ecsm_init(&ecsm_config);
     54 
     55     thisHand = isLeftHand ? 0 : (ROWS_PER_HAND);
     56     thatHand = ROWS_PER_HAND - thisHand;
     57 
     58     split_post_init();
     59 }
     60 
     61 bool matrix_scan_custom(matrix_row_t current_matrix[]) {
     62     bool updated = ecsm_matrix_scan(current_matrix);
     63 
     64     static int cnt = 0;
     65     if (cnt++ == 300) {
     66         cnt = 0;
     67         ecsm_print_matrix();
     68         print("\n");
     69     }
     70 
     71     return updated;
     72 }