diff options
Diffstat (limited to 'keyboards')
68 files changed, 292 insertions, 171 deletions
diff --git a/keyboards/cipulot/ec_menhir/rules.mk b/keyboards/cipulot/common/common_cipulot.mk index e7d73cefc9..a1bbedab18 100644 --- a/keyboards/cipulot/ec_menhir/rules.mk +++ b/keyboards/cipulot/common/common_cipulot.mk @@ -2,3 +2,7 @@ CUSTOM_MATRIX = lite ANALOG_DRIVER_REQUIRED = yes VPATH += keyboards/cipulot/common SRC += matrix.c ec_board.c ec_switch_matrix.c + +ifeq ($(strip $(VIA_ENABLE)), yes) + SRC += via_ec.c +endif diff --git a/keyboards/cipulot/common/ec_board.c b/keyboards/cipulot/common/ec_board.c index d9ba197589..0ccb9f6d3c 100644 --- a/keyboards/cipulot/common/ec_board.c +++ b/keyboards/cipulot/common/ec_board.c @@ -17,6 +17,10 @@ #include "ec_switch_matrix.h" #include "keyboard.h" +#ifdef SPLIT_KEYBOARD +# include "transactions.h" +#endif + void eeconfig_init_kb(void) { // Default values eeprom_ec_config.actuation_mode = DEFAULT_ACTUATION_MODE; @@ -57,8 +61,14 @@ void keyboard_post_init_kb(void) { 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]); 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]); 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]); + 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]); + 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]); } } +#ifdef SPLIT_KEYBOARD + transaction_register_rpc(RPC_ID_VIA_CMD, via_cmd_slave_handler); +#endif + keyboard_post_init_user(); } diff --git a/keyboards/cipulot/common/ec_switch_matrix.c b/keyboards/cipulot/common/ec_switch_matrix.c index 33123bd236..25c745703b 100644 --- a/keyboards/cipulot/common/ec_switch_matrix.c +++ b/keyboards/cipulot/common/ec_switch_matrix.c @@ -37,8 +37,14 @@ const pin_t amux_en_pins[] = AMUX_EN_PINS; const pin_t amux_n_col_sizes[] = AMUX_COL_CHANNELS_SIZES; const pin_t amux_n_col_channels[][AMUX_MAX_COLS_COUNT] = {AMUX_COL_CHANNELS}; +#ifdef UNUSED_POSITIONS_LIST +const uint8_t UNUSED_POSITIONS[][2] = UNUSED_POSITIONS_LIST; +# define UNUSED_POSITIONS_COUNT ARRAY_SIZE(UNUSED_POSITIONS) +#endif + #define AMUX_SEL_PINS_COUNT ARRAY_SIZE(amux_sel_pins) #define EXPECTED_AMUX_SEL_PINS_COUNT ceil(log2(AMUX_MAX_COLS_COUNT) + // Checks for the correctness of the configuration _Static_assert(ARRAY_SIZE(amux_en_pins) == AMUX_COUNT, "AMUX_EN_PINS doesn't have the minimum number of bits required to enable all the multiplexers available"); // Check that number of select pins is enough to select all the channels @@ -70,6 +76,16 @@ void init_amux(void) { } } +// Disable all the unused rows +void disable_unused_row(uint8_t row) { + // disable all the other rows apart from the current selected one + for (uint8_t idx = 0; idx < MATRIX_ROWS; idx++) { + if (idx != row) { + gpio_write_pin_low(row_pins[idx]); + } + } +} + // Select the multiplexer channel of the specified multiplexer void select_amux_channel(uint8_t channel, uint8_t col) { // Get the channel for the specified multiplexer @@ -158,6 +174,10 @@ void ec_noise_floor(void) { sum += amux_n_col_sizes[i]; uint8_t adjusted_col = col + sum; for (uint8_t row = 0; row < MATRIX_ROWS; row++) { +#ifdef UNUSED_POSITIONS_LIST + if (is_unused_position(row, adjusted_col)) continue; +#endif + disable_unused_row(row); ec_config.noise_floor[row][adjusted_col] += ec_readkey_raw(amux, row, col); } } @@ -180,11 +200,15 @@ bool ec_matrix_scan(matrix_row_t current_matrix[]) { for (uint8_t amux = 0; amux < AMUX_COUNT; amux++) { disable_unused_amux(amux); for (uint8_t col = 0; col < amux_n_col_sizes[amux]; col++) { + uint8_t sum = 0; + for (uint8_t i = 0; i < (amux > 0 ? amux : 0); i++) + sum += amux_n_col_sizes[i]; + uint8_t adjusted_col = col + sum; for (uint8_t row = 0; row < MATRIX_ROWS; row++) { - uint8_t sum = 0; - for (uint8_t i = 0; i < (amux > 0 ? amux : 0); i++) - sum += amux_n_col_sizes[i]; - uint8_t adjusted_col = col + sum; +#ifdef UNUSED_POSITIONS_LIST + if (is_unused_position(row, adjusted_col)) continue; +#endif + disable_unused_row(row); sw_value[row][adjusted_col] = ec_readkey_raw(amux, row, col); if (ec_config.bottoming_calibration) { @@ -266,7 +290,7 @@ bool ec_update_key(matrix_row_t* current_row, uint8_t row, uint8_t col, uint16_t uprintf("Key pressed: %d, %d, %d\n", row, col, sw_value); } // Has key moved up enough to be released? - else if (sw_value < ec_config.extremum[row][col] - ec_config.mode_1_release_offset) { + else if (sw_value < ec_config.extremum[row][col] - ec_config.rescaled_mode_1_release_offset[row][col]) { ec_config.extremum[row][col] = sw_value; *current_row &= ~(1 << col); uprintf("Key released: %d, %d, %d\n", row, col, sw_value); @@ -280,7 +304,7 @@ bool ec_update_key(matrix_row_t* current_row, uint8_t row, uint8_t col, uint16_t ec_config.extremum[row][col] = sw_value; } // Has key moved down enough to be pressed? - else if (sw_value > ec_config.extremum[row][col] + ec_config.mode_1_actuation_offset) { + else if (sw_value > ec_config.extremum[row][col] + ec_config.rescaled_mode_1_actuation_offset[row][col]) { ec_config.extremum[row][col] = sw_value; *current_row |= (1 << col); uprintf("Key pressed: %d, %d, %d\n", row, col, sw_value); @@ -312,6 +336,18 @@ void ec_print_matrix(void) { print("\n"); } +// Check if the position is unused +#ifdef UNUSED_POSITIONS_LIST +bool is_unused_position(uint8_t row, uint8_t col) { + for (uint8_t i = 0; i < UNUSED_POSITIONS_COUNT; i++) { + if (UNUSED_POSITIONS[i][0] == row && UNUSED_POSITIONS[i][1] == col) { + return true; + } + } + return false; +} +#endif + // Rescale the value to a different range uint16_t rescale(uint16_t x, uint16_t in_min, uint16_t in_max, uint16_t out_min, uint16_t out_max) { return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; diff --git a/keyboards/cipulot/common/ec_switch_matrix.h b/keyboards/cipulot/common/ec_switch_matrix.h index 4b424911da..8fbca372bf 100644 --- a/keyboards/cipulot/common/ec_switch_matrix.h +++ b/keyboards/cipulot/common/ec_switch_matrix.h @@ -37,11 +37,13 @@ typedef struct { uint16_t mode_0_actuation_threshold; // threshold for key press in mode 0 uint16_t mode_0_release_threshold; // threshold for key release in mode 0 uint16_t mode_1_initial_deadzone_offset; // threshold for key press in mode 1 (initial deadzone) + uint8_t mode_1_actuation_offset; // offset for key press in mode 1 (1-255) + uint8_t mode_1_release_offset; // offset for key release in mode 1 (1-255) uint16_t rescaled_mode_0_actuation_threshold[MATRIX_ROWS][MATRIX_COLS]; // threshold for key press in mode 0 rescaled to actual scale uint16_t rescaled_mode_0_release_threshold[MATRIX_ROWS][MATRIX_COLS]; // threshold for key release in mode 0 rescaled to actual scale 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 - uint8_t mode_1_actuation_offset; // offset for key press in mode 1 (1-255) - uint8_t mode_1_release_offset; // offset for key release in mode 1 (1-255) + uint8_t rescaled_mode_1_actuation_offset[MATRIX_ROWS][MATRIX_COLS]; // offset for key press in mode 1 rescaled to actual scale + uint8_t rescaled_mode_1_release_offset[MATRIX_ROWS][MATRIX_COLS]; // offset for key release in mode 1 rescaled to actual scale uint16_t extremum[MATRIX_ROWS][MATRIX_COLS]; // extremum values for mode 1 uint16_t noise_floor[MATRIX_ROWS][MATRIX_COLS]; // noise floor detected during startup bool bottoming_calibration; // calibration mode for bottoming out values (true: calibration mode, false: normal mode) @@ -58,6 +60,7 @@ extern ec_config_t ec_config; void init_row(void); void init_amux(void); +void disable_unused_row(uint8_t row); void select_amux_channel(uint8_t channel, uint8_t col); void disable_unused_amux(uint8_t channel); void discharge_capacitor(void); @@ -71,3 +74,11 @@ bool ec_update_key(matrix_row_t* current_row, uint8_t row, uint8_t col, uint void ec_print_matrix(void); uint16_t rescale(uint16_t x, uint16_t in_min, uint16_t in_max, uint16_t out_min, uint16_t out_max); + +#ifdef UNUSED_POSITIONS_LIST +bool is_unused_position(uint8_t row, uint8_t col); +#endif + +#ifdef SPLIT_KEYBOARD +void via_cmd_slave_handler(uint8_t m2s_size, const void* m2s_buffer, uint8_t s2m_size, void* s2m_buffer); +#endif 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 diff --git a/keyboards/cipulot/ec_23u/post_rules.mk b/keyboards/cipulot/ec_23u/post_rules.mk index d726a112a8..5dba48cc5f 100644 --- a/keyboards/cipulot/ec_23u/post_rules.mk +++ b/keyboards/cipulot/ec_23u/post_rules.mk @@ -1,3 +1 @@ -ifeq ($(strip $(VIA_ENABLE)), yes) - SRC += keyboards/cipulot/common/via_ec.c -endif +include keyboards/cipulot/common/common_cipulot.mk diff --git a/keyboards/cipulot/ec_23u/rules.mk b/keyboards/cipulot/ec_23u/rules.mk index 318e0215ce..3aa0e2bf06 100644 --- a/keyboards/cipulot/ec_23u/rules.mk +++ b/keyboards/cipulot/ec_23u/rules.mk @@ -1,5 +1 @@ -CUSTOM_MATRIX = lite -ANALOG_DRIVER_REQUIRED = yes -VPATH += keyboards/cipulot/common -SRC += matrix.c ec_board.c ec_switch_matrix.c OPT = 2 diff --git a/keyboards/cipulot/ec_60/config.h b/keyboards/cipulot/ec_60/config.h index 2452550143..a409df2dfc 100644 --- a/keyboards/cipulot/ec_60/config.h +++ b/keyboards/cipulot/ec_60/config.h @@ -19,6 +19,8 @@ #define MATRIX_ROWS 5 #define MATRIX_COLS 15 +#define UNUSED_POSITIONS_LIST { {1, 14}, {2, 14}, {4, 3}, {4, 8} } + #define MATRIX_ROW_PINS \ { B15, A8, B0, A7, B1 } diff --git a/keyboards/cipulot/ec_60/post_rules.mk b/keyboards/cipulot/ec_60/post_rules.mk index d726a112a8..5dba48cc5f 100644 --- a/keyboards/cipulot/ec_60/post_rules.mk +++ b/keyboards/cipulot/ec_60/post_rules.mk @@ -1,3 +1 @@ -ifeq ($(strip $(VIA_ENABLE)), yes) - SRC += keyboards/cipulot/common/via_ec.c -endif +include keyboards/cipulot/common/common_cipulot.mk diff --git a/keyboards/cipulot/ec_60/rules.mk b/keyboards/cipulot/ec_60/rules.mk index ce525670a6..1716098b3e 100644 --- a/keyboards/cipulot/ec_60/rules.mk +++ b/keyboards/cipulot/ec_60/rules.mk @@ -1,5 +1 @@ -CUSTOM_MATRIX = lite -ANALOG_DRIVER_REQUIRED = yes -VPATH += keyboards/cipulot/common -SRC += matrix.c ec_board.c ec_switch_matrix.c OPT = 3 diff --git a/keyboards/cipulot/ec_60x/config.h b/keyboards/cipulot/ec_60x/config.h index 1a8d105d68..1784076d21 100644 --- a/keyboards/cipulot/ec_60x/config.h +++ b/keyboards/cipulot/ec_60x/config.h @@ -19,6 +19,8 @@ #define MATRIX_ROWS 5 #define MATRIX_COLS 15 +#define UNUSED_POSITIONS_LIST { {2, 14}, {4, 3}, {4, 5}, {4, 7}, {4, 9}, {4, 14} } + #define MATRIX_ROW_PINS \ { A8, A15, B12, B8, B9} diff --git a/keyboards/cipulot/ec_60x/post_rules.mk b/keyboards/cipulot/ec_60x/post_rules.mk index d726a112a8..5dba48cc5f 100644 --- a/keyboards/cipulot/ec_60x/post_rules.mk +++ b/keyboards/cipulot/ec_60x/post_rules.mk @@ -1,3 +1 @@ -ifeq ($(strip $(VIA_ENABLE)), yes) - SRC += keyboards/cipulot/common/via_ec.c -endif +include keyboards/cipulot/common/common_cipulot.mk diff --git a/keyboards/cipulot/ec_60x/rules.mk b/keyboards/cipulot/ec_60x/rules.mk index 318e0215ce..3aa0e2bf06 100644 --- a/keyboards/cipulot/ec_60x/rules.mk +++ b/keyboards/cipulot/ec_60x/rules.mk @@ -1,5 +1 @@ -CUSTOM_MATRIX = lite -ANALOG_DRIVER_REQUIRED = yes -VPATH += keyboards/cipulot/common -SRC += matrix.c ec_board.c ec_switch_matrix.c OPT = 2 diff --git a/keyboards/cipulot/ec_660c/config.h b/keyboards/cipulot/ec_660c/config.h index 9e883c40da..16b2ade719 100644 --- a/keyboards/cipulot/ec_660c/config.h +++ b/keyboards/cipulot/ec_660c/config.h @@ -19,6 +19,8 @@ #define MATRIX_ROWS 5 #define MATRIX_COLS 15 +#define UNUSED_POSITIONS_LIST { {3, 14}, {4, 3}, {4, 4}, {4, 5}, {4, 7}, {4, 8} } + #define MATRIX_ROW_PINS \ { B1, B10, B0, A1, A0 } diff --git a/keyboards/cipulot/ec_660c/post_rules.mk b/keyboards/cipulot/ec_660c/post_rules.mk index d726a112a8..5dba48cc5f 100644 --- a/keyboards/cipulot/ec_660c/post_rules.mk +++ b/keyboards/cipulot/ec_660c/post_rules.mk @@ -1,3 +1 @@ -ifeq ($(strip $(VIA_ENABLE)), yes) - SRC += keyboards/cipulot/common/via_ec.c -endif +include keyboards/cipulot/common/common_cipulot.mk diff --git a/keyboards/cipulot/ec_660c/rules.mk b/keyboards/cipulot/ec_660c/rules.mk index ce525670a6..1716098b3e 100644 --- a/keyboards/cipulot/ec_660c/rules.mk +++ b/keyboards/cipulot/ec_660c/rules.mk @@ -1,5 +1 @@ -CUSTOM_MATRIX = lite -ANALOG_DRIVER_REQUIRED = yes -VPATH += keyboards/cipulot/common -SRC += matrix.c ec_board.c ec_switch_matrix.c OPT = 3 diff --git a/keyboards/cipulot/ec_980c/config.h b/keyboards/cipulot/ec_980c/config.h index e3723822e3..bd8afcb687 100644 --- a/keyboards/cipulot/ec_980c/config.h +++ b/keyboards/cipulot/ec_980c/config.h @@ -19,6 +19,8 @@ #define MATRIX_ROWS 6 #define MATRIX_COLS 19 +#define UNUSED_POSITIONS_LIST { {0, 1}, {0, 10}, {3, 14}, {4, 13}, {5, 4}, {5, 7}, {5, 12} } + #define MATRIX_ROW_PINS \ { B13, B12, B14, A9, B6, B7 } diff --git a/keyboards/cipulot/ec_980c/ec_980c.c b/keyboards/cipulot/ec_980c/ec_980c.c index 49b5248745..eaa636ede6 100644 --- a/keyboards/cipulot/ec_980c/ec_980c.c +++ b/keyboards/cipulot/ec_980c/ec_980c.c @@ -69,6 +69,8 @@ void keyboard_post_init_kb(void) { 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]); 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]); 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]); + 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]); + 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]); } } diff --git a/keyboards/cipulot/ec_980c/ec_switch_matrix.c b/keyboards/cipulot/ec_980c/ec_switch_matrix.c index 33123bd236..00a0b632fb 100644 --- a/keyboards/cipulot/ec_980c/ec_switch_matrix.c +++ b/keyboards/cipulot/ec_980c/ec_switch_matrix.c @@ -37,6 +37,11 @@ const pin_t amux_en_pins[] = AMUX_EN_PINS; const pin_t amux_n_col_sizes[] = AMUX_COL_CHANNELS_SIZES; const pin_t amux_n_col_channels[][AMUX_MAX_COLS_COUNT] = {AMUX_COL_CHANNELS}; +#ifdef UNUSED_POSITIONS_LIST +const uint8_t UNUSED_POSITIONS[][2] = UNUSED_POSITIONS_LIST; +# define UNUSED_POSITIONS_COUNT (sizeof(UNUSED_POSITIONS) / sizeof(UNUSED_POSITIONS[0])) +#endif + #define AMUX_SEL_PINS_COUNT ARRAY_SIZE(amux_sel_pins) #define EXPECTED_AMUX_SEL_PINS_COUNT ceil(log2(AMUX_MAX_COLS_COUNT) // Checks for the correctness of the configuration @@ -70,6 +75,16 @@ void init_amux(void) { } } +// Disable all the unused rows +void disable_unused_row(uint8_t row) { + // disable all the other rows apart from the current selected one + for (uint8_t idx = 0; idx < MATRIX_ROWS; idx++) { + if (idx != row) { + gpio_write_pin_low(row_pins[idx]); + } + } +} + // Select the multiplexer channel of the specified multiplexer void select_amux_channel(uint8_t channel, uint8_t col) { // Get the channel for the specified multiplexer @@ -158,6 +173,10 @@ void ec_noise_floor(void) { sum += amux_n_col_sizes[i]; uint8_t adjusted_col = col + sum; for (uint8_t row = 0; row < MATRIX_ROWS; row++) { +#ifdef UNUSED_POSITIONS_LIST + if (is_unused_position(row, adjusted_col)) continue; +#endif + disable_unused_row(row); ec_config.noise_floor[row][adjusted_col] += ec_readkey_raw(amux, row, col); } } @@ -180,11 +199,15 @@ bool ec_matrix_scan(matrix_row_t current_matrix[]) { for (uint8_t amux = 0; amux < AMUX_COUNT; amux++) { disable_unused_amux(amux); for (uint8_t col = 0; col < amux_n_col_sizes[amux]; col++) { + uint8_t sum = 0; + for (uint8_t i = 0; i < (amux > 0 ? amux : 0); i++) + sum += amux_n_col_sizes[i]; + uint8_t adjusted_col = col + sum; for (uint8_t row = 0; row < MATRIX_ROWS; row++) { - uint8_t sum = 0; - for (uint8_t i = 0; i < (amux > 0 ? amux : 0); i++) - sum += amux_n_col_sizes[i]; - uint8_t adjusted_col = col + sum; +#ifdef UNUSED_POSITIONS_LIST + if (is_unused_position(row, adjusted_col)) continue; +#endif + disable_unused_row(row); sw_value[row][adjusted_col] = ec_readkey_raw(amux, row, col); if (ec_config.bottoming_calibration) { @@ -229,7 +252,7 @@ uint16_t ec_readkey_raw(uint8_t channel, uint8_t row, uint8_t col) { } // Update press/release state of key -bool ec_update_key(matrix_row_t* current_row, uint8_t row, uint8_t col, uint16_t sw_value) { +bool ec_update_key(matrix_row_t *current_row, uint8_t row, uint8_t col, uint16_t sw_value) { bool current_state = (*current_row >> col) & 1; // Real Time Noise Floor Calibration @@ -266,7 +289,7 @@ bool ec_update_key(matrix_row_t* current_row, uint8_t row, uint8_t col, uint16_t uprintf("Key pressed: %d, %d, %d\n", row, col, sw_value); } // Has key moved up enough to be released? - else if (sw_value < ec_config.extremum[row][col] - ec_config.mode_1_release_offset) { + else if (sw_value < ec_config.extremum[row][col] - ec_config.rescaled_mode_1_release_offset[row][col]) { ec_config.extremum[row][col] = sw_value; *current_row &= ~(1 << col); uprintf("Key released: %d, %d, %d\n", row, col, sw_value); @@ -280,7 +303,7 @@ bool ec_update_key(matrix_row_t* current_row, uint8_t row, uint8_t col, uint16_t ec_config.extremum[row][col] = sw_value; } // Has key moved down enough to be pressed? - else if (sw_value > ec_config.extremum[row][col] + ec_config.mode_1_actuation_offset) { + else if (sw_value > ec_config.extremum[row][col] + ec_config.rescaled_mode_1_actuation_offset[row][col]) { ec_config.extremum[row][col] = sw_value; *current_row |= (1 << col); uprintf("Key pressed: %d, %d, %d\n", row, col, sw_value); @@ -312,6 +335,18 @@ void ec_print_matrix(void) { print("\n"); } +// Check if the position is unused +#ifdef UNUSED_POSITIONS_LIST +bool is_unused_position(uint8_t row, uint8_t col) { + for (uint8_t i = 0; i < UNUSED_POSITIONS_COUNT; i++) { + if (UNUSED_POSITIONS[i][0] == row && UNUSED_POSITIONS[i][1] == col) { + return true; + } + } + return false; +} +#endif + // Rescale the value to a different range uint16_t rescale(uint16_t x, uint16_t in_min, uint16_t in_max, uint16_t out_min, uint16_t out_max) { return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; diff --git a/keyboards/cipulot/ec_980c/ec_switch_matrix.h b/keyboards/cipulot/ec_980c/ec_switch_matrix.h index 8a75b5de5f..a89f8970ab 100644 --- a/keyboards/cipulot/ec_980c/ec_switch_matrix.h +++ b/keyboards/cipulot/ec_980c/ec_switch_matrix.h @@ -47,11 +47,13 @@ typedef struct { uint16_t mode_0_actuation_threshold; // threshold for key press in mode 0 uint16_t mode_0_release_threshold; // threshold for key release in mode 0 uint16_t mode_1_initial_deadzone_offset; // threshold for key press in mode 1 (initial deadzone) + uint8_t mode_1_actuation_offset; // offset for key press in mode 1 (1-255) + uint8_t mode_1_release_offset; // offset for key release in mode 1 (1-255) uint16_t rescaled_mode_0_actuation_threshold[MATRIX_ROWS][MATRIX_COLS]; // threshold for key press in mode 0 rescaled to actual scale uint16_t rescaled_mode_0_release_threshold[MATRIX_ROWS][MATRIX_COLS]; // threshold for key release in mode 0 rescaled to actual scale 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 - uint8_t mode_1_actuation_offset; // offset for key press in mode 1 (1-255) - uint8_t mode_1_release_offset; // offset for key release in mode 1 (1-255) + uint8_t rescaled_mode_1_actuation_offset[MATRIX_ROWS][MATRIX_COLS]; // offset for key press in mode 1 rescaled to actual scale + uint8_t rescaled_mode_1_release_offset[MATRIX_ROWS][MATRIX_COLS]; // offset for key release in mode 1 rescaled to actual scale uint16_t extremum[MATRIX_ROWS][MATRIX_COLS]; // extremum values for mode 1 uint16_t noise_floor[MATRIX_ROWS][MATRIX_COLS]; // noise floor detected during startup bool bottoming_calibration; // calibration mode for bottoming out values (true: calibration mode, false: normal mode) @@ -81,3 +83,7 @@ bool ec_update_key(matrix_row_t* current_row, uint8_t row, uint8_t col, uint void ec_print_matrix(void); uint16_t rescale(uint16_t x, uint16_t in_min, uint16_t in_max, uint16_t out_min, uint16_t out_max); + +#ifdef UNUSED_POSITIONS_LIST +bool is_unused_position(uint8_t row, uint8_t col); +#endif diff --git a/keyboards/cipulot/ec_alveus/1_0_0/config.h b/keyboards/cipulot/ec_alveus/1_0_0/config.h index ab51289c02..995ede408b 100644 --- a/keyboards/cipulot/ec_alveus/1_0_0/config.h +++ b/keyboards/cipulot/ec_alveus/1_0_0/config.h @@ -19,6 +19,8 @@ #define MATRIX_ROWS 5 #define MATRIX_COLS 16 +#define UNUSED_POSITIONS_LIST { {2, 12}, {3, 11}, {3, 12}, {4, 3}, {4, 4}, {4, 6}, {4, 7}, {4, 8}, {4, 9}, {4, 10} } + #define MATRIX_ROW_PINS \ { A14, B3, A15, B5, B4 } diff --git a/keyboards/cipulot/ec_alveus/1_0_0/post_rules.mk b/keyboards/cipulot/ec_alveus/1_0_0/post_rules.mk index d726a112a8..5dba48cc5f 100644 --- a/keyboards/cipulot/ec_alveus/1_0_0/post_rules.mk +++ b/keyboards/cipulot/ec_alveus/1_0_0/post_rules.mk @@ -1,3 +1 @@ -ifeq ($(strip $(VIA_ENABLE)), yes) - SRC += keyboards/cipulot/common/via_ec.c -endif +include keyboards/cipulot/common/common_cipulot.mk diff --git a/keyboards/cipulot/ec_alveus/1_0_0/rules.mk b/keyboards/cipulot/ec_alveus/1_0_0/rules.mk index ce525670a6..1716098b3e 100644 --- a/keyboards/cipulot/ec_alveus/1_0_0/rules.mk +++ b/keyboards/cipulot/ec_alveus/1_0_0/rules.mk @@ -1,5 +1 @@ -CUSTOM_MATRIX = lite -ANALOG_DRIVER_REQUIRED = yes -VPATH += keyboards/cipulot/common -SRC += matrix.c ec_board.c ec_switch_matrix.c OPT = 3 diff --git a/keyboards/cipulot/ec_alveus/1_2_0/config.h b/keyboards/cipulot/ec_alveus/1_2_0/config.h index ab51289c02..05276c1d75 100644 --- a/keyboards/cipulot/ec_alveus/1_2_0/config.h +++ b/keyboards/cipulot/ec_alveus/1_2_0/config.h @@ -19,6 +19,8 @@ #define MATRIX_ROWS 5 #define MATRIX_COLS 16 +#define UNUSED_POSITIONS_LIST { {3, 11}, {3, 12}, {4, 3}, {4, 4}, {4, 6}, {4, 7}, {4, 8}, {4, 9}, {4, 10} } + #define MATRIX_ROW_PINS \ { A14, B3, A15, B5, B4 } diff --git a/keyboards/cipulot/ec_alveus/1_2_0/post_rules.mk b/keyboards/cipulot/ec_alveus/1_2_0/post_rules.mk index d726a112a8..5dba48cc5f 100644 --- a/keyboards/cipulot/ec_alveus/1_2_0/post_rules.mk +++ b/keyboards/cipulot/ec_alveus/1_2_0/post_rules.mk @@ -1,3 +1 @@ -ifeq ($(strip $(VIA_ENABLE)), yes) - SRC += keyboards/cipulot/common/via_ec.c -endif +include keyboards/cipulot/common/common_cipulot.mk diff --git a/keyboards/cipulot/ec_alveus/1_2_0/rules.mk b/keyboards/cipulot/ec_alveus/1_2_0/rules.mk index ce525670a6..1716098b3e 100644 --- a/keyboards/cipulot/ec_alveus/1_2_0/rules.mk +++ b/keyboards/cipulot/ec_alveus/1_2_0/rules.mk @@ -1,5 +1 @@ -CUSTOM_MATRIX = lite -ANALOG_DRIVER_REQUIRED = yes -VPATH += keyboards/cipulot/common -SRC += matrix.c ec_board.c ec_switch_matrix.c OPT = 3 diff --git a/keyboards/cipulot/ec_dolice/config.h b/keyboards/cipulot/ec_dolice/config.h index a5c56e7949..2048fd4449 100644 --- a/keyboards/cipulot/ec_dolice/config.h +++ b/keyboards/cipulot/ec_dolice/config.h @@ -19,6 +19,8 @@ #define MATRIX_ROWS 5 #define MATRIX_COLS 15 +#define UNUSED_POSITIONS_LIST { {2, 14}, {4, 0}, {4, 2}, {4, 4}, {4, 7}, {4, 9}, {4, 11}, {4, 12}, {4, 13} } + #define MATRIX_ROW_PINS \ { B13, A8, B12, B14, B15 } diff --git a/keyboards/cipulot/ec_dolice/post_rules.mk b/keyboards/cipulot/ec_dolice/post_rules.mk index d726a112a8..5dba48cc5f 100644 --- a/keyboards/cipulot/ec_dolice/post_rules.mk +++ b/keyboards/cipulot/ec_dolice/post_rules.mk @@ -1,3 +1 @@ -ifeq ($(strip $(VIA_ENABLE)), yes) - SRC += keyboards/cipulot/common/via_ec.c -endif +include keyboards/cipulot/common/common_cipulot.mk diff --git a/keyboards/cipulot/ec_dolice/rules.mk b/keyboards/cipulot/ec_dolice/rules.mk index ce525670a6..1716098b3e 100644 --- a/keyboards/cipulot/ec_dolice/rules.mk +++ b/keyboards/cipulot/ec_dolice/rules.mk @@ -1,5 +1 @@ -CUSTOM_MATRIX = lite -ANALOG_DRIVER_REQUIRED = yes -VPATH += keyboards/cipulot/common -SRC += matrix.c ec_board.c ec_switch_matrix.c OPT = 3 diff --git a/keyboards/cipulot/ec_menhir/config.h b/keyboards/cipulot/ec_menhir/config.h index bd0094c7f1..d70fed7a3b 100644 --- a/keyboards/cipulot/ec_menhir/config.h +++ b/keyboards/cipulot/ec_menhir/config.h @@ -19,6 +19,8 @@ #define MATRIX_ROWS 4 #define MATRIX_COLS 12 +#define UNUSED_POSITIONS_LIST { {2, 11}, {3, 0}, {3, 3}, {3, 7}, {3, 10}, {3, 11} } + #define MATRIX_ROW_PINS \ { A0, A3, A2, A1 } diff --git a/keyboards/cipulot/ec_menhir/post_rules.mk b/keyboards/cipulot/ec_menhir/post_rules.mk index d726a112a8..5dba48cc5f 100644 --- a/keyboards/cipulot/ec_menhir/post_rules.mk +++ b/keyboards/cipulot/ec_menhir/post_rules.mk @@ -1,3 +1 @@ -ifeq ($(strip $(VIA_ENABLE)), yes) - SRC += keyboards/cipulot/common/via_ec.c -endif +include keyboards/cipulot/common/common_cipulot.mk diff --git a/keyboards/cipulot/ec_pro2/config.h b/keyboards/cipulot/ec_pro2/config.h index a05e716823..63c81a6364 100644 --- a/keyboards/cipulot/ec_pro2/config.h +++ b/keyboards/cipulot/ec_pro2/config.h @@ -19,6 +19,8 @@ #define MATRIX_ROWS 5 #define MATRIX_COLS 15 +#define UNUSED_POSITIONS_LIST { {1, 14}, {2, 14}, {3, 12}, {4, 0}, {4, 3}, {4, 4}, {4, 5}, {4, 7}, {4, 8}, {4, 11}, {4, 12}, {4, 13}, {4, 14} } + #define MATRIX_ROW_PINS \ { B15, A8, B0, A7, B1 } diff --git a/keyboards/cipulot/ec_pro2/post_rules.mk b/keyboards/cipulot/ec_pro2/post_rules.mk index d726a112a8..5dba48cc5f 100644 --- a/keyboards/cipulot/ec_pro2/post_rules.mk +++ b/keyboards/cipulot/ec_pro2/post_rules.mk @@ -1,3 +1 @@ -ifeq ($(strip $(VIA_ENABLE)), yes) - SRC += keyboards/cipulot/common/via_ec.c -endif +include keyboards/cipulot/common/common_cipulot.mk diff --git a/keyboards/cipulot/ec_pro2/rules.mk b/keyboards/cipulot/ec_pro2/rules.mk index 318e0215ce..3aa0e2bf06 100644 --- a/keyboards/cipulot/ec_pro2/rules.mk +++ b/keyboards/cipulot/ec_pro2/rules.mk @@ -1,5 +1 @@ -CUSTOM_MATRIX = lite -ANALOG_DRIVER_REQUIRED = yes -VPATH += keyboards/cipulot/common -SRC += matrix.c ec_board.c ec_switch_matrix.c OPT = 2 diff --git a/keyboards/cipulot/ec_prox/ansi_iso/config.h b/keyboards/cipulot/ec_prox/ansi_iso/config.h index bf25d0b712..00794921a3 100644 --- a/keyboards/cipulot/ec_prox/ansi_iso/config.h +++ b/keyboards/cipulot/ec_prox/ansi_iso/config.h @@ -19,6 +19,8 @@ #define MATRIX_ROWS 5 #define MATRIX_COLS 15 +#define UNUSED_POSITIONS_LIST { {1, 14}, {2, 14}, {3, 12}, {4, 0}, {4, 3}, {4, 4}, {4, 5}, {4, 7}, {4, 8}, {4, 11}, {4, 12}, {4, 13}, {4, 14} } + #define MATRIX_ROW_PINS \ { A7, B0, A4, A5, A6 } diff --git a/keyboards/cipulot/ec_prox/ansi_iso/post_rules.mk b/keyboards/cipulot/ec_prox/ansi_iso/post_rules.mk index d726a112a8..5dba48cc5f 100644 --- a/keyboards/cipulot/ec_prox/ansi_iso/post_rules.mk +++ b/keyboards/cipulot/ec_prox/ansi_iso/post_rules.mk @@ -1,3 +1 @@ -ifeq ($(strip $(VIA_ENABLE)), yes) - SRC += keyboards/cipulot/common/via_ec.c -endif +include keyboards/cipulot/common/common_cipulot.mk diff --git a/keyboards/cipulot/ec_prox/ansi_iso/rules.mk b/keyboards/cipulot/ec_prox/ansi_iso/rules.mk index 318e0215ce..3aa0e2bf06 100644 --- a/keyboards/cipulot/ec_prox/ansi_iso/rules.mk +++ b/keyboards/cipulot/ec_prox/ansi_iso/rules.mk @@ -1,5 +1 @@ -CUSTOM_MATRIX = lite -ANALOG_DRIVER_REQUIRED = yes -VPATH += keyboards/cipulot/common -SRC += matrix.c ec_board.c ec_switch_matrix.c OPT = 2 diff --git a/keyboards/cipulot/ec_prox/jis/config.h b/keyboards/cipulot/ec_prox/jis/config.h index fd3c048bc3..d7461097cd 100644 --- a/keyboards/cipulot/ec_prox/jis/config.h +++ b/keyboards/cipulot/ec_prox/jis/config.h @@ -19,6 +19,8 @@ #define MATRIX_ROWS 5 #define MATRIX_COLS 14 +#define UNUSED_POSITIONS_LIST { {4, 6} } + #define MATRIX_ROW_PINS \ { A7, B0, A4, A5, A6 } diff --git a/keyboards/cipulot/ec_prox/jis/post_rules.mk b/keyboards/cipulot/ec_prox/jis/post_rules.mk index d726a112a8..5dba48cc5f 100644 --- a/keyboards/cipulot/ec_prox/jis/post_rules.mk +++ b/keyboards/cipulot/ec_prox/jis/post_rules.mk @@ -1,3 +1 @@ -ifeq ($(strip $(VIA_ENABLE)), yes) - SRC += keyboards/cipulot/common/via_ec.c -endif +include keyboards/cipulot/common/common_cipulot.mk diff --git a/keyboards/cipulot/ec_prox/jis/rules.mk b/keyboards/cipulot/ec_prox/jis/rules.mk index 318e0215ce..3aa0e2bf06 100644 --- a/keyboards/cipulot/ec_prox/jis/rules.mk +++ b/keyboards/cipulot/ec_prox/jis/rules.mk @@ -1,5 +1 @@ -CUSTOM_MATRIX = lite -ANALOG_DRIVER_REQUIRED = yes -VPATH += keyboards/cipulot/common -SRC += matrix.c ec_board.c ec_switch_matrix.c OPT = 2 diff --git a/keyboards/cipulot/ec_theca/config.h b/keyboards/cipulot/ec_theca/config.h index d9fea55967..e62801b10f 100644 --- a/keyboards/cipulot/ec_theca/config.h +++ b/keyboards/cipulot/ec_theca/config.h @@ -19,6 +19,8 @@ #define MATRIX_ROWS 6 #define MATRIX_COLS 16 +#define UNUSED_POSITIONS_LIST { {3, 12}, {4, 11}, {4, 12}, {5, 3}, {5, 4}, {5, 6}, {5, 7}, {5, 8}, {5, 9} } + #define MATRIX_ROW_PINS \ { B4, A14, B3, A15, B6, B5 } diff --git a/keyboards/cipulot/ec_theca/post_rules.mk b/keyboards/cipulot/ec_theca/post_rules.mk index d726a112a8..5dba48cc5f 100644 --- a/keyboards/cipulot/ec_theca/post_rules.mk +++ b/keyboards/cipulot/ec_theca/post_rules.mk @@ -1,3 +1 @@ -ifeq ($(strip $(VIA_ENABLE)), yes) - SRC += keyboards/cipulot/common/via_ec.c -endif +include keyboards/cipulot/common/common_cipulot.mk diff --git a/keyboards/cipulot/ec_theca/rules.mk b/keyboards/cipulot/ec_theca/rules.mk index ce525670a6..1716098b3e 100644 --- a/keyboards/cipulot/ec_theca/rules.mk +++ b/keyboards/cipulot/ec_theca/rules.mk @@ -1,5 +1 @@ -CUSTOM_MATRIX = lite -ANALOG_DRIVER_REQUIRED = yes -VPATH += keyboards/cipulot/common -SRC += matrix.c ec_board.c ec_switch_matrix.c OPT = 3 diff --git a/keyboards/cipulot/ec_tkl/config.h b/keyboards/cipulot/ec_tkl/config.h index 95a7f9137a..d2178fa869 100644 --- a/keyboards/cipulot/ec_tkl/config.h +++ b/keyboards/cipulot/ec_tkl/config.h @@ -19,6 +19,8 @@ #define MATRIX_ROWS 6 #define MATRIX_COLS 16 +#define UNUSED_POSITIONS_LIST { {5, 3}, {5, 5} } + #define MATRIX_ROW_PINS \ { B6, B5, B12, B10, B13, B7 } diff --git a/keyboards/cipulot/ec_tkl/post_rules.mk b/keyboards/cipulot/ec_tkl/post_rules.mk index d726a112a8..5dba48cc5f 100644 --- a/keyboards/cipulot/ec_tkl/post_rules.mk +++ b/keyboards/cipulot/ec_tkl/post_rules.mk @@ -1,3 +1 @@ -ifeq ($(strip $(VIA_ENABLE)), yes) - SRC += keyboards/cipulot/common/via_ec.c -endif +include keyboards/cipulot/common/common_cipulot.mk diff --git a/keyboards/cipulot/ec_tkl/rules.mk b/keyboards/cipulot/ec_tkl/rules.mk index 318e0215ce..3aa0e2bf06 100644 --- a/keyboards/cipulot/ec_tkl/rules.mk +++ b/keyboards/cipulot/ec_tkl/rules.mk @@ -1,5 +1 @@ -CUSTOM_MATRIX = lite -ANALOG_DRIVER_REQUIRED = yes -VPATH += keyboards/cipulot/common -SRC += matrix.c ec_board.c ec_switch_matrix.c OPT = 2 diff --git a/keyboards/cipulot/ec_typeb/config.h b/keyboards/cipulot/ec_typeb/config.h index bf25d0b712..908bae13e6 100644 --- a/keyboards/cipulot/ec_typeb/config.h +++ b/keyboards/cipulot/ec_typeb/config.h @@ -19,6 +19,8 @@ #define MATRIX_ROWS 5 #define MATRIX_COLS 15 +#define UNUSED_POSITIONS_LIST { {1, 14}, {2, 12}, {2, 14}, {3, 1}, {3, 12}, {4, 0}, {4, 3}, {4, 4}, {4, 5}, {4, 7}, {4, 8}, {4, 11}, {4, 12}, {4, 13}, {4, 14} } + #define MATRIX_ROW_PINS \ { A7, B0, A4, A5, A6 } diff --git a/keyboards/cipulot/ec_typeb/post_rules.mk b/keyboards/cipulot/ec_typeb/post_rules.mk index d726a112a8..5dba48cc5f 100644 --- a/keyboards/cipulot/ec_typeb/post_rules.mk +++ b/keyboards/cipulot/ec_typeb/post_rules.mk @@ -1,3 +1 @@ -ifeq ($(strip $(VIA_ENABLE)), yes) - SRC += keyboards/cipulot/common/via_ec.c -endif +include keyboards/cipulot/common/common_cipulot.mk diff --git a/keyboards/cipulot/ec_typeb/rules.mk b/keyboards/cipulot/ec_typeb/rules.mk index ce525670a6..1716098b3e 100644 --- a/keyboards/cipulot/ec_typeb/rules.mk +++ b/keyboards/cipulot/ec_typeb/rules.mk @@ -1,5 +1 @@ -CUSTOM_MATRIX = lite -ANALOG_DRIVER_REQUIRED = yes -VPATH += keyboards/cipulot/common -SRC += matrix.c ec_board.c ec_switch_matrix.c OPT = 3 diff --git a/keyboards/cipulot/ec_typek/config.h b/keyboards/cipulot/ec_typek/config.h index a6619c600c..9821dcbba6 100644 --- a/keyboards/cipulot/ec_typek/config.h +++ b/keyboards/cipulot/ec_typek/config.h @@ -17,6 +17,8 @@ #define MATRIX_ROWS 5 #define MATRIX_COLS 15 +#define UNUSED_POSITIONS_LIST { {2, 13}, {4, 2}, {4, 4}, {4, 9}, {4, 11}, {4, 12}, {4, 14} } + #define MATRIX_ROW_PINS \ { B14, B13, B12, A6, A7 } diff --git a/keyboards/cipulot/ec_typek/ec_switch_matrix.c b/keyboards/cipulot/ec_typek/ec_switch_matrix.c index da58a75bbc..ca55537825 100644 --- a/keyboards/cipulot/ec_typek/ec_switch_matrix.c +++ b/keyboards/cipulot/ec_typek/ec_switch_matrix.c @@ -37,6 +37,11 @@ const pin_t amux_en_pins[] = AMUX_EN_PINS; const pin_t amux_n_col_sizes[] = AMUX_COL_CHANNELS_SIZES; const pin_t amux_n_col_channels[][AMUX_MAX_COLS_COUNT] = {AMUX_COL_CHANNELS}; +#ifdef UNUSED_POSITIONS_LIST +const uint8_t UNUSED_POSITIONS[][2] = UNUSED_POSITIONS_LIST; +# define UNUSED_POSITIONS_COUNT (sizeof(UNUSED_POSITIONS) / sizeof(UNUSED_POSITIONS[0])) +#endif + #define AMUX_SEL_PINS_COUNT ARRAY_SIZE(amux_sel_pins) #define EXPECTED_AMUX_SEL_PINS_COUNT ceil(log2(AMUX_MAX_COLS_COUNT) // Checks for the correctness of the configuration @@ -70,6 +75,16 @@ void init_amux(void) { } } +// Disable all the unused rows +void disable_unused_row(uint8_t row) { + // disable all the other rows apart from the current selected one + for (uint8_t idx = 0; idx < MATRIX_ROWS; idx++) { + if (idx != row) { + gpio_write_pin_low(row_pins[idx]); + } + } +} + // Select the multiplexer channel of the specified multiplexer void select_amux_channel(uint8_t channel, uint8_t col) { // Get the channel for the specified multiplexer @@ -158,6 +173,10 @@ void ec_noise_floor(void) { sum += amux_n_col_sizes[i]; uint8_t adjusted_col = col + sum; for (uint8_t row = 0; row < MATRIX_ROWS; row++) { +#ifdef UNUSED_POSITIONS_LIST + if (is_unused_position(row, adjusted_col)) continue; +#endif + disable_unused_row(row); ec_config.noise_floor[row][adjusted_col] += ec_readkey_raw(amux, row, col); } } @@ -180,11 +199,15 @@ bool ec_matrix_scan(matrix_row_t current_matrix[]) { for (uint8_t amux = 0; amux < AMUX_COUNT; amux++) { disable_unused_amux(amux); for (uint8_t col = 0; col < amux_n_col_sizes[amux]; col++) { + uint8_t sum = 0; + for (uint8_t i = 0; i < (amux > 0 ? amux : 0); i++) + sum += amux_n_col_sizes[i]; + uint8_t adjusted_col = col + sum; for (uint8_t row = 0; row < MATRIX_ROWS; row++) { - uint8_t sum = 0; - for (uint8_t i = 0; i < (amux > 0 ? amux : 0); i++) - sum += amux_n_col_sizes[i]; - uint8_t adjusted_col = col + sum; +#ifdef UNUSED_POSITIONS_LIST + if (is_unused_position(row, adjusted_col)) continue; +#endif + disable_unused_row(row); sw_value[row][adjusted_col] = ec_readkey_raw(amux, row, col); if (ec_config.bottoming_calibration) { @@ -229,7 +252,7 @@ uint16_t ec_readkey_raw(uint8_t channel, uint8_t row, uint8_t col) { } // Update press/release state of key -bool ec_update_key(matrix_row_t* current_row, uint8_t row, uint8_t col, uint16_t sw_value) { +bool ec_update_key(matrix_row_t *current_row, uint8_t row, uint8_t col, uint16_t sw_value) { bool current_state = (*current_row >> col) & 1; // Real Time Noise Floor Calibration @@ -266,7 +289,7 @@ bool ec_update_key(matrix_row_t* current_row, uint8_t row, uint8_t col, uint16_t uprintf("Key pressed: %d, %d, %d\n", row, col, sw_value); } // Has key moved up enough to be released? - else if (sw_value < ec_config.extremum[row][col] - ec_config.mode_1_release_offset) { + else if (sw_value < ec_config.extremum[row][col] - ec_config.rescaled_mode_1_release_offset[row][col]) { ec_config.extremum[row][col] = sw_value; *current_row &= ~(1 << col); uprintf("Key released: %d, %d, %d\n", row, col, sw_value); @@ -280,7 +303,7 @@ bool ec_update_key(matrix_row_t* current_row, uint8_t row, uint8_t col, uint16_t ec_config.extremum[row][col] = sw_value; } // Has key moved down enough to be pressed? - else if (sw_value > ec_config.extremum[row][col] + ec_config.mode_1_actuation_offset) { + else if (sw_value > ec_config.extremum[row][col] + ec_config.rescaled_mode_1_actuation_offset[row][col]) { ec_config.extremum[row][col] = sw_value; *current_row |= (1 << col); uprintf("Key pressed: %d, %d, %d\n", row, col, sw_value); @@ -312,6 +335,18 @@ void ec_print_matrix(void) { print("\n"); } +// Check if the position is unused +#ifdef UNUSED_POSITIONS_LIST +bool is_unused_position(uint8_t row, uint8_t col) { + for (uint8_t i = 0; i < UNUSED_POSITIONS_COUNT; i++) { + if (UNUSED_POSITIONS[i][0] == row && UNUSED_POSITIONS[i][1] == col) { + return true; + } + } + return false; +} +#endif + // Rescale the value to a different range uint16_t rescale(uint16_t x, uint16_t in_min, uint16_t in_max, uint16_t out_min, uint16_t out_max) { return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; diff --git a/keyboards/cipulot/ec_typek/ec_switch_matrix.h b/keyboards/cipulot/ec_typek/ec_switch_matrix.h index fad20360bc..e3b6afb976 100644 --- a/keyboards/cipulot/ec_typek/ec_switch_matrix.h +++ b/keyboards/cipulot/ec_typek/ec_switch_matrix.h @@ -33,13 +33,13 @@ typedef struct PACKED { indicator_config num; indicator_config caps; indicator_config scroll; - uint8_t actuation_mode; // 0: normal board-wide APC, 1: Rapid trigger from specific board-wide actuation point, 2: Rapid trigger from resting point - uint16_t mode_0_actuation_threshold; // threshold for key press in mode 0 - uint16_t mode_0_release_threshold; // threshold for key release in mode 0 - uint16_t mode_1_initial_deadzone_offset; // threshold for key press in mode 1 - uint8_t mode_1_actuation_offset; // offset for key press in mode 1 and 2 (1-255) - uint8_t mode_1_release_offset; // offset for key release in mode 1 and 2 (1-255) - uint16_t bottoming_reading[MATRIX_ROWS][MATRIX_COLS]; // bottoming reading + uint8_t actuation_mode; // 0: normal board-wide APC, 1: Rapid trigger from specific board-wide actuation point, 2: Rapid trigger from resting point + uint16_t mode_0_actuation_threshold; // threshold for key press in mode 0 + uint16_t mode_0_release_threshold; // threshold for key release in mode 0 + uint16_t mode_1_initial_deadzone_offset; // threshold for key press in mode 1 + uint8_t mode_1_actuation_offset; // offset for key press in mode 1 and 2 (1-255) + uint8_t mode_1_release_offset; // offset for key release in mode 1 and 2 (1-255) + uint16_t bottoming_reading[MATRIX_ROWS][MATRIX_COLS]; // bottoming reading } eeprom_ec_config_t; typedef struct { @@ -47,11 +47,13 @@ typedef struct { uint16_t mode_0_actuation_threshold; // threshold for key press in mode 0 uint16_t mode_0_release_threshold; // threshold for key release in mode 0 uint16_t mode_1_initial_deadzone_offset; // threshold for key press in mode 1 (initial deadzone) + uint8_t mode_1_actuation_offset; // offset for key press in mode 1 (1-255) + uint8_t mode_1_release_offset; // offset for key release in mode 1 (1-255) uint16_t rescaled_mode_0_actuation_threshold[MATRIX_ROWS][MATRIX_COLS]; // threshold for key press in mode 0 rescaled to actual scale uint16_t rescaled_mode_0_release_threshold[MATRIX_ROWS][MATRIX_COLS]; // threshold for key release in mode 0 rescaled to actual scale 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 - uint8_t mode_1_actuation_offset; // offset for key press in mode 1 (1-255) - uint8_t mode_1_release_offset; // offset for key release in mode 1 (1-255) + uint8_t rescaled_mode_1_actuation_offset[MATRIX_ROWS][MATRIX_COLS]; // offset for key press in mode 1 rescaled to actual scale + uint8_t rescaled_mode_1_release_offset[MATRIX_ROWS][MATRIX_COLS]; // offset for key release in mode 1 rescaled to actual scale uint16_t extremum[MATRIX_ROWS][MATRIX_COLS]; // extremum values for mode 1 uint16_t noise_floor[MATRIX_ROWS][MATRIX_COLS]; // noise floor detected during startup bool bottoming_calibration; // calibration mode for bottoming out values (true: calibration mode, false: normal mode) @@ -82,3 +84,7 @@ void ec_print_matrix(void); uint16_t rescale(uint16_t x, uint16_t in_min, uint16_t in_max, uint16_t out_min, uint16_t out_max); bool indicators_callback(void); + +#ifdef UNUSED_POSITIONS_LIST +bool is_unused_position(uint8_t row, uint8_t col); +#endif diff --git a/keyboards/cipulot/ec_typek/ec_typek.c b/keyboards/cipulot/ec_typek/ec_typek.c index b899ddbb8a..d4241f66f1 100644 --- a/keyboards/cipulot/ec_typek/ec_typek.c +++ b/keyboards/cipulot/ec_typek/ec_typek.c @@ -69,6 +69,8 @@ void keyboard_post_init_kb(void) { 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]); 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]); 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]); + 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]); + 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]); } } @@ -82,7 +84,7 @@ void keyboard_post_init_kb(void) { // This function gets called when caps, num, scroll change bool led_update_kb(led_t led_state) { - if(led_update_user(led_state)) { + if (led_update_user(led_state)) { indicators_callback(); } return true; diff --git a/keyboards/cipulot/ec_vero/config.h b/keyboards/cipulot/ec_vero/config.h index 89f7474b55..d86c0b6ab0 100644 --- a/keyboards/cipulot/ec_vero/config.h +++ b/keyboards/cipulot/ec_vero/config.h @@ -19,6 +19,8 @@ #define MATRIX_ROWS 5 #define MATRIX_COLS 15 +#define UNUSED_POSITIONS_LIST { {2, 14}, {3, 12}, {4, 0}, {4, 3}, {4, 4}, {4, 5}, {4, 7}, {4, 8}, {4, 9}, {4, 12}, {4, 13}, {4, 14} } + #define MATRIX_ROW_PINS \ { B7, B6, A9, A10, B3 } diff --git a/keyboards/cipulot/ec_vero/post_rules.mk b/keyboards/cipulot/ec_vero/post_rules.mk index d726a112a8..5dba48cc5f 100644 --- a/keyboards/cipulot/ec_vero/post_rules.mk +++ b/keyboards/cipulot/ec_vero/post_rules.mk @@ -1,3 +1 @@ -ifeq ($(strip $(VIA_ENABLE)), yes) - SRC += keyboards/cipulot/common/via_ec.c -endif +include keyboards/cipulot/common/common_cipulot.mk diff --git a/keyboards/cipulot/ec_vero/rules.mk b/keyboards/cipulot/ec_vero/rules.mk index ce525670a6..1716098b3e 100644 --- a/keyboards/cipulot/ec_vero/rules.mk +++ b/keyboards/cipulot/ec_vero/rules.mk @@ -1,5 +1 @@ -CUSTOM_MATRIX = lite -ANALOG_DRIVER_REQUIRED = yes -VPATH += keyboards/cipulot/common -SRC += matrix.c ec_board.c ec_switch_matrix.c OPT = 3 diff --git a/keyboards/cipulot/ec_virgo/config.h b/keyboards/cipulot/ec_virgo/config.h index 2fce8cd7fa..87cfbcdd76 100644 --- a/keyboards/cipulot/ec_virgo/config.h +++ b/keyboards/cipulot/ec_virgo/config.h @@ -19,6 +19,8 @@ #define MATRIX_ROWS 6 #define MATRIX_COLS 18 +#define UNUSED_POSITIONS_LIST { {0, 6}, {0, 14}, {3, 14}, {3, 15}, {3, 16}, {3, 17}, {4, 12}, {4, 15}, {4, 17}, {5, 1}, {5, 4}, {5, 8}, {5, 11}, {5, 12}, {5, 14} } + #define MATRIX_ROW_PINS \ { B6, B7, B5, B4, B3, A15 } diff --git a/keyboards/cipulot/ec_virgo/post_rules.mk b/keyboards/cipulot/ec_virgo/post_rules.mk index d726a112a8..5dba48cc5f 100644 --- a/keyboards/cipulot/ec_virgo/post_rules.mk +++ b/keyboards/cipulot/ec_virgo/post_rules.mk @@ -1,3 +1 @@ -ifeq ($(strip $(VIA_ENABLE)), yes) - SRC += keyboards/cipulot/common/via_ec.c -endif +include keyboards/cipulot/common/common_cipulot.mk diff --git a/keyboards/cipulot/ec_virgo/rules.mk b/keyboards/cipulot/ec_virgo/rules.mk index ce525670a6..1716098b3e 100644 --- a/keyboards/cipulot/ec_virgo/rules.mk +++ b/keyboards/cipulot/ec_virgo/rules.mk @@ -1,5 +1 @@ -CUSTOM_MATRIX = lite -ANALOG_DRIVER_REQUIRED = yes -VPATH += keyboards/cipulot/common -SRC += matrix.c ec_board.c ec_switch_matrix.c OPT = 3 diff --git a/keyboards/cipulot/mnk_60_ec/config.h b/keyboards/cipulot/mnk_60_ec/config.h index 1a7df48657..1f31c91aaa 100644 --- a/keyboards/cipulot/mnk_60_ec/config.h +++ b/keyboards/cipulot/mnk_60_ec/config.h @@ -19,6 +19,8 @@ #define MATRIX_ROWS 5 #define MATRIX_COLS 14 +#define UNUSED_POSITIONS_LIST { {3, 13}, {4, 3}, {4, 4}, {4, 6}, {4, 7}, {4, 8}, {4, 9}, {4, 13} } + #define MATRIX_ROW_PINS \ { B13, B14, B15, A8, A15 } diff --git a/keyboards/cipulot/mnk_60_ec/post_rules.mk b/keyboards/cipulot/mnk_60_ec/post_rules.mk index d726a112a8..5dba48cc5f 100644 --- a/keyboards/cipulot/mnk_60_ec/post_rules.mk +++ b/keyboards/cipulot/mnk_60_ec/post_rules.mk @@ -1,3 +1 @@ -ifeq ($(strip $(VIA_ENABLE)), yes) - SRC += keyboards/cipulot/common/via_ec.c -endif +include keyboards/cipulot/common/common_cipulot.mk diff --git a/keyboards/cipulot/mnk_60_ec/rules.mk b/keyboards/cipulot/mnk_60_ec/rules.mk index ce525670a6..1716098b3e 100644 --- a/keyboards/cipulot/mnk_60_ec/rules.mk +++ b/keyboards/cipulot/mnk_60_ec/rules.mk @@ -1,5 +1 @@ -CUSTOM_MATRIX = lite -ANALOG_DRIVER_REQUIRED = yes -VPATH += keyboards/cipulot/common -SRC += matrix.c ec_board.c ec_switch_matrix.c OPT = 3 diff --git a/keyboards/cipulot/mnk_65_ec/config.h b/keyboards/cipulot/mnk_65_ec/config.h index 01d1248c43..9d880ba3bd 100644 --- a/keyboards/cipulot/mnk_65_ec/config.h +++ b/keyboards/cipulot/mnk_65_ec/config.h @@ -19,6 +19,8 @@ #define MATRIX_ROWS 5 #define MATRIX_COLS 15 +#define UNUSED_POSITIONS_LIST { {2, 13}, {3, 13}, {4, 3}, {4, 4}, {4, 6}, {4, 7}, {4, 8}, {4, 10}, {4, 13} } + #define MATRIX_ROW_PINS \ { B14, B15, A8, B12, A15 } diff --git a/keyboards/cipulot/mnk_65_ec/post_rules.mk b/keyboards/cipulot/mnk_65_ec/post_rules.mk index d726a112a8..5dba48cc5f 100644 --- a/keyboards/cipulot/mnk_65_ec/post_rules.mk +++ b/keyboards/cipulot/mnk_65_ec/post_rules.mk @@ -1,3 +1 @@ -ifeq ($(strip $(VIA_ENABLE)), yes) - SRC += keyboards/cipulot/common/via_ec.c -endif +include keyboards/cipulot/common/common_cipulot.mk diff --git a/keyboards/cipulot/mnk_65_ec/rules.mk b/keyboards/cipulot/mnk_65_ec/rules.mk index ce525670a6..1716098b3e 100644 --- a/keyboards/cipulot/mnk_65_ec/rules.mk +++ b/keyboards/cipulot/mnk_65_ec/rules.mk @@ -1,5 +1 @@ -CUSTOM_MATRIX = lite -ANALOG_DRIVER_REQUIRED = yes -VPATH += keyboards/cipulot/common -SRC += matrix.c ec_board.c ec_switch_matrix.c OPT = 3 diff --git a/keyboards/cipulot/rf_r1_8_9xu/config.h b/keyboards/cipulot/rf_r1_8_9xu/config.h index cd98ff7f3d..91e3a459c3 100644 --- a/keyboards/cipulot/rf_r1_8_9xu/config.h +++ b/keyboards/cipulot/rf_r1_8_9xu/config.h @@ -19,6 +19,8 @@ #define MATRIX_ROWS 6 #define MATRIX_COLS 16 +#define UNUSED_POSITIONS_LIST { {5, 3}, {5, 5} } + #define MATRIX_ROW_PINS \ { B15, A8, B13, B12, B14, B0 } diff --git a/keyboards/cipulot/rf_r1_8_9xu/post_rules.mk b/keyboards/cipulot/rf_r1_8_9xu/post_rules.mk index d726a112a8..5dba48cc5f 100644 --- a/keyboards/cipulot/rf_r1_8_9xu/post_rules.mk +++ b/keyboards/cipulot/rf_r1_8_9xu/post_rules.mk @@ -1,3 +1 @@ -ifeq ($(strip $(VIA_ENABLE)), yes) - SRC += keyboards/cipulot/common/via_ec.c -endif +include keyboards/cipulot/common/common_cipulot.mk diff --git a/keyboards/cipulot/rf_r1_8_9xu/rules.mk b/keyboards/cipulot/rf_r1_8_9xu/rules.mk index 318e0215ce..3aa0e2bf06 100644 --- a/keyboards/cipulot/rf_r1_8_9xu/rules.mk +++ b/keyboards/cipulot/rf_r1_8_9xu/rules.mk @@ -1,5 +1 @@ -CUSTOM_MATRIX = lite -ANALOG_DRIVER_REQUIRED = yes -VPATH += keyboards/cipulot/common -SRC += matrix.c ec_board.c ec_switch_matrix.c OPT = 2 |