diff options
Diffstat (limited to 'keyboards/cipulot/common/via_ec.c')
-rw-r--r-- | keyboards/cipulot/common/via_ec.c | 60 |
1 files changed, 52 insertions, 8 deletions
diff --git a/keyboards/cipulot/common/via_ec.c b/keyboards/cipulot/common/via_ec.c index ce4e813f75..ed34a579b2 100644 --- a/keyboards/cipulot/common/via_ec.c +++ b/keyboards/cipulot/common/via_ec.c @@ -19,6 +19,10 @@ #include "print.h" #include "via.h" +#ifdef SPLIT_KEYBOARD +# include "transactions.h" +#endif + #ifdef VIA_ENABLE void ec_rescale_values(uint8_t item); @@ -50,6 +54,12 @@ void via_config_set_value(uint8_t *data) { uint8_t *value_id = &(data[0]); uint8_t *value_data = &(data[1]); +# ifdef SPLIT_KEYBOARD + if (is_keyboard_master()) { + transaction_rpc_send(RPC_ID_VIA_CMD, 30, data); + } +# endif + switch (*value_id) { case id_actuation_mode: { eeprom_ec_config.actuation_mode = value_data[0]; @@ -115,6 +125,8 @@ void via_config_set_value(uint8_t *data) { ec_rescale_values(0); ec_rescale_values(1); ec_rescale_values(2); + ec_rescale_values(3); + ec_rescale_values(4); uprintf("#############################\n"); uprintf("# Noise floor data acquired #\n"); uprintf("#############################\n"); @@ -124,13 +136,14 @@ void via_config_set_value(uint8_t *data) { case id_show_calibration_data: { if (value_data[0] == 0) { ec_show_calibration_data(); - break; } + break; } case id_clear_bottoming_calibration_data: { if (value_data[0] == 0) { ec_clear_bottoming_calibration_data(); } + break; } default: { // Unhandled value. @@ -240,6 +253,22 @@ void ec_rescale_values(uint8_t item) { } } break; + // Rescale the Rapid Trigger mode actuation offsets + case 3: + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + 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]); + } + } + break; + // Rescale the Rapid Trigger mode release offsets + case 4: + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + 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]); + } + } + break; default: // Unhandled item. @@ -258,9 +287,11 @@ void ec_save_threshold_data(uint8_t option) { // Save Rapid Trigger mode thresholds and rescale them for runtime usage else if (option == 1) { eeprom_ec_config.mode_1_initial_deadzone_offset = ec_config.mode_1_initial_deadzone_offset; - eeprom_ec_config.mode_1_actuation_offset = ec_config.mode_1_actuation_offset; - eeprom_ec_config.mode_1_release_offset = ec_config.mode_1_release_offset; + eeprom_ec_config.mode_1_actuation_offset = ec_config.mode_1_actuation_offset; + eeprom_ec_config.mode_1_release_offset = ec_config.mode_1_release_offset; ec_rescale_values(2); + ec_rescale_values(3); + ec_rescale_values(4); } eeconfig_update_kb_datablock(&eeprom_ec_config); uprintf("####################################\n"); @@ -272,11 +303,12 @@ void ec_save_threshold_data(uint8_t option) { void ec_save_bottoming_reading(void) { for (uint8_t row = 0; row < MATRIX_ROWS; row++) { for (uint8_t col = 0; col < MATRIX_COLS; col++) { - // If the bottom reading doesn't go over the noise floor by BOTTOMING_CALIBRATION_THRESHOLD, it is likely that: - // 1. The key is not actually in the matrix - // 2. The key is on an alternative layout, therefore not being pressed - // 3. The key in in the current layout but not being pressed - if (ec_config.bottoming_reading[row][col] < (ec_config.noise_floor[row][col] + BOTTOMING_CALIBRATION_THRESHOLD)) { + // If the calibration starter flag is still set on the key, it indicates that the key was skipped during the scan because it is not physically present. + // If the flag is not set, it means a bottoming reading was taken. If this reading doesn't exceed the noise floor by the BOTTOMING_CALIBRATION_THRESHOLD, it likely indicates one of the following: + // 1. The key is part of an alternative layout and is not being pressed. + // 2. The key is in the current layout but is not being pressed. + // In both conditions we should set the bottoming reading to the maximum value to avoid false positives. + if (ec_config.bottoming_calibration_starter[row][col] || ec_config.bottoming_reading[row][col] < (ec_config.noise_floor[row][col] + BOTTOMING_CALIBRATION_THRESHOLD)) { eeprom_ec_config.bottoming_reading[row][col] = 1023; } else { eeprom_ec_config.bottoming_reading[row][col] = ec_config.bottoming_reading[row][col]; @@ -287,6 +319,8 @@ void ec_save_bottoming_reading(void) { ec_rescale_values(0); ec_rescale_values(1); ec_rescale_values(2); + ec_rescale_values(3); + ec_rescale_values(4); eeconfig_update_kb_datablock(&eeprom_ec_config); } @@ -360,4 +394,14 @@ void ec_clear_bottoming_calibration_data(void) { uprintf("######################################\n"); } +# ifdef SPLIT_KEYBOARD +void via_cmd_slave_handler(uint8_t m2s_size, const void *m2s_buffer, uint8_t s2m_size, void *s2m_buffer) { + if (m2s_size == (RAW_EPSIZE-2)) { + via_config_set_value((uint8_t *)m2s_buffer); + } else { + uprintf("Unexpected response in slave handler\n"); + } +} +# endif + #endif // VIA_ENABLE |