qmk_firmware

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

ec_switch_matrix.h (5151B)


      1 /* Copyright 2023 Cipulot
      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 3 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 #pragma once
     18 
     19 #include <stdint.h>
     20 #include <stdbool.h>
     21 #include "matrix.h"
     22 #include "eeconfig.h"
     23 #include "util.h"
     24 
     25 typedef struct _indicator_config_t {
     26     uint8_t h;
     27     uint8_t s;
     28     uint8_t v;
     29     bool    enabled;
     30 } indicator_config;
     31 
     32 typedef struct PACKED {
     33     indicator_config num;
     34     indicator_config caps;
     35     indicator_config scroll;
     36     uint8_t          actuation_mode;                              // 0: normal board-wide APC, 1: Rapid trigger from specific board-wide actuation point, 2: Rapid trigger from resting point
     37     uint16_t         mode_0_actuation_threshold;                  // threshold for key press in mode 0
     38     uint16_t         mode_0_release_threshold;                    // threshold for key release in mode 0
     39     uint16_t         mode_1_initial_deadzone_offset;              // threshold for key press in mode 1
     40     uint8_t          mode_1_actuation_offset;                     // offset for key press in mode 1 and 2 (1-255)
     41     uint8_t          mode_1_release_offset;                       // offset for key release in mode 1 and 2 (1-255)
     42     uint16_t         bottoming_reading[MATRIX_ROWS][MATRIX_COLS]; // bottoming reading
     43 } eeprom_ec_config_t;
     44 
     45 typedef struct {
     46     uint8_t  actuation_mode;                                                    // 0: normal board-wide APC, 1: Rapid trigger from specific board-wide actuation point (it can be very near that baseline noise and be "full travel")
     47     uint16_t mode_0_actuation_threshold;                                        // threshold for key press in mode 0
     48     uint16_t mode_0_release_threshold;                                          // threshold for key release in mode 0
     49     uint16_t mode_1_initial_deadzone_offset;                                    // threshold for key press in mode 1 (initial deadzone)
     50     uint8_t  mode_1_actuation_offset;                                           // offset for key press in mode 1 (1-255)
     51     uint8_t  mode_1_release_offset;                                             // offset for key release in mode 1 (1-255)
     52     uint16_t rescaled_mode_0_actuation_threshold[MATRIX_ROWS][MATRIX_COLS];     // threshold for key press in mode 0 rescaled to actual scale
     53     uint16_t rescaled_mode_0_release_threshold[MATRIX_ROWS][MATRIX_COLS];       // threshold for key release in mode 0 rescaled to actual scale
     54     uint16_t rescaled_mode_1_initial_deadzone_offset[MATRIX_ROWS][MATRIX_COLS]; // threshold for key press in mode 1 (initial deadzone) rescaled to actual scale
     55     uint8_t  rescaled_mode_1_actuation_offset[MATRIX_ROWS][MATRIX_COLS];        // offset for key press in mode 1 rescaled to actual scale
     56     uint8_t  rescaled_mode_1_release_offset[MATRIX_ROWS][MATRIX_COLS];          // offset for key release in mode 1 rescaled to actual scale
     57     uint16_t extremum[MATRIX_ROWS][MATRIX_COLS];                                // extremum values for mode 1
     58     uint16_t noise_floor[MATRIX_ROWS][MATRIX_COLS];                             // noise floor detected during startup
     59     bool     bottoming_calibration;                                             // calibration mode for bottoming out values (true: calibration mode, false: normal mode)
     60     bool     bottoming_calibration_starter[MATRIX_ROWS][MATRIX_COLS];           // calibration mode for bottoming out values (true: calibration mode, false: normal mode)
     61     uint16_t bottoming_reading[MATRIX_ROWS][MATRIX_COLS];                       // bottoming reading
     62 } ec_config_t;
     63 
     64 // Check if the size of the reserved persistent memory is the same as the size of struct eeprom_ec_config_t
     65 _Static_assert(sizeof(eeprom_ec_config_t) == EECONFIG_KB_DATA_SIZE, "Mismatch in keyboard EECONFIG stored data");
     66 
     67 extern eeprom_ec_config_t eeprom_ec_config;
     68 
     69 extern ec_config_t ec_config;
     70 
     71 void init_row(void);
     72 void init_amux(void);
     73 void select_amux_channel(uint8_t channel, uint8_t col);
     74 void disable_unused_amux(uint8_t channel);
     75 void discharge_capacitor(void);
     76 void charge_capacitor(uint8_t row);
     77 
     78 int      ec_init(void);
     79 void     ec_noise_floor(void);
     80 bool     ec_matrix_scan(matrix_row_t current_matrix[]);
     81 uint16_t ec_readkey_raw(uint8_t channel, uint8_t row, uint8_t col);
     82 bool     ec_update_key(matrix_row_t* current_row, uint8_t row, uint8_t col, uint16_t sw_value);
     83 void     ec_print_matrix(void);
     84 
     85 uint16_t rescale(uint16_t x, uint16_t in_min, uint16_t in_max, uint16_t out_min, uint16_t out_max);
     86 
     87 #ifdef UNUSED_POSITIONS_LIST
     88 bool is_unused_position(uint8_t row, uint8_t col);
     89 #endif