logo

qmk_firmware

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

ec_board.c (4037B)


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