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