ec_switch_matrix.h (5063B)
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 PACKED { 26 uint8_t actuation_mode; // 0: normal board-wide APC, 1: Rapid trigger from specific board-wide actuation point, 2: Rapid trigger from resting point 27 uint16_t mode_0_actuation_threshold; // threshold for key press in mode 0 28 uint16_t mode_0_release_threshold; // threshold for key release in mode 0 29 uint16_t mode_1_initial_deadzone_offset; // threshold for key press in mode 1 30 uint8_t mode_1_actuation_offset; // offset for key press in mode 1 and 2 (1-255) 31 uint8_t mode_1_release_offset; // offset for key release in mode 1 and 2 (1-255) 32 uint16_t bottoming_reading[MATRIX_ROWS][MATRIX_COLS]; // bottoming reading 33 } eeprom_ec_config_t; 34 35 typedef struct { 36 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") 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 (initial deadzone) 40 uint8_t mode_1_actuation_offset; // offset for key press in mode 1 (1-255) 41 uint8_t mode_1_release_offset; // offset for key release in mode 1 (1-255) 42 uint16_t rescaled_mode_0_actuation_threshold[MATRIX_ROWS][MATRIX_COLS]; // threshold for key press in mode 0 rescaled to actual scale 43 uint16_t rescaled_mode_0_release_threshold[MATRIX_ROWS][MATRIX_COLS]; // threshold for key release in mode 0 rescaled to actual scale 44 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 45 uint8_t rescaled_mode_1_actuation_offset[MATRIX_ROWS][MATRIX_COLS]; // offset for key press in mode 1 rescaled to actual scale 46 uint8_t rescaled_mode_1_release_offset[MATRIX_ROWS][MATRIX_COLS]; // offset for key release in mode 1 rescaled to actual scale 47 uint16_t extremum[MATRIX_ROWS][MATRIX_COLS]; // extremum values for mode 1 48 uint16_t noise_floor[MATRIX_ROWS][MATRIX_COLS]; // noise floor detected during startup 49 bool bottoming_calibration; // calibration mode for bottoming out values (true: calibration mode, false: normal mode) 50 bool bottoming_calibration_starter[MATRIX_ROWS][MATRIX_COLS]; // calibration mode for bottoming out values (true: calibration mode, false: normal mode) 51 uint16_t bottoming_reading[MATRIX_ROWS][MATRIX_COLS]; // bottoming reading 52 } ec_config_t; 53 54 // Check if the size of the reserved persistent memory is the same as the size of struct eeprom_ec_config_t 55 _Static_assert(sizeof(eeprom_ec_config_t) == EECONFIG_KB_DATA_SIZE, "Mismatch in keyboard EECONFIG stored data"); 56 57 extern eeprom_ec_config_t eeprom_ec_config; 58 59 extern ec_config_t ec_config; 60 61 void init_row(void); 62 void init_amux(void); 63 void disable_unused_row(uint8_t row); 64 void select_amux_channel(uint8_t channel, uint8_t col); 65 void disable_unused_amux(uint8_t channel); 66 void discharge_capacitor(void); 67 void charge_capacitor(uint8_t row); 68 69 int ec_init(void); 70 void ec_noise_floor(void); 71 bool ec_matrix_scan(matrix_row_t current_matrix[]); 72 uint16_t ec_readkey_raw(uint8_t channel, uint8_t row, uint8_t col); 73 bool ec_update_key(matrix_row_t* current_row, uint8_t row, uint8_t col, uint16_t sw_value); 74 void ec_print_matrix(void); 75 76 uint16_t rescale(uint16_t x, uint16_t in_min, uint16_t in_max, uint16_t out_min, uint16_t out_max); 77 78 #ifdef UNUSED_POSITIONS_LIST 79 bool is_unused_position(uint8_t row, uint8_t col); 80 #endif 81 82 #ifdef SPLIT_KEYBOARD 83 void via_cmd_slave_handler(uint8_t m2s_size, const void* m2s_buffer, uint8_t s2m_size, void* s2m_buffer); 84 #endif