logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

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