ec_board.c 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. #include "ec_switch_matrix.h"
  17. #include "keyboard.h"
  18. void eeconfig_init_kb(void) {
  19. // Default values
  20. eeprom_ec_config.actuation_mode = DEFAULT_ACTUATION_MODE;
  21. eeprom_ec_config.mode_0_actuation_threshold = DEFAULT_MODE_0_ACTUATION_LEVEL;
  22. eeprom_ec_config.mode_0_release_threshold = DEFAULT_MODE_0_RELEASE_LEVEL;
  23. eeprom_ec_config.mode_1_initial_deadzone_offset = DEFAULT_MODE_1_INITIAL_DEADZONE_OFFSET;
  24. eeprom_ec_config.mode_1_actuation_offset = DEFAULT_MODE_1_ACTUATION_OFFSET;
  25. eeprom_ec_config.mode_1_release_offset = DEFAULT_MODE_1_RELEASE_OFFSET;
  26. for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
  27. for (uint8_t col = 0; col < MATRIX_COLS; col++) {
  28. eeprom_ec_config.bottoming_reading[row][col] = DEFAULT_BOTTOMING_READING;
  29. }
  30. }
  31. // Write default value to EEPROM now
  32. eeconfig_update_kb_datablock(&eeprom_ec_config);
  33. eeconfig_init_user();
  34. }
  35. // On Keyboard startup
  36. void keyboard_post_init_kb(void) {
  37. // Read custom menu variables from memory
  38. eeconfig_read_kb_datablock(&eeprom_ec_config);
  39. // Set runtime values to EEPROM values
  40. ec_config.actuation_mode = eeprom_ec_config.actuation_mode;
  41. ec_config.mode_0_actuation_threshold = eeprom_ec_config.mode_0_actuation_threshold;
  42. ec_config.mode_0_release_threshold = eeprom_ec_config.mode_0_release_threshold;
  43. ec_config.mode_1_initial_deadzone_offset = eeprom_ec_config.mode_1_initial_deadzone_offset;
  44. ec_config.mode_1_actuation_offset = eeprom_ec_config.mode_1_actuation_offset;
  45. ec_config.mode_1_release_offset = eeprom_ec_config.mode_1_release_offset;
  46. ec_config.bottoming_calibration = false;
  47. for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
  48. for (uint8_t col = 0; col < MATRIX_COLS; col++) {
  49. ec_config.bottoming_calibration_starter[row][col] = true;
  50. ec_config.bottoming_reading[row][col] = eeprom_ec_config.bottoming_reading[row][col];
  51. ec_config.rescaled_mode_0_actuation_threshold[row][col] = rescale(ec_config.mode_0_actuation_threshold, 0, 1023, ec_config.noise_floor[row][col], eeprom_ec_config.bottoming_reading[row][col]);
  52. ec_config.rescaled_mode_0_release_threshold[row][col] = rescale(ec_config.mode_0_release_threshold, 0, 1023, ec_config.noise_floor[row][col], eeprom_ec_config.bottoming_reading[row][col]);
  53. ec_config.rescaled_mode_1_initial_deadzone_offset[row][col] = rescale(ec_config.mode_1_initial_deadzone_offset, 0, 1023, ec_config.noise_floor[row][col], eeprom_ec_config.bottoming_reading[row][col]);
  54. }
  55. }
  56. keyboard_post_init_user();
  57. }