mirror of
https://github.com/qmk/qmk_firmware.git
synced 2025-07-22 07:32:02 +00:00
fully functional. Changed every '400' to '255' for coherency.
This commit is contained in:
parent
6325c8e568
commit
162a64c2be
@ -35,7 +35,7 @@ typedef struct {
|
|||||||
uint16_t extremum;
|
uint16_t extremum;
|
||||||
int16_t offset;
|
int16_t offset;
|
||||||
bool is_analog;
|
bool is_analog;
|
||||||
bool dynamic_actuation_bool;
|
bool continuous_dynamic_actuation;
|
||||||
// uint16_t SMA_buffer[1<<(SMA_FILTER_SAMPLE_EXPONENT)];
|
// uint16_t SMA_buffer[1<<(SMA_FILTER_SAMPLE_EXPONENT)];
|
||||||
uint8_t SMA_samplesExponent;
|
uint8_t SMA_samplesExponent;
|
||||||
uint8_t SMA_samples;
|
uint8_t SMA_samples;
|
||||||
|
@ -13,17 +13,17 @@ SPDX-License-Identifier: GPL-2.0-or-later */
|
|||||||
# define MAX(x, y) (((x) > (y)) ? (x) : (y))
|
# define MAX(x, y) (((x) > (y)) ? (x) : (y))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// /* Equation parameters for the sensor-magnet linearity mapping */
|
|
||||||
// const double lut_a = 0.200347177016;
|
|
||||||
// const double lut_b = 0.00955994866154;
|
|
||||||
// const double lut_c = 6.01110636956;
|
|
||||||
// const double lut_d = 1966.74076381;
|
|
||||||
|
|
||||||
/* Equation parameters for the sensor-magnet linearity mapping */
|
// /* Equation parameters for the sensor-magnet linearity mapping */
|
||||||
const double lut_a = -366.805673399;
|
// const double lut_a = -366.805673399;
|
||||||
const double lut_b = 0.00617870508512;
|
// const double lut_b = 0.00617870508512;
|
||||||
const double lut_c = -1.49468890703;
|
// const double lut_c = -1.49468890703;
|
||||||
const double lut_d = 2094.38794157;
|
// const double lut_d = 2094.38794157;
|
||||||
|
|
||||||
|
const double lut_a = -0.203212;
|
||||||
|
const double lut_b = 0.00955995;
|
||||||
|
const double lut_c = 5.99691;
|
||||||
|
const double lut_d = 2122.25924;
|
||||||
|
|
||||||
uint16_t distance_to_adc(uint16_t distance) {
|
uint16_t distance_to_adc(uint16_t distance) {
|
||||||
double intermediate = lut_a * exp(lut_b * distance + lut_c) + lut_d;
|
double intermediate = lut_a * exp(lut_b * distance + lut_c) + lut_d;
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
#include "debounce.h"
|
#include "debounce.h"
|
||||||
#include "scanfunctions.h"
|
#include "scanfunctions.h"
|
||||||
#include "sma.c"
|
#include "sma.c"
|
||||||
|
#include "quantum/matrix.h"
|
||||||
|
|
||||||
|
|
||||||
#ifndef MATRIX_INPUT_PRESSED_STATE
|
#ifndef MATRIX_INPUT_PRESSED_STATE
|
||||||
# define MATRIX_INPUT_PRESSED_STATE 0
|
# define MATRIX_INPUT_PRESSED_STATE 0
|
||||||
@ -27,6 +29,30 @@ static uint16_t restAdcValue = 0;
|
|||||||
matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values
|
matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values
|
||||||
matrix_row_t matrix[MATRIX_ROWS]; // debounced values
|
matrix_row_t matrix[MATRIX_ROWS]; // debounced values
|
||||||
|
|
||||||
|
static inline uint8_t readMatrixPin(pin_t pin) {
|
||||||
|
if (pin != NO_PIN) {
|
||||||
|
return (gpio_read_pin(pin) == MATRIX_INPUT_PRESSED_STATE) ? 0 : 1;
|
||||||
|
} else {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void matrix_read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) {
|
||||||
|
// Start with a clear matrix row
|
||||||
|
matrix_row_t current_row_value = 0;
|
||||||
|
|
||||||
|
matrix_row_t row_shifter = MATRIX_ROW_SHIFTER;
|
||||||
|
for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++, row_shifter <<= 1) {
|
||||||
|
pin_t pin = matrix_pins[current_row][col_index];
|
||||||
|
current_row_value |= readMatrixPin(pin) ? 0 : row_shifter;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the matrix
|
||||||
|
current_matrix[current_row] = current_row_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Setup only rows 1, leave row 0 untouched (for analog)
|
// Setup only rows 1, leave row 0 untouched (for analog)
|
||||||
void matrix_init_pins(void) {
|
void matrix_init_pins(void) {
|
||||||
for (int row = 0; row < MATRIX_ROWS; row++) {
|
for (int row = 0; row < MATRIX_ROWS; row++) {
|
||||||
@ -56,10 +82,6 @@ void matrix_init_custom(void) {
|
|||||||
get_sensor_offsets();
|
get_sensor_offsets();
|
||||||
}
|
}
|
||||||
|
|
||||||
// User-defined overridable functions
|
|
||||||
__attribute__((weak)) void matrix_init_pins(void);
|
|
||||||
__attribute__((weak)) void matrix_read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row);
|
|
||||||
__attribute__((weak)) void matrix_read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col, matrix_row_t row_shifter);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -70,7 +92,7 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) {
|
|||||||
memcpy(previous_matrix, current_matrix, sizeof(previous_matrix));
|
memcpy(previous_matrix, current_matrix, sizeof(previous_matrix));
|
||||||
|
|
||||||
for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) {
|
for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) {
|
||||||
if (!keys[current_row][0].is_analog) {
|
if (current_row == 1) {
|
||||||
matrix_read_cols_on_row(current_matrix, current_row);
|
matrix_read_cols_on_row(current_matrix, current_row);
|
||||||
} else {
|
} else {
|
||||||
for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) {
|
for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) {
|
||||||
@ -105,9 +127,4 @@ uint8_t matrix_scan(void) {
|
|||||||
return (uint8_t)changed;
|
return (uint8_t)changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((weak)) void matrix_init_kb(void) { matrix_init_user(); }
|
|
||||||
__attribute__((weak)) void matrix_scan_kb(void) { matrix_scan_user(); }
|
|
||||||
__attribute__((weak)) void matrix_init_user(void) {}
|
|
||||||
__attribute__((weak)) void matrix_scan_user(void) {}
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ matrix scanning:
|
|||||||
4. if a new peak is observed, update it in the key structure
|
4. if a new peak is observed, update it in the key structure
|
||||||
peak here is a up or down, since keeping track of both doesn't make sense
|
peak here is a up or down, since keeping track of both doesn't make sense
|
||||||
|
|
||||||
|
https://www.desmos.com/calculator/qtbbjbsyvi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -35,12 +35,12 @@ void deregister_key(matrix_row_t *current_row, uint8_t current_col) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void matrix_read_cols_static_actuation(matrix_row_t *current_row, uint8_t current_col, hybrid_key_t *key) {
|
void matrix_read_cols_static_actuation(matrix_row_t *current_row, uint8_t current_col, hybrid_key_t *key) {
|
||||||
if (*current_row & (1 << current_col)) { //if the key is currently pressed
|
if (*current_row & (1 << current_col)) {
|
||||||
if (key->value < MAX(g_config.actuation_point - g_config.release_hysteresis, 0)) {
|
if (key->value <= MAX(g_config.actuation_point - g_config.release_hysteresis, 0)) {
|
||||||
deregister_key(current_row, current_col);
|
deregister_key(current_row, current_col);
|
||||||
}
|
}
|
||||||
} else { //if the key is currently not pressed
|
} else {
|
||||||
if (key->value > MIN(g_config.actuation_point + g_config.press_hysteresis, 255)) {
|
if (key->value >= MIN(g_config.actuation_point + g_config.press_hysteresis, CALIBRATION_RANGE)) {
|
||||||
register_key(current_row, current_col);
|
register_key(current_row, current_col);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -53,13 +53,14 @@ if the key is pressed, the extremum is the lowest value reached,
|
|||||||
if the key is not pressed, the extremum is the highest value reached. */
|
if the key is not pressed, the extremum is the highest value reached. */
|
||||||
|
|
||||||
void matrix_read_cols_dynamic_actuation(matrix_row_t *current_row, uint8_t current_col, hybrid_key_t *key) {
|
void matrix_read_cols_dynamic_actuation(matrix_row_t *current_row, uint8_t current_col, hybrid_key_t *key) {
|
||||||
if (key->dynamic_actuation_bool) {
|
if (key->value > g_config.actuation_point) {
|
||||||
|
/* In DA zone? */
|
||||||
if (*current_row & (1 << current_col)) {
|
if (*current_row & (1 << current_col)) {
|
||||||
/* Key is pressed
|
/* Key is pressed
|
||||||
Is key still moving down? */
|
Is key still moving down? */
|
||||||
if (key->value > key->extremum) {
|
if (key->value > key->extremum) {
|
||||||
update_extremum(key);
|
update_extremum(key);
|
||||||
} else if (key->value < key->extremum - g_config.release_sensitivity) {
|
} else if (key->value <= MAX(key->extremum - g_config.release_sensitivity, 0)) {
|
||||||
/* Has key moved up enough to be released? */
|
/* Has key moved up enough to be released? */
|
||||||
deregister_key(current_row, current_col);
|
deregister_key(current_row, current_col);
|
||||||
update_extremum(key);
|
update_extremum(key);
|
||||||
@ -69,32 +70,31 @@ void matrix_read_cols_dynamic_actuation(matrix_row_t *current_row, uint8_t curre
|
|||||||
Is the key still moving up? */
|
Is the key still moving up? */
|
||||||
if (key->value < key->extremum) {
|
if (key->value < key->extremum) {
|
||||||
update_extremum(key);
|
update_extremum(key);
|
||||||
} else if (key->value > key->extremum + g_config.press_sensitivity) {
|
} else if (key->value >= MIN(key->extremum + g_config.press_sensitivity, CALIBRATION_RANGE)) {
|
||||||
/* Has key moved down enough to be pressed? */
|
/* Has key moved down enough to be pressed? */
|
||||||
register_key(current_row, current_col);
|
register_key(current_row, current_col);
|
||||||
update_extremum(key);
|
update_extremum(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (key->value < g_config.actuation_point - 5) {
|
} else {
|
||||||
|
/* Out of DA zone
|
||||||
|
Always deregister key */
|
||||||
deregister_key(current_row, current_col);
|
deregister_key(current_row, current_col);
|
||||||
|
if (key->value > key->extremum) {
|
||||||
update_extremum(key);
|
update_extremum(key);
|
||||||
key->dynamic_actuation_bool = false;
|
|
||||||
}
|
}
|
||||||
} else if (key->value > g_config.actuation_point) {
|
|
||||||
register_key(current_row, current_col);
|
|
||||||
update_extremum(key);
|
|
||||||
key->dynamic_actuation_bool = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void matrix_read_cols_continuous_dynamic_actuation(matrix_row_t *current_row, uint8_t current_col, hybrid_key_t *key) {
|
void matrix_read_cols_continuous_dynamic_actuation(matrix_row_t *current_row, uint8_t current_col, hybrid_key_t *key) {
|
||||||
if (key->dynamic_actuation_bool) {
|
if (key->continuous_dynamic_actuation) {
|
||||||
if (*current_row & (1 << current_col)) {
|
if (*current_row & (1 << current_col)) {
|
||||||
/* Key is pressed
|
/* Key is pressed
|
||||||
Is key still moving down? */
|
Is key still moving down? */
|
||||||
if (key->value > key->extremum) {
|
if (key->value > key->extremum) {
|
||||||
update_extremum(key);
|
update_extremum(key);
|
||||||
} else if (key->value < key->extremum - g_config.release_sensitivity) {
|
|
||||||
|
} else if (key->value <= MAX(key->extremum - g_config.release_sensitivity, 0)) {
|
||||||
/* Has key moved up enough to be released? */
|
/* Has key moved up enough to be released? */
|
||||||
deregister_key(current_row, current_col);
|
deregister_key(current_row, current_col);
|
||||||
update_extremum(key);
|
update_extremum(key);
|
||||||
@ -104,7 +104,7 @@ void matrix_read_cols_continuous_dynamic_actuation(matrix_row_t *current_row, ui
|
|||||||
Is the key still moving up? */
|
Is the key still moving up? */
|
||||||
if (key->value < key->extremum) {
|
if (key->value < key->extremum) {
|
||||||
update_extremum(key);
|
update_extremum(key);
|
||||||
} else if (key->value > key->extremum + g_config.press_sensitivity) {
|
} else if (key->value >= MIN(key->extremum + g_config.press_sensitivity, CALIBRATION_RANGE)) {
|
||||||
/* Has key moved down enough to be pressed? */
|
/* Has key moved down enough to be pressed? */
|
||||||
register_key(current_row, current_col);
|
register_key(current_row, current_col);
|
||||||
update_extremum(key);
|
update_extremum(key);
|
||||||
@ -113,11 +113,11 @@ void matrix_read_cols_continuous_dynamic_actuation(matrix_row_t *current_row, ui
|
|||||||
if (key->value == 0) {
|
if (key->value == 0) {
|
||||||
deregister_key(current_row, current_col);
|
deregister_key(current_row, current_col);
|
||||||
update_extremum(key);
|
update_extremum(key);
|
||||||
key->dynamic_actuation_bool = false;
|
key->continuous_dynamic_actuation = false;
|
||||||
}
|
}
|
||||||
} else if (key->value > g_config.actuation_point) {
|
} else if (key->value > g_config.actuation_point) {
|
||||||
register_key(current_row, current_col);
|
register_key(current_row, current_col);
|
||||||
update_extremum(key);
|
update_extremum(key);
|
||||||
key->dynamic_actuation_bool = true;
|
key->continuous_dynamic_actuation = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,12 +53,12 @@ bool debug_print(void) {
|
|||||||
|
|
||||||
// uprintf("%s", buffer);
|
// uprintf("%s", buffer);
|
||||||
|
|
||||||
int raw_analog_value[3];
|
// int raw_analog_value[3];
|
||||||
for (uint8_t col = 0; col < MATRIX_COLS; col++) {
|
// for (uint8_t col = 0; col < MATRIX_COLS; col++) {
|
||||||
|
|
||||||
raw_analog_value[col] = analogReadPin(matrix_pins[0][col]);
|
// raw_analog_value[col] = analogReadPin(matrix_pins[0][col]);
|
||||||
}
|
// }
|
||||||
printf("raw_analog_value = %d, %d, %d\n", raw_analog_value[0], raw_analog_value[1], raw_analog_value[2]);
|
// printf("raw_analog_value = %d, %d, %d\n", raw_analog_value[0], raw_analog_value[1], raw_analog_value[2]);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user