mirror of
https://github.com/qmk/qmk_firmware
synced 2025-01-03 05:30:18 +00:00
Cipulot Updates (#24539)
This commit is contained in:
@ -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
|
@ -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();
|
||||
}
|
||||
|
@ -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++) {
|
||||
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;
|
||||
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);
|
||||
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;
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
@ -261,6 +290,8 @@ void ec_save_threshold_data(uint8_t option) {
|
||||
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
|
||||
|
@ -1,3 +1 @@
|
||||
ifeq ($(strip $(VIA_ENABLE)), yes)
|
||||
SRC += keyboards/cipulot/common/via_ec.c
|
||||
endif
|
||||
include keyboards/cipulot/common/common_cipulot.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
|
||||
|
@ -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 }
|
||||
|
||||
|
@ -1,3 +1 @@
|
||||
ifeq ($(strip $(VIA_ENABLE)), yes)
|
||||
SRC += keyboards/cipulot/common/via_ec.c
|
||||
endif
|
||||
include keyboards/cipulot/common/common_cipulot.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
|
||||
|
@ -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}
|
||||
|
||||
|
@ -1,3 +1 @@
|
||||
ifeq ($(strip $(VIA_ENABLE)), yes)
|
||||
SRC += keyboards/cipulot/common/via_ec.c
|
||||
endif
|
||||
include keyboards/cipulot/common/common_cipulot.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
|
||||
|
@ -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 }
|
||||
|
||||
|
@ -1,3 +1 @@
|
||||
ifeq ($(strip $(VIA_ENABLE)), yes)
|
||||
SRC += keyboards/cipulot/common/via_ec.c
|
||||
endif
|
||||
include keyboards/cipulot/common/common_cipulot.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
|
||||
|
@ -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 }
|
||||
|
||||
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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++) {
|
||||
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;
|
||||
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);
|
||||
sw_value[row][adjusted_col] = ec_readkey_raw(amux, row, col);
|
||||
|
||||
if (ec_config.bottoming_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;
|
||||
|
@ -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
|
||||
|
@ -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 }
|
||||
|
||||
|
@ -1,3 +1 @@
|
||||
ifeq ($(strip $(VIA_ENABLE)), yes)
|
||||
SRC += keyboards/cipulot/common/via_ec.c
|
||||
endif
|
||||
include keyboards/cipulot/common/common_cipulot.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
|
||||
|
@ -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 }
|
||||
|
||||
|
@ -1,3 +1 @@
|
||||
ifeq ($(strip $(VIA_ENABLE)), yes)
|
||||
SRC += keyboards/cipulot/common/via_ec.c
|
||||
endif
|
||||
include keyboards/cipulot/common/common_cipulot.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
|
||||
|
@ -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 }
|
||||
|
||||
|
@ -1,3 +1 @@
|
||||
ifeq ($(strip $(VIA_ENABLE)), yes)
|
||||
SRC += keyboards/cipulot/common/via_ec.c
|
||||
endif
|
||||
include keyboards/cipulot/common/common_cipulot.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
|
||||
|
@ -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 }
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user