1
0

ec_switch_matrix.h 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 PACKED {
  23. uint8_t actuation_mode; // 0: normal board-wide APC, 1: Rapid trigger from specific board-wide actuation point, 2: Rapid trigger from resting point
  24. uint16_t mode_0_actuation_threshold; // threshold for key press in mode 0
  25. uint16_t mode_0_release_threshold; // threshold for key release in mode 0
  26. uint16_t mode_1_initial_deadzone_offset; // threshold for key press in mode 1
  27. uint8_t mode_1_actuation_offset; // offset for key press in mode 1 and 2 (1-255)
  28. uint8_t mode_1_release_offset; // offset for key release in mode 1 and 2 (1-255)
  29. uint16_t bottoming_reading[MATRIX_ROWS][MATRIX_COLS]; // bottoming reading
  30. } eeprom_ec_config_t;
  31. typedef struct {
  32. 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")
  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 (initial deadzone)
  36. uint16_t rescaled_mode_0_actuation_threshold[MATRIX_ROWS][MATRIX_COLS]; // threshold for key press in mode 0 rescaled to actual scale
  37. uint16_t rescaled_mode_0_release_threshold[MATRIX_ROWS][MATRIX_COLS]; // threshold for key release in mode 0 rescaled to actual scale
  38. 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
  39. uint8_t mode_1_actuation_offset; // offset for key press in mode 1 (1-255)
  40. uint8_t mode_1_release_offset; // offset for key release in mode 1 (1-255)
  41. uint16_t extremum[MATRIX_ROWS][MATRIX_COLS]; // extremum values for mode 1
  42. uint16_t noise_floor[MATRIX_ROWS][MATRIX_COLS]; // noise floor detected during startup
  43. bool bottoming_calibration; // calibration mode for bottoming out values (true: calibration mode, false: normal mode)
  44. bool bottoming_calibration_starter[MATRIX_ROWS][MATRIX_COLS]; // calibration mode for bottoming out values (true: calibration mode, false: normal mode)
  45. uint16_t bottoming_reading[MATRIX_ROWS][MATRIX_COLS]; // bottoming reading
  46. } ec_config_t;
  47. // Check if the size of the reserved persistent memory is the same as the size of struct eeprom_ec_config_t
  48. _Static_assert(sizeof(eeprom_ec_config_t) == EECONFIG_KB_DATA_SIZE, "Mismatch in keyboard EECONFIG stored data");
  49. extern eeprom_ec_config_t eeprom_ec_config;
  50. extern ec_config_t ec_config;
  51. void init_row(void);
  52. void init_amux(void);
  53. void select_amux_channel(uint8_t channel, uint8_t col);
  54. void disable_unused_amux(uint8_t channel);
  55. void discharge_capacitor(void);
  56. void charge_capacitor(uint8_t row);
  57. int ec_init(void);
  58. void ec_noise_floor(void);
  59. bool ec_matrix_scan(matrix_row_t current_matrix[]);
  60. uint16_t ec_readkey_raw(uint8_t channel, uint8_t row, uint8_t col);
  61. bool ec_update_key(matrix_row_t* current_row, uint8_t row, uint8_t col, uint16_t sw_value);
  62. void ec_print_matrix(void);
  63. uint16_t rescale(uint16_t x, uint16_t in_min, uint16_t in_max, uint16_t out_min, uint16_t out_max);