From e7629ab63e6504d937d52cceb557085de3fceb8e Mon Sep 17 00:00:00 2001 From: peepeetee Date: Wed, 11 Oct 2023 22:03:54 -0500 Subject: [PATCH 01/43] initial commit of cobbled together code, mainly working but still tuning the switches --- keyboards/momokai/tap_trio_pro/analogkeys.h | 26 +++ keyboards/momokai/tap_trio_pro/config.h | 99 ++++++++++ keyboards/momokai/tap_trio_pro/halconf.h | 8 + keyboards/momokai/tap_trio_pro/info.json | 74 ++++++++ .../tap_trio_pro/keymaps/default/keymap.c | 19 ++ .../tap_trio_pro/keymaps/default/rules.mk | 1 + .../momokai/tap_trio_pro/keymaps/via/keymap.c | 18 ++ .../momokai/tap_trio_pro/keymaps/via/rules.mk | 4 + keyboards/momokai/tap_trio_pro/lut.c | 28 +++ keyboards/momokai/tap_trio_pro/lut.h | 12 ++ keyboards/momokai/tap_trio_pro/matrix.c | 120 ++++++++++++ keyboards/momokai/tap_trio_pro/readme.md | 27 +++ keyboards/momokai/tap_trio_pro/rules.mk | 6 + .../momokai/tap_trio_pro/scanfunctions.c | 115 ++++++++++++ .../momokai/tap_trio_pro/scanfunctions.h | 21 +++ keyboards/momokai/tap_trio_pro/tap_trio_pro.c | 175 ++++++++++++++++++ keyboards/momokai/tap_trio_pro/tap_trio_pro.h | 9 + 17 files changed, 762 insertions(+) create mode 100644 keyboards/momokai/tap_trio_pro/analogkeys.h create mode 100644 keyboards/momokai/tap_trio_pro/config.h create mode 100644 keyboards/momokai/tap_trio_pro/halconf.h create mode 100644 keyboards/momokai/tap_trio_pro/info.json create mode 100644 keyboards/momokai/tap_trio_pro/keymaps/default/keymap.c create mode 100644 keyboards/momokai/tap_trio_pro/keymaps/default/rules.mk create mode 100644 keyboards/momokai/tap_trio_pro/keymaps/via/keymap.c create mode 100644 keyboards/momokai/tap_trio_pro/keymaps/via/rules.mk create mode 100644 keyboards/momokai/tap_trio_pro/lut.c create mode 100644 keyboards/momokai/tap_trio_pro/lut.h create mode 100644 keyboards/momokai/tap_trio_pro/matrix.c create mode 100644 keyboards/momokai/tap_trio_pro/readme.md create mode 100644 keyboards/momokai/tap_trio_pro/rules.mk create mode 100644 keyboards/momokai/tap_trio_pro/scanfunctions.c create mode 100644 keyboards/momokai/tap_trio_pro/scanfunctions.h create mode 100644 keyboards/momokai/tap_trio_pro/tap_trio_pro.c create mode 100644 keyboards/momokai/tap_trio_pro/tap_trio_pro.h diff --git a/keyboards/momokai/tap_trio_pro/analogkeys.h b/keyboards/momokai/tap_trio_pro/analogkeys.h new file mode 100644 index 00000000000..35a54150f0c --- /dev/null +++ b/keyboards/momokai/tap_trio_pro/analogkeys.h @@ -0,0 +1,26 @@ +/* Copyright 2023 RephlexZero (@RephlexZero) +SPDX-License-Identifier: GPL-2.0-or-later */ +#include + +enum analog_key_modes { dynamic_actuation = 0, continuous_dynamic_actuation, static_actuation, flashing }; + +/* global struct to save keypress logic params */ +typedef struct { + uint8_t mode; + uint8_t actuation_point; + uint8_t press_sensitivity; + uint8_t release_sensitivity; + uint8_t press_hysteresis; + uint8_t release_hysteresis; +} analog_config; /* 6 bytes */ +_Static_assert(sizeof(analog_config) == EECONFIG_KB_DATA_SIZE, "Size mismatch"); +extern analog_config g_config; + +typedef struct { + /* For individual analog key data */ + uint8_t value; + uint8_t extremum; + int16_t offset; + bool dynamic_actuation_bool; +} key_t; +extern key_t keys[MATRIX_ROWS][MATRIX_COLS]; diff --git a/keyboards/momokai/tap_trio_pro/config.h b/keyboards/momokai/tap_trio_pro/config.h new file mode 100644 index 00000000000..d73e8158477 --- /dev/null +++ b/keyboards/momokai/tap_trio_pro/config.h @@ -0,0 +1,99 @@ +// Copyright 2023 peepeetee (@peepeetee) RephlexZero (@RephlexZero) +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + + +#define DEBOUNCE 0 + +#define DYNAMIC_KEYMAP_LAYER_COUNT 1 + +#define EECONFIG_KB_DATA_SIZE 6 + +//#define DEBUG_ENABLE +#define DEBUG_MATRIX_SCAN_RATE + +#define ADC_RESOLUTION 12 + +#define CALIBRATION_RANGE 255 + + + + + + +/* + * Feature disable options + * These options are also useful to firmware size reduction. + */ + +/* disable debug print */ +//#define NO_DEBUG + +/* disable print */ +//#define NO_PRINT + +/* disable action features */ +//#define NO_ACTION_LAYER +//#define NO_ACTION_TAPPING +//#define NO_ACTION_ONESHOT + +#ifdef RGB_MATRIX_ENABLE +#define RGB_MATRIX_LED_COUNT 3 +#define RGB_MATRIX_KEYPRESSES // reacts to keypresses +#define RGB_MATRIX_FRAMEBUFFER_EFFECTS +#define RGB_DISABLE_WHEN_USB_SUSPENDED // turn off effects when suspended +#define RGB_MATRIX_MAXIMUM_BRIGHTNESS 200 + // RGB Matrix Animation modes. Explicitly enabled + // For full list of effects, see: + // https://docs.qmk.fm/#/feature_rgb_matrix?id=rgb-matrix-effects + #define ENABLE_RGB_MATRIX_SOLID_COLOR + #define ENABLE_RGB_MATRIX_ALPHAS_MODS + #define ENABLE_RGB_MATRIX_GRADIENT_UP_DOWN + #define ENABLE_RGB_MATRIX_GRADIENT_LEFT_RIGHT + #define ENABLE_RGB_MATRIX_BREATHING + #define ENABLE_RGB_MATRIX_BAND_SAT + #define ENABLE_RGB_MATRIX_BAND_VAL + #define ENABLE_RGB_MATRIX_BAND_PINWHEEL_SAT + #define ENABLE_RGB_MATRIX_BAND_PINWHEEL_VAL + #define ENABLE_RGB_MATRIX_BAND_SPIRAL_SAT + #define ENABLE_RGB_MATRIX_BAND_SPIRAL_VAL + #define ENABLE_RGB_MATRIX_CYCLE_ALL + #define ENABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT + #define ENABLE_RGB_MATRIX_CYCLE_UP_DOWN + #define ENABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON + #define ENABLE_RGB_MATRIX_CYCLE_OUT_IN + #define ENABLE_RGB_MATRIX_CYCLE_OUT_IN_DUAL + #define ENABLE_RGB_MATRIX_CYCLE_PINWHEEL + #define ENABLE_RGB_MATRIX_CYCLE_SPIRAL + #define ENABLE_RGB_MATRIX_DUAL_BEACON + #define ENABLE_RGB_MATRIX_RAINBOW_BEACON + #define ENABLE_RGB_MATRIX_RAINBOW_PINWHEELS + #define ENABLE_RGB_MATRIX_RAINDROPS + #define ENABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS + #define ENABLE_RGB_MATRIX_HUE_BREATHING + #define ENABLE_RGB_MATRIX_HUE_PENDULUM + #define ENABLE_RGB_MATRIX_HUE_WAVE + #define ENABLE_RGB_MATRIX_PIXEL_RAIN + #define ENABLE_RGB_MATRIX_PIXEL_FLOW + #define ENABLE_RGB_MATRIX_PIXEL_FRACTAL + + // enabled only if RGB_MATRIX_FRAMEBUFFER_EFFECTS is defined + #define ENABLE_RGB_MATRIX_TYPING_HEATMAP + // #define ENABLE_RGB_MATRIX_DIGITAL_RAIN + + // enabled only of RGB_MATRIX_KEYPRESSES or RGB_MATRIX_KEYRELEASES is defined + #define ENABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE + #define ENABLE_RGB_MATRIX_SOLID_REACTIVE + #define ENABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE + #define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE + #define ENABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS + #define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS + #define ENABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS + #define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS + #define ENABLE_RGB_MATRIX_SPLASH + #define ENABLE_RGB_MATRIX_MULTISPLASH + #define ENABLE_RGB_MATRIX_SOLID_SPLASH + #define ENABLE_RGB_MATRIX_SOLID_MULTISPLASH +#endif + diff --git a/keyboards/momokai/tap_trio_pro/halconf.h b/keyboards/momokai/tap_trio_pro/halconf.h new file mode 100644 index 00000000000..b93f31a1c46 --- /dev/null +++ b/keyboards/momokai/tap_trio_pro/halconf.h @@ -0,0 +1,8 @@ +/* Copyright 2023 peepeetee (@peepeetee) +SPDX-License-Identifier: GPL-2.0-or-later */ +#pragma once + +#undef HAL_USE_ADC +#define HAL_USE_ADC TRUE + +#include_next diff --git a/keyboards/momokai/tap_trio_pro/info.json b/keyboards/momokai/tap_trio_pro/info.json new file mode 100644 index 00000000000..ff512592314 --- /dev/null +++ b/keyboards/momokai/tap_trio_pro/info.json @@ -0,0 +1,74 @@ +{ + "manufacturer": "momokai", + "keyboard_name": "hall_effect", + "maintainer": "peepeetee", + "bootloader": "rp2040", + "features": { + "bootmagic": false, + "command": false, + "console": false, + "extrakey": true, + "mousekey": true, + "rgb_matrix": true, + "nkro": true, + "deferred_exec": true + }, + "bootmagic": { + "matrix": [2, 0] + }, + "build": { + "lto": true + }, + "matrix_pins": { + "direct":[ + ["NO_PIN", "GP0", "NO_PIN" ], + ["GP28", "GP27", "GP26" ], + ["GP10", "GP9", "GP8" ] + ] + }, + "processor": "RP2040", + "url": "", + "usb": { + "device_version": "1.0.0", + "pid": "0x0016", + "vid": "0x69F9" + }, + "encoder": { + "enabled": true, + "rotary": [ + { + "pin_a": "GP1", + "pin_b": "GP2" + } + ] + }, + "ws2812": { + "pin": "GP29", + "driver": "vendor" + }, + "rgb_matrix": { + + "driver": "ws2812", + "layout": [ + {"flags": 4, "matrix": [1, 0], "x": 0, "y": 0}, + {"flags": 4, "matrix": [1, 1], "x": 0, "y": 32}, + {"flags": 4, "matrix": [1, 2], "x": 0, "y": 64} + ] + + }, + "layouts": { + "LAYOUT": { + "layout": [ + {"matrix": [0, 1], "x": 1, "y": 0}, + + {"matrix": [1, 0], "x": 0, "y": 1}, + {"matrix": [1, 1], "x": 1, "y": 1}, + {"matrix": [1, 2], "x": 2, "y": 1}, + + {"matrix": [2, 0], "x": 0.5, "y": 2.25, "w": 0.5, "h": 0.5}, + {"matrix": [2, 1], "x": 1, "y": 2.25, "w": 0.5, "h": 0.5}, + {"matrix": [2, 2], "x": 1.5, "y": 2.25, "w": 0.5, "h": 0.5} + ] + } + } +} diff --git a/keyboards/momokai/tap_trio_pro/keymaps/default/keymap.c b/keyboards/momokai/tap_trio_pro/keymaps/default/keymap.c new file mode 100644 index 00000000000..e58069e5ae9 --- /dev/null +++ b/keyboards/momokai/tap_trio_pro/keymaps/default/keymap.c @@ -0,0 +1,19 @@ +// Copyright 2023 peepeetee +// SPDX-License-Identifier: GPL-2.0-or-later + +#include QMK_KEYBOARD_H + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [0] = LAYOUT( + KC_MUTE, + KC_Z, KC_X, KC_C, + KC_GRV, KC_ESC, KC_F2 + ) +}; + +#if defined(ENCODER_MAP_ENABLE) +const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = { + [0] = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU) } + +}; +#endif diff --git a/keyboards/momokai/tap_trio_pro/keymaps/default/rules.mk b/keyboards/momokai/tap_trio_pro/keymaps/default/rules.mk new file mode 100644 index 00000000000..ee325681483 --- /dev/null +++ b/keyboards/momokai/tap_trio_pro/keymaps/default/rules.mk @@ -0,0 +1 @@ +ENCODER_MAP_ENABLE = yes diff --git a/keyboards/momokai/tap_trio_pro/keymaps/via/keymap.c b/keyboards/momokai/tap_trio_pro/keymaps/via/keymap.c new file mode 100644 index 00000000000..c83cbad8efe --- /dev/null +++ b/keyboards/momokai/tap_trio_pro/keymaps/via/keymap.c @@ -0,0 +1,18 @@ +// Copyright 2023 peepeetee +// SPDX-License-Identifier: GPL-2.0-or-later + +#include QMK_KEYBOARD_H + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [0] = LAYOUT( + KC_MUTE, + KC_Z, KC_X, KC_C, + KC_GRV, KC_ESC, KC_F2 + ), +}; + +#if defined(ENCODER_MAP_ENABLE) +const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = { + [0] = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU) }, +}; +#endif diff --git a/keyboards/momokai/tap_trio_pro/keymaps/via/rules.mk b/keyboards/momokai/tap_trio_pro/keymaps/via/rules.mk new file mode 100644 index 00000000000..293c5ffdeb9 --- /dev/null +++ b/keyboards/momokai/tap_trio_pro/keymaps/via/rules.mk @@ -0,0 +1,4 @@ +VIA_ENABLE = yes +LTO_ENABLE = yes + +ENCODER_MAP_ENABLE = yes diff --git a/keyboards/momokai/tap_trio_pro/lut.c b/keyboards/momokai/tap_trio_pro/lut.c new file mode 100644 index 00000000000..0f87156ac91 --- /dev/null +++ b/keyboards/momokai/tap_trio_pro/lut.c @@ -0,0 +1,28 @@ +/* Copyright 2023 RephlexZero (@RephlexZero) +SPDX-License-Identifier: GPL-2.0-or-later */ +#include +#include "scanfunctions.h" +#include "util.h" + +/* Equation parameters for the sensor-magnet linearity mapping */ +const double a = 16654600.6755; +const double b = -0.00955994866577; +const double c = -1278.75103145; +const double d = 16652478.4163; + +uint16_t distance_to_adc(uint8_t distance) { + distance = MIN(MAX(distance, 0), 255); + return a * (1 - exp(-b * (distance + c))) - d; +} + +uint8_t adc_to_distance(uint16_t adc) { + return MIN(MAX(((log(1 - ((adc + d) / a)) / -b) - c), 0), 255); +} + +uint8_t lut[4096] = {0}; + +void generate_lut(void) { + for (uint16_t i = 0; i < a - d; i++) { + lut[i] = adc_to_distance(i); + } +} \ No newline at end of file diff --git a/keyboards/momokai/tap_trio_pro/lut.h b/keyboards/momokai/tap_trio_pro/lut.h new file mode 100644 index 00000000000..0ec9aa5454f --- /dev/null +++ b/keyboards/momokai/tap_trio_pro/lut.h @@ -0,0 +1,12 @@ +/* Copyright 2023 RephlexZero (@RephlexZero) +SPDX-License-Identifier: GPL-2.0-or-later */ +#pragma once +#include + +extern uint8_t lut[4096]; + +uint16_t distance_to_adc(uint8_t distance); + +uint8_t adc_to_distance(uint16_t adc); + +void generate_lut(void); diff --git a/keyboards/momokai/tap_trio_pro/matrix.c b/keyboards/momokai/tap_trio_pro/matrix.c new file mode 100644 index 00000000000..f988556bbff --- /dev/null +++ b/keyboards/momokai/tap_trio_pro/matrix.c @@ -0,0 +1,120 @@ +/* Copyright 2023 RephlexZero (@RephlexZero) peepeetee (@peepeetee) +SPDX-License-Identifier: GPL-2.0-or-later */ +#include +#include +#include +#include +#include "print.h" +#include "quantum.h" +#include "analog.h" +#include "lut.h" +#include "scanfunctions.h" + +pin_t matrix_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; + +key_t keys[MATRIX_ROWS][MATRIX_COLS] = {0}; + + +# define ROWS_PER_HAND (MATRIX_ROWS) + +extern matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values +extern matrix_row_t matrix[MATRIX_ROWS]; // debounced values + + +void matrix_init_pins(void) { + //default implementation for rows 0 and 2 only + for (int row = 0; row < ROWS_PER_HAND || row != 1; row++) { + for (int col = 0; col < MATRIX_COLS; col++) { + pin_t pin = matrix_pins[row][col]; + if (pin != NO_PIN) { + setPinInputHigh(pin); + } + } + } +} + +void matrix_init_custom(void) { + generate_lut(); + get_sensor_offsets(); + wait_ms(100); // Let ADC reach steady state + get_sensor_offsets(); + + + + + //default implementation for rows 0 and 2 + matrix_init_pins(); + + // initialize matrix state: all keys off + memset(matrix, 0, sizeof(matrix)); + memset(raw_matrix, 0, sizeof(raw_matrix)); + + // debounce_init(ROWS_PER_HAND); + + // matrix_init_kb(); +} + +matrix_row_t previous_matrix[MATRIX_ROWS]; + +#ifndef MATRIX_INPUT_PRESSED_STATE +# define MATRIX_INPUT_PRESSED_STATE 0 +#endif + +static inline uint8_t readMatrixPin(pin_t pin) { + if (pin != NO_PIN) { + return (readPin(pin) == MATRIX_INPUT_PRESSED_STATE) ? 0 : 1; + } else { + return 1; + } +} + +bool matrix_scan_custom(matrix_row_t current_matrix[]) { + memcpy(previous_matrix, current_matrix, sizeof(previous_matrix)); + + for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { + if (current_row != 1) { + //default implementation for rows 0 and 2 + for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { + // 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 = direct_pins[current_row][col_index]; + 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; + } + } + if (current_row == 1) { + //use ADC for row 1 + for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { + key_t *key = &keys[current_row][current_col]; + key->value = lut[analogReadPin(matrix_pins[current_row][current_col]) + key->offset]; + key->value = MIN((key->value << 8) / lut[1100 + key->offset], 255); + + switch (g_config.mode) { + case dynamic_actuation: + matrix_read_cols_dynamic_actuation(¤t_matrix[current_row], current_col, key); + break; + case continuous_dynamic_actuation: + matrix_read_cols_continuous_dynamic_actuation(¤t_matrix[current_row], current_col, key); + break; + case static_actuation: + matrix_read_cols_static_actuation(¤t_matrix[current_row], current_col, key); + break; + case flashing: + default: + bootloader_jump(); + break; + } + } + } + + } + return memcmp(previous_matrix, current_matrix, sizeof(previous_matrix)) != 0; +} diff --git a/keyboards/momokai/tap_trio_pro/readme.md b/keyboards/momokai/tap_trio_pro/readme.md new file mode 100644 index 00000000000..2069f6826fa --- /dev/null +++ b/keyboards/momokai/tap_trio_pro/readme.md @@ -0,0 +1,27 @@ +# momokai/hall_effect + +![momokai/hall_effect](imgur.com image replace me!) + +*A short description of the keyboard/project* + +* Keyboard Maintainer: [peepeetee](https://github.com/peepeetee) +* Hardware Supported: *The PCBs, controllers supported* +* Hardware Availability: *Links to where you can find this hardware* + +Make example for this keyboard (after setting up your build environment): + + make momokai/hall_effect:default + +Flashing example for this keyboard: + + make momokai/hall_effect:default:flash + +See the [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) and the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. Brand new to QMK? Start with our [Complete Newbs Guide](https://docs.qmk.fm/#/newbs). + +## Bootloader + +Enter the bootloader in 3 ways: + +* **Bootmagic reset**: Hold down the key at (0,0) in the matrix (usually the top left key or Escape) and plug in the keyboard +* **Physical reset button**: Briefly press the button on the back of the PCB - some may have pads you must short instead +* **Keycode in layout**: Press the key mapped to `QK_BOOT` if it is available diff --git a/keyboards/momokai/tap_trio_pro/rules.mk b/keyboards/momokai/tap_trio_pro/rules.mk new file mode 100644 index 00000000000..074558d5561 --- /dev/null +++ b/keyboards/momokai/tap_trio_pro/rules.mk @@ -0,0 +1,6 @@ +QUANTUM_LIB_SRC += analog.c +SRC += matrix.c lut.c scanfunctions.c + +CUSTOM_MATRIX = lite + +OPT = 3 diff --git a/keyboards/momokai/tap_trio_pro/scanfunctions.c b/keyboards/momokai/tap_trio_pro/scanfunctions.c new file mode 100644 index 00000000000..552cdc3867a --- /dev/null +++ b/keyboards/momokai/tap_trio_pro/scanfunctions.c @@ -0,0 +1,115 @@ +/* Copyright 2023 RephlexZero (@RephlexZero) +SPDX-License-Identifier: GPL-2.0-or-later */ +#include "quantum.h" +#include "analog.h" +#include "scanfunctions.h" + +extern pin_t matrix_pins[MATRIX_ROWS][MATRIX_COLS]; +void get_sensor_offsets(void) { + uint16_t rest_adc_value = distance_to_adc(0); + for (uint8_t i = 0; i < MATRIX_ROWS; i++) { + for (uint8_t j = 0; j < MATRIX_COLS; j++) { + keys[i][j].offset = rest_adc_value - analogReadPin(matrix_pins[i][j]); + } + } +} + +void update_extremum(key_t *key) { + key->extremum = key->value; +} + +void register_key(matrix_row_t *current_row, uint8_t current_col) { + *current_row |= (1 << current_col); +} + +void deregister_key(matrix_row_t *current_row, uint8_t current_col) { + *current_row &= ~(1 << current_col); +} + +void matrix_read_cols_static_actuation(matrix_row_t *current_row, uint8_t current_col, key_t *key) { + if (*current_row & (1 << current_col)) { + if (key->value < MAX(g_config.actuation_point - g_config.release_hysteresis, 0)) { + deregister_key(current_row, current_col); + } + } else { + if (key->value > MIN(g_config.actuation_point + g_config.press_hysteresis, 255)) { + register_key(current_row, current_col); + } + } +} + +/* Extremum is the highest or lowest value of the key reached +this functionality changes based on whether the key is pressed or not, +assuming your sensor value decreases when the key is pressed, +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. */ + +void matrix_read_cols_dynamic_actuation(matrix_row_t *current_row, uint8_t current_col, key_t *key) { + if (key->dynamic_actuation_bool) { + if (*current_row & (1 << current_col)) { + /* Key is pressed + Is key still moving down? */ + if (key->value > key->extremum) { + update_extremum(key); + } else if (key->value < key->extremum - g_config.release_sensitivity) { + /* Has key moved up enough to be released? */ + deregister_key(current_row, current_col); + update_extremum(key); + } + } else { + /* Key is not pressed + Is the key still moving up? */ + if (key->value < key->extremum) { + update_extremum(key); + } else if (key->value > key->extremum + g_config.press_sensitivity) { + /* Has key moved down enough to be pressed? */ + register_key(current_row, current_col); + update_extremum(key); + } + } + if (key->value < g_config.actuation_point - 5) { + deregister_key(current_row, current_col); + 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, key_t *key) { + if (key->dynamic_actuation_bool) { + if (*current_row & (1 << current_col)) { + /* Key is pressed + Is key still moving down? */ + if (key->value > key->extremum) { + update_extremum(key); + } else if (key->value < key->extremum - g_config.release_sensitivity) { + /* Has key moved up enough to be released? */ + deregister_key(current_row, current_col); + update_extremum(key); + } + } else { + /* Key is not pressed + Is the key still moving up? */ + if (key->value < key->extremum) { + update_extremum(key); + } else if (key->value > key->extremum + g_config.press_sensitivity) { + /* Has key moved down enough to be pressed? */ + register_key(current_row, current_col); + update_extremum(key); + } + } + if (key->value == 0) { + deregister_key(current_row, current_col); + 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; + } +} \ No newline at end of file diff --git a/keyboards/momokai/tap_trio_pro/scanfunctions.h b/keyboards/momokai/tap_trio_pro/scanfunctions.h new file mode 100644 index 00000000000..71df75b83bb --- /dev/null +++ b/keyboards/momokai/tap_trio_pro/scanfunctions.h @@ -0,0 +1,21 @@ +/* Copyright 2023 RephlexZero (@RephlexZero) +SPDX-License-Identifier: GPL-2.0-or-later */ +#pragma once +#include "analogkeys.h" +#include +#include "quantum.h" +#include "lut.h" + +void update_extremum(key_t *key); + +void register_key(matrix_row_t *current_row, uint8_t current_col); + +void deregister_key(matrix_row_t *current_row, uint8_t current_col); + +void get_sensor_offsets(void); + +void matrix_read_cols_dynamic_actuation(matrix_row_t *current_row, uint8_t current_col, key_t *key); + +void matrix_read_cols_continuous_dynamic_actuation(matrix_row_t *current_row, uint8_t current_col, key_t *key); + +void matrix_read_cols_static_actuation(matrix_row_t *current_row, uint8_t current_col, key_t *key); \ No newline at end of file diff --git a/keyboards/momokai/tap_trio_pro/tap_trio_pro.c b/keyboards/momokai/tap_trio_pro/tap_trio_pro.c new file mode 100644 index 00000000000..ea5e8239a68 --- /dev/null +++ b/keyboards/momokai/tap_trio_pro/tap_trio_pro.c @@ -0,0 +1,175 @@ +/* Copyright 2023 RephlexZero (@RephlexZero) peepeetee (@peepeetee) +SPDX-License-Identifier: GPL-2.0-or-later */ +#include +#include +#include "tap_trio_pro.h" +#include "quantum.h" +#include "analog.h" +#include "eeprom.h" +#include "scanfunctions.h" + +analog_config g_config = { + .mode = dynamic_actuation, + .actuation_point = 32, + .press_sensitivity = 32, + .release_sensitivity = 32, + .press_hysteresis = 0, + .release_hysteresis = 5 +}; + +extern pin_t matrix_pins[MATRIX_ROWS][MATRIX_COLS]; +void bootmagic_lite(void) { + if (analogReadPin(matrix_pins[BOOTMAGIC_LITE_ROW][BOOTMAGIC_LITE_COLUMN]) < 1350) { + bootloader_jump(); + } +} + +uint32_t idle_recalibrate_callback(uint32_t trigger_time, void *cb_arg) { + get_sensor_offsets(); + return 10000; +} + +deferred_token idle_recalibrate_token; +bool process_record_kb(uint16_t keycode, keyrecord_t *record) { + extend_deferred_exec(idle_recalibrate_token, 300000); + return true; +} + +#ifdef DEBUG_ENABLE +static uint8_t i = 0; +void housekeeping_task_kb(void) { + if (i == 0) { + char formattedString[200]; // Adjust the buffer size as needed + + snprintf(formattedString, sizeof(formattedString), "Mode: %d Actuation Point: %d Press/Release Sensitivity: %d/%d\n", g_config.mode, g_config.actuation_point, g_config.press_sensitivity, g_config.release_sensitivity); + + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + snprintf(formattedString + strlen(formattedString), sizeof(formattedString) - strlen(formattedString), "%d/%d/%d ", keys[row][col].value, keys[row][col].extremum, analogReadPin(matrix_pins[row][col])); + } + strcat(formattedString, "\n\n"); + } + + uprintf("%s", formattedString); + } + i++; +} +#endif + +void values_load(void) { + eeconfig_read_kb_datablock(&g_config); +} + +void values_save(void) { + eeconfig_update_kb_datablock(&g_config); +} + +void eeconfig_init_kb() { + values_save(); +} + +void keyboard_post_init_kb(void) { + idle_recalibrate_token = defer_exec(300000, idle_recalibrate_callback, NULL); + values_load(); +} + +#ifdef VIA_ENABLE +void via_custom_value_command_kb(uint8_t *data, uint8_t length) { + /* data = [ command_id, channel_id, value_id, value_data ] */ + uint8_t *command_id = &(data[0]); + uint8_t *channel_id = &(data[1]); + uint8_t *value_id_and_data = &(data[2]); + + if (*channel_id == id_custom_channel) { + switch (*command_id) { + case id_custom_set_value: { + via_config_set_value(value_id_and_data); + break; + } + case id_custom_get_value: { + via_config_get_value(value_id_and_data); + break; + } + case id_custom_save: { + values_save(); + break; + } + default: { + /* Unhandled message */ + *command_id = id_unhandled; + break; + } + } + return; + } + + /* Return the unhandled state */ + *command_id = id_unhandled; + + /* DO NOT call raw_hid_send(data,length) here, let caller do this */ +} + +enum via_dynamic_actuation { + id_mode = 1, + id_actuation_point, + id_press_sensitivity, + id_release_sensitivity, + id_press_hysteresis, + id_release_hysteresis, +}; + +void via_config_set_value(uint8_t *data) { + /* data = [ value_id, value_data ] */ + uint8_t *value_id = &(data[0]); + uint8_t *value_data = &(data[1]); + + switch (*value_id) { + case id_mode: + g_config.mode = *value_data; + break; + case id_actuation_point: + g_config.actuation_point = *value_data * 255 / 40; + break; + case id_press_sensitivity: + g_config.press_sensitivity = *value_data * 255 / 40; + break; + case id_release_sensitivity: + g_config.release_sensitivity = *value_data * 255 / 40; + break; + case id_press_hysteresis: + g_config.press_hysteresis = *value_data * 255 / 40; + break; + case id_release_hysteresis: + g_config.release_hysteresis = *value_data * 255 / 40; + break; + } +} + +void via_config_get_value(uint8_t *data) { + uint8_t *value_id = &(data[0]); + uint8_t *value_data = &(data[1]); + + switch (*value_id) { + case id_mode: + *value_data = g_config.mode; + break; + case id_actuation_point: + *value_data = g_config.actuation_point * 40 / 255; + break; + case id_press_sensitivity: + *value_data = g_config.press_sensitivity * 40 / 255; + break; + case id_release_sensitivity: + *value_data = g_config.release_sensitivity * 40 / 255; + break; + case id_press_hysteresis: + *value_data = g_config.press_hysteresis * 40 / 255; + break; + case id_release_hysteresis: + *value_data = g_config.release_hysteresis * 40 / 255; + break; + } +} +#endif + + diff --git a/keyboards/momokai/tap_trio_pro/tap_trio_pro.h b/keyboards/momokai/tap_trio_pro/tap_trio_pro.h new file mode 100644 index 00000000000..78dba6508e7 --- /dev/null +++ b/keyboards/momokai/tap_trio_pro/tap_trio_pro.h @@ -0,0 +1,9 @@ +/* Copyright 2023 RephlexZero (@RephlexZero) +SPDX-License-Identifier: GPL-2.0-or-later */ +#pragma once + +#ifdef VIA_ENABLE +void via_config_set_value(uint8_t *data); + +void via_config_get_value(uint8_t *data); +#endif From ff202a42766369c0119767b40882d6c7f05bb6e5 Mon Sep 17 00:00:00 2001 From: peepeetee Date: Mon, 23 Oct 2023 02:52:05 -0500 Subject: [PATCH 02/43] fix infinite loop, start adding debug setup --- keyboards/momokai/tap_trio_pro/config.h | 21 +------------------ keyboards/momokai/tap_trio_pro/halconf.h | 3 +++ keyboards/momokai/tap_trio_pro/info.json | 5 +++-- .../tap_trio_pro/keymaps/debug/keymap.c | 19 +++++++++++++++++ .../tap_trio_pro/keymaps/debug/rules.mk | 1 + keyboards/momokai/tap_trio_pro/matrix.c | 12 ++++++----- 6 files changed, 34 insertions(+), 27 deletions(-) create mode 100644 keyboards/momokai/tap_trio_pro/keymaps/debug/keymap.c create mode 100644 keyboards/momokai/tap_trio_pro/keymaps/debug/rules.mk diff --git a/keyboards/momokai/tap_trio_pro/config.h b/keyboards/momokai/tap_trio_pro/config.h index d73e8158477..d13d284be69 100644 --- a/keyboards/momokai/tap_trio_pro/config.h +++ b/keyboards/momokai/tap_trio_pro/config.h @@ -10,7 +10,7 @@ #define EECONFIG_KB_DATA_SIZE 6 -//#define DEBUG_ENABLE +#define DEBUG_ENABLE #define DEBUG_MATRIX_SCAN_RATE #define ADC_RESOLUTION 12 @@ -19,25 +19,6 @@ - - - -/* - * Feature disable options - * These options are also useful to firmware size reduction. - */ - -/* disable debug print */ -//#define NO_DEBUG - -/* disable print */ -//#define NO_PRINT - -/* disable action features */ -//#define NO_ACTION_LAYER -//#define NO_ACTION_TAPPING -//#define NO_ACTION_ONESHOT - #ifdef RGB_MATRIX_ENABLE #define RGB_MATRIX_LED_COUNT 3 #define RGB_MATRIX_KEYPRESSES // reacts to keypresses diff --git a/keyboards/momokai/tap_trio_pro/halconf.h b/keyboards/momokai/tap_trio_pro/halconf.h index b93f31a1c46..227487f6060 100644 --- a/keyboards/momokai/tap_trio_pro/halconf.h +++ b/keyboards/momokai/tap_trio_pro/halconf.h @@ -2,6 +2,9 @@ SPDX-License-Identifier: GPL-2.0-or-later */ #pragma once +#undef HAL_USE_I2C +#define HAL_USE_I2C TRUE + #undef HAL_USE_ADC #define HAL_USE_ADC TRUE diff --git a/keyboards/momokai/tap_trio_pro/info.json b/keyboards/momokai/tap_trio_pro/info.json index ff512592314..bad9403c433 100644 --- a/keyboards/momokai/tap_trio_pro/info.json +++ b/keyboards/momokai/tap_trio_pro/info.json @@ -1,12 +1,13 @@ { "manufacturer": "momokai", - "keyboard_name": "hall_effect", + "keyboard_name": "tap_trio_pro", "maintainer": "peepeetee", "bootloader": "rp2040", "features": { "bootmagic": false, "command": false, - "console": false, + "console": true, + "debug": true, "extrakey": true, "mousekey": true, "rgb_matrix": true, diff --git a/keyboards/momokai/tap_trio_pro/keymaps/debug/keymap.c b/keyboards/momokai/tap_trio_pro/keymaps/debug/keymap.c new file mode 100644 index 00000000000..6933af6614c --- /dev/null +++ b/keyboards/momokai/tap_trio_pro/keymaps/debug/keymap.c @@ -0,0 +1,19 @@ +// Copyright 2023 peepeetee +// SPDX-License-Identifier: GPL-2.0-or-later + +#include QMK_KEYBOARD_H + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [0] = LAYOUT( + KC_MUTE, + KC_TRNS, KC_TRNS, KC_TRNS, + 1, 2, 3 + ) +}; + +#if defined(ENCODER_MAP_ENABLE) +const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = { + [0] = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU) } + +}; +#endif diff --git a/keyboards/momokai/tap_trio_pro/keymaps/debug/rules.mk b/keyboards/momokai/tap_trio_pro/keymaps/debug/rules.mk new file mode 100644 index 00000000000..ee325681483 --- /dev/null +++ b/keyboards/momokai/tap_trio_pro/keymaps/debug/rules.mk @@ -0,0 +1 @@ +ENCODER_MAP_ENABLE = yes diff --git a/keyboards/momokai/tap_trio_pro/matrix.c b/keyboards/momokai/tap_trio_pro/matrix.c index f988556bbff..8557df07ba9 100644 --- a/keyboards/momokai/tap_trio_pro/matrix.c +++ b/keyboards/momokai/tap_trio_pro/matrix.c @@ -23,11 +23,13 @@ extern matrix_row_t matrix[MATRIX_ROWS]; // debounced values void matrix_init_pins(void) { //default implementation for rows 0 and 2 only - for (int row = 0; row < ROWS_PER_HAND || row != 1; row++) { - for (int col = 0; col < MATRIX_COLS; col++) { - pin_t pin = matrix_pins[row][col]; - if (pin != NO_PIN) { - setPinInputHigh(pin); + for (int row = 0; row < ROWS_PER_HAND; row++) { + if (row != 1){ + for (int col = 0; col < MATRIX_COLS; col++) { + pin_t pin = matrix_pins[row][col]; + if (pin != NO_PIN) { + setPinInputHigh(pin); + } } } } From dc8e3585fb3aa8b9701c2bf48358aacb0bf800a3 Mon Sep 17 00:00:00 2001 From: peepeetee Date: Fri, 27 Oct 2023 22:12:23 -0500 Subject: [PATCH 03/43] writes more matrix code, fixes various issues so it compiles, still riddled with issues especially with (1,0) being pressed --- keyboards/momokai/tap_trio_pro/config.h | 2 +- keyboards/momokai/tap_trio_pro/halconf.h | 3 - keyboards/momokai/tap_trio_pro/info.json | 7 +- .../tap_trio_pro/keymaps/debug/keymap.c | 2 +- keyboards/momokai/tap_trio_pro/matrix.c | 220 +++++++++++++----- keyboards/momokai/tap_trio_pro/rules.mk | 2 +- .../momokai/tap_trio_pro/scanfunctions.c | 9 +- keyboards/momokai/tap_trio_pro/tap_trio_pro.c | 48 +++- 8 files changed, 213 insertions(+), 80 deletions(-) diff --git a/keyboards/momokai/tap_trio_pro/config.h b/keyboards/momokai/tap_trio_pro/config.h index d13d284be69..84b02898339 100644 --- a/keyboards/momokai/tap_trio_pro/config.h +++ b/keyboards/momokai/tap_trio_pro/config.h @@ -10,7 +10,7 @@ #define EECONFIG_KB_DATA_SIZE 6 -#define DEBUG_ENABLE +// #define DEBUG_ENABLE #define DEBUG_MATRIX_SCAN_RATE #define ADC_RESOLUTION 12 diff --git a/keyboards/momokai/tap_trio_pro/halconf.h b/keyboards/momokai/tap_trio_pro/halconf.h index 227487f6060..b93f31a1c46 100644 --- a/keyboards/momokai/tap_trio_pro/halconf.h +++ b/keyboards/momokai/tap_trio_pro/halconf.h @@ -2,9 +2,6 @@ SPDX-License-Identifier: GPL-2.0-or-later */ #pragma once -#undef HAL_USE_I2C -#define HAL_USE_I2C TRUE - #undef HAL_USE_ADC #define HAL_USE_ADC TRUE diff --git a/keyboards/momokai/tap_trio_pro/info.json b/keyboards/momokai/tap_trio_pro/info.json index bad9403c433..a5587b72e50 100644 --- a/keyboards/momokai/tap_trio_pro/info.json +++ b/keyboards/momokai/tap_trio_pro/info.json @@ -4,10 +4,10 @@ "maintainer": "peepeetee", "bootloader": "rp2040", "features": { - "bootmagic": false, + "bootmagic": true, "command": false, "console": true, - "debug": true, + "debug": false, "extrakey": true, "mousekey": true, "rgb_matrix": true, @@ -18,7 +18,8 @@ "matrix": [2, 0] }, "build": { - "lto": true + "lto": true, + "debounce_type": "sym_eager_pk" }, "matrix_pins": { "direct":[ diff --git a/keyboards/momokai/tap_trio_pro/keymaps/debug/keymap.c b/keyboards/momokai/tap_trio_pro/keymaps/debug/keymap.c index 6933af6614c..e4ef63117c3 100644 --- a/keyboards/momokai/tap_trio_pro/keymaps/debug/keymap.c +++ b/keyboards/momokai/tap_trio_pro/keymaps/debug/keymap.c @@ -7,7 +7,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [0] = LAYOUT( KC_MUTE, KC_TRNS, KC_TRNS, KC_TRNS, - 1, 2, 3 + KC_1, KC_2, KC_3 ) }; diff --git a/keyboards/momokai/tap_trio_pro/matrix.c b/keyboards/momokai/tap_trio_pro/matrix.c index 8557df07ba9..9dd5b084588 100644 --- a/keyboards/momokai/tap_trio_pro/matrix.c +++ b/keyboards/momokai/tap_trio_pro/matrix.c @@ -1,4 +1,7 @@ -/* Copyright 2023 RephlexZero (@RephlexZero) peepeetee (@peepeetee) +/* +Copyright 2012-2018 Jun Wako, Jack Humbert, Yiancar +Copyright 2023 RephlexZero (@RephlexZero) +Copyright 2023 peepeetee SPDX-License-Identifier: GPL-2.0-or-later */ #include #include @@ -7,61 +10,33 @@ SPDX-License-Identifier: GPL-2.0-or-later */ #include "print.h" #include "quantum.h" #include "analog.h" +#include "debounce.h" #include "lut.h" #include "scanfunctions.h" -pin_t matrix_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; -key_t keys[MATRIX_ROWS][MATRIX_COLS] = {0}; - - -# define ROWS_PER_HAND (MATRIX_ROWS) - -extern matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values -extern matrix_row_t matrix[MATRIX_ROWS]; // debounced values - - -void matrix_init_pins(void) { - //default implementation for rows 0 and 2 only - for (int row = 0; row < ROWS_PER_HAND; row++) { - if (row != 1){ - for (int col = 0; col < MATRIX_COLS; col++) { - pin_t pin = matrix_pins[row][col]; - if (pin != NO_PIN) { - setPinInputHigh(pin); - } - } - } - } -} - -void matrix_init_custom(void) { - generate_lut(); - get_sensor_offsets(); - wait_ms(100); // Let ADC reach steady state - get_sensor_offsets(); - - - - - //default implementation for rows 0 and 2 - matrix_init_pins(); - - // initialize matrix state: all keys off - memset(matrix, 0, sizeof(matrix)); - memset(raw_matrix, 0, sizeof(raw_matrix)); - - // debounce_init(ROWS_PER_HAND); - - // matrix_init_kb(); -} - -matrix_row_t previous_matrix[MATRIX_ROWS]; +// # define ROWS_PER_HAND (MATRIX_ROWS) #ifndef MATRIX_INPUT_PRESSED_STATE # define MATRIX_INPUT_PRESSED_STATE 0 #endif +// static const pin_t direct_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; +//aliased to matrix_pins based on rephlex's convention + +static const pin_t direct_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; + + +/* matrix state(1:on, 0:off) */ +matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values +matrix_row_t matrix[MATRIX_ROWS]; // debounced values + +// 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); + + static inline uint8_t readMatrixPin(pin_t pin) { if (pin != NO_PIN) { return (readPin(pin) == MATRIX_INPUT_PRESSED_STATE) ? 0 : 1; @@ -70,27 +45,121 @@ static inline uint8_t readMatrixPin(pin_t pin) { } } + +//2k/matrix.c row 15 +pin_t matrix_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; + +// key_t keys[MATRIX_ROWS][MATRIX_COLS] = {0}; +//analog key data, defined in analogkeys.h + +key_t keys[MATRIX_ROWS][MATRIX_COLS] = {0}; + + + +// matrix code + +//setup only rows 0 and 2, leave row 1 untouched +__attribute__((weak)) void matrix_init_pins(void) { + for (int row = 0; row < MATRIX_ROWS; row++) { + if (row != 1){ + for (int col = 0; col < MATRIX_COLS; col++) { + pin_t pin = direct_pins[row][col]; + if (pin != NO_PIN) { + setPinInputHigh(pin); + } + } + } + } +} + +__attribute__((weak)) 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 = direct_pins[current_row][col_index]; + current_row_value |= readMatrixPin(pin) ? 0 : row_shifter; + } + + // Update the matrix + current_matrix[current_row] = current_row_value; +} + + + + + + + + + +matrix_row_t matrix_get_row(uint8_t row) { + + // TODO: return the requested row data + //matrix_common.c row 68 + + return matrix[row]; +} + + +# define print_matrix_header() print("\nr/c 01234567\n") +# define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row)) + + + +void matrix_print(void) { + // TODO: use print() to dump the current matrix state to console + //matrix_common.c row 84 + + print_matrix_header(); + + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + print_hex8(row); + print(": "); + print_matrix_row(row); + print("\n"); + } + +} + +void matrix_init(void) { + // TODO: initialize hardware and global matrix state here + //matrix.c row 274 + //matrix_common.c row 149 + + + // initialize key pins + matrix_init_pins(); + //matrix_init_custom(); + + generate_lut(); + get_sensor_offsets(); + wait_ms(100); // Let ADC reach steady state + get_sensor_offsets(); + + // initialize matrix state: all keys off + for (uint8_t i = 0; i < MATRIX_ROWS; i++) { + raw_matrix[i] = 0; + matrix[i] = 0; + } + + // Unless hardware debouncing - Init the configured debounce routine + debounce_init(MATRIX_ROWS); + + // This *must* be called for correct keyboard behavior + matrix_init_kb(); +} + +matrix_row_t previous_matrix[MATRIX_ROWS]; + bool matrix_scan_custom(matrix_row_t current_matrix[]) { memcpy(previous_matrix, current_matrix, sizeof(previous_matrix)); for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { if (current_row != 1) { //default implementation for rows 0 and 2 - for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { - // 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 = direct_pins[current_row][col_index]; - 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; - } + matrix_read_cols_on_row(current_matrix, current_row); } if (current_row == 1) { //use ADC for row 1 @@ -120,3 +189,30 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) { } return memcmp(previous_matrix, current_matrix, sizeof(previous_matrix)) != 0; } + + +uint8_t matrix_scan(void) { + // TODO: add matrix scanning routine here + //matrix.c row 324 + //matrix_common.c row 169 + + bool changed = matrix_scan_custom(raw_matrix); + + // Unless hardware debouncing - use the configured debounce routine + changed = debounce(raw_matrix, matrix, MATRIX_ROWS, changed); + + // This *must* be called for correct keyboard behavior + matrix_scan_kb(); + + 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) {} + diff --git a/keyboards/momokai/tap_trio_pro/rules.mk b/keyboards/momokai/tap_trio_pro/rules.mk index 074558d5561..9de2c450db6 100644 --- a/keyboards/momokai/tap_trio_pro/rules.mk +++ b/keyboards/momokai/tap_trio_pro/rules.mk @@ -1,6 +1,6 @@ QUANTUM_LIB_SRC += analog.c SRC += matrix.c lut.c scanfunctions.c -CUSTOM_MATRIX = lite +CUSTOM_MATRIX = yes OPT = 3 diff --git a/keyboards/momokai/tap_trio_pro/scanfunctions.c b/keyboards/momokai/tap_trio_pro/scanfunctions.c index 552cdc3867a..73d9947d5ef 100644 --- a/keyboards/momokai/tap_trio_pro/scanfunctions.c +++ b/keyboards/momokai/tap_trio_pro/scanfunctions.c @@ -1,4 +1,5 @@ /* Copyright 2023 RephlexZero (@RephlexZero) +Copyright 2023 peepeetee SPDX-License-Identifier: GPL-2.0-or-later */ #include "quantum.h" #include "analog.h" @@ -7,11 +8,13 @@ SPDX-License-Identifier: GPL-2.0-or-later */ extern pin_t matrix_pins[MATRIX_ROWS][MATRIX_COLS]; void get_sensor_offsets(void) { uint16_t rest_adc_value = distance_to_adc(0); - for (uint8_t i = 0; i < MATRIX_ROWS; i++) { + // for (uint8_t i = 0; i < MATRIX_ROWS; i++) { + //do this for row 1 only + uint8_t i = 1; for (uint8_t j = 0; j < MATRIX_COLS; j++) { keys[i][j].offset = rest_adc_value - analogReadPin(matrix_pins[i][j]); } - } + // } } void update_extremum(key_t *key) { @@ -112,4 +115,4 @@ void matrix_read_cols_continuous_dynamic_actuation(matrix_row_t *current_row, ui update_extremum(key); key->dynamic_actuation_bool = true; } -} \ No newline at end of file +} diff --git a/keyboards/momokai/tap_trio_pro/tap_trio_pro.c b/keyboards/momokai/tap_trio_pro/tap_trio_pro.c index ea5e8239a68..e3c0226b574 100644 --- a/keyboards/momokai/tap_trio_pro/tap_trio_pro.c +++ b/keyboards/momokai/tap_trio_pro/tap_trio_pro.c @@ -9,7 +9,7 @@ SPDX-License-Identifier: GPL-2.0-or-later */ #include "scanfunctions.h" analog_config g_config = { - .mode = dynamic_actuation, + .mode = static_actuation, .actuation_point = 32, .press_sensitivity = 32, .release_sensitivity = 32, @@ -18,11 +18,47 @@ analog_config g_config = { }; extern pin_t matrix_pins[MATRIX_ROWS][MATRIX_COLS]; -void bootmagic_lite(void) { - if (analogReadPin(matrix_pins[BOOTMAGIC_LITE_ROW][BOOTMAGIC_LITE_COLUMN]) < 1350) { - bootloader_jump(); - } -} + +// void bootmagic_lite(void) { +// if (BOOTMAGIC_LITE_ROW == 1) { +// if (analogReadPin(matrix_pins[BOOTMAGIC_LITE_ROW][BOOTMAGIC_LITE_COLUMN]) < 1350) { +// bootloader_jump(); +// } +// } +// else { +// // default implementation + +// // We need multiple scans because debouncing can't be turned off. +// matrix_scan(); +// #if defined(DEBOUNCE) && DEBOUNCE > 0 +// wait_ms(DEBOUNCE * 2); +// #else +// wait_ms(30); +// #endif +// matrix_scan(); + +// // If the configured key (commonly Esc) is held down on power up, +// // reset the EEPROM valid state and jump to bootloader. +// // This isn't very generalized, but we need something that doesn't +// // rely on user's keymaps in firmware or EEPROM. +// uint8_t row = BOOTMAGIC_LITE_ROW; +// uint8_t col = BOOTMAGIC_LITE_COLUMN; + +// #if defined(SPLIT_KEYBOARD) && defined(BOOTMAGIC_LITE_ROW_RIGHT) && defined(BOOTMAGIC_LITE_COLUMN_RIGHT) +// if (!is_keyboard_left()) { +// row = BOOTMAGIC_LITE_ROW_RIGHT; +// col = BOOTMAGIC_LITE_COLUMN_RIGHT; +// } +// #endif + +// if (matrix_get_row(row) & (1 << col)) { +// bootmagic_lite_reset_eeprom(); + +// // Jump to bootloader. +// bootloader_jump(); +// } +// } +// } uint32_t idle_recalibrate_callback(uint32_t trigger_time, void *cb_arg) { get_sensor_offsets(); From d207671fb060a5d9800c1b1b30976939a1445c5d Mon Sep 17 00:00:00 2001 From: peepeetee Date: Thu, 2 Nov 2023 16:37:07 -0500 Subject: [PATCH 04/43] flip encoder rotation direction --- keyboards/momokai/tap_trio_pro/info.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/keyboards/momokai/tap_trio_pro/info.json b/keyboards/momokai/tap_trio_pro/info.json index a5587b72e50..ea350a37868 100644 --- a/keyboards/momokai/tap_trio_pro/info.json +++ b/keyboards/momokai/tap_trio_pro/info.json @@ -39,8 +39,8 @@ "enabled": true, "rotary": [ { - "pin_a": "GP1", - "pin_b": "GP2" + "pin_a": "GP2", + "pin_b": "GP1" } ] }, From 5c77ef5fbe6d41fb5381eadf80be816a6e043cd4 Mon Sep 17 00:00:00 2001 From: peepeetee Date: Fri, 3 Nov 2023 01:22:27 -0500 Subject: [PATCH 05/43] more clueless rummaging through the code to figure out what is up with GP28 --- keyboards/momokai/tap_trio_pro/info.json | 2 +- .../keymaps/blank_hall_effect/keymap.c | 19 +++++++++++++++++++ .../keymaps/blank_hall_effect/rules.mk | 1 + .../tap_trio_pro/keymaps/debug/keymap.c | 4 ++-- keyboards/momokai/tap_trio_pro/tap_trio_pro.c | 14 +++++++------- 5 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 keyboards/momokai/tap_trio_pro/keymaps/blank_hall_effect/keymap.c create mode 100644 keyboards/momokai/tap_trio_pro/keymaps/blank_hall_effect/rules.mk diff --git a/keyboards/momokai/tap_trio_pro/info.json b/keyboards/momokai/tap_trio_pro/info.json index ea350a37868..a9cb99676b8 100644 --- a/keyboards/momokai/tap_trio_pro/info.json +++ b/keyboards/momokai/tap_trio_pro/info.json @@ -24,7 +24,7 @@ "matrix_pins": { "direct":[ ["NO_PIN", "GP0", "NO_PIN" ], - ["GP28", "GP27", "GP26" ], + ["NO_PIN", "GP27", "GP26" ], ["GP10", "GP9", "GP8" ] ] }, diff --git a/keyboards/momokai/tap_trio_pro/keymaps/blank_hall_effect/keymap.c b/keyboards/momokai/tap_trio_pro/keymaps/blank_hall_effect/keymap.c new file mode 100644 index 00000000000..e4ef63117c3 --- /dev/null +++ b/keyboards/momokai/tap_trio_pro/keymaps/blank_hall_effect/keymap.c @@ -0,0 +1,19 @@ +// Copyright 2023 peepeetee +// SPDX-License-Identifier: GPL-2.0-or-later + +#include QMK_KEYBOARD_H + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [0] = LAYOUT( + KC_MUTE, + KC_TRNS, KC_TRNS, KC_TRNS, + KC_1, KC_2, KC_3 + ) +}; + +#if defined(ENCODER_MAP_ENABLE) +const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = { + [0] = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU) } + +}; +#endif diff --git a/keyboards/momokai/tap_trio_pro/keymaps/blank_hall_effect/rules.mk b/keyboards/momokai/tap_trio_pro/keymaps/blank_hall_effect/rules.mk new file mode 100644 index 00000000000..ee325681483 --- /dev/null +++ b/keyboards/momokai/tap_trio_pro/keymaps/blank_hall_effect/rules.mk @@ -0,0 +1 @@ +ENCODER_MAP_ENABLE = yes diff --git a/keyboards/momokai/tap_trio_pro/keymaps/debug/keymap.c b/keyboards/momokai/tap_trio_pro/keymaps/debug/keymap.c index e4ef63117c3..6805a35b232 100644 --- a/keyboards/momokai/tap_trio_pro/keymaps/debug/keymap.c +++ b/keyboards/momokai/tap_trio_pro/keymaps/debug/keymap.c @@ -6,8 +6,8 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [0] = LAYOUT( KC_MUTE, - KC_TRNS, KC_TRNS, KC_TRNS, - KC_1, KC_2, KC_3 + KC_1, KC_2, KC_3, + KC_4, KC_5, KC_6 ) }; diff --git a/keyboards/momokai/tap_trio_pro/tap_trio_pro.c b/keyboards/momokai/tap_trio_pro/tap_trio_pro.c index e3c0226b574..1dcc1defbf1 100644 --- a/keyboards/momokai/tap_trio_pro/tap_trio_pro.c +++ b/keyboards/momokai/tap_trio_pro/tap_trio_pro.c @@ -100,14 +100,14 @@ void values_save(void) { eeconfig_update_kb_datablock(&g_config); } -void eeconfig_init_kb() { - values_save(); -} +// void eeconfig_init_kb() { +// values_save(); +// } -void keyboard_post_init_kb(void) { - idle_recalibrate_token = defer_exec(300000, idle_recalibrate_callback, NULL); - values_load(); -} +// void keyboard_post_init_kb(void) { +// idle_recalibrate_token = defer_exec(300000, idle_recalibrate_callback, NULL); +// values_load(); +// } #ifdef VIA_ENABLE void via_custom_value_command_kb(uint8_t *data, uint8_t length) { From 22008aad40964f3b1bead9b193c035965aec8304 Mon Sep 17 00:00:00 2001 From: peepeetee Date: Thu, 16 Nov 2023 19:08:46 -0600 Subject: [PATCH 06/43] stashing progress --- keyboards/momokai/tap_trio_pro/config.h | 2 +- keyboards/momokai/tap_trio_pro/info.json | 4 ++-- keyboards/momokai/tap_trio_pro/matrix.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/keyboards/momokai/tap_trio_pro/config.h b/keyboards/momokai/tap_trio_pro/config.h index 84b02898339..d13d284be69 100644 --- a/keyboards/momokai/tap_trio_pro/config.h +++ b/keyboards/momokai/tap_trio_pro/config.h @@ -10,7 +10,7 @@ #define EECONFIG_KB_DATA_SIZE 6 -// #define DEBUG_ENABLE +#define DEBUG_ENABLE #define DEBUG_MATRIX_SCAN_RATE #define ADC_RESOLUTION 12 diff --git a/keyboards/momokai/tap_trio_pro/info.json b/keyboards/momokai/tap_trio_pro/info.json index a9cb99676b8..33114807770 100644 --- a/keyboards/momokai/tap_trio_pro/info.json +++ b/keyboards/momokai/tap_trio_pro/info.json @@ -7,7 +7,7 @@ "bootmagic": true, "command": false, "console": true, - "debug": false, + "debug": true, "extrakey": true, "mousekey": true, "rgb_matrix": true, @@ -24,7 +24,7 @@ "matrix_pins": { "direct":[ ["NO_PIN", "GP0", "NO_PIN" ], - ["NO_PIN", "GP27", "GP26" ], + ["GP28", "GP27", "GP26" ], ["GP10", "GP9", "GP8" ] ] }, diff --git a/keyboards/momokai/tap_trio_pro/matrix.c b/keyboards/momokai/tap_trio_pro/matrix.c index 9dd5b084588..581a5da5b7d 100644 --- a/keyboards/momokai/tap_trio_pro/matrix.c +++ b/keyboards/momokai/tap_trio_pro/matrix.c @@ -61,14 +61,14 @@ key_t keys[MATRIX_ROWS][MATRIX_COLS] = {0}; //setup only rows 0 and 2, leave row 1 untouched __attribute__((weak)) void matrix_init_pins(void) { for (int row = 0; row < MATRIX_ROWS; row++) { - if (row != 1){ + // if (row != 1){ for (int col = 0; col < MATRIX_COLS; col++) { pin_t pin = direct_pins[row][col]; if (pin != NO_PIN) { setPinInputHigh(pin); } } - } + // } } } From c834c29f06423dab426f785bdb5580bcd25f77de Mon Sep 17 00:00:00 2001 From: peepeetee Date: Wed, 3 Jan 2024 21:04:14 -0600 Subject: [PATCH 07/43] fix duplicate identifier key_t --- keyboards/momokai/tap_trio_pro/analogkeys.h | 4 ++-- keyboards/momokai/tap_trio_pro/matrix.c | 6 +++--- keyboards/momokai/tap_trio_pro/scanfunctions.c | 8 ++++---- keyboards/momokai/tap_trio_pro/scanfunctions.h | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/keyboards/momokai/tap_trio_pro/analogkeys.h b/keyboards/momokai/tap_trio_pro/analogkeys.h index 35a54150f0c..6280fdb96fc 100644 --- a/keyboards/momokai/tap_trio_pro/analogkeys.h +++ b/keyboards/momokai/tap_trio_pro/analogkeys.h @@ -22,5 +22,5 @@ typedef struct { uint8_t extremum; int16_t offset; bool dynamic_actuation_bool; -} key_t; -extern key_t keys[MATRIX_ROWS][MATRIX_COLS]; +} hall_effect_key_t; +extern hall_effect_key_t keys[MATRIX_ROWS][MATRIX_COLS]; diff --git a/keyboards/momokai/tap_trio_pro/matrix.c b/keyboards/momokai/tap_trio_pro/matrix.c index 581a5da5b7d..41bd5b27686 100644 --- a/keyboards/momokai/tap_trio_pro/matrix.c +++ b/keyboards/momokai/tap_trio_pro/matrix.c @@ -49,10 +49,10 @@ static inline uint8_t readMatrixPin(pin_t pin) { //2k/matrix.c row 15 pin_t matrix_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; -// key_t keys[MATRIX_ROWS][MATRIX_COLS] = {0}; +// hall_effect_key_t keys[MATRIX_ROWS][MATRIX_COLS] = {0}; //analog key data, defined in analogkeys.h -key_t keys[MATRIX_ROWS][MATRIX_COLS] = {0}; +hall_effect_key_t keys[MATRIX_ROWS][MATRIX_COLS] = {0}; @@ -164,7 +164,7 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) { if (current_row == 1) { //use ADC for row 1 for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { - key_t *key = &keys[current_row][current_col]; + hall_effect_key_t *key = &keys[current_row][current_col]; key->value = lut[analogReadPin(matrix_pins[current_row][current_col]) + key->offset]; key->value = MIN((key->value << 8) / lut[1100 + key->offset], 255); diff --git a/keyboards/momokai/tap_trio_pro/scanfunctions.c b/keyboards/momokai/tap_trio_pro/scanfunctions.c index 73d9947d5ef..5cd94a15173 100644 --- a/keyboards/momokai/tap_trio_pro/scanfunctions.c +++ b/keyboards/momokai/tap_trio_pro/scanfunctions.c @@ -17,7 +17,7 @@ void get_sensor_offsets(void) { // } } -void update_extremum(key_t *key) { +void update_extremum(hall_effect_key_t *key) { key->extremum = key->value; } @@ -29,7 +29,7 @@ void deregister_key(matrix_row_t *current_row, uint8_t current_col) { *current_row &= ~(1 << current_col); } -void matrix_read_cols_static_actuation(matrix_row_t *current_row, uint8_t current_col, key_t *key) { +void matrix_read_cols_static_actuation(matrix_row_t *current_row, uint8_t current_col, hall_effect_key_t *key) { if (*current_row & (1 << current_col)) { if (key->value < MAX(g_config.actuation_point - g_config.release_hysteresis, 0)) { deregister_key(current_row, current_col); @@ -47,7 +47,7 @@ assuming your sensor value decreases when the key is pressed, 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. */ -void matrix_read_cols_dynamic_actuation(matrix_row_t *current_row, uint8_t current_col, key_t *key) { +void matrix_read_cols_dynamic_actuation(matrix_row_t *current_row, uint8_t current_col, hall_effect_key_t *key) { if (key->dynamic_actuation_bool) { if (*current_row & (1 << current_col)) { /* Key is pressed @@ -82,7 +82,7 @@ void matrix_read_cols_dynamic_actuation(matrix_row_t *current_row, uint8_t curre } } -void matrix_read_cols_continuous_dynamic_actuation(matrix_row_t *current_row, uint8_t current_col, key_t *key) { +void matrix_read_cols_continuous_dynamic_actuation(matrix_row_t *current_row, uint8_t current_col, hall_effect_key_t *key) { if (key->dynamic_actuation_bool) { if (*current_row & (1 << current_col)) { /* Key is pressed diff --git a/keyboards/momokai/tap_trio_pro/scanfunctions.h b/keyboards/momokai/tap_trio_pro/scanfunctions.h index 71df75b83bb..7310d84a4f9 100644 --- a/keyboards/momokai/tap_trio_pro/scanfunctions.h +++ b/keyboards/momokai/tap_trio_pro/scanfunctions.h @@ -6,7 +6,7 @@ SPDX-License-Identifier: GPL-2.0-or-later */ #include "quantum.h" #include "lut.h" -void update_extremum(key_t *key); +void update_extremum(hall_effect_key_t *key); void register_key(matrix_row_t *current_row, uint8_t current_col); @@ -14,8 +14,8 @@ void deregister_key(matrix_row_t *current_row, uint8_t current_col); void get_sensor_offsets(void); -void matrix_read_cols_dynamic_actuation(matrix_row_t *current_row, uint8_t current_col, key_t *key); +void matrix_read_cols_dynamic_actuation(matrix_row_t *current_row, uint8_t current_col, hall_effect_key_t *key); -void matrix_read_cols_continuous_dynamic_actuation(matrix_row_t *current_row, uint8_t current_col, key_t *key); +void matrix_read_cols_continuous_dynamic_actuation(matrix_row_t *current_row, uint8_t current_col, hall_effect_key_t *key); -void matrix_read_cols_static_actuation(matrix_row_t *current_row, uint8_t current_col, key_t *key); \ No newline at end of file +void matrix_read_cols_static_actuation(matrix_row_t *current_row, uint8_t current_col, hall_effect_key_t *key); \ No newline at end of file From e543447d96933b3ec2f9ae334214ba6c79f8ab42 Mon Sep 17 00:00:00 2001 From: peepeetee Date: Wed, 10 Jan 2024 18:27:58 -0600 Subject: [PATCH 08/43] add a scratchpad file --- keyboards/momokai/tap_trio_pro/Scratchpad.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 keyboards/momokai/tap_trio_pro/Scratchpad.md diff --git a/keyboards/momokai/tap_trio_pro/Scratchpad.md b/keyboards/momokai/tap_trio_pro/Scratchpad.md new file mode 100644 index 00000000000..e69de29bb2d From 474ce608183442ff3a381aa0e4e59c2e06e7103e Mon Sep 17 00:00:00 2001 From: peepeetee Date: Sat, 13 Jan 2024 03:29:18 -0600 Subject: [PATCH 09/43] add my ramblings, very small review (result wise) of matrix.c, preparing to start over --- keyboards/momokai/tap_trio_pro/Scratchpad.md | 4 ++++ keyboards/momokai/tap_trio_pro/matrix.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/keyboards/momokai/tap_trio_pro/Scratchpad.md b/keyboards/momokai/tap_trio_pro/Scratchpad.md index e69de29bb2d..52b1cc05657 100644 --- a/keyboards/momokai/tap_trio_pro/Scratchpad.md +++ b/keyboards/momokai/tap_trio_pro/Scratchpad.md @@ -0,0 +1,4 @@ +as of 126dc933b203435abb76081603b8fa7978f4181d the SMD keys no longer work + +at the start, all keys are outputted in order --> initialization or infinite loop + diff --git a/keyboards/momokai/tap_trio_pro/matrix.c b/keyboards/momokai/tap_trio_pro/matrix.c index 41bd5b27686..865b033707d 100644 --- a/keyboards/momokai/tap_trio_pro/matrix.c +++ b/keyboards/momokai/tap_trio_pro/matrix.c @@ -145,7 +145,7 @@ void matrix_init(void) { } // Unless hardware debouncing - Init the configured debounce routine - debounce_init(MATRIX_ROWS); + //debounce_init(MATRIX_ROWS); // This *must* be called for correct keyboard behavior matrix_init_kb(); From f98ff9b4fa0d52e5bac24ce7f84fb07f6d9d68de Mon Sep 17 00:00:00 2001 From: peepeetee Date: Sun, 14 Jan 2024 02:21:20 -0600 Subject: [PATCH 10/43] reset development --- keyboards/momokai/tap_trio_pro/analogkeys.h | 4 +- keyboards/momokai/tap_trio_pro/config.h | 64 ------- keyboards/momokai/tap_trio_pro/info.json | 54 +++++- keyboards/momokai/tap_trio_pro/matrix.c | 175 +----------------- keyboards/momokai/tap_trio_pro/mcuconf.h | 8 + keyboards/momokai/tap_trio_pro/rules.mk | 2 +- .../momokai/tap_trio_pro/scanfunctions.c | 15 +- .../momokai/tap_trio_pro/scanfunctions.h | 8 +- keyboards/momokai/tap_trio_pro/tap_trio_pro.c | 124 ++++++------- 9 files changed, 131 insertions(+), 323 deletions(-) create mode 100644 keyboards/momokai/tap_trio_pro/mcuconf.h diff --git a/keyboards/momokai/tap_trio_pro/analogkeys.h b/keyboards/momokai/tap_trio_pro/analogkeys.h index 6280fdb96fc..8e138293615 100644 --- a/keyboards/momokai/tap_trio_pro/analogkeys.h +++ b/keyboards/momokai/tap_trio_pro/analogkeys.h @@ -22,5 +22,5 @@ typedef struct { uint8_t extremum; int16_t offset; bool dynamic_actuation_bool; -} hall_effect_key_t; -extern hall_effect_key_t keys[MATRIX_ROWS][MATRIX_COLS]; +} analog_key_t; +extern analog_key_t keys[MATRIX_ROWS][MATRIX_COLS]; diff --git a/keyboards/momokai/tap_trio_pro/config.h b/keyboards/momokai/tap_trio_pro/config.h index d13d284be69..24af395e9cd 100644 --- a/keyboards/momokai/tap_trio_pro/config.h +++ b/keyboards/momokai/tap_trio_pro/config.h @@ -3,9 +3,6 @@ #pragma once - -#define DEBOUNCE 0 - #define DYNAMIC_KEYMAP_LAYER_COUNT 1 #define EECONFIG_KB_DATA_SIZE 6 @@ -17,64 +14,3 @@ #define CALIBRATION_RANGE 255 - - -#ifdef RGB_MATRIX_ENABLE -#define RGB_MATRIX_LED_COUNT 3 -#define RGB_MATRIX_KEYPRESSES // reacts to keypresses -#define RGB_MATRIX_FRAMEBUFFER_EFFECTS -#define RGB_DISABLE_WHEN_USB_SUSPENDED // turn off effects when suspended -#define RGB_MATRIX_MAXIMUM_BRIGHTNESS 200 - // RGB Matrix Animation modes. Explicitly enabled - // For full list of effects, see: - // https://docs.qmk.fm/#/feature_rgb_matrix?id=rgb-matrix-effects - #define ENABLE_RGB_MATRIX_SOLID_COLOR - #define ENABLE_RGB_MATRIX_ALPHAS_MODS - #define ENABLE_RGB_MATRIX_GRADIENT_UP_DOWN - #define ENABLE_RGB_MATRIX_GRADIENT_LEFT_RIGHT - #define ENABLE_RGB_MATRIX_BREATHING - #define ENABLE_RGB_MATRIX_BAND_SAT - #define ENABLE_RGB_MATRIX_BAND_VAL - #define ENABLE_RGB_MATRIX_BAND_PINWHEEL_SAT - #define ENABLE_RGB_MATRIX_BAND_PINWHEEL_VAL - #define ENABLE_RGB_MATRIX_BAND_SPIRAL_SAT - #define ENABLE_RGB_MATRIX_BAND_SPIRAL_VAL - #define ENABLE_RGB_MATRIX_CYCLE_ALL - #define ENABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT - #define ENABLE_RGB_MATRIX_CYCLE_UP_DOWN - #define ENABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON - #define ENABLE_RGB_MATRIX_CYCLE_OUT_IN - #define ENABLE_RGB_MATRIX_CYCLE_OUT_IN_DUAL - #define ENABLE_RGB_MATRIX_CYCLE_PINWHEEL - #define ENABLE_RGB_MATRIX_CYCLE_SPIRAL - #define ENABLE_RGB_MATRIX_DUAL_BEACON - #define ENABLE_RGB_MATRIX_RAINBOW_BEACON - #define ENABLE_RGB_MATRIX_RAINBOW_PINWHEELS - #define ENABLE_RGB_MATRIX_RAINDROPS - #define ENABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS - #define ENABLE_RGB_MATRIX_HUE_BREATHING - #define ENABLE_RGB_MATRIX_HUE_PENDULUM - #define ENABLE_RGB_MATRIX_HUE_WAVE - #define ENABLE_RGB_MATRIX_PIXEL_RAIN - #define ENABLE_RGB_MATRIX_PIXEL_FLOW - #define ENABLE_RGB_MATRIX_PIXEL_FRACTAL - - // enabled only if RGB_MATRIX_FRAMEBUFFER_EFFECTS is defined - #define ENABLE_RGB_MATRIX_TYPING_HEATMAP - // #define ENABLE_RGB_MATRIX_DIGITAL_RAIN - - // enabled only of RGB_MATRIX_KEYPRESSES or RGB_MATRIX_KEYRELEASES is defined - #define ENABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE - #define ENABLE_RGB_MATRIX_SOLID_REACTIVE - #define ENABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE - #define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE - #define ENABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS - #define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS - #define ENABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS - #define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS - #define ENABLE_RGB_MATRIX_SPLASH - #define ENABLE_RGB_MATRIX_MULTISPLASH - #define ENABLE_RGB_MATRIX_SOLID_SPLASH - #define ENABLE_RGB_MATRIX_SOLID_MULTISPLASH -#endif - diff --git a/keyboards/momokai/tap_trio_pro/info.json b/keyboards/momokai/tap_trio_pro/info.json index 33114807770..3eaa3fe825f 100644 --- a/keyboards/momokai/tap_trio_pro/info.json +++ b/keyboards/momokai/tap_trio_pro/info.json @@ -18,8 +18,7 @@ "matrix": [2, 0] }, "build": { - "lto": true, - "debounce_type": "sym_eager_pk" + "lto": true }, "matrix_pins": { "direct":[ @@ -28,6 +27,9 @@ ["GP10", "GP9", "GP8" ] ] }, + + "debounce": 0, + "processor": "RP2040", "url": "", "usb": { @@ -51,6 +53,54 @@ "rgb_matrix": { "driver": "ws2812", + "led_count": 3, + "sleep": true, + "animations": { + "solid_color": true, + "alphas_mods": true, + "gradient_up_down": true, + "gradient_left_right": true, + "breathing": true, + "band_sat": true, + "band_val": true, + "band_pinwheel_sat": true, + "band_pinwheel_val": true, + "band_spiral_sat": true, + "band_spiral_val": true, + "cycle_all": true, + "cycle_left_right": true, + "cycle_up_down": true, + "cycle_out_in": true, + "cycle_out_in_dual": true, + "rainbow_moving_chevron": true, + "cycle_pinwheel": true, + "cycle_spiral": true, + "dual_beacon": true, + "rainbow_beacon": true, + "rainbow_pinwheels": true, + "raindrops": true, + "jellybean_raindrops": true, + "hue_breathing": true, + "hue_pendulum": true, + "hue_wave": true, + "pixel_fractal": true, + "pixel_flow": true, + "pixel_rain": true, + "typing_heatmap": true, + "digital_rain": true, + "solid_reactive_simple": true, + "solid_reactive": true, + "solid_reactive_wide": true, + "solid_reactive_multiwide": true, + "solid_reactive_cross": true, + "solid_reactive_multicross": true, + "solid_reactive_nexus": true, + "solid_reactive_multinexus": true, + "splash": true, + "multisplash": true, + "solid_splash": true, + "solid_multisplash": true + }, "layout": [ {"flags": 4, "matrix": [1, 0], "x": 0, "y": 0}, {"flags": 4, "matrix": [1, 1], "x": 0, "y": 32}, diff --git a/keyboards/momokai/tap_trio_pro/matrix.c b/keyboards/momokai/tap_trio_pro/matrix.c index 865b033707d..08fe92a723b 100644 --- a/keyboards/momokai/tap_trio_pro/matrix.c +++ b/keyboards/momokai/tap_trio_pro/matrix.c @@ -1,154 +1,24 @@ -/* -Copyright 2012-2018 Jun Wako, Jack Humbert, Yiancar -Copyright 2023 RephlexZero (@RephlexZero) +/* Copyright 2023 RephlexZero (@RephlexZero) Copyright 2023 peepeetee SPDX-License-Identifier: GPL-2.0-or-later */ #include #include #include #include -#include "print.h" #include "quantum.h" #include "analog.h" -#include "debounce.h" #include "lut.h" #include "scanfunctions.h" - -// # define ROWS_PER_HAND (MATRIX_ROWS) - -#ifndef MATRIX_INPUT_PRESSED_STATE -# define MATRIX_INPUT_PRESSED_STATE 0 -#endif - -// static const pin_t direct_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; -//aliased to matrix_pins based on rephlex's convention - -static const pin_t direct_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; - - -/* matrix state(1:on, 0:off) */ -matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values -matrix_row_t matrix[MATRIX_ROWS]; // debounced values - -// 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); - - -static inline uint8_t readMatrixPin(pin_t pin) { - if (pin != NO_PIN) { - return (readPin(pin) == MATRIX_INPUT_PRESSED_STATE) ? 0 : 1; - } else { - return 1; - } -} - - -//2k/matrix.c row 15 pin_t matrix_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; -// hall_effect_key_t keys[MATRIX_ROWS][MATRIX_COLS] = {0}; -//analog key data, defined in analogkeys.h - -hall_effect_key_t keys[MATRIX_ROWS][MATRIX_COLS] = {0}; - - - -// matrix code - -//setup only rows 0 and 2, leave row 1 untouched -__attribute__((weak)) void matrix_init_pins(void) { - for (int row = 0; row < MATRIX_ROWS; row++) { - // if (row != 1){ - for (int col = 0; col < MATRIX_COLS; col++) { - pin_t pin = direct_pins[row][col]; - if (pin != NO_PIN) { - setPinInputHigh(pin); - } - } - // } - } -} - -__attribute__((weak)) 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 = direct_pins[current_row][col_index]; - current_row_value |= readMatrixPin(pin) ? 0 : row_shifter; - } - - // Update the matrix - current_matrix[current_row] = current_row_value; -} - - - - - - - - - -matrix_row_t matrix_get_row(uint8_t row) { - - // TODO: return the requested row data - //matrix_common.c row 68 - - return matrix[row]; -} - - -# define print_matrix_header() print("\nr/c 01234567\n") -# define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row)) - - - -void matrix_print(void) { - // TODO: use print() to dump the current matrix state to console - //matrix_common.c row 84 - - print_matrix_header(); - - for (uint8_t row = 0; row < MATRIX_ROWS; row++) { - print_hex8(row); - print(": "); - print_matrix_row(row); - print("\n"); - } - -} - -void matrix_init(void) { - // TODO: initialize hardware and global matrix state here - //matrix.c row 274 - //matrix_common.c row 149 - - - // initialize key pins - matrix_init_pins(); - //matrix_init_custom(); +analog_key_t keys[MATRIX_ROWS][MATRIX_COLS] = {0}; +void matrix_init_custom(void) { generate_lut(); get_sensor_offsets(); wait_ms(100); // Let ADC reach steady state get_sensor_offsets(); - - // initialize matrix state: all keys off - for (uint8_t i = 0; i < MATRIX_ROWS; i++) { - raw_matrix[i] = 0; - matrix[i] = 0; - } - - // Unless hardware debouncing - Init the configured debounce routine - //debounce_init(MATRIX_ROWS); - - // This *must* be called for correct keyboard behavior - matrix_init_kb(); } matrix_row_t previous_matrix[MATRIX_ROWS]; @@ -157,14 +27,8 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) { memcpy(previous_matrix, current_matrix, sizeof(previous_matrix)); for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { - if (current_row != 1) { - //default implementation for rows 0 and 2 - matrix_read_cols_on_row(current_matrix, current_row); - } - if (current_row == 1) { - //use ADC for row 1 - for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { - hall_effect_key_t *key = &keys[current_row][current_col]; + for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { + analog_key_t *key = &keys[current_row][current_col]; key->value = lut[analogReadPin(matrix_pins[current_row][current_col]) + key->offset]; key->value = MIN((key->value << 8) / lut[1100 + key->offset], 255); @@ -184,35 +48,6 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) { break; } } - } - } return memcmp(previous_matrix, current_matrix, sizeof(previous_matrix)) != 0; } - - -uint8_t matrix_scan(void) { - // TODO: add matrix scanning routine here - //matrix.c row 324 - //matrix_common.c row 169 - - bool changed = matrix_scan_custom(raw_matrix); - - // Unless hardware debouncing - use the configured debounce routine - changed = debounce(raw_matrix, matrix, MATRIX_ROWS, changed); - - // This *must* be called for correct keyboard behavior - matrix_scan_kb(); - - 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) {} - diff --git a/keyboards/momokai/tap_trio_pro/mcuconf.h b/keyboards/momokai/tap_trio_pro/mcuconf.h new file mode 100644 index 00000000000..b0e2bba2ded --- /dev/null +++ b/keyboards/momokai/tap_trio_pro/mcuconf.h @@ -0,0 +1,8 @@ +/* Copyright 2023 RephlexZero (@RephlexZero) +SPDX-License-Identifier: GPL-2.0-or-later */ +#pragma once + +#include_next + +#undef RP_I2C_USE_I2C1 +#define RP_I2C_USE_I2C1 TRUE \ No newline at end of file diff --git a/keyboards/momokai/tap_trio_pro/rules.mk b/keyboards/momokai/tap_trio_pro/rules.mk index 9de2c450db6..074558d5561 100644 --- a/keyboards/momokai/tap_trio_pro/rules.mk +++ b/keyboards/momokai/tap_trio_pro/rules.mk @@ -1,6 +1,6 @@ QUANTUM_LIB_SRC += analog.c SRC += matrix.c lut.c scanfunctions.c -CUSTOM_MATRIX = yes +CUSTOM_MATRIX = lite OPT = 3 diff --git a/keyboards/momokai/tap_trio_pro/scanfunctions.c b/keyboards/momokai/tap_trio_pro/scanfunctions.c index 5cd94a15173..e85b191fbb6 100644 --- a/keyboards/momokai/tap_trio_pro/scanfunctions.c +++ b/keyboards/momokai/tap_trio_pro/scanfunctions.c @@ -1,5 +1,4 @@ /* Copyright 2023 RephlexZero (@RephlexZero) -Copyright 2023 peepeetee SPDX-License-Identifier: GPL-2.0-or-later */ #include "quantum.h" #include "analog.h" @@ -8,16 +7,14 @@ SPDX-License-Identifier: GPL-2.0-or-later */ extern pin_t matrix_pins[MATRIX_ROWS][MATRIX_COLS]; void get_sensor_offsets(void) { uint16_t rest_adc_value = distance_to_adc(0); - // for (uint8_t i = 0; i < MATRIX_ROWS; i++) { - //do this for row 1 only - uint8_t i = 1; + for (uint8_t i = 0; i < MATRIX_ROWS; i++) { for (uint8_t j = 0; j < MATRIX_COLS; j++) { keys[i][j].offset = rest_adc_value - analogReadPin(matrix_pins[i][j]); } - // } + } } -void update_extremum(hall_effect_key_t *key) { +void update_extremum(analog_key_t *key) { key->extremum = key->value; } @@ -29,7 +26,7 @@ void deregister_key(matrix_row_t *current_row, uint8_t current_col) { *current_row &= ~(1 << current_col); } -void matrix_read_cols_static_actuation(matrix_row_t *current_row, uint8_t current_col, hall_effect_key_t *key) { +void matrix_read_cols_static_actuation(matrix_row_t *current_row, uint8_t current_col, analog_key_t *key) { if (*current_row & (1 << current_col)) { if (key->value < MAX(g_config.actuation_point - g_config.release_hysteresis, 0)) { deregister_key(current_row, current_col); @@ -47,7 +44,7 @@ assuming your sensor value decreases when the key is pressed, 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. */ -void matrix_read_cols_dynamic_actuation(matrix_row_t *current_row, uint8_t current_col, hall_effect_key_t *key) { +void matrix_read_cols_dynamic_actuation(matrix_row_t *current_row, uint8_t current_col, analog_key_t *key) { if (key->dynamic_actuation_bool) { if (*current_row & (1 << current_col)) { /* Key is pressed @@ -82,7 +79,7 @@ void matrix_read_cols_dynamic_actuation(matrix_row_t *current_row, uint8_t curre } } -void matrix_read_cols_continuous_dynamic_actuation(matrix_row_t *current_row, uint8_t current_col, hall_effect_key_t *key) { +void matrix_read_cols_continuous_dynamic_actuation(matrix_row_t *current_row, uint8_t current_col, analog_key_t *key) { if (key->dynamic_actuation_bool) { if (*current_row & (1 << current_col)) { /* Key is pressed diff --git a/keyboards/momokai/tap_trio_pro/scanfunctions.h b/keyboards/momokai/tap_trio_pro/scanfunctions.h index 7310d84a4f9..5417da46fab 100644 --- a/keyboards/momokai/tap_trio_pro/scanfunctions.h +++ b/keyboards/momokai/tap_trio_pro/scanfunctions.h @@ -6,7 +6,7 @@ SPDX-License-Identifier: GPL-2.0-or-later */ #include "quantum.h" #include "lut.h" -void update_extremum(hall_effect_key_t *key); +void update_extremum(analog_key_t *key); void register_key(matrix_row_t *current_row, uint8_t current_col); @@ -14,8 +14,8 @@ void deregister_key(matrix_row_t *current_row, uint8_t current_col); void get_sensor_offsets(void); -void matrix_read_cols_dynamic_actuation(matrix_row_t *current_row, uint8_t current_col, hall_effect_key_t *key); +void matrix_read_cols_dynamic_actuation(matrix_row_t *current_row, uint8_t current_col, analog_key_t *key); -void matrix_read_cols_continuous_dynamic_actuation(matrix_row_t *current_row, uint8_t current_col, hall_effect_key_t *key); +void matrix_read_cols_continuous_dynamic_actuation(matrix_row_t *current_row, uint8_t current_col, analog_key_t *key); -void matrix_read_cols_static_actuation(matrix_row_t *current_row, uint8_t current_col, hall_effect_key_t *key); \ No newline at end of file +void matrix_read_cols_static_actuation(matrix_row_t *current_row, uint8_t current_col, analog_key_t *key); diff --git a/keyboards/momokai/tap_trio_pro/tap_trio_pro.c b/keyboards/momokai/tap_trio_pro/tap_trio_pro.c index 1dcc1defbf1..d13be785e04 100644 --- a/keyboards/momokai/tap_trio_pro/tap_trio_pro.c +++ b/keyboards/momokai/tap_trio_pro/tap_trio_pro.c @@ -1,15 +1,18 @@ /* Copyright 2023 RephlexZero (@RephlexZero) peepeetee (@peepeetee) SPDX-License-Identifier: GPL-2.0-or-later */ #include +#include #include #include "tap_trio_pro.h" #include "quantum.h" #include "analog.h" #include "eeprom.h" #include "scanfunctions.h" +#include "print.h" + analog_config g_config = { - .mode = static_actuation, + .mode = dynamic_actuation, .actuation_point = 32, .press_sensitivity = 32, .release_sensitivity = 32, @@ -17,53 +20,42 @@ analog_config g_config = { .release_hysteresis = 5 }; +#ifdef BOOTMAGIC_ENABLE extern pin_t matrix_pins[MATRIX_ROWS][MATRIX_COLS]; - -// void bootmagic_lite(void) { -// if (BOOTMAGIC_LITE_ROW == 1) { -// if (analogReadPin(matrix_pins[BOOTMAGIC_LITE_ROW][BOOTMAGIC_LITE_COLUMN]) < 1350) { -// bootloader_jump(); -// } -// } -// else { -// // default implementation - -// // We need multiple scans because debouncing can't be turned off. -// matrix_scan(); -// #if defined(DEBOUNCE) && DEBOUNCE > 0 -// wait_ms(DEBOUNCE * 2); -// #else -// wait_ms(30); -// #endif -// matrix_scan(); - -// // If the configured key (commonly Esc) is held down on power up, -// // reset the EEPROM valid state and jump to bootloader. -// // This isn't very generalized, but we need something that doesn't -// // rely on user's keymaps in firmware or EEPROM. -// uint8_t row = BOOTMAGIC_LITE_ROW; -// uint8_t col = BOOTMAGIC_LITE_COLUMN; - -// #if defined(SPLIT_KEYBOARD) && defined(BOOTMAGIC_LITE_ROW_RIGHT) && defined(BOOTMAGIC_LITE_COLUMN_RIGHT) -// if (!is_keyboard_left()) { -// row = BOOTMAGIC_LITE_ROW_RIGHT; -// col = BOOTMAGIC_LITE_COLUMN_RIGHT; -// } -// #endif - -// if (matrix_get_row(row) & (1 << col)) { -// bootmagic_lite_reset_eeprom(); - -// // Jump to bootloader. -// bootloader_jump(); -// } -// } -// } - -uint32_t idle_recalibrate_callback(uint32_t trigger_time, void *cb_arg) { - get_sensor_offsets(); - return 10000; +void bootmagic_lite(void) { + if (analogReadPin(matrix_pins[BOOTMAGIC_LITE_ROW][BOOTMAGIC_LITE_COLUMN]) < 1350) { + bootloader_jump(); + } } +#endif + +#ifdef DEFERRED_EXEC_ENABLE + +# ifdef DEBUG_ENABLE +deferred_token debug_token; +bool debug_print(void) { + char buffer[MATRIX_ROWS * MATRIX_COLS * 5 + MATRIX_ROWS * 2]; + buffer[0] = '\0'; + + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + analog_key_t *key = &keys[row][col]; + char temp[6]; + snprintf(temp, sizeof(temp), "%5u", key->value); + strcat(buffer, temp); + } + strcat(buffer, "\n"); + } + + uprintf("Analog values:\n%s", buffer); + return true; +} + +uint32_t debug_print_callback(uint32_t trigger_time, void *cb_arg) { + debug_print(); + return 25; +} +# endif deferred_token idle_recalibrate_token; bool process_record_kb(uint16_t keycode, keyrecord_t *record) { @@ -71,24 +63,9 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) { return true; } -#ifdef DEBUG_ENABLE -static uint8_t i = 0; -void housekeeping_task_kb(void) { - if (i == 0) { - char formattedString[200]; // Adjust the buffer size as needed - - snprintf(formattedString, sizeof(formattedString), "Mode: %d Actuation Point: %d Press/Release Sensitivity: %d/%d\n", g_config.mode, g_config.actuation_point, g_config.press_sensitivity, g_config.release_sensitivity); - - for (uint8_t row = 0; row < MATRIX_ROWS; row++) { - for (uint8_t col = 0; col < MATRIX_COLS; col++) { - snprintf(formattedString + strlen(formattedString), sizeof(formattedString) - strlen(formattedString), "%d/%d/%d ", keys[row][col].value, keys[row][col].extremum, analogReadPin(matrix_pins[row][col])); - } - strcat(formattedString, "\n\n"); - } - - uprintf("%s", formattedString); - } - i++; +uint32_t idle_recalibrate_callback(uint32_t trigger_time, void *cb_arg) { + get_sensor_offsets(); + return 10000; } #endif @@ -100,14 +77,19 @@ void values_save(void) { eeconfig_update_kb_datablock(&g_config); } -// void eeconfig_init_kb() { -// values_save(); -// } +void eeconfig_init_kb() { + values_save(); +} -// void keyboard_post_init_kb(void) { -// idle_recalibrate_token = defer_exec(300000, idle_recalibrate_callback, NULL); -// values_load(); -// } +void keyboard_post_init_kb(void) { +#ifdef DEFERRED_EXEC_ENABLE +# ifdef DEBUG_ENABLE + debug_token = defer_exec(1000, debug_print_callback, NULL); +# endif + idle_recalibrate_token = defer_exec(300000, idle_recalibrate_callback, NULL); +#endif + values_load(); +} #ifdef VIA_ENABLE void via_custom_value_command_kb(uint8_t *data, uint8_t length) { From 9e48bf3cb0da96ae2d564b9441b1d84d673e57fb Mon Sep 17 00:00:00 2001 From: peepeetee Date: Tue, 16 Jan 2024 23:09:50 -0600 Subject: [PATCH 11/43] add more testing infrastructure, changes the analog key datatype --- keyboards/momokai/tap_trio_pro/Scratchpad.md | 1 + keyboards/momokai/tap_trio_pro/analogkeys.h | 5 +++-- keyboards/momokai/tap_trio_pro/config.h | 2 +- .../tap_trio_pro/keymaps/blank/keymap.c | 19 +++++++++++++++++++ .../tap_trio_pro/keymaps/blank/rules.mk | 1 + keyboards/momokai/tap_trio_pro/lut.c | 2 +- keyboards/momokai/tap_trio_pro/matrix.c | 16 ++++++++++++++-- .../momokai/tap_trio_pro/scanfunctions.c | 12 ++++++------ .../momokai/tap_trio_pro/scanfunctions.h | 8 ++++---- keyboards/momokai/tap_trio_pro/tap_trio_pro.c | 14 ++++++++------ 10 files changed, 58 insertions(+), 22 deletions(-) create mode 100644 keyboards/momokai/tap_trio_pro/keymaps/blank/keymap.c create mode 100644 keyboards/momokai/tap_trio_pro/keymaps/blank/rules.mk diff --git a/keyboards/momokai/tap_trio_pro/Scratchpad.md b/keyboards/momokai/tap_trio_pro/Scratchpad.md index 52b1cc05657..7700a1e7958 100644 --- a/keyboards/momokai/tap_trio_pro/Scratchpad.md +++ b/keyboards/momokai/tap_trio_pro/Scratchpad.md @@ -2,3 +2,4 @@ as of 126dc933b203435abb76081603b8fa7978f4181d the SMD keys no longer work at the start, all keys are outputted in order --> initialization or infinite loop +analogReadPin limits our options, I would like to change hybrid_key_t to include weather it is a hall effect key diff --git a/keyboards/momokai/tap_trio_pro/analogkeys.h b/keyboards/momokai/tap_trio_pro/analogkeys.h index 8e138293615..44a908de265 100644 --- a/keyboards/momokai/tap_trio_pro/analogkeys.h +++ b/keyboards/momokai/tap_trio_pro/analogkeys.h @@ -21,6 +21,7 @@ typedef struct { uint8_t value; uint8_t extremum; int16_t offset; + bool is_analog; bool dynamic_actuation_bool; -} analog_key_t; -extern analog_key_t keys[MATRIX_ROWS][MATRIX_COLS]; +} hybrid_key_t; +extern hybrid_key_t keys[MATRIX_ROWS][MATRIX_COLS]; diff --git a/keyboards/momokai/tap_trio_pro/config.h b/keyboards/momokai/tap_trio_pro/config.h index 24af395e9cd..469a829fa92 100644 --- a/keyboards/momokai/tap_trio_pro/config.h +++ b/keyboards/momokai/tap_trio_pro/config.h @@ -8,7 +8,7 @@ #define EECONFIG_KB_DATA_SIZE 6 #define DEBUG_ENABLE -#define DEBUG_MATRIX_SCAN_RATE +// #define DEBUG_MATRIX_SCAN_RATE #define ADC_RESOLUTION 12 diff --git a/keyboards/momokai/tap_trio_pro/keymaps/blank/keymap.c b/keyboards/momokai/tap_trio_pro/keymaps/blank/keymap.c new file mode 100644 index 00000000000..e1796ecabb9 --- /dev/null +++ b/keyboards/momokai/tap_trio_pro/keymaps/blank/keymap.c @@ -0,0 +1,19 @@ +// Copyright 2023 peepeetee +// SPDX-License-Identifier: GPL-2.0-or-later + +#include QMK_KEYBOARD_H + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [0] = LAYOUT( + KC_MUTE, + KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS + ) +}; + +#if defined(ENCODER_MAP_ENABLE) +const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = { + [0] = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU) } + +}; +#endif diff --git a/keyboards/momokai/tap_trio_pro/keymaps/blank/rules.mk b/keyboards/momokai/tap_trio_pro/keymaps/blank/rules.mk new file mode 100644 index 00000000000..ee325681483 --- /dev/null +++ b/keyboards/momokai/tap_trio_pro/keymaps/blank/rules.mk @@ -0,0 +1 @@ +ENCODER_MAP_ENABLE = yes diff --git a/keyboards/momokai/tap_trio_pro/lut.c b/keyboards/momokai/tap_trio_pro/lut.c index 0f87156ac91..bc1143268cd 100644 --- a/keyboards/momokai/tap_trio_pro/lut.c +++ b/keyboards/momokai/tap_trio_pro/lut.c @@ -25,4 +25,4 @@ void generate_lut(void) { for (uint16_t i = 0; i < a - d; i++) { lut[i] = adc_to_distance(i); } -} \ No newline at end of file +} diff --git a/keyboards/momokai/tap_trio_pro/matrix.c b/keyboards/momokai/tap_trio_pro/matrix.c index 08fe92a723b..9544e4dd178 100644 --- a/keyboards/momokai/tap_trio_pro/matrix.c +++ b/keyboards/momokai/tap_trio_pro/matrix.c @@ -12,9 +12,12 @@ SPDX-License-Identifier: GPL-2.0-or-later */ pin_t matrix_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; -analog_key_t keys[MATRIX_ROWS][MATRIX_COLS] = {0}; +hybrid_key_t keys[MATRIX_ROWS][MATRIX_COLS] = {0}; void matrix_init_custom(void) { + for (uint8_t i = 0; i < MATRIX_COLS; i++) { + keys[1][i].is_analog = true; + } generate_lut(); get_sensor_offsets(); wait_ms(100); // Let ADC reach steady state @@ -23,13 +26,22 @@ void matrix_init_custom(void) { matrix_row_t previous_matrix[MATRIX_ROWS]; +//matrix_row_t is an alias for u_int8_t + + bool matrix_scan_custom(matrix_row_t current_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_col = 0; current_col < MATRIX_COLS; current_col++) { - analog_key_t *key = &keys[current_row][current_col]; + hybrid_key_t *key = &keys[current_row][current_col]; + + // TODO: current row has to be 1!!!!!!!!!! + + key->value = lut[analogReadPin(matrix_pins[current_row][current_col]) + key->offset]; + //limits our options, I would like to change hybrid_key_t to include weather it is a hall effect key + key->value = MIN((key->value << 8) / lut[1100 + key->offset], 255); switch (g_config.mode) { diff --git a/keyboards/momokai/tap_trio_pro/scanfunctions.c b/keyboards/momokai/tap_trio_pro/scanfunctions.c index e85b191fbb6..96efe969e2e 100644 --- a/keyboards/momokai/tap_trio_pro/scanfunctions.c +++ b/keyboards/momokai/tap_trio_pro/scanfunctions.c @@ -14,7 +14,7 @@ void get_sensor_offsets(void) { } } -void update_extremum(analog_key_t *key) { +void update_extremum(hybrid_key_t *key) { key->extremum = key->value; } @@ -26,12 +26,12 @@ void deregister_key(matrix_row_t *current_row, uint8_t current_col) { *current_row &= ~(1 << current_col); } -void matrix_read_cols_static_actuation(matrix_row_t *current_row, uint8_t current_col, analog_key_t *key) { - if (*current_row & (1 << current_col)) { +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 (key->value < MAX(g_config.actuation_point - g_config.release_hysteresis, 0)) { deregister_key(current_row, current_col); } - } else { + } else { //if the key is currently not pressed if (key->value > MIN(g_config.actuation_point + g_config.press_hysteresis, 255)) { register_key(current_row, current_col); } @@ -44,7 +44,7 @@ assuming your sensor value decreases when the key is pressed, 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. */ -void matrix_read_cols_dynamic_actuation(matrix_row_t *current_row, uint8_t current_col, analog_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 (*current_row & (1 << current_col)) { /* Key is pressed @@ -79,7 +79,7 @@ void matrix_read_cols_dynamic_actuation(matrix_row_t *current_row, uint8_t curre } } -void matrix_read_cols_continuous_dynamic_actuation(matrix_row_t *current_row, uint8_t current_col, analog_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 (*current_row & (1 << current_col)) { /* Key is pressed diff --git a/keyboards/momokai/tap_trio_pro/scanfunctions.h b/keyboards/momokai/tap_trio_pro/scanfunctions.h index 5417da46fab..f44a1f0aa22 100644 --- a/keyboards/momokai/tap_trio_pro/scanfunctions.h +++ b/keyboards/momokai/tap_trio_pro/scanfunctions.h @@ -6,7 +6,7 @@ SPDX-License-Identifier: GPL-2.0-or-later */ #include "quantum.h" #include "lut.h" -void update_extremum(analog_key_t *key); +void update_extremum(hybrid_key_t *key); void register_key(matrix_row_t *current_row, uint8_t current_col); @@ -14,8 +14,8 @@ void deregister_key(matrix_row_t *current_row, uint8_t current_col); void get_sensor_offsets(void); -void matrix_read_cols_dynamic_actuation(matrix_row_t *current_row, uint8_t current_col, analog_key_t *key); +void matrix_read_cols_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, analog_key_t *key); +void matrix_read_cols_continuous_dynamic_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, analog_key_t *key); +void matrix_read_cols_static_actuation(matrix_row_t *current_row, uint8_t current_col, hybrid_key_t *key); diff --git a/keyboards/momokai/tap_trio_pro/tap_trio_pro.c b/keyboards/momokai/tap_trio_pro/tap_trio_pro.c index d13be785e04..1999caca1e0 100644 --- a/keyboards/momokai/tap_trio_pro/tap_trio_pro.c +++ b/keyboards/momokai/tap_trio_pro/tap_trio_pro.c @@ -34,20 +34,22 @@ void bootmagic_lite(void) { # ifdef DEBUG_ENABLE deferred_token debug_token; bool debug_print(void) { - char buffer[MATRIX_ROWS * MATRIX_COLS * 5 + MATRIX_ROWS * 2]; + uint8_t hall_effect_rows = 1; + char buffer[hall_effect_rows * MATRIX_COLS * 5 + MATRIX_ROWS * 2]; buffer[0] = '\0'; - for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + // for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + uint8_t row = 1; for (uint8_t col = 0; col < MATRIX_COLS; col++) { - analog_key_t *key = &keys[row][col]; + hybrid_key_t *key = &keys[row][col]; char temp[6]; snprintf(temp, sizeof(temp), "%5u", key->value); strcat(buffer, temp); } - strcat(buffer, "\n"); - } + strcat(buffer, "\n"); + // } - uprintf("Analog values:\n%s", buffer); + uprintf("%s", buffer); return true; } From 6c5f12cc79fd5257026c66b83bfb321daf63e451 Mon Sep 17 00:00:00 2001 From: peepeetee Date: Sat, 20 Jan 2024 05:27:54 -0600 Subject: [PATCH 12/43] figured out how to test print to console --- keyboards/momokai/tap_trio_pro/matrix.c | 82 +++++++++++++------ .../momokai/tap_trio_pro/scanfunctions.c | 6 ++ keyboards/momokai/tap_trio_pro/tap_trio_pro.c | 7 +- 3 files changed, 68 insertions(+), 27 deletions(-) diff --git a/keyboards/momokai/tap_trio_pro/matrix.c b/keyboards/momokai/tap_trio_pro/matrix.c index 9544e4dd178..25480993127 100644 --- a/keyboards/momokai/tap_trio_pro/matrix.c +++ b/keyboards/momokai/tap_trio_pro/matrix.c @@ -10,14 +10,21 @@ SPDX-License-Identifier: GPL-2.0-or-later */ #include "lut.h" #include "scanfunctions.h" -pin_t matrix_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; +#ifndef MATRIX_INPUT_PRESSED_STATE +# define MATRIX_INPUT_PRESSED_STATE 0 +#endif -hybrid_key_t keys[MATRIX_ROWS][MATRIX_COLS] = {0}; +pin_t matrix_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; + +hybrid_key_t keys[MATRIX_ROWS][MATRIX_COLS] = {0}; void matrix_init_custom(void) { + + wait_ms(3500); //give time to try to have hid_listen spin up for (uint8_t i = 0; i < MATRIX_COLS; i++) { - keys[1][i].is_analog = true; + keys[1][i].is_analog = true; } + printf("%s", "test print at start of matrix init\n"); generate_lut(); get_sensor_offsets(); wait_ms(100); // Let ADC reach steady state @@ -26,38 +33,65 @@ void matrix_init_custom(void) { matrix_row_t previous_matrix[MATRIX_ROWS]; -//matrix_row_t is an alias for u_int8_t +// matrix_row_t is an alias for u_int8_t +static inline uint8_t readMatrixPin(pin_t pin) { + if (pin != NO_PIN) { + return (readPin(pin) == MATRIX_INPUT_PRESSED_STATE) ? 0 : 1; + } else { + return 1; + } +} + +__attribute__((weak)) 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; +} bool matrix_scan_custom(matrix_row_t current_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_col = 0; current_col < MATRIX_COLS; current_col++) { - hybrid_key_t *key = &keys[current_row][current_col]; + if (keys[current_row][0].is_analog == false) { + // matrix_read_cols_on_row(current_matrix, current_row); - // TODO: current row has to be 1!!!!!!!!!! + } + else { + for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { + hybrid_key_t *key = &keys[current_row][current_col]; - key->value = lut[analogReadPin(matrix_pins[current_row][current_col]) + key->offset]; - //limits our options, I would like to change hybrid_key_t to include weather it is a hall effect key + // TODO: current row has to be 1!!!!!!!!!! - key->value = MIN((key->value << 8) / lut[1100 + key->offset], 255); + key->value = lut[analogReadPin(matrix_pins[current_row][current_col]) + key->offset]; + // limits our options, I would like to change hybrid_key_t to include weather it is a hall effect key - switch (g_config.mode) { - case dynamic_actuation: - matrix_read_cols_dynamic_actuation(¤t_matrix[current_row], current_col, key); - break; - case continuous_dynamic_actuation: - matrix_read_cols_continuous_dynamic_actuation(¤t_matrix[current_row], current_col, key); - break; - case static_actuation: - matrix_read_cols_static_actuation(¤t_matrix[current_row], current_col, key); - break; - case flashing: - default: - bootloader_jump(); - break; + key->value = MIN((key->value << 8) / lut[1100 + key->offset], 255); + + switch (g_config.mode) { + case dynamic_actuation: + matrix_read_cols_dynamic_actuation(¤t_matrix[current_row], current_col, key); + break; + case continuous_dynamic_actuation: + matrix_read_cols_continuous_dynamic_actuation(¤t_matrix[current_row], current_col, key); + break; + case static_actuation: + matrix_read_cols_static_actuation(¤t_matrix[current_row], current_col, key); + break; + case flashing: + default: + bootloader_jump(); + break; + } } } } diff --git a/keyboards/momokai/tap_trio_pro/scanfunctions.c b/keyboards/momokai/tap_trio_pro/scanfunctions.c index 96efe969e2e..c5ee0e818c7 100644 --- a/keyboards/momokai/tap_trio_pro/scanfunctions.c +++ b/keyboards/momokai/tap_trio_pro/scanfunctions.c @@ -5,17 +5,23 @@ SPDX-License-Identifier: GPL-2.0-or-later */ #include "scanfunctions.h" extern pin_t matrix_pins[MATRIX_ROWS][MATRIX_COLS]; + + void get_sensor_offsets(void) { uint16_t rest_adc_value = distance_to_adc(0); for (uint8_t i = 0; i < MATRIX_ROWS; i++) { for (uint8_t j = 0; j < MATRIX_COLS; j++) { + if (keys[i][j].is_analog) { keys[i][j].offset = rest_adc_value - analogReadPin(matrix_pins[i][j]); + } } } } void update_extremum(hybrid_key_t *key) { + if (key->is_analog){ key->extremum = key->value; + } } void register_key(matrix_row_t *current_row, uint8_t current_col) { diff --git a/keyboards/momokai/tap_trio_pro/tap_trio_pro.c b/keyboards/momokai/tap_trio_pro/tap_trio_pro.c index 1999caca1e0..b8354cbab43 100644 --- a/keyboards/momokai/tap_trio_pro/tap_trio_pro.c +++ b/keyboards/momokai/tap_trio_pro/tap_trio_pro.c @@ -12,11 +12,11 @@ SPDX-License-Identifier: GPL-2.0-or-later */ analog_config g_config = { - .mode = dynamic_actuation, + .mode = static_actuation, .actuation_point = 32, .press_sensitivity = 32, .release_sensitivity = 32, - .press_hysteresis = 0, + .press_hysteresis = 5, .release_hysteresis = 5 }; @@ -50,11 +50,12 @@ bool debug_print(void) { // } uprintf("%s", buffer); + return true; } uint32_t debug_print_callback(uint32_t trigger_time, void *cb_arg) { - debug_print(); + // debug_print(); return 25; } # endif From 708b97921287714adc29c9253ea35409e53eefed Mon Sep 17 00:00:00 2001 From: peepeetee Date: Sun, 21 Jan 2024 02:24:06 -0600 Subject: [PATCH 13/43] turn debounce on, add some test prints --- keyboards/momokai/tap_trio_pro/info.json | 1 - keyboards/momokai/tap_trio_pro/matrix.c | 45 ++++++++++++++++++- .../momokai/tap_trio_pro/scanfunctions.c | 1 + 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/keyboards/momokai/tap_trio_pro/info.json b/keyboards/momokai/tap_trio_pro/info.json index 3eaa3fe825f..2e67d6fa211 100644 --- a/keyboards/momokai/tap_trio_pro/info.json +++ b/keyboards/momokai/tap_trio_pro/info.json @@ -28,7 +28,6 @@ ] }, - "debounce": 0, "processor": "RP2040", "url": "", diff --git a/keyboards/momokai/tap_trio_pro/matrix.c b/keyboards/momokai/tap_trio_pro/matrix.c index 25480993127..a76eb8f6243 100644 --- a/keyboards/momokai/tap_trio_pro/matrix.c +++ b/keyboards/momokai/tap_trio_pro/matrix.c @@ -21,13 +21,54 @@ hybrid_key_t keys[MATRIX_ROWS][MATRIX_COLS] = {0}; void matrix_init_custom(void) { wait_ms(3500); //give time to try to have hid_listen spin up + + printf("%s\n", "test print at start of matrix init"); + wait_ms(250); + + + // printf("%s\n", "2nd test print at start of matrix init"); + // wait_ms(250); + // printf("%u\n", MATRIX_COLS); + // wait_ms(250); + // printf("%u\n", MATRIX_ROWS); + // wait_ms(250); + // for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + // for (uint8_t col = 0; col < MATRIX_COLS; col++) { + // printf("%lu\n", matrix_pins[row][col]); + // wait_ms(250); + // } + // wait_ms(250); + // printf("\n"); + // } + + // wait_ms(250); + + + for (uint8_t i = 0; i < MATRIX_COLS; i++) { keys[1][i].is_analog = true; } - printf("%s", "test print at start of matrix init\n"); + + // for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + // for (uint8_t col = 0; col < MATRIX_COLS; col++) { + + // printf("keys[%u][%u].value = %u\n", row, col, keys[row][col].value); + // wait_ms(250); + // printf("keys[%u][%u].extremum = %u\n", row, col, keys[row][col].extremum); + // wait_ms(250); + // printf("keys[%u][%u].offset = %u\n", row, col, keys[row][col].offset); + // wait_ms(250); + // printf("keys[%u][%u].is_analog = %s\n", row, col, keys[row][col].is_analog ? "true" : "false"); + // wait_ms(250); + // printf("keys[%u][%u].dynamic_actuation_bool = %s\n", row, col, keys[row][col].dynamic_actuation_bool ? "true" : "false"); + // } + // wait_ms(250); + // printf("\n"); + // } + generate_lut(); get_sensor_offsets(); - wait_ms(100); // Let ADC reach steady state + wait_ms(200); // Let ADC reach steady state get_sensor_offsets(); } diff --git a/keyboards/momokai/tap_trio_pro/scanfunctions.c b/keyboards/momokai/tap_trio_pro/scanfunctions.c index c5ee0e818c7..f14af7b4173 100644 --- a/keyboards/momokai/tap_trio_pro/scanfunctions.c +++ b/keyboards/momokai/tap_trio_pro/scanfunctions.c @@ -13,6 +13,7 @@ void get_sensor_offsets(void) { for (uint8_t j = 0; j < MATRIX_COLS; j++) { if (keys[i][j].is_analog) { keys[i][j].offset = rest_adc_value - analogReadPin(matrix_pins[i][j]); + printf("Offset: %d\n", keys[i][j].offset); } } } From 0f4a4e25cdfbfcc010c48c0d06f4b0d97e42bc75 Mon Sep 17 00:00:00 2001 From: peepeetee Date: Wed, 24 Jan 2024 22:32:33 -0600 Subject: [PATCH 14/43] playing with debounce --- keyboards/momokai/tap_trio_pro/config.h | 1 + keyboards/momokai/tap_trio_pro/debounce.c | 150 ++++++++++++++++++++++ keyboards/momokai/tap_trio_pro/rules.mk | 3 + 3 files changed, 154 insertions(+) create mode 100644 keyboards/momokai/tap_trio_pro/debounce.c diff --git a/keyboards/momokai/tap_trio_pro/config.h b/keyboards/momokai/tap_trio_pro/config.h index 469a829fa92..7f3ac385716 100644 --- a/keyboards/momokai/tap_trio_pro/config.h +++ b/keyboards/momokai/tap_trio_pro/config.h @@ -14,3 +14,4 @@ #define CALIBRATION_RANGE 255 +#define DEBOUNCE 16 diff --git a/keyboards/momokai/tap_trio_pro/debounce.c b/keyboards/momokai/tap_trio_pro/debounce.c new file mode 100644 index 00000000000..f4723db46d0 --- /dev/null +++ b/keyboards/momokai/tap_trio_pro/debounce.c @@ -0,0 +1,150 @@ +/* +Copyright 2017 Alex Ong +Copyright 2021 Simon Arlott +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +/* +Basic per-key algorithm. Uses an 8-bit counter per key. +After pressing a key, it immediately changes state, and sets a counter. +No further inputs are accepted until DEBOUNCE milliseconds have occurred. +*/ + +#include "debounce.h" +#include "timer.h" +#include + +#ifdef PROTOCOL_CHIBIOS +# if CH_CFG_USE_MEMCORE == FALSE +# error ChibiOS is configured without a memory allocator. Your keyboard may have set `#define CH_CFG_USE_MEMCORE FALSE`, which is incompatible with this debounce algorithm. +# endif +#endif + +#ifndef DEBOUNCE +# define DEBOUNCE 255 +#endif + +// Maximum debounce: 255ms +#if DEBOUNCE > UINT8_MAX +# undef DEBOUNCE +# define DEBOUNCE UINT8_MAX +#endif + +#define ROW_SHIFTER ((matrix_row_t)1) + +typedef uint8_t debounce_counter_t; + +#if DEBOUNCE > 0 +static debounce_counter_t *debounce_counters; +static fast_timer_t last_time; +static bool counters_need_update; +static bool matrix_need_update; +static bool cooked_changed; + +# define DEBOUNCE_ELAPSED 0 + +static void update_debounce_counters(uint8_t num_rows, uint8_t elapsed_time); +static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows); + +// we use num_rows rather than MATRIX_ROWS to support split keyboards +void debounce_init(uint8_t num_rows) { + debounce_counters = (debounce_counter_t *)malloc(num_rows * MATRIX_COLS * sizeof(debounce_counter_t)); + int i = 0; + for (uint8_t r = 0; r < num_rows; r++) { + for (uint8_t c = 0; c < MATRIX_COLS; c++) { + debounce_counters[i++] = DEBOUNCE_ELAPSED; + } + } +} + +void debounce_free(void) { + free(debounce_counters); + debounce_counters = NULL; +} + +bool debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) { + bool updated_last = false; + cooked_changed = false; + + if (counters_need_update) { + fast_timer_t now = timer_read_fast(); + fast_timer_t elapsed_time = TIMER_DIFF_FAST(now, last_time); + + last_time = now; + updated_last = true; + if (elapsed_time > UINT8_MAX) { + elapsed_time = UINT8_MAX; + } + + if (elapsed_time > 0) { + update_debounce_counters(num_rows, elapsed_time); + } + } + + if (changed || matrix_need_update) { + if (!updated_last) { + last_time = timer_read_fast(); + } + + transfer_matrix_values(raw, cooked, num_rows); + } + + return cooked_changed; +} + +// If the current time is > debounce counter, set the counter to enable input. +static void update_debounce_counters(uint8_t num_rows, uint8_t elapsed_time) { + counters_need_update = false; + matrix_need_update = false; + debounce_counter_t *debounce_pointer = debounce_counters; + for (uint8_t row = 0; row < num_rows; row++) { + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + if (*debounce_pointer != DEBOUNCE_ELAPSED) { + if (*debounce_pointer <= elapsed_time) { + *debounce_pointer = DEBOUNCE_ELAPSED; + matrix_need_update = true; + } else { + *debounce_pointer -= elapsed_time; + counters_need_update = true; + } + } + debounce_pointer++; + } + } +} + +// upload from raw_matrix to final matrix; +static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows) { + matrix_need_update = false; + debounce_counter_t *debounce_pointer = debounce_counters; + for (uint8_t row = 0; row < num_rows; row++) { + matrix_row_t delta = raw[row] ^ cooked[row]; + matrix_row_t existing_row = cooked[row]; + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + matrix_row_t col_mask = (ROW_SHIFTER << col); + if (delta & col_mask) { + if (*debounce_pointer == DEBOUNCE_ELAPSED) { + *debounce_pointer = DEBOUNCE; + counters_need_update = true; + existing_row ^= col_mask; // flip the bit. + cooked_changed = true; + } + } + debounce_pointer++; + } + cooked[row] = existing_row; + } +} + +#else +# include "none.c" +#endif diff --git a/keyboards/momokai/tap_trio_pro/rules.mk b/keyboards/momokai/tap_trio_pro/rules.mk index 074558d5561..68309ad1185 100644 --- a/keyboards/momokai/tap_trio_pro/rules.mk +++ b/keyboards/momokai/tap_trio_pro/rules.mk @@ -1,6 +1,9 @@ QUANTUM_LIB_SRC += analog.c SRC += matrix.c lut.c scanfunctions.c +# debounce.c CUSTOM_MATRIX = lite +# DEBOUNCE_TYPE = custom + OPT = 3 From d2ab532f737626e6861a4c8bb88d10ff30169878 Mon Sep 17 00:00:00 2001 From: peepeetee Date: Thu, 8 Feb 2024 15:19:29 -0600 Subject: [PATCH 15/43] stashing changes --- keyboards/momokai/tap_trio_pro/debounce.c | 44 ++++++++++------------- keyboards/momokai/tap_trio_pro/rules.mk | 5 ++- 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/keyboards/momokai/tap_trio_pro/debounce.c b/keyboards/momokai/tap_trio_pro/debounce.c index f4723db46d0..156535a3733 100644 --- a/keyboards/momokai/tap_trio_pro/debounce.c +++ b/keyboards/momokai/tap_trio_pro/debounce.c @@ -1,5 +1,6 @@ /* Copyright 2017 Alex Ong +Copyright 2020 Andrei Purdea Copyright 2021 Simon Arlott This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -14,9 +15,8 @@ along with this program. If not, see . */ /* -Basic per-key algorithm. Uses an 8-bit counter per key. -After pressing a key, it immediately changes state, and sets a counter. -No further inputs are accepted until DEBOUNCE milliseconds have occurred. +Basic symmetric per-key algorithm. Uses an 8-bit counter per key. +When no state changes have occured for DEBOUNCE milliseconds, we push the state. */ #include "debounce.h" @@ -30,7 +30,7 @@ No further inputs are accepted until DEBOUNCE milliseconds have occurred. #endif #ifndef DEBOUNCE -# define DEBOUNCE 255 +# define DEBOUNCE 5 #endif // Maximum debounce: 255ms @@ -47,13 +47,12 @@ typedef uint8_t debounce_counter_t; static debounce_counter_t *debounce_counters; static fast_timer_t last_time; static bool counters_need_update; -static bool matrix_need_update; static bool cooked_changed; # define DEBOUNCE_ELAPSED 0 -static void update_debounce_counters(uint8_t num_rows, uint8_t elapsed_time); -static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows); +static void update_debounce_counters_and_transfer_if_expired(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t elapsed_time); +static void start_debounce_counters(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows); // we use num_rows rather than MATRIX_ROWS to support split keyboards void debounce_init(uint8_t num_rows) { @@ -86,32 +85,32 @@ bool debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool } if (elapsed_time > 0) { - update_debounce_counters(num_rows, elapsed_time); + update_debounce_counters_and_transfer_if_expired(raw, cooked, num_rows, elapsed_time); } } - if (changed || matrix_need_update) { + if (changed) { if (!updated_last) { last_time = timer_read_fast(); } - transfer_matrix_values(raw, cooked, num_rows); + start_debounce_counters(raw, cooked, num_rows); } return cooked_changed; } -// If the current time is > debounce counter, set the counter to enable input. -static void update_debounce_counters(uint8_t num_rows, uint8_t elapsed_time) { +static void update_debounce_counters_and_transfer_if_expired(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t elapsed_time) { counters_need_update = false; - matrix_need_update = false; debounce_counter_t *debounce_pointer = debounce_counters; for (uint8_t row = 0; row < num_rows; row++) { for (uint8_t col = 0; col < MATRIX_COLS; col++) { if (*debounce_pointer != DEBOUNCE_ELAPSED) { if (*debounce_pointer <= elapsed_time) { - *debounce_pointer = DEBOUNCE_ELAPSED; - matrix_need_update = true; + *debounce_pointer = DEBOUNCE_ELAPSED; + matrix_row_t cooked_next = (cooked[row] & ~(ROW_SHIFTER << col)) | (raw[row] & (ROW_SHIFTER << col)); + cooked_changed |= cooked[row] ^ cooked_next; + cooked[row] = cooked_next; } else { *debounce_pointer -= elapsed_time; counters_need_update = true; @@ -122,26 +121,21 @@ static void update_debounce_counters(uint8_t num_rows, uint8_t elapsed_time) { } } -// upload from raw_matrix to final matrix; -static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows) { - matrix_need_update = false; +static void start_debounce_counters(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows) { debounce_counter_t *debounce_pointer = debounce_counters; for (uint8_t row = 0; row < num_rows; row++) { - matrix_row_t delta = raw[row] ^ cooked[row]; - matrix_row_t existing_row = cooked[row]; + matrix_row_t delta = raw[row] ^ cooked[row]; for (uint8_t col = 0; col < MATRIX_COLS; col++) { - matrix_row_t col_mask = (ROW_SHIFTER << col); - if (delta & col_mask) { + if (delta & (ROW_SHIFTER << col)) { if (*debounce_pointer == DEBOUNCE_ELAPSED) { *debounce_pointer = DEBOUNCE; counters_need_update = true; - existing_row ^= col_mask; // flip the bit. - cooked_changed = true; } + } else { + *debounce_pointer = DEBOUNCE_ELAPSED; } debounce_pointer++; } - cooked[row] = existing_row; } } diff --git a/keyboards/momokai/tap_trio_pro/rules.mk b/keyboards/momokai/tap_trio_pro/rules.mk index 68309ad1185..a0995187ba5 100644 --- a/keyboards/momokai/tap_trio_pro/rules.mk +++ b/keyboards/momokai/tap_trio_pro/rules.mk @@ -1,9 +1,8 @@ QUANTUM_LIB_SRC += analog.c -SRC += matrix.c lut.c scanfunctions.c -# debounce.c +SRC += matrix.c lut.c scanfunctions.c debounce.c CUSTOM_MATRIX = lite -# DEBOUNCE_TYPE = custom +DEBOUNCE_TYPE = custom OPT = 3 From 71295118c7e51fe81c96ed318db7b4f79b65b74d Mon Sep 17 00:00:00 2001 From: peepeetee Date: Sat, 17 Feb 2024 16:47:15 -0600 Subject: [PATCH 16/43] continue refactoring keypress handling --- .../momokai/tap_trio_pro/debounce_analog.c | 0 .../{debounce.c => debounce_digital.c} | 0 keyboards/momokai/tap_trio_pro/matrix.c | 40 +++++++++++++++++++ keyboards/momokai/tap_trio_pro/rules.mk | 4 +- 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 keyboards/momokai/tap_trio_pro/debounce_analog.c rename keyboards/momokai/tap_trio_pro/{debounce.c => debounce_digital.c} (100%) diff --git a/keyboards/momokai/tap_trio_pro/debounce_analog.c b/keyboards/momokai/tap_trio_pro/debounce_analog.c new file mode 100644 index 00000000000..e69de29bb2d diff --git a/keyboards/momokai/tap_trio_pro/debounce.c b/keyboards/momokai/tap_trio_pro/debounce_digital.c similarity index 100% rename from keyboards/momokai/tap_trio_pro/debounce.c rename to keyboards/momokai/tap_trio_pro/debounce_digital.c diff --git a/keyboards/momokai/tap_trio_pro/matrix.c b/keyboards/momokai/tap_trio_pro/matrix.c index a76eb8f6243..45b9fb9901c 100644 --- a/keyboards/momokai/tap_trio_pro/matrix.c +++ b/keyboards/momokai/tap_trio_pro/matrix.c @@ -9,6 +9,7 @@ SPDX-License-Identifier: GPL-2.0-or-later */ #include "analog.h" #include "lut.h" #include "scanfunctions.h" +#include "debounce_digital.c" #ifndef MATRIX_INPUT_PRESSED_STATE # define MATRIX_INPUT_PRESSED_STATE 0 @@ -18,6 +19,8 @@ pin_t matrix_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; hybrid_key_t keys[MATRIX_ROWS][MATRIX_COLS] = {0}; + + void matrix_init_custom(void) { wait_ms(3500); //give time to try to have hid_listen spin up @@ -72,6 +75,43 @@ void matrix_init_custom(void) { get_sensor_offsets(); } +/* matrix state(1:on, 0:off) */ +matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values +matrix_row_t matrix[MATRIX_ROWS]; // debounced values + +void matrix_init(void) { + // TODO: initialize hardware and global matrix state here + //matrix.c row 274 + //matrix_common.c row 149 + + + // initialize key pins + // matrix_init_pins(); + for (int row = 0; row < MATRIX_ROWS; row++) { + // if (row != 1){ + for (int col = 0; col < MATRIX_COLS; col++) { + pin_t pin = matrix_pins[row][col]; + if (pin != NO_PIN) { + setPinInputHigh(pin); + } + } + // } + } + matrix_init_custom(); + + // initialize matrix state: all keys off + for (uint8_t i = 0; i < MATRIX_ROWS; i++) { + raw_matrix[i] = 0; + matrix[i] = 0; + } + + // Unless hardware debouncing - Init the configured debounce routine + debounce_init(MATRIX_ROWS); + + // This *must* be called for correct keyboard behavior + matrix_init_kb(); +} + matrix_row_t previous_matrix[MATRIX_ROWS]; // matrix_row_t is an alias for u_int8_t diff --git a/keyboards/momokai/tap_trio_pro/rules.mk b/keyboards/momokai/tap_trio_pro/rules.mk index a0995187ba5..dc430028408 100644 --- a/keyboards/momokai/tap_trio_pro/rules.mk +++ b/keyboards/momokai/tap_trio_pro/rules.mk @@ -1,7 +1,7 @@ QUANTUM_LIB_SRC += analog.c -SRC += matrix.c lut.c scanfunctions.c debounce.c +SRC += matrix.c lut.c scanfunctions.c debounce_analog.c debounce_digital.c -CUSTOM_MATRIX = lite +CUSTOM_MATRIX = yes DEBOUNCE_TYPE = custom From c995640b1a7b1f136592dfe2404f3e9d9dd99e9f Mon Sep 17 00:00:00 2001 From: peepeetee Date: Thu, 22 Feb 2024 07:24:11 -0600 Subject: [PATCH 17/43] fully functional, needs stability and rapid trigger --- keyboards/momokai/tap_trio_pro/matrix.c | 89 ++++++++++++++++++++++++- keyboards/momokai/tap_trio_pro/rules.mk | 2 +- 2 files changed, 88 insertions(+), 3 deletions(-) diff --git a/keyboards/momokai/tap_trio_pro/matrix.c b/keyboards/momokai/tap_trio_pro/matrix.c index 45b9fb9901c..8a8d4e0dfff 100644 --- a/keyboards/momokai/tap_trio_pro/matrix.c +++ b/keyboards/momokai/tap_trio_pro/matrix.c @@ -10,6 +10,8 @@ SPDX-License-Identifier: GPL-2.0-or-later */ #include "lut.h" #include "scanfunctions.h" #include "debounce_digital.c" +#include "debounce_analog.c" +#include "matrix_helpers.c" #ifndef MATRIX_INPUT_PRESSED_STATE # define MATRIX_INPUT_PRESSED_STATE 0 @@ -79,6 +81,62 @@ void matrix_init_custom(void) { matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values matrix_row_t matrix[MATRIX_ROWS]; // debounced values +//setup only rows 0 and 2, leave row 1 untouched +__attribute__((weak)) void matrix_init_pins(void) { + for (int row = 0; row < MATRIX_ROWS; row++) { + // if (row != 1){ + for (int col = 0; col < MATRIX_COLS; col++) { + pin_t pin = matrix_pins[row][col]; + if (pin != NO_PIN) { + setPinInputHigh(pin); + } + } + // } + } +} + +// 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); + + +// static inline uint8_t readMatrixPin(pin_t pin) { +// if (pin != NO_PIN) { +// return (readPin(pin) == MATRIX_INPUT_PRESSED_STATE) ? 0 : 1; +// } else { +// return 1; +// } +// } + +matrix_row_t matrix_get_row(uint8_t row) { + + // TODO: return the requested row data + //matrix_common.c row 68 + + return matrix[row]; +} + + +# define print_matrix_header() print("\nr/c 01234567\n") +# define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row)) + +void matrix_print(void) { + // TODO: use print() to dump the current matrix state to console + //matrix_common.c row 84 + + print_matrix_header(); + + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + print_hex8(row); + print(": "); + print_matrix_row(row); + print("\n"); + } + +} + + void matrix_init(void) { // TODO: initialize hardware and global matrix state here //matrix.c row 274 @@ -86,7 +144,7 @@ void matrix_init(void) { // initialize key pins - // matrix_init_pins(); + matrix_init_pins(); for (int row = 0; row < MATRIX_ROWS; row++) { // if (row != 1){ for (int col = 0; col < MATRIX_COLS; col++) { @@ -143,7 +201,7 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) { for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { if (keys[current_row][0].is_analog == false) { - // matrix_read_cols_on_row(current_matrix, current_row); + matrix_read_cols_on_row(current_matrix, current_row); } @@ -178,3 +236,30 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) { } return memcmp(previous_matrix, current_matrix, sizeof(previous_matrix)) != 0; } + +uint8_t matrix_scan(void) { + // TODO: add matrix scanning routine here + //matrix.c row 324 + //matrix_common.c row 169 + + bool changed = matrix_scan_custom(raw_matrix); + + // Unless hardware debouncing - use the configured debounce routine + changed = debounce(raw_matrix, matrix, MATRIX_ROWS, changed); + + // This *must* be called for correct keyboard behavior + matrix_scan_kb(); + + 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) {} + + diff --git a/keyboards/momokai/tap_trio_pro/rules.mk b/keyboards/momokai/tap_trio_pro/rules.mk index dc430028408..ca10ef90802 100644 --- a/keyboards/momokai/tap_trio_pro/rules.mk +++ b/keyboards/momokai/tap_trio_pro/rules.mk @@ -1,5 +1,5 @@ QUANTUM_LIB_SRC += analog.c -SRC += matrix.c lut.c scanfunctions.c debounce_analog.c debounce_digital.c +SRC += matrix.c lut.c scanfunctions.c CUSTOM_MATRIX = yes From 81b788d50032dd876c9cf415e5d2de407f82b62f Mon Sep 17 00:00:00 2001 From: peepeetee Date: Sat, 24 Feb 2024 02:40:25 -0600 Subject: [PATCH 18/43] add #pragma once, start attempting to refactor matrix.c by splitting boilerplate code --- keyboards/momokai/tap_trio_pro/analogkeys.h | 3 +++ .../momokai/tap_trio_pro/debounce_digital.c | 2 ++ keyboards/momokai/tap_trio_pro/matrix.c | 2 +- keyboards/momokai/tap_trio_pro/matrix_helpers.c | 16 ++++++++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 keyboards/momokai/tap_trio_pro/matrix_helpers.c diff --git a/keyboards/momokai/tap_trio_pro/analogkeys.h b/keyboards/momokai/tap_trio_pro/analogkeys.h index 44a908de265..c5033af719c 100644 --- a/keyboards/momokai/tap_trio_pro/analogkeys.h +++ b/keyboards/momokai/tap_trio_pro/analogkeys.h @@ -1,5 +1,8 @@ /* Copyright 2023 RephlexZero (@RephlexZero) SPDX-License-Identifier: GPL-2.0-or-later */ + +#pragma once + #include enum analog_key_modes { dynamic_actuation = 0, continuous_dynamic_actuation, static_actuation, flashing }; diff --git a/keyboards/momokai/tap_trio_pro/debounce_digital.c b/keyboards/momokai/tap_trio_pro/debounce_digital.c index 156535a3733..6b235604a54 100644 --- a/keyboards/momokai/tap_trio_pro/debounce_digital.c +++ b/keyboards/momokai/tap_trio_pro/debounce_digital.c @@ -19,6 +19,8 @@ Basic symmetric per-key algorithm. Uses an 8-bit counter per key. When no state changes have occured for DEBOUNCE milliseconds, we push the state. */ +#pragma once + #include "debounce.h" #include "timer.h" #include diff --git a/keyboards/momokai/tap_trio_pro/matrix.c b/keyboards/momokai/tap_trio_pro/matrix.c index 8a8d4e0dfff..1bc385ddb43 100644 --- a/keyboards/momokai/tap_trio_pro/matrix.c +++ b/keyboards/momokai/tap_trio_pro/matrix.c @@ -11,7 +11,7 @@ SPDX-License-Identifier: GPL-2.0-or-later */ #include "scanfunctions.h" #include "debounce_digital.c" #include "debounce_analog.c" -#include "matrix_helpers.c" +// #include "matrix_helpers.c" #ifndef MATRIX_INPUT_PRESSED_STATE # define MATRIX_INPUT_PRESSED_STATE 0 diff --git a/keyboards/momokai/tap_trio_pro/matrix_helpers.c b/keyboards/momokai/tap_trio_pro/matrix_helpers.c new file mode 100644 index 00000000000..6713ff1205e --- /dev/null +++ b/keyboards/momokai/tap_trio_pro/matrix_helpers.c @@ -0,0 +1,16 @@ +/* +Copyright 2012-2018 Jun Wako, Jack Humbert, Yiancar +Copyright 2023 peepeetee +SPDX-License-Identifier: GPL-2.0-or-later */ + +#pragma once + +#include +#include +#include +#include +#include "quantum.h" +#include "analog.h" +#include "lut.h" +#include "scanfunctions.h" + From ab68b06f26db8d695f7aaf495358ed4e70b023df Mon Sep 17 00:00:00 2001 From: peepeetee Date: Sun, 25 Feb 2024 01:48:09 -0600 Subject: [PATCH 19/43] keep refactoring the code --- .../{debounce_digital.c => debounce.c} | 0 .../momokai/tap_trio_pro/debounce_analog.c | 0 keyboards/momokai/tap_trio_pro/matrix.c | 20 ++++++++++++------- 3 files changed, 13 insertions(+), 7 deletions(-) rename keyboards/momokai/tap_trio_pro/{debounce_digital.c => debounce.c} (100%) delete mode 100644 keyboards/momokai/tap_trio_pro/debounce_analog.c diff --git a/keyboards/momokai/tap_trio_pro/debounce_digital.c b/keyboards/momokai/tap_trio_pro/debounce.c similarity index 100% rename from keyboards/momokai/tap_trio_pro/debounce_digital.c rename to keyboards/momokai/tap_trio_pro/debounce.c diff --git a/keyboards/momokai/tap_trio_pro/debounce_analog.c b/keyboards/momokai/tap_trio_pro/debounce_analog.c deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/keyboards/momokai/tap_trio_pro/matrix.c b/keyboards/momokai/tap_trio_pro/matrix.c index 1bc385ddb43..2c0711d0f73 100644 --- a/keyboards/momokai/tap_trio_pro/matrix.c +++ b/keyboards/momokai/tap_trio_pro/matrix.c @@ -9,8 +9,7 @@ SPDX-License-Identifier: GPL-2.0-or-later */ #include "analog.h" #include "lut.h" #include "scanfunctions.h" -#include "debounce_digital.c" -#include "debounce_analog.c" +#include "debounce.c" // #include "matrix_helpers.c" #ifndef MATRIX_INPUT_PRESSED_STATE @@ -21,6 +20,11 @@ pin_t matrix_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; hybrid_key_t keys[MATRIX_ROWS][MATRIX_COLS] = {0}; +/* matrix state(1:on, 0:off) */ +matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values +matrix_row_t matrix[MATRIX_ROWS]; // debounced values + + void matrix_init_custom(void) { @@ -77,9 +81,7 @@ void matrix_init_custom(void) { get_sensor_offsets(); } -/* matrix state(1:on, 0:off) */ -matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values -matrix_row_t matrix[MATRIX_ROWS]; // debounced values + //setup only rows 0 and 2, leave row 1 untouched __attribute__((weak)) void matrix_init_pins(void) { @@ -170,9 +172,7 @@ void matrix_init(void) { matrix_init_kb(); } -matrix_row_t previous_matrix[MATRIX_ROWS]; -// matrix_row_t is an alias for u_int8_t static inline uint8_t readMatrixPin(pin_t pin) { if (pin != NO_PIN) { @@ -197,6 +197,12 @@ __attribute__((weak)) void matrix_read_cols_on_row(matrix_row_t current_matrix[] } bool matrix_scan_custom(matrix_row_t current_matrix[]) { + + matrix_row_t previous_matrix[MATRIX_ROWS]; + + // matrix_row_t is an alias for u_int8_t + + memcpy(previous_matrix, current_matrix, sizeof(previous_matrix)); for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { From 3755e504778369b4bf96bd25a6e2d7bcb3cd12b3 Mon Sep 17 00:00:00 2001 From: peepeetee Date: Tue, 12 Mar 2024 17:10:43 -0500 Subject: [PATCH 20/43] bootmagic lite rename --- keyboards/momokai/tap_trio_pro/tap_trio_pro.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/keyboards/momokai/tap_trio_pro/tap_trio_pro.c b/keyboards/momokai/tap_trio_pro/tap_trio_pro.c index b8354cbab43..1804eba5213 100644 --- a/keyboards/momokai/tap_trio_pro/tap_trio_pro.c +++ b/keyboards/momokai/tap_trio_pro/tap_trio_pro.c @@ -23,7 +23,7 @@ analog_config g_config = { #ifdef BOOTMAGIC_ENABLE extern pin_t matrix_pins[MATRIX_ROWS][MATRIX_COLS]; void bootmagic_lite(void) { - if (analogReadPin(matrix_pins[BOOTMAGIC_LITE_ROW][BOOTMAGIC_LITE_COLUMN]) < 1350) { + if (analogReadPin(matrix_pins[BOOTMAGIC_ROW][BOOTMAGIC_COLUMN]) < 1350) { bootloader_jump(); } } From 1f96833780f766f675aae8ae3af15a63c5cd3d67 Mon Sep 17 00:00:00 2001 From: peepeetee Date: Tue, 19 Mar 2024 19:02:43 -0500 Subject: [PATCH 21/43] add some scratchpad code and psudocode for my headspace --- keyboards/momokai/tap_trio_pro/psudocode | 18 ++++++++++++ keyboards/momokai/tap_trio_pro/sma.c | 22 +++++++++++++++ keyboards/momokai/tap_trio_pro/sma.h | 35 ++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 keyboards/momokai/tap_trio_pro/psudocode create mode 100644 keyboards/momokai/tap_trio_pro/sma.c create mode 100644 keyboards/momokai/tap_trio_pro/sma.h diff --git a/keyboards/momokai/tap_trio_pro/psudocode b/keyboards/momokai/tap_trio_pro/psudocode new file mode 100644 index 00000000000..29ccab57ddf --- /dev/null +++ b/keyboards/momokai/tap_trio_pro/psudocode @@ -0,0 +1,18 @@ +matrix scanning: + + scan values + put values in SMA filter + get value out, update sensor boundaries if sma initialized + + calebrate key if this is first pass + + + run algos on the key: + regular(look at the methods already implemented) + rapid trigger: + default boundaries are hysteresis values + if continuous rapid trigger, + + + + diff --git a/keyboards/momokai/tap_trio_pro/sma.c b/keyboards/momokai/tap_trio_pro/sma.c new file mode 100644 index 00000000000..f0a4bea3e67 --- /dev/null +++ b/keyboards/momokai/tap_trio_pro/sma.c @@ -0,0 +1,22 @@ +#include +#include "helpers/sma_filter.hpp" + +// On the call operator the next value is given into the filter, with the new average being returned. +uint16_t SMAFilter::operator()(uint16_t value) +{ + // Calculate the new sum by removing the oldest element and adding the new one. + sum = sum - buffer[index] + value; + + // Overwrite the oldest element in the circular buffer with the new one. + buffer[index] = value; + + // Move the index by 1 or restart at 0 if the end is reached. + index = (index + 1) % samples; + + // If the index is 0 here (meaning the circular index just reset), set the fully initialized state to true. + if(index == 0) + initialized = true; + + // Divide the number by the amount of samples using bitshifting and return it. + return sum >> samplesExponent; +} diff --git a/keyboards/momokai/tap_trio_pro/sma.h b/keyboards/momokai/tap_trio_pro/sma.h new file mode 100644 index 00000000000..b4837004a30 --- /dev/null +++ b/keyboards/momokai/tap_trio_pro/sma.h @@ -0,0 +1,35 @@ +#pragma once + +#include + +class SMAFilter +{ +public: + // Initialize the SMAFilter instance with the specified sample exponent. + // (1 = 1 sample, 2 = 4 samples, 3 = 8 samples, ...) + SMAFilter(uint8_t samplesExponent) + : samplesExponent(samplesExponent) + , samples(1 << samplesExponent) + , buffer(new uint16_t[samples] {0}) + {} + + // The call operator for passing values through the filter. + uint16_t operator()(uint16_t value); + + // Bool whether the whole buffer has been written at least once. + bool initialized = false; + +private: + // The amount of samples and the exponent. + uint8_t samplesExponent; + uint8_t samples; + + // The buffer containing all values. + uint16_t *buffer; + + // The index of the oldest and thus next element to overwrite. + uint8_t index = 0; + + // The sum of all values in the buffer. + uint32_t sum = 0; +}; From 88074980572268417451b8a9b0a8967cfb3e24ea Mon Sep 17 00:00:00 2001 From: peepeetee Date: Fri, 26 Apr 2024 18:17:39 -0500 Subject: [PATCH 22/43] stashing progress --- keyboards/momokai/tap_trio_pro/analogkeys.h | 8 +++- keyboards/momokai/tap_trio_pro/config.h | 3 ++ keyboards/momokai/tap_trio_pro/matrix.c | 9 ++++ keyboards/momokai/tap_trio_pro/psudocode | 29 +++++++++++-- keyboards/momokai/tap_trio_pro/sma.c | 48 +++++++++++++-------- keyboards/momokai/tap_trio_pro/sma.h | 37 +++------------- 6 files changed, 80 insertions(+), 54 deletions(-) diff --git a/keyboards/momokai/tap_trio_pro/analogkeys.h b/keyboards/momokai/tap_trio_pro/analogkeys.h index c5033af719c..dd3b969060a 100644 --- a/keyboards/momokai/tap_trio_pro/analogkeys.h +++ b/keyboards/momokai/tap_trio_pro/analogkeys.h @@ -1,4 +1,4 @@ -/* Copyright 2023 RephlexZero (@RephlexZero) +/* Copyright 2023 RephlexZero (@RephlexZero) 2024 peepeetee (@peepeetee) 2024 minisbett (@minisbett) SPDX-License-Identifier: GPL-2.0-or-later */ #pragma once @@ -26,5 +26,11 @@ typedef struct { int16_t offset; bool is_analog; bool dynamic_actuation_bool; + // uint16_t SMA_buffer[1<<(SMA_FILTER_SAMPLE_EXPONENT)]; + uint8_t SMA_samplesExponent; + uint8_t SMA_samples; + uint16_t *SMA_buffer; + uint32_t SMA_sum; + uint8_t SMA_index; } hybrid_key_t; extern hybrid_key_t keys[MATRIX_ROWS][MATRIX_COLS]; diff --git a/keyboards/momokai/tap_trio_pro/config.h b/keyboards/momokai/tap_trio_pro/config.h index 7f3ac385716..00627bd4541 100644 --- a/keyboards/momokai/tap_trio_pro/config.h +++ b/keyboards/momokai/tap_trio_pro/config.h @@ -15,3 +15,6 @@ #define CALIBRATION_RANGE 255 #define DEBOUNCE 16 + +//this configuration for the SMA filter, default is 4 for 2^4 = 16 samples +#define SMA_FILTER_SAMPLE_EXPONENT 4 diff --git a/keyboards/momokai/tap_trio_pro/matrix.c b/keyboards/momokai/tap_trio_pro/matrix.c index 2c0711d0f73..ed316ffe362 100644 --- a/keyboards/momokai/tap_trio_pro/matrix.c +++ b/keyboards/momokai/tap_trio_pro/matrix.c @@ -10,12 +10,19 @@ SPDX-License-Identifier: GPL-2.0-or-later */ #include "lut.h" #include "scanfunctions.h" #include "debounce.c" +#include "sma.c" // #include "matrix_helpers.c" #ifndef MATRIX_INPUT_PRESSED_STATE # define MATRIX_INPUT_PRESSED_STATE 0 #endif + +// //configuration for the SMA filter, default is 4 for 2^4 = 16 samples +// #ifndef SMA_FILTER_SAMPLE_EXPONENT +// # define SMA_FILTER_SAMPLE_EXPONENT 4 +// #endif + pin_t matrix_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; hybrid_key_t keys[MATRIX_ROWS][MATRIX_COLS] = {0}; @@ -56,6 +63,8 @@ void matrix_init_custom(void) { for (uint8_t i = 0; i < MATRIX_COLS; i++) { keys[1][i].is_analog = true; + //should really be done at compile time + initialize_SMA_filter(keys[1][i], SMA_FILTER_SAMPLE_EXPONENT); } // for (uint8_t row = 0; row < MATRIX_ROWS; row++) { diff --git a/keyboards/momokai/tap_trio_pro/psudocode b/keyboards/momokai/tap_trio_pro/psudocode index 29ccab57ddf..1493a6892ad 100644 --- a/keyboards/momokai/tap_trio_pro/psudocode +++ b/keyboards/momokai/tap_trio_pro/psudocode @@ -1,8 +1,16 @@ matrix scanning: scan values - put values in SMA filter - get value out, update sensor boundaries if sma initialized + put values in SMA filter: + for each key, there is a sma filter instance + the filter takes in a 2^4=16 values in a circular buffer + 3 variables: 4 -> 2^4 -> uint16_t[2^4] + state variable: is filter initialized for this key? + pointer: where in the circular buffer are we? + sum: sum of values in the circular buffer, so that we don't have to access the whole buffer, just 2 elements. + + + get value out, update sensor boundaries only if sma initialized calebrate key if this is first pass @@ -10,8 +18,21 @@ matrix scanning: run algos on the key: regular(look at the methods already implemented) rapid trigger: - default boundaries are hysteresis values - if continuous rapid trigger, + 1. + default boundaries are hysteresis values, reset state once reached + (if continuous rapid trigger, reset state only if fully released) + 2. + when rapid trigger state is false + if value is in rapid trigger zone, press and set rapid trigger state + if state is false && lower than lower hysteresis, press key and set rapid trigger state + 3. + when rapid trigger state is true + if pressed && left rt zone or value is 'sensitivity' above peak, release + if not pressed and key is in trigger zone and value is sensitivity below peak, press + + 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 + diff --git a/keyboards/momokai/tap_trio_pro/sma.c b/keyboards/momokai/tap_trio_pro/sma.c index f0a4bea3e67..5b162ce80b8 100644 --- a/keyboards/momokai/tap_trio_pro/sma.c +++ b/keyboards/momokai/tap_trio_pro/sma.c @@ -1,22 +1,36 @@ -#include -#include "helpers/sma_filter.hpp" +/* Copyright 2024 peepeetee (@peepeetee) 2024 minisbett (@minisbett) +SPDX-License-Identifier: GPL-2.0-or-later */ -// On the call operator the next value is given into the filter, with the new average being returned. -uint16_t SMAFilter::operator()(uint16_t value) -{ - // Calculate the new sum by removing the oldest element and adding the new one. - sum = sum - buffer[index] + value; +#include +#include "analogkeys.h" - // Overwrite the oldest element in the circular buffer with the new one. - buffer[index] = value; - // Move the index by 1 or restart at 0 if the end is reached. - index = (index + 1) % samples; - // If the index is 0 here (meaning the circular index just reset), set the fully initialized state to true. - if(index == 0) - initialized = true; - - // Divide the number by the amount of samples using bitshifting and return it. - return sum >> samplesExponent; +void initialize_SMA_filter(hybrid_key_t key, uint8_t samplesExponent) { + key.SMA_samplesExponent = samplesExponent; + key.SMA_samples = 1 << samplesExponent; + key.SMA_buffer = malloc(key.SMA_samples*sizeof(uint16_t)); + printf("%s\n", "SMA_buffer test print"); + key.SMA_sum = 0; + key.SMA_index = 0; } + +uint16_t SMA_filter(hybrid_key_t key, uint16_t value) { + key.SMA_sum = key.SMA_sum - key.SMA_buffer[key.SMA_index] + value; + key.SMA_buffer[key.SMA_index] = value; + key.SMA_index = (key.SMA_index + 1) % key.SMA_samples; + printf("%s\n", "SMA_filter test print"); + printf("%s\n", "SMA_sum and SMA_index:"); + printf("%lu\n", key.SMA_sum); + printf("%x\n", key.SMA_index); + for(int i = 0; i < key.SMA_samples; i++) { + printf("%u\n", key.SMA_buffer[i]); + } + printf("%s\n", "current value:"); + printf("%x\n", key.SMA_buffer[key.SMA_index]); + return key.SMA_sum >> key.SMA_samplesExponent; +} + + + + diff --git a/keyboards/momokai/tap_trio_pro/sma.h b/keyboards/momokai/tap_trio_pro/sma.h index b4837004a30..b22f5dccf40 100644 --- a/keyboards/momokai/tap_trio_pro/sma.h +++ b/keyboards/momokai/tap_trio_pro/sma.h @@ -1,35 +1,8 @@ + #pragma once +#include +#include "analogkeys.h" -#include +void initialize_SMA_filter(hybrid_key_t key, uint8_t samplesExponent); -class SMAFilter -{ -public: - // Initialize the SMAFilter instance with the specified sample exponent. - // (1 = 1 sample, 2 = 4 samples, 3 = 8 samples, ...) - SMAFilter(uint8_t samplesExponent) - : samplesExponent(samplesExponent) - , samples(1 << samplesExponent) - , buffer(new uint16_t[samples] {0}) - {} - - // The call operator for passing values through the filter. - uint16_t operator()(uint16_t value); - - // Bool whether the whole buffer has been written at least once. - bool initialized = false; - -private: - // The amount of samples and the exponent. - uint8_t samplesExponent; - uint8_t samples; - - // The buffer containing all values. - uint16_t *buffer; - - // The index of the oldest and thus next element to overwrite. - uint8_t index = 0; - - // The sum of all values in the buffer. - uint32_t sum = 0; -}; +uint16_t SMA_filter(hybrid_key_t key, uint16_t value); From fe3629a05c3952c66c001447ac350978f04500a3 Mon Sep 17 00:00:00 2001 From: peepeetee Date: Sat, 27 Apr 2024 17:50:46 -0500 Subject: [PATCH 23/43] amend psudocode --- keyboards/momokai/tap_trio_pro/psudocode | 2 ++ 1 file changed, 2 insertions(+) diff --git a/keyboards/momokai/tap_trio_pro/psudocode b/keyboards/momokai/tap_trio_pro/psudocode index 1493a6892ad..f97629e6d0c 100644 --- a/keyboards/momokai/tap_trio_pro/psudocode +++ b/keyboards/momokai/tap_trio_pro/psudocode @@ -9,6 +9,8 @@ matrix scanning: pointer: where in the circular buffer are we? sum: sum of values in the circular buffer, so that we don't have to access the whole buffer, just 2 elements. + special case: initialization + return unfiltered value if the buffer is not filled yet get value out, update sensor boundaries only if sma initialized From 8781b54ee14a24651ea6d8bd463d59cc28850ce7 Mon Sep 17 00:00:00 2001 From: peepeetee Date: Sun, 28 Apr 2024 19:32:59 -0500 Subject: [PATCH 24/43] amend sma logic, polish some functions --- keyboards/momokai/tap_trio_pro/analogkeys.h | 2 ++ keyboards/momokai/tap_trio_pro/scanfunctions.c | 3 ++- keyboards/momokai/tap_trio_pro/sma.c | 11 ++++++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/keyboards/momokai/tap_trio_pro/analogkeys.h b/keyboards/momokai/tap_trio_pro/analogkeys.h index dd3b969060a..21178b12d12 100644 --- a/keyboards/momokai/tap_trio_pro/analogkeys.h +++ b/keyboards/momokai/tap_trio_pro/analogkeys.h @@ -16,6 +16,7 @@ typedef struct { uint8_t press_hysteresis; uint8_t release_hysteresis; } analog_config; /* 6 bytes */ +//size defined in config.h _Static_assert(sizeof(analog_config) == EECONFIG_KB_DATA_SIZE, "Size mismatch"); extern analog_config g_config; @@ -32,5 +33,6 @@ typedef struct { uint16_t *SMA_buffer; uint32_t SMA_sum; uint8_t SMA_index; + bool SMA_filled; } hybrid_key_t; extern hybrid_key_t keys[MATRIX_ROWS][MATRIX_COLS]; diff --git a/keyboards/momokai/tap_trio_pro/scanfunctions.c b/keyboards/momokai/tap_trio_pro/scanfunctions.c index f14af7b4173..02a698f6bcb 100644 --- a/keyboards/momokai/tap_trio_pro/scanfunctions.c +++ b/keyboards/momokai/tap_trio_pro/scanfunctions.c @@ -1,4 +1,4 @@ -/* Copyright 2023 RephlexZero (@RephlexZero) +/* Copyright 2023 RephlexZero (@RephlexZero) 2024 peepeetee (@peepeetee) SPDX-License-Identifier: GPL-2.0-or-later */ #include "quantum.h" #include "analog.h" @@ -7,6 +7,7 @@ SPDX-License-Identifier: GPL-2.0-or-later */ extern pin_t matrix_pins[MATRIX_ROWS][MATRIX_COLS]; +//detects sensor offsets when the key is not pressed void get_sensor_offsets(void) { uint16_t rest_adc_value = distance_to_adc(0); for (uint8_t i = 0; i < MATRIX_ROWS; i++) { diff --git a/keyboards/momokai/tap_trio_pro/sma.c b/keyboards/momokai/tap_trio_pro/sma.c index 5b162ce80b8..eda3d229555 100644 --- a/keyboards/momokai/tap_trio_pro/sma.c +++ b/keyboards/momokai/tap_trio_pro/sma.c @@ -9,7 +9,10 @@ SPDX-License-Identifier: GPL-2.0-or-later */ void initialize_SMA_filter(hybrid_key_t key, uint8_t samplesExponent) { key.SMA_samplesExponent = samplesExponent; key.SMA_samples = 1 << samplesExponent; - key.SMA_buffer = malloc(key.SMA_samples*sizeof(uint16_t)); + key.SMA_buffer = malloc((key.SMA_samples)*sizeof(uint16_t)); + for (int i = 0; i < key.SMA_samples; i++) { + key.SMA_buffer[i] = 0; + } printf("%s\n", "SMA_buffer test print"); key.SMA_sum = 0; key.SMA_index = 0; @@ -19,6 +22,12 @@ uint16_t SMA_filter(hybrid_key_t key, uint16_t value) { key.SMA_sum = key.SMA_sum - key.SMA_buffer[key.SMA_index] + value; key.SMA_buffer[key.SMA_index] = value; key.SMA_index = (key.SMA_index + 1) % key.SMA_samples; + if (!key.SMA_filled) { + if (key.SMA_index == 0) { + key.SMA_filled = true; + } + } + printf("%s\n", "SMA_filter test print"); printf("%s\n", "SMA_sum and SMA_index:"); printf("%lu\n", key.SMA_sum); From 20e7dae92a62877d973c9a7c072c03e41d144f06 Mon Sep 17 00:00:00 2001 From: peepeetee Date: Fri, 3 May 2024 04:01:08 -0500 Subject: [PATCH 25/43] cleanup code, add raw value output --- keyboards/momokai/tap_trio_pro/config.h | 2 +- keyboards/momokai/tap_trio_pro/lut.c | 26 ++++++++----- keyboards/momokai/tap_trio_pro/matrix.c | 5 +++ keyboards/momokai/tap_trio_pro/tap_trio_pro.c | 37 +++++++++++-------- 4 files changed, 44 insertions(+), 26 deletions(-) diff --git a/keyboards/momokai/tap_trio_pro/config.h b/keyboards/momokai/tap_trio_pro/config.h index 00627bd4541..bf2bde16828 100644 --- a/keyboards/momokai/tap_trio_pro/config.h +++ b/keyboards/momokai/tap_trio_pro/config.h @@ -10,7 +10,7 @@ #define DEBUG_ENABLE // #define DEBUG_MATRIX_SCAN_RATE -#define ADC_RESOLUTION 12 +#define ADC_RESOLUTION 8 #define CALIBRATION_RANGE 255 diff --git a/keyboards/momokai/tap_trio_pro/lut.c b/keyboards/momokai/tap_trio_pro/lut.c index bc1143268cd..77882c9e301 100644 --- a/keyboards/momokai/tap_trio_pro/lut.c +++ b/keyboards/momokai/tap_trio_pro/lut.c @@ -1,28 +1,34 @@ -/* Copyright 2023 RephlexZero (@RephlexZero) +/* Copyright 2023 RephlexZero (@RephlexZero) 2024 peepeetee (@peepeetee) SPDX-License-Identifier: GPL-2.0-or-later */ #include #include "scanfunctions.h" #include "util.h" /* Equation parameters for the sensor-magnet linearity mapping */ -const double a = 16654600.6755; -const double b = -0.00955994866577; -const double c = -1278.75103145; -const double d = 16652478.4163; +const double a = 0.200347177016; +const double b = 0.00955994866154; +const double c = 6.01110636956; +const double d = 1966.74076381; uint16_t distance_to_adc(uint8_t distance) { - distance = MIN(MAX(distance, 0), 255); - return a * (1 - exp(-b * (distance + c))) - d; + double intermediate = a * exp(b * distance + c) + d; + uint16_t adc = (uint16_t) MAX(0, MIN(intermediate, 4095)); + return adc; } uint8_t adc_to_distance(uint16_t adc) { - return MIN(MAX(((log(1 - ((adc + d) / a)) / -b) - c), 0), 255); + if (adc <= d) { + return 0; + } + double intermediate = (log((adc - d) / a) - c) / b; + uint8_t distance = (uint8_t) MAX(0, MIN(intermediate, 255)); + return distance; } -uint8_t lut[4096] = {0}; +uint8_t lut[ADC_RESOLUTION_MAX] = {0}; void generate_lut(void) { - for (uint16_t i = 0; i < a - d; i++) { + for (uint16_t i = 0; i < ADC_RESOLUTION_MAX; i++) { lut[i] = adc_to_distance(i); } } diff --git a/keyboards/momokai/tap_trio_pro/matrix.c b/keyboards/momokai/tap_trio_pro/matrix.c index ed316ffe362..4909557c695 100644 --- a/keyboards/momokai/tap_trio_pro/matrix.c +++ b/keyboards/momokai/tap_trio_pro/matrix.c @@ -212,6 +212,11 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) { // matrix_row_t is an alias for u_int8_t + + + + + memcpy(previous_matrix, current_matrix, sizeof(previous_matrix)); for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { diff --git a/keyboards/momokai/tap_trio_pro/tap_trio_pro.c b/keyboards/momokai/tap_trio_pro/tap_trio_pro.c index 1804eba5213..0d4410ad064 100644 --- a/keyboards/momokai/tap_trio_pro/tap_trio_pro.c +++ b/keyboards/momokai/tap_trio_pro/tap_trio_pro.c @@ -34,28 +34,35 @@ void bootmagic_lite(void) { # ifdef DEBUG_ENABLE deferred_token debug_token; bool debug_print(void) { - uint8_t hall_effect_rows = 1; - char buffer[hall_effect_rows * MATRIX_COLS * 5 + MATRIX_ROWS * 2]; - buffer[0] = '\0'; + // uint8_t hall_effect_rows = 1; + // char buffer[hall_effect_rows * MATRIX_COLS * 5 + MATRIX_ROWS * 2]; + // buffer[0] = '\0'; - // for (uint8_t row = 0; row < MATRIX_ROWS; row++) { - uint8_t row = 1; - for (uint8_t col = 0; col < MATRIX_COLS; col++) { - hybrid_key_t *key = &keys[row][col]; - char temp[6]; - snprintf(temp, sizeof(temp), "%5u", key->value); - strcat(buffer, temp); - } - strcat(buffer, "\n"); - // } + // // for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + // uint8_t row = 1; + // for (uint8_t col = 0; col < MATRIX_COLS; col++) { + // hybrid_key_t *key = &keys[row][col]; + // char temp[6]; + // snprintf(temp, sizeof(temp), "%5u", key->value); + // strcat(buffer, temp); + // } + // strcat(buffer, "\n"); + // // } - uprintf("%s", buffer); + // uprintf("%s", buffer); + + int raw_analog_value[3]; + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + + raw_analog_value[col] = analogReadPin(matrix_pins[1][col]); + } + printf("raw_analog_value = %d, %d, %d\n", raw_analog_value[0], raw_analog_value[1], raw_analog_value[2]); return true; } uint32_t debug_print_callback(uint32_t trigger_time, void *cb_arg) { - // debug_print(); + debug_print(); return 25; } # endif From 13ebfbcea4e07de800b3ef9957469f169bdab75b Mon Sep 17 00:00:00 2001 From: peepeetee Date: Fri, 3 May 2024 04:01:57 -0500 Subject: [PATCH 26/43] update psudocode --- keyboards/momokai/tap_trio_pro/psudocode | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/keyboards/momokai/tap_trio_pro/psudocode b/keyboards/momokai/tap_trio_pro/psudocode index f97629e6d0c..27c083297ec 100644 --- a/keyboards/momokai/tap_trio_pro/psudocode +++ b/keyboards/momokai/tap_trio_pro/psudocode @@ -14,6 +14,19 @@ matrix scanning: get value out, update sensor boundaries only if sma initialized + on minipad, TRAVEL_DISTANCE_IN_0_01MM is set to 400, which is the range of motion switches have. + i.e. at rest - bottomed out = 4mm + + sensor calibration logic: + on rephlex, the sensors are updated only when they are at their highest, at the start and in a maintaince task that runs periodically: + + + on minipad, the sensors are updated dynamically when they are actuated on an ougoing basis: + There is an up deadzone and a down deadzone + + + + calebrate key if this is first pass From 6cd2830537a1768b62f0fb974c91c9c6b63dbe88 Mon Sep 17 00:00:00 2001 From: peepeetee Date: Wed, 8 May 2024 20:19:11 -0500 Subject: [PATCH 27/43] add oled driver --- keyboards/momokai/tap_trio_pro/config.h | 8 +++++++- keyboards/momokai/tap_trio_pro/info.json | 1 + keyboards/momokai/tap_trio_pro/tap_trio_pro.c | 13 +++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/keyboards/momokai/tap_trio_pro/config.h b/keyboards/momokai/tap_trio_pro/config.h index bf2bde16828..9b8c47c2aae 100644 --- a/keyboards/momokai/tap_trio_pro/config.h +++ b/keyboards/momokai/tap_trio_pro/config.h @@ -10,7 +10,8 @@ #define DEBUG_ENABLE // #define DEBUG_MATRIX_SCAN_RATE -#define ADC_RESOLUTION 8 +#define ADC_RESOLUTION 12 +#define ADC_RESOLUTION_MAX 1 << 12 #define CALIBRATION_RANGE 255 @@ -18,3 +19,8 @@ //this configuration for the SMA filter, default is 4 for 2^4 = 16 samples #define SMA_FILTER_SAMPLE_EXPONENT 4 + +#define I2C1_SCL_PIN GP19 +#define I2C1_SDA_PIN GP18 +#define OLED_BRIGHTNESS 128 +#define OLED_UPDATE_INTERVAL 1000 diff --git a/keyboards/momokai/tap_trio_pro/info.json b/keyboards/momokai/tap_trio_pro/info.json index 2e67d6fa211..f1276672dbd 100644 --- a/keyboards/momokai/tap_trio_pro/info.json +++ b/keyboards/momokai/tap_trio_pro/info.json @@ -11,6 +11,7 @@ "extrakey": true, "mousekey": true, "rgb_matrix": true, + "oled": true, "nkro": true, "deferred_exec": true }, diff --git a/keyboards/momokai/tap_trio_pro/tap_trio_pro.c b/keyboards/momokai/tap_trio_pro/tap_trio_pro.c index 0d4410ad064..099ccbb71f2 100644 --- a/keyboards/momokai/tap_trio_pro/tap_trio_pro.c +++ b/keyboards/momokai/tap_trio_pro/tap_trio_pro.c @@ -201,3 +201,16 @@ void via_config_get_value(uint8_t *data) { #endif +#ifdef OLED_ENABLE +bool oled_task_kb() { + static const char image[] PROGMEM = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xf0, 0xfc, 0xff, 0xf8, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xfc, 0xbf, 0xbf, 0x9f, 0x9f, 0x1f, 0x1f, 0x1f, 0x5f, 0x5f, 0x5f, 0x1f, 0x1f, 0x1f, 0x7f, 0xff, 0xff, 0xfe, 0xf8, 0xe0, 0x80, 0x87, 0xff, 0xff, 0xfe, 0xf8, 0xf0, 0xe0, 0x80, 0x00, 0x00, 0x00, 0x27, 0x27, 0x27, 0x27, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x0f, 0x0e, 0x08, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x80, 0xe0, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x37, 0xe0, 0xe0, 0xe0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf8, 0xf8, 0xf8, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf0, 0xf0, 0x30, 0xf0, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xf0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x7f, 0x7f, 0x3f, 0x9f, 0xbf, 0xbf, 0xbf, 0xbf, 0x9f, 0x9f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, 0xe0, 0xe0, 0x80, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xf8, 0xf0, 0x00, 0x00, 0x00, 0xf0, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x07, 0x0f, 0x0f, 0x0f, 0x1f, 0x1f, 0x1f, 0x1f, 0x3f, 0x3f, 0x3f, 0x3f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x3f, 0x3f, 0x3f, 0x3f, 0x1f, 0x1f, 0x1f, 0x0f, 0x0f, 0x0f, 0x07, 0x03, 0x00, 0x00, 0x00, 0x80, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x3f, 0x3f, 0x1f, 0x80, 0xc0, 0xcf, 0xcf, 0xdf, 0x9f, 0x3f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; + + oled_write_raw_P(image, sizeof(image)); + + return false; +} +#endif + From 9b985746fc70f0b20671f7f93e61072fd1bd16c2 Mon Sep 17 00:00:00 2001 From: peepeetee Date: Tue, 21 May 2024 01:02:06 -0500 Subject: [PATCH 28/43] cleanup code; debug --- keyboards/momokai/tap_trio_pro/debounce.c | 146 ------------------ keyboards/momokai/tap_trio_pro/info.json | 1 + keyboards/momokai/tap_trio_pro/matrix.c | 30 +--- .../momokai/tap_trio_pro/matrix_helpers.c | 16 -- keyboards/momokai/tap_trio_pro/rules.mk | 2 - keyboards/momokai/tap_trio_pro/tap_trio_pro.c | 2 +- 6 files changed, 10 insertions(+), 187 deletions(-) delete mode 100644 keyboards/momokai/tap_trio_pro/debounce.c delete mode 100644 keyboards/momokai/tap_trio_pro/matrix_helpers.c diff --git a/keyboards/momokai/tap_trio_pro/debounce.c b/keyboards/momokai/tap_trio_pro/debounce.c deleted file mode 100644 index 6b235604a54..00000000000 --- a/keyboards/momokai/tap_trio_pro/debounce.c +++ /dev/null @@ -1,146 +0,0 @@ -/* -Copyright 2017 Alex Ong -Copyright 2020 Andrei Purdea -Copyright 2021 Simon Arlott -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -/* -Basic symmetric per-key algorithm. Uses an 8-bit counter per key. -When no state changes have occured for DEBOUNCE milliseconds, we push the state. -*/ - -#pragma once - -#include "debounce.h" -#include "timer.h" -#include - -#ifdef PROTOCOL_CHIBIOS -# if CH_CFG_USE_MEMCORE == FALSE -# error ChibiOS is configured without a memory allocator. Your keyboard may have set `#define CH_CFG_USE_MEMCORE FALSE`, which is incompatible with this debounce algorithm. -# endif -#endif - -#ifndef DEBOUNCE -# define DEBOUNCE 5 -#endif - -// Maximum debounce: 255ms -#if DEBOUNCE > UINT8_MAX -# undef DEBOUNCE -# define DEBOUNCE UINT8_MAX -#endif - -#define ROW_SHIFTER ((matrix_row_t)1) - -typedef uint8_t debounce_counter_t; - -#if DEBOUNCE > 0 -static debounce_counter_t *debounce_counters; -static fast_timer_t last_time; -static bool counters_need_update; -static bool cooked_changed; - -# define DEBOUNCE_ELAPSED 0 - -static void update_debounce_counters_and_transfer_if_expired(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t elapsed_time); -static void start_debounce_counters(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows); - -// we use num_rows rather than MATRIX_ROWS to support split keyboards -void debounce_init(uint8_t num_rows) { - debounce_counters = (debounce_counter_t *)malloc(num_rows * MATRIX_COLS * sizeof(debounce_counter_t)); - int i = 0; - for (uint8_t r = 0; r < num_rows; r++) { - for (uint8_t c = 0; c < MATRIX_COLS; c++) { - debounce_counters[i++] = DEBOUNCE_ELAPSED; - } - } -} - -void debounce_free(void) { - free(debounce_counters); - debounce_counters = NULL; -} - -bool debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) { - bool updated_last = false; - cooked_changed = false; - - if (counters_need_update) { - fast_timer_t now = timer_read_fast(); - fast_timer_t elapsed_time = TIMER_DIFF_FAST(now, last_time); - - last_time = now; - updated_last = true; - if (elapsed_time > UINT8_MAX) { - elapsed_time = UINT8_MAX; - } - - if (elapsed_time > 0) { - update_debounce_counters_and_transfer_if_expired(raw, cooked, num_rows, elapsed_time); - } - } - - if (changed) { - if (!updated_last) { - last_time = timer_read_fast(); - } - - start_debounce_counters(raw, cooked, num_rows); - } - - return cooked_changed; -} - -static void update_debounce_counters_and_transfer_if_expired(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t elapsed_time) { - counters_need_update = false; - debounce_counter_t *debounce_pointer = debounce_counters; - for (uint8_t row = 0; row < num_rows; row++) { - for (uint8_t col = 0; col < MATRIX_COLS; col++) { - if (*debounce_pointer != DEBOUNCE_ELAPSED) { - if (*debounce_pointer <= elapsed_time) { - *debounce_pointer = DEBOUNCE_ELAPSED; - matrix_row_t cooked_next = (cooked[row] & ~(ROW_SHIFTER << col)) | (raw[row] & (ROW_SHIFTER << col)); - cooked_changed |= cooked[row] ^ cooked_next; - cooked[row] = cooked_next; - } else { - *debounce_pointer -= elapsed_time; - counters_need_update = true; - } - } - debounce_pointer++; - } - } -} - -static void start_debounce_counters(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows) { - debounce_counter_t *debounce_pointer = debounce_counters; - for (uint8_t row = 0; row < num_rows; row++) { - matrix_row_t delta = raw[row] ^ cooked[row]; - for (uint8_t col = 0; col < MATRIX_COLS; col++) { - if (delta & (ROW_SHIFTER << col)) { - if (*debounce_pointer == DEBOUNCE_ELAPSED) { - *debounce_pointer = DEBOUNCE; - counters_need_update = true; - } - } else { - *debounce_pointer = DEBOUNCE_ELAPSED; - } - debounce_pointer++; - } - } -} - -#else -# include "none.c" -#endif diff --git a/keyboards/momokai/tap_trio_pro/info.json b/keyboards/momokai/tap_trio_pro/info.json index f1276672dbd..d731d34cbec 100644 --- a/keyboards/momokai/tap_trio_pro/info.json +++ b/keyboards/momokai/tap_trio_pro/info.json @@ -18,6 +18,7 @@ "bootmagic": { "matrix": [2, 0] }, + "debounce": 0, "build": { "lto": true }, diff --git a/keyboards/momokai/tap_trio_pro/matrix.c b/keyboards/momokai/tap_trio_pro/matrix.c index 4909557c695..a7e5b8e5188 100644 --- a/keyboards/momokai/tap_trio_pro/matrix.c +++ b/keyboards/momokai/tap_trio_pro/matrix.c @@ -8,8 +8,8 @@ SPDX-License-Identifier: GPL-2.0-or-later */ #include "quantum.h" #include "analog.h" #include "lut.h" +#include "debounce.h" #include "scanfunctions.h" -#include "debounce.c" #include "sma.c" // #include "matrix_helpers.c" @@ -64,7 +64,7 @@ void matrix_init_custom(void) { for (uint8_t i = 0; i < MATRIX_COLS; i++) { keys[1][i].is_analog = true; //should really be done at compile time - initialize_SMA_filter(keys[1][i], SMA_FILTER_SAMPLE_EXPONENT); + // initialize_SMA_filter(keys[1][i], SMA_FILTER_SAMPLE_EXPONENT); } // for (uint8_t row = 0; row < MATRIX_ROWS; row++) { @@ -94,15 +94,16 @@ void matrix_init_custom(void) { //setup only rows 0 and 2, leave row 1 untouched __attribute__((weak)) void matrix_init_pins(void) { + // if (keys[row][0].is_analog == false) for (int row = 0; row < MATRIX_ROWS; row++) { - // if (row != 1){ + if (row != 1){ for (int col = 0; col < MATRIX_COLS; col++) { pin_t pin = matrix_pins[row][col]; if (pin != NO_PIN) { setPinInputHigh(pin); } } - // } + } } } @@ -156,16 +157,6 @@ void matrix_init(void) { // initialize key pins matrix_init_pins(); - for (int row = 0; row < MATRIX_ROWS; row++) { - // if (row != 1){ - for (int col = 0; col < MATRIX_COLS; col++) { - pin_t pin = matrix_pins[row][col]; - if (pin != NO_PIN) { - setPinInputHigh(pin); - } - } - // } - } matrix_init_custom(); // initialize matrix state: all keys off @@ -175,7 +166,7 @@ void matrix_init(void) { } // Unless hardware debouncing - Init the configured debounce routine - debounce_init(MATRIX_ROWS); + // debounce_init(MATRIX_ROWS); // This *must* be called for correct keyboard behavior matrix_init_kb(); @@ -205,18 +196,13 @@ __attribute__((weak)) void matrix_read_cols_on_row(matrix_row_t current_matrix[] current_matrix[current_row] = current_row_value; } +matrix_row_t previous_matrix[MATRIX_ROWS]; + bool matrix_scan_custom(matrix_row_t current_matrix[]) { - matrix_row_t previous_matrix[MATRIX_ROWS]; // matrix_row_t is an alias for u_int8_t - - - - - - memcpy(previous_matrix, current_matrix, sizeof(previous_matrix)); for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { diff --git a/keyboards/momokai/tap_trio_pro/matrix_helpers.c b/keyboards/momokai/tap_trio_pro/matrix_helpers.c deleted file mode 100644 index 6713ff1205e..00000000000 --- a/keyboards/momokai/tap_trio_pro/matrix_helpers.c +++ /dev/null @@ -1,16 +0,0 @@ -/* -Copyright 2012-2018 Jun Wako, Jack Humbert, Yiancar -Copyright 2023 peepeetee -SPDX-License-Identifier: GPL-2.0-or-later */ - -#pragma once - -#include -#include -#include -#include -#include "quantum.h" -#include "analog.h" -#include "lut.h" -#include "scanfunctions.h" - diff --git a/keyboards/momokai/tap_trio_pro/rules.mk b/keyboards/momokai/tap_trio_pro/rules.mk index ca10ef90802..9de2c450db6 100644 --- a/keyboards/momokai/tap_trio_pro/rules.mk +++ b/keyboards/momokai/tap_trio_pro/rules.mk @@ -3,6 +3,4 @@ SRC += matrix.c lut.c scanfunctions.c CUSTOM_MATRIX = yes -DEBOUNCE_TYPE = custom - OPT = 3 diff --git a/keyboards/momokai/tap_trio_pro/tap_trio_pro.c b/keyboards/momokai/tap_trio_pro/tap_trio_pro.c index 099ccbb71f2..6eabd2d0735 100644 --- a/keyboards/momokai/tap_trio_pro/tap_trio_pro.c +++ b/keyboards/momokai/tap_trio_pro/tap_trio_pro.c @@ -12,7 +12,7 @@ SPDX-License-Identifier: GPL-2.0-or-later */ analog_config g_config = { - .mode = static_actuation, + .mode = dynamic_actuation, .actuation_point = 32, .press_sensitivity = 32, .release_sensitivity = 32, From 21fef7962bbec7c69507cda9052695d18643a571 Mon Sep 17 00:00:00 2001 From: peepeetee Date: Sun, 2 Jun 2024 00:38:59 -0500 Subject: [PATCH 29/43] increase depression resolution to 16 bits(incomplete), add debugging setup --- keyboards/momokai/tap_trio_pro/analogkeys.h | 4 +- keyboards/momokai/tap_trio_pro/driver.c | 11 +++++ keyboards/momokai/tap_trio_pro/lut.c | 53 +++++++++++++++------ keyboards/momokai/tap_trio_pro/lut.h | 6 +-- 4 files changed, 54 insertions(+), 20 deletions(-) create mode 100644 keyboards/momokai/tap_trio_pro/driver.c diff --git a/keyboards/momokai/tap_trio_pro/analogkeys.h b/keyboards/momokai/tap_trio_pro/analogkeys.h index 21178b12d12..879602e1c66 100644 --- a/keyboards/momokai/tap_trio_pro/analogkeys.h +++ b/keyboards/momokai/tap_trio_pro/analogkeys.h @@ -22,8 +22,8 @@ extern analog_config g_config; typedef struct { /* For individual analog key data */ - uint8_t value; - uint8_t extremum; + uint16_t value; + uint16_t extremum; int16_t offset; bool is_analog; bool dynamic_actuation_bool; diff --git a/keyboards/momokai/tap_trio_pro/driver.c b/keyboards/momokai/tap_trio_pro/driver.c new file mode 100644 index 00000000000..04e4abdc7b1 --- /dev/null +++ b/keyboards/momokai/tap_trio_pro/driver.c @@ -0,0 +1,11 @@ + +#include +#include +#include + +#include "lut.h" + +int main() { + __builtin_trap(); + return 0; +} \ No newline at end of file diff --git a/keyboards/momokai/tap_trio_pro/lut.c b/keyboards/momokai/tap_trio_pro/lut.c index 77882c9e301..eb8f3e23430 100644 --- a/keyboards/momokai/tap_trio_pro/lut.c +++ b/keyboards/momokai/tap_trio_pro/lut.c @@ -1,31 +1,54 @@ /* Copyright 2023 RephlexZero (@RephlexZero) 2024 peepeetee (@peepeetee) SPDX-License-Identifier: GPL-2.0-or-later */ #include -#include "scanfunctions.h" -#include "util.h" +#include +// #include "scanfunctions.h" +// #include "util.h" + +#if !defined(MIN) +# define MIN(x, y) (((x) < (y)) ? (x) : (y)) +#endif + +#if !defined(MAX) +# define MAX(x, y) (((x) > (y)) ? (x) : (y)) +#endif + +// /* Equation parameters for the sensor-magnet linearity mapping */ +// const double a = 0.200347177016; +// const double b = 0.00955994866154; +// const double c = 6.01110636956; +// const double d = 1966.74076381; /* Equation parameters for the sensor-magnet linearity mapping */ -const double a = 0.200347177016; -const double b = 0.00955994866154; -const double c = 6.01110636956; -const double d = 1966.74076381; +// const double a = 1; +// const double b = 0.0061787; +// const double c = 4.34; +// const double d = 1935.43; -uint16_t distance_to_adc(uint8_t distance) { - double intermediate = a * exp(b * distance + c) + d; +const double a = 0.00609446727442; +const double b = 4.40340283615; +const double c = 2122.25923605; + +uint16_t distance_to_adc(uint16_t distance) { + // double intermediate = a * exp(b * distance + c) + d; + double intermediate = ((-exp(a*distance + b)) + c); uint16_t adc = (uint16_t) MAX(0, MIN(intermediate, 4095)); return adc; } -uint8_t adc_to_distance(uint16_t adc) { - if (adc <= d) { - return 0; - } - double intermediate = (log((adc - d) / a) - c) / b; - uint8_t distance = (uint8_t) MAX(0, MIN(intermediate, 255)); +uint16_t adc_to_distance(uint16_t adc) { + // if (adc <= d) { + // return 0; + // } + + // double intermediate = ((log((adc - d) / a)) - c) / b; + + double intermediate = ((log(c-adc)-b)/a); + uint16_t distance = (uint16_t) MAX(0, MIN(intermediate, 255)); return distance; } -uint8_t lut[ADC_RESOLUTION_MAX] = {0}; +uint16_t lut[ADC_RESOLUTION_MAX] = {0}; void generate_lut(void) { for (uint16_t i = 0; i < ADC_RESOLUTION_MAX; i++) { diff --git a/keyboards/momokai/tap_trio_pro/lut.h b/keyboards/momokai/tap_trio_pro/lut.h index 0ec9aa5454f..bfb9fc254f3 100644 --- a/keyboards/momokai/tap_trio_pro/lut.h +++ b/keyboards/momokai/tap_trio_pro/lut.h @@ -3,10 +3,10 @@ SPDX-License-Identifier: GPL-2.0-or-later */ #pragma once #include -extern uint8_t lut[4096]; +extern uint16_t lut[4096]; -uint16_t distance_to_adc(uint8_t distance); +uint16_t distance_to_adc(uint16_t distance); -uint8_t adc_to_distance(uint16_t adc); +uint16_t adc_to_distance(uint16_t adc); void generate_lut(void); From 3d11feebf2b36d28f7ffa79d5461a16702999381 Mon Sep 17 00:00:00 2001 From: peepeetee Date: Thu, 6 Jun 2024 12:52:57 -0500 Subject: [PATCH 30/43] tuned, working --- keyboards/momokai/tap_trio_pro/config.h | 3 +- keyboards/momokai/tap_trio_pro/driver.c | 2 ++ keyboards/momokai/tap_trio_pro/lut.c | 38 ++++++++++++------------- keyboards/momokai/tap_trio_pro/lut.h | 6 +++- keyboards/momokai/tap_trio_pro/matrix.c | 9 ++++-- 5 files changed, 34 insertions(+), 24 deletions(-) diff --git a/keyboards/momokai/tap_trio_pro/config.h b/keyboards/momokai/tap_trio_pro/config.h index 9b8c47c2aae..e9e0704bf57 100644 --- a/keyboards/momokai/tap_trio_pro/config.h +++ b/keyboards/momokai/tap_trio_pro/config.h @@ -6,12 +6,11 @@ #define DYNAMIC_KEYMAP_LAYER_COUNT 1 #define EECONFIG_KB_DATA_SIZE 6 - #define DEBUG_ENABLE // #define DEBUG_MATRIX_SCAN_RATE #define ADC_RESOLUTION 12 -#define ADC_RESOLUTION_MAX 1 << 12 +#define ADC_RESOLUTION_MAX 4096 //1 << 12 #define CALIBRATION_RANGE 255 diff --git a/keyboards/momokai/tap_trio_pro/driver.c b/keyboards/momokai/tap_trio_pro/driver.c index 04e4abdc7b1..313136fa0f5 100644 --- a/keyboards/momokai/tap_trio_pro/driver.c +++ b/keyboards/momokai/tap_trio_pro/driver.c @@ -1,3 +1,5 @@ +/* Copyright 2024 Jenna Fligor (@Ex-32) +SPDX-License-Identifier: GPL-2.0-or-later */ #include #include diff --git a/keyboards/momokai/tap_trio_pro/lut.c b/keyboards/momokai/tap_trio_pro/lut.c index eb8f3e23430..5f54f0d91fb 100644 --- a/keyboards/momokai/tap_trio_pro/lut.c +++ b/keyboards/momokai/tap_trio_pro/lut.c @@ -1,4 +1,4 @@ -/* Copyright 2023 RephlexZero (@RephlexZero) 2024 peepeetee (@peepeetee) +/* Copyright 2023 RephlexZero (@RephlexZero) 2024 peepeetee (@peepeetee) 2024 Jenna Fligor (@Ex-32) SPDX-License-Identifier: GPL-2.0-or-later */ #include #include @@ -14,37 +14,37 @@ SPDX-License-Identifier: GPL-2.0-or-later */ #endif // /* Equation parameters for the sensor-magnet linearity mapping */ -// const double a = 0.200347177016; -// const double b = 0.00955994866154; -// const double c = 6.01110636956; -// const double d = 1966.74076381; +// 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 */ -// const double a = 1; -// const double b = 0.0061787; -// const double c = 4.34; -// const double d = 1935.43; +// const double lut_a = 1; +// const double lut_b = 0.0061787; +// const double lut_c = 4.34; +// const double lut_d = 1935.43; -const double a = 0.00609446727442; -const double b = 4.40340283615; -const double c = 2122.25923605; +const double lut_a = 0.00609446727442; +const double lut_b = 4.40340283615; +const double lut_c = 2000; uint16_t distance_to_adc(uint16_t distance) { - // double intermediate = a * exp(b * distance + c) + d; - double intermediate = ((-exp(a*distance + b)) + c); - uint16_t adc = (uint16_t) MAX(0, MIN(intermediate, 4095)); + // double intermediate = lut_a * exp(lut_b * distance + lut_c) + lut_d; + double intermediate = ((-exp(lut_a*distance + lut_b)) + lut_c); + uint16_t adc = (uint16_t) MAX(0, MIN(intermediate, ADC_RESOLUTION_MAX -1)); return adc; } uint16_t adc_to_distance(uint16_t adc) { - // if (adc <= d) { + // if (adc <= lut_c) { // return 0; // } - // double intermediate = ((log((adc - d) / a)) - c) / b; + // double intermediate = ((log((adc - lut_d) / lut_a)) - lut_c) / lut_b; - double intermediate = ((log(c-adc)-b)/a); - uint16_t distance = (uint16_t) MAX(0, MIN(intermediate, 255)); + double intermediate = ((log(lut_c-adc)-lut_b)/lut_a); + uint16_t distance = (uint16_t) MAX(0, MIN(intermediate, 400)); return distance; } diff --git a/keyboards/momokai/tap_trio_pro/lut.h b/keyboards/momokai/tap_trio_pro/lut.h index bfb9fc254f3..8889c153654 100644 --- a/keyboards/momokai/tap_trio_pro/lut.h +++ b/keyboards/momokai/tap_trio_pro/lut.h @@ -3,7 +3,11 @@ SPDX-License-Identifier: GPL-2.0-or-later */ #pragma once #include -extern uint16_t lut[4096]; +extern uint16_t lut[ADC_RESOLUTION_MAX]; + +const double lut_a; +const double lut_b; +const double lut_c; uint16_t distance_to_adc(uint16_t distance); diff --git a/keyboards/momokai/tap_trio_pro/matrix.c b/keyboards/momokai/tap_trio_pro/matrix.c index a7e5b8e5188..71e18f043f1 100644 --- a/keyboards/momokai/tap_trio_pro/matrix.c +++ b/keyboards/momokai/tap_trio_pro/matrix.c @@ -27,6 +27,9 @@ pin_t matrix_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; hybrid_key_t keys[MATRIX_ROWS][MATRIX_COLS] = {0}; +static uint16_t pressedAdcValue = 0; +static uint16_t restAdcValue = 0; + /* matrix state(1:on, 0:off) */ matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values matrix_row_t matrix[MATRIX_ROWS]; // debounced values @@ -85,7 +88,9 @@ void matrix_init_custom(void) { // } generate_lut(); - get_sensor_offsets(); + pressedAdcValue = distance_to_adc(400); + restAdcValue = distance_to_adc(0); + // get_sensor_offsets(); wait_ms(200); // Let ADC reach steady state get_sensor_offsets(); } @@ -220,7 +225,7 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) { key->value = lut[analogReadPin(matrix_pins[current_row][current_col]) + key->offset]; // limits our options, I would like to change hybrid_key_t to include weather it is a hall effect key - key->value = MIN((key->value << 8) / lut[1100 + key->offset], 255); + // key->value = MIN((key->value << 8) / lut[1100 + key->offset], 400); switch (g_config.mode) { case dynamic_actuation: From 2247f948f67d16cc06415b0a9e5f4d82b66c50b7 Mon Sep 17 00:00:00 2001 From: peepeetee Date: Thu, 16 Jan 2025 22:02:39 -0600 Subject: [PATCH 31/43] rename info.json to keyboard.json --- keyboards/momokai/tap_trio_pro/{info.json => keyboard.json} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename keyboards/momokai/tap_trio_pro/{info.json => keyboard.json} (100%) diff --git a/keyboards/momokai/tap_trio_pro/info.json b/keyboards/momokai/tap_trio_pro/keyboard.json similarity index 100% rename from keyboards/momokai/tap_trio_pro/info.json rename to keyboards/momokai/tap_trio_pro/keyboard.json From 148dee0ea4b4d0d434cec7524959957fcf063d8b Mon Sep 17 00:00:00 2001 From: peepeetee Date: Wed, 22 Jan 2025 21:30:32 -0600 Subject: [PATCH 32/43] fix lut, formatting changes --- keyboards/momokai/tap_trio_pro/lut.c | 35 +++++++------------ keyboards/momokai/tap_trio_pro/matrix.c | 6 ++-- .../momokai/tap_trio_pro/scanfunctions.c | 4 +-- 3 files changed, 17 insertions(+), 28 deletions(-) diff --git a/keyboards/momokai/tap_trio_pro/lut.c b/keyboards/momokai/tap_trio_pro/lut.c index 5f54f0d91fb..63171016c80 100644 --- a/keyboards/momokai/tap_trio_pro/lut.c +++ b/keyboards/momokai/tap_trio_pro/lut.c @@ -1,4 +1,4 @@ -/* Copyright 2023 RephlexZero (@RephlexZero) 2024 peepeetee (@peepeetee) 2024 Jenna Fligor (@Ex-32) +/* Copyright 202 RephlexZero (@RephlexZero) 2024 peepeetee (@peepeetee) 2024 Jenna Fligor (@Ex-32) SPDX-License-Identifier: GPL-2.0-or-later */ #include #include @@ -20,32 +20,23 @@ SPDX-License-Identifier: GPL-2.0-or-later */ // const double lut_d = 1966.74076381; /* Equation parameters for the sensor-magnet linearity mapping */ -// const double lut_a = 1; -// const double lut_b = 0.0061787; -// const double lut_c = 4.34; -// const double lut_d = 1935.43; - -const double lut_a = 0.00609446727442; -const double lut_b = 4.40340283615; -const double lut_c = 2000; +const double lut_a = -366.805673399; +const double lut_b = 0.00617870508512; +const double lut_c = -1.49468890703; +const double lut_d = 2094.38794157; uint16_t distance_to_adc(uint16_t distance) { - // double intermediate = lut_a * exp(lut_b * distance + lut_c) + lut_d; - double intermediate = ((-exp(lut_a*distance + lut_b)) + lut_c); - uint16_t adc = (uint16_t) MAX(0, MIN(intermediate, ADC_RESOLUTION_MAX -1)); - return adc; + double intermediate = lut_a * exp(lut_b * distance + lut_c) + lut_d; + return (uint16_t) fmax(0, fmin(intermediate, 4095)); } uint16_t adc_to_distance(uint16_t adc) { - // if (adc <= lut_c) { - // return 0; - // } - - // double intermediate = ((log((adc - lut_d) / lut_a)) - lut_c) / lut_b; - - double intermediate = ((log(lut_c-adc)-lut_b)/lut_a); - uint16_t distance = (uint16_t) MAX(0, MIN(intermediate, 400)); - return distance; + double check = (adc - lut_d) / lut_a; + if (check <= 0) { + return 0; + } + double intermediate = (log(check) - lut_c) / lut_b; + return (uint16_t) fmax(0, fmin(intermediate, 255)); } uint16_t lut[ADC_RESOLUTION_MAX] = {0}; diff --git a/keyboards/momokai/tap_trio_pro/matrix.c b/keyboards/momokai/tap_trio_pro/matrix.c index 71e18f043f1..aa96df6799f 100644 --- a/keyboards/momokai/tap_trio_pro/matrix.c +++ b/keyboards/momokai/tap_trio_pro/matrix.c @@ -213,10 +213,8 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) { for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { if (keys[current_row][0].is_analog == false) { matrix_read_cols_on_row(current_matrix, current_row); - - } - - else { + + } else { for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { hybrid_key_t *key = &keys[current_row][current_col]; diff --git a/keyboards/momokai/tap_trio_pro/scanfunctions.c b/keyboards/momokai/tap_trio_pro/scanfunctions.c index 02a698f6bcb..0a0e37a9b7c 100644 --- a/keyboards/momokai/tap_trio_pro/scanfunctions.c +++ b/keyboards/momokai/tap_trio_pro/scanfunctions.c @@ -13,8 +13,8 @@ void get_sensor_offsets(void) { for (uint8_t i = 0; i < MATRIX_ROWS; i++) { for (uint8_t j = 0; j < MATRIX_COLS; j++) { if (keys[i][j].is_analog) { - keys[i][j].offset = rest_adc_value - analogReadPin(matrix_pins[i][j]); - printf("Offset: %d\n", keys[i][j].offset); + keys[i][j].offset = rest_adc_value - analogReadPin(matrix_pins[i][j]); + printf("Offset: %d\n", keys[i][j].offset); } } } From d5cbafa745a96ae6eaf89524217cbc631fd4faa1 Mon Sep 17 00:00:00 2001 From: Jenna Fligor Date: Sat, 25 Jan 2025 22:48:28 -0600 Subject: [PATCH 33/43] via working --- keyboards/momokai/tap_trio_pro/analogkeys.h | 12 ++++++-- keyboards/momokai/tap_trio_pro/keyboard.json | 30 ++++++------------- .../momokai/tap_trio_pro/keymaps/via/keymap.c | 7 ----- keyboards/momokai/tap_trio_pro/tap_trio_pro.c | 14 +++++---- 4 files changed, 27 insertions(+), 36 deletions(-) diff --git a/keyboards/momokai/tap_trio_pro/analogkeys.h b/keyboards/momokai/tap_trio_pro/analogkeys.h index 879602e1c66..c4f05c1ed99 100644 --- a/keyboards/momokai/tap_trio_pro/analogkeys.h +++ b/keyboards/momokai/tap_trio_pro/analogkeys.h @@ -1,11 +1,19 @@ -/* Copyright 2023 RephlexZero (@RephlexZero) 2024 peepeetee (@peepeetee) 2024 minisbett (@minisbett) +/* Copyright 2023 RephlexZero (@RephlexZero) + 2024 peepeetee (@peepeetee) + 2024 minisbett (@minisbett) + 2025 Jenna Fligor (@Ex-32) SPDX-License-Identifier: GPL-2.0-or-later */ #pragma once #include -enum analog_key_modes { dynamic_actuation = 0, continuous_dynamic_actuation, static_actuation, flashing }; +enum analog_key_modes { + dynamic_actuation = 0, + continuous_dynamic_actuation = 1, + static_actuation = 2, + flashing = 3, +}; /* global struct to save keypress logic params */ typedef struct { diff --git a/keyboards/momokai/tap_trio_pro/keyboard.json b/keyboards/momokai/tap_trio_pro/keyboard.json index d731d34cbec..bdf19928a10 100644 --- a/keyboards/momokai/tap_trio_pro/keyboard.json +++ b/keyboards/momokai/tap_trio_pro/keyboard.json @@ -16,17 +16,16 @@ "deferred_exec": true }, "bootmagic": { - "matrix": [2, 0] + "matrix": [1, 0] }, "debounce": 0, "build": { "lto": true }, "matrix_pins": { - "direct":[ - ["NO_PIN", "GP0", "NO_PIN" ], - ["GP28", "GP27", "GP26" ], - ["GP10", "GP9", "GP8" ] + "direct": [ + ["GP28", "GP27", "GP26" ], + ["GP10", "GP9", "GP8" ] ] }, @@ -38,15 +37,6 @@ "pid": "0x0016", "vid": "0x69F9" }, - "encoder": { - "enabled": true, - "rotary": [ - { - "pin_a": "GP2", - "pin_b": "GP1" - } - ] - }, "ws2812": { "pin": "GP29", "driver": "vendor" @@ -112,15 +102,13 @@ "layouts": { "LAYOUT": { "layout": [ + {"matrix": [0, 0], "x": 0, "y": 0}, {"matrix": [0, 1], "x": 1, "y": 0}, + {"matrix": [0, 2], "x": 2, "y": 0}, - {"matrix": [1, 0], "x": 0, "y": 1}, - {"matrix": [1, 1], "x": 1, "y": 1}, - {"matrix": [1, 2], "x": 2, "y": 1}, - - {"matrix": [2, 0], "x": 0.5, "y": 2.25, "w": 0.5, "h": 0.5}, - {"matrix": [2, 1], "x": 1, "y": 2.25, "w": 0.5, "h": 0.5}, - {"matrix": [2, 2], "x": 1.5, "y": 2.25, "w": 0.5, "h": 0.5} + {"matrix": [1, 0], "x": 0.5, "y": 1.25, "w": 0.5, "h": 0.5}, + {"matrix": [1, 1], "x": 1, "y": 1.25, "w": 0.5, "h": 0.5}, + {"matrix": [1, 2], "x": 1.5, "y": 1.25, "w": 0.5, "h": 0.5} ] } } diff --git a/keyboards/momokai/tap_trio_pro/keymaps/via/keymap.c b/keyboards/momokai/tap_trio_pro/keymaps/via/keymap.c index c83cbad8efe..84824e214c1 100644 --- a/keyboards/momokai/tap_trio_pro/keymaps/via/keymap.c +++ b/keyboards/momokai/tap_trio_pro/keymaps/via/keymap.c @@ -5,14 +5,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [0] = LAYOUT( - KC_MUTE, KC_Z, KC_X, KC_C, KC_GRV, KC_ESC, KC_F2 ), }; - -#if defined(ENCODER_MAP_ENABLE) -const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = { - [0] = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU) }, -}; -#endif diff --git a/keyboards/momokai/tap_trio_pro/tap_trio_pro.c b/keyboards/momokai/tap_trio_pro/tap_trio_pro.c index 6eabd2d0735..c85cbacab43 100644 --- a/keyboards/momokai/tap_trio_pro/tap_trio_pro.c +++ b/keyboards/momokai/tap_trio_pro/tap_trio_pro.c @@ -1,4 +1,6 @@ -/* Copyright 2023 RephlexZero (@RephlexZero) peepeetee (@peepeetee) +/* Copyright 2023 RephlexZero (@RephlexZero) + 2023 peepeetee (@peepeetee) + 2025 Jenna Fligor (@Ex-32) SPDX-License-Identifier: GPL-2.0-or-later */ #include #include @@ -139,11 +141,11 @@ void via_custom_value_command_kb(uint8_t *data, uint8_t length) { enum via_dynamic_actuation { id_mode = 1, - id_actuation_point, - id_press_sensitivity, - id_release_sensitivity, - id_press_hysteresis, - id_release_hysteresis, + id_actuation_point = 2, + id_press_sensitivity = 3, + id_release_sensitivity = 4, + id_press_hysteresis = 5, + id_release_hysteresis = 6, }; void via_config_set_value(uint8_t *data) { From 6325c8e5689f19fa42bb660085453b3c779055b8 Mon Sep 17 00:00:00 2001 From: peepeetee Date: Sat, 21 Jun 2025 00:02:13 +0800 Subject: [PATCH 34/43] cleanup code, fix hall effect keys row off by one error --- keyboards/momokai/tap_trio_pro/analogkeys.h | 1 + .../tap_trio_pro/keymaps/debug/keymap.c | 1 - .../tap_trio_pro/keymaps/default/keymap.c | 1 - keyboards/momokai/tap_trio_pro/lut.c | 4 +- keyboards/momokai/tap_trio_pro/lut.h | 1 + keyboards/momokai/tap_trio_pro/matrix.c | 211 +++--------------- keyboards/momokai/tap_trio_pro/rules.mk | 2 +- keyboards/momokai/tap_trio_pro/tap_trio_pro.c | 18 +- 8 files changed, 33 insertions(+), 206 deletions(-) diff --git a/keyboards/momokai/tap_trio_pro/analogkeys.h b/keyboards/momokai/tap_trio_pro/analogkeys.h index c4f05c1ed99..3010db03299 100644 --- a/keyboards/momokai/tap_trio_pro/analogkeys.h +++ b/keyboards/momokai/tap_trio_pro/analogkeys.h @@ -7,6 +7,7 @@ SPDX-License-Identifier: GPL-2.0-or-later */ #pragma once #include +#include enum analog_key_modes { dynamic_actuation = 0, diff --git a/keyboards/momokai/tap_trio_pro/keymaps/debug/keymap.c b/keyboards/momokai/tap_trio_pro/keymaps/debug/keymap.c index 6805a35b232..76958852559 100644 --- a/keyboards/momokai/tap_trio_pro/keymaps/debug/keymap.c +++ b/keyboards/momokai/tap_trio_pro/keymaps/debug/keymap.c @@ -5,7 +5,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [0] = LAYOUT( - KC_MUTE, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6 ) diff --git a/keyboards/momokai/tap_trio_pro/keymaps/default/keymap.c b/keyboards/momokai/tap_trio_pro/keymaps/default/keymap.c index e58069e5ae9..d34d4b49ce9 100644 --- a/keyboards/momokai/tap_trio_pro/keymaps/default/keymap.c +++ b/keyboards/momokai/tap_trio_pro/keymaps/default/keymap.c @@ -5,7 +5,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [0] = LAYOUT( - KC_MUTE, KC_Z, KC_X, KC_C, KC_GRV, KC_ESC, KC_F2 ) diff --git a/keyboards/momokai/tap_trio_pro/lut.c b/keyboards/momokai/tap_trio_pro/lut.c index 63171016c80..38f4dbbcaba 100644 --- a/keyboards/momokai/tap_trio_pro/lut.c +++ b/keyboards/momokai/tap_trio_pro/lut.c @@ -2,8 +2,8 @@ SPDX-License-Identifier: GPL-2.0-or-later */ #include #include -// #include "scanfunctions.h" -// #include "util.h" +#include "scanfunctions.h" +#include "util.h" #if !defined(MIN) # define MIN(x, y) (((x) < (y)) ? (x) : (y)) diff --git a/keyboards/momokai/tap_trio_pro/lut.h b/keyboards/momokai/tap_trio_pro/lut.h index 8889c153654..4f46ea25f32 100644 --- a/keyboards/momokai/tap_trio_pro/lut.h +++ b/keyboards/momokai/tap_trio_pro/lut.h @@ -8,6 +8,7 @@ extern uint16_t lut[ADC_RESOLUTION_MAX]; const double lut_a; const double lut_b; const double lut_c; +const double lut_d; uint16_t distance_to_adc(uint16_t distance); diff --git a/keyboards/momokai/tap_trio_pro/matrix.c b/keyboards/momokai/tap_trio_pro/matrix.c index aa96df6799f..b0e1a59be2a 100644 --- a/keyboards/momokai/tap_trio_pro/matrix.c +++ b/keyboards/momokai/tap_trio_pro/matrix.c @@ -1,6 +1,6 @@ /* Copyright 2023 RephlexZero (@RephlexZero) -Copyright 2023 peepeetee -SPDX-License-Identifier: GPL-2.0-or-later */ + Copyright 2023 peepeetee + SPDX-License-Identifier: GPL-2.0-or-later */ #include #include #include @@ -11,97 +11,26 @@ SPDX-License-Identifier: GPL-2.0-or-later */ #include "debounce.h" #include "scanfunctions.h" #include "sma.c" -// #include "matrix_helpers.c" #ifndef MATRIX_INPUT_PRESSED_STATE # define MATRIX_INPUT_PRESSED_STATE 0 #endif - -// //configuration for the SMA filter, default is 4 for 2^4 = 16 samples -// #ifndef SMA_FILTER_SAMPLE_EXPONENT -// # define SMA_FILTER_SAMPLE_EXPONENT 4 -// #endif - +// Pin and key matrix definitions pin_t matrix_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; - hybrid_key_t keys[MATRIX_ROWS][MATRIX_COLS] = {0}; static uint16_t pressedAdcValue = 0; static uint16_t restAdcValue = 0; -/* matrix state(1:on, 0:off) */ +/* Matrix state: 1 = on, 0 = off */ matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values matrix_row_t matrix[MATRIX_ROWS]; // debounced values - - - -void matrix_init_custom(void) { - - wait_ms(3500); //give time to try to have hid_listen spin up - - printf("%s\n", "test print at start of matrix init"); - wait_ms(250); - - - // printf("%s\n", "2nd test print at start of matrix init"); - // wait_ms(250); - // printf("%u\n", MATRIX_COLS); - // wait_ms(250); - // printf("%u\n", MATRIX_ROWS); - // wait_ms(250); - // for (uint8_t row = 0; row < MATRIX_ROWS; row++) { - // for (uint8_t col = 0; col < MATRIX_COLS; col++) { - // printf("%lu\n", matrix_pins[row][col]); - // wait_ms(250); - // } - // wait_ms(250); - // printf("\n"); - // } - - // wait_ms(250); - - - - for (uint8_t i = 0; i < MATRIX_COLS; i++) { - keys[1][i].is_analog = true; - //should really be done at compile time - // initialize_SMA_filter(keys[1][i], SMA_FILTER_SAMPLE_EXPONENT); - } - - // for (uint8_t row = 0; row < MATRIX_ROWS; row++) { - // for (uint8_t col = 0; col < MATRIX_COLS; col++) { - - // printf("keys[%u][%u].value = %u\n", row, col, keys[row][col].value); - // wait_ms(250); - // printf("keys[%u][%u].extremum = %u\n", row, col, keys[row][col].extremum); - // wait_ms(250); - // printf("keys[%u][%u].offset = %u\n", row, col, keys[row][col].offset); - // wait_ms(250); - // printf("keys[%u][%u].is_analog = %s\n", row, col, keys[row][col].is_analog ? "true" : "false"); - // wait_ms(250); - // printf("keys[%u][%u].dynamic_actuation_bool = %s\n", row, col, keys[row][col].dynamic_actuation_bool ? "true" : "false"); - // } - // wait_ms(250); - // printf("\n"); - // } - - generate_lut(); - pressedAdcValue = distance_to_adc(400); - restAdcValue = distance_to_adc(0); - // get_sensor_offsets(); - wait_ms(200); // Let ADC reach steady state - get_sensor_offsets(); -} - - - -//setup only rows 0 and 2, leave row 1 untouched -__attribute__((weak)) void matrix_init_pins(void) { - // if (keys[row][0].is_analog == false) +// Setup only rows 1, leave row 0 untouched (for analog) +void matrix_init_pins(void) { for (int row = 0; row < MATRIX_ROWS; row++) { - if (row != 1){ + if (row != 0) { for (int col = 0; col < MATRIX_COLS; col++) { pin_t pin = matrix_pins[row][col]; if (pin != NO_PIN) { @@ -112,118 +41,41 @@ __attribute__((weak)) void matrix_init_pins(void) { } } -// user-defined overridable functions +void matrix_init_custom(void) { + // Analog row setup (should ideally be done at compile time) + for (uint8_t i = 0; i < MATRIX_COLS; i++) { + keys[0][i].is_analog = true; + // initialize_SMA_filter(&keys[1][i], SMA_FILTER_SAMPLE_EXPONENT); + } + + matrix_init_pins(); + generate_lut(); + pressedAdcValue = distance_to_adc(400); + restAdcValue = distance_to_adc(0); + wait_ms(100); // Let ADC reach steady state + 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); -// static inline uint8_t readMatrixPin(pin_t pin) { -// if (pin != NO_PIN) { -// return (readPin(pin) == MATRIX_INPUT_PRESSED_STATE) ? 0 : 1; -// } else { -// return 1; -// } -// } - -matrix_row_t matrix_get_row(uint8_t row) { - - // TODO: return the requested row data - //matrix_common.c row 68 - - return matrix[row]; -} -# define print_matrix_header() print("\nr/c 01234567\n") -# define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row)) - -void matrix_print(void) { - // TODO: use print() to dump the current matrix state to console - //matrix_common.c row 84 - - print_matrix_header(); - - for (uint8_t row = 0; row < MATRIX_ROWS; row++) { - print_hex8(row); - print(": "); - print_matrix_row(row); - print("\n"); - } - -} - - -void matrix_init(void) { - // TODO: initialize hardware and global matrix state here - //matrix.c row 274 - //matrix_common.c row 149 - - - // initialize key pins - matrix_init_pins(); - matrix_init_custom(); - - // initialize matrix state: all keys off - for (uint8_t i = 0; i < MATRIX_ROWS; i++) { - raw_matrix[i] = 0; - matrix[i] = 0; - } - - // Unless hardware debouncing - Init the configured debounce routine - // debounce_init(MATRIX_ROWS); - - // This *must* be called for correct keyboard behavior - matrix_init_kb(); -} - - - -static inline uint8_t readMatrixPin(pin_t pin) { - if (pin != NO_PIN) { - return (readPin(pin) == MATRIX_INPUT_PRESSED_STATE) ? 0 : 1; - } else { - return 1; - } -} - -__attribute__((weak)) 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; -} - -matrix_row_t previous_matrix[MATRIX_ROWS]; +static matrix_row_t previous_matrix[MATRIX_ROWS]; bool matrix_scan_custom(matrix_row_t current_matrix[]) { - - - // matrix_row_t is an alias for u_int8_t - memcpy(previous_matrix, current_matrix, sizeof(previous_matrix)); for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { - if (keys[current_row][0].is_analog == false) { + if (!keys[current_row][0].is_analog) { matrix_read_cols_on_row(current_matrix, current_row); - } else { for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { hybrid_key_t *key = &keys[current_row][current_col]; - - // TODO: current row has to be 1!!!!!!!!!! - key->value = lut[analogReadPin(matrix_pins[current_row][current_col]) + key->offset]; - // limits our options, I would like to change hybrid_key_t to include weather it is a hall effect key - - // key->value = MIN((key->value << 8) / lut[1100 + key->offset], 400); switch (g_config.mode) { case dynamic_actuation: @@ -247,28 +99,15 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) { } uint8_t matrix_scan(void) { - // TODO: add matrix scanning routine here - //matrix.c row 324 - //matrix_common.c row 169 - bool changed = matrix_scan_custom(raw_matrix); - - // Unless hardware debouncing - use the configured debounce routine changed = debounce(raw_matrix, matrix, MATRIX_ROWS, changed); - - // This *must* be called for correct keyboard behavior matrix_scan_kb(); - 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) {} diff --git a/keyboards/momokai/tap_trio_pro/rules.mk b/keyboards/momokai/tap_trio_pro/rules.mk index 9de2c450db6..074558d5561 100644 --- a/keyboards/momokai/tap_trio_pro/rules.mk +++ b/keyboards/momokai/tap_trio_pro/rules.mk @@ -1,6 +1,6 @@ QUANTUM_LIB_SRC += analog.c SRC += matrix.c lut.c scanfunctions.c -CUSTOM_MATRIX = yes +CUSTOM_MATRIX = lite OPT = 3 diff --git a/keyboards/momokai/tap_trio_pro/tap_trio_pro.c b/keyboards/momokai/tap_trio_pro/tap_trio_pro.c index c85cbacab43..914015fef8b 100644 --- a/keyboards/momokai/tap_trio_pro/tap_trio_pro.c +++ b/keyboards/momokai/tap_trio_pro/tap_trio_pro.c @@ -56,7 +56,7 @@ bool debug_print(void) { int raw_analog_value[3]; for (uint8_t col = 0; col < MATRIX_COLS; col++) { - raw_analog_value[col] = analogReadPin(matrix_pins[1][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]); @@ -82,11 +82,11 @@ uint32_t idle_recalibrate_callback(uint32_t trigger_time, void *cb_arg) { #endif void values_load(void) { - eeconfig_read_kb_datablock(&g_config); + eeconfig_read_kb_datablock(&g_config, 0, EECONFIG_KB_DATA_SIZE); } void values_save(void) { - eeconfig_update_kb_datablock(&g_config); + eeconfig_update_kb_datablock(&g_config, 0, EECONFIG_KB_DATA_SIZE); } void eeconfig_init_kb() { @@ -203,16 +203,4 @@ void via_config_get_value(uint8_t *data) { #endif -#ifdef OLED_ENABLE -bool oled_task_kb() { - static const char image[] PROGMEM = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xf0, 0xfc, 0xff, 0xf8, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xfc, 0xbf, 0xbf, 0x9f, 0x9f, 0x1f, 0x1f, 0x1f, 0x5f, 0x5f, 0x5f, 0x1f, 0x1f, 0x1f, 0x7f, 0xff, 0xff, 0xfe, 0xf8, 0xe0, 0x80, 0x87, 0xff, 0xff, 0xfe, 0xf8, 0xf0, 0xe0, 0x80, 0x00, 0x00, 0x00, 0x27, 0x27, 0x27, 0x27, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x0f, 0x0e, 0x08, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x80, 0xe0, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x37, 0xe0, 0xe0, 0xe0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf8, 0xf8, 0xf8, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf0, 0xf0, 0x30, 0xf0, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xf0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x7f, 0x7f, 0x3f, 0x9f, 0xbf, 0xbf, 0xbf, 0xbf, 0x9f, 0x9f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, 0xe0, 0xe0, 0x80, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xf8, 0xf0, 0x00, 0x00, 0x00, 0xf0, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x07, 0x0f, 0x0f, 0x0f, 0x1f, 0x1f, 0x1f, 0x1f, 0x3f, 0x3f, 0x3f, 0x3f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x3f, 0x3f, 0x3f, 0x3f, 0x1f, 0x1f, 0x1f, 0x0f, 0x0f, 0x0f, 0x07, 0x03, 0x00, 0x00, 0x00, 0x80, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x3f, 0x3f, 0x1f, 0x80, 0xc0, 0xcf, 0xcf, 0xdf, 0x9f, 0x3f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; - - oled_write_raw_P(image, sizeof(image)); - - return false; -} -#endif From 162a64c2be2dfbc9938c4e9180f1a6c54b3917d9 Mon Sep 17 00:00:00 2001 From: peepeetee Date: Sat, 21 Jun 2025 23:15:19 +0800 Subject: [PATCH 35/43] fully functional. Changed every '400' to '255' for coherency. --- keyboards/momokai/tap_trio_pro/analogkeys.h | 2 +- keyboards/momokai/tap_trio_pro/lut.c | 20 +++++----- keyboards/momokai/tap_trio_pro/matrix.c | 37 +++++++++++++----- keyboards/momokai/tap_trio_pro/psudocode | 2 +- .../momokai/tap_trio_pro/scanfunctions.c | 38 +++++++++---------- keyboards/momokai/tap_trio_pro/tap_trio_pro.c | 10 ++--- 6 files changed, 63 insertions(+), 46 deletions(-) diff --git a/keyboards/momokai/tap_trio_pro/analogkeys.h b/keyboards/momokai/tap_trio_pro/analogkeys.h index 3010db03299..d855a3345ca 100644 --- a/keyboards/momokai/tap_trio_pro/analogkeys.h +++ b/keyboards/momokai/tap_trio_pro/analogkeys.h @@ -35,7 +35,7 @@ typedef struct { uint16_t extremum; int16_t offset; bool is_analog; - bool dynamic_actuation_bool; + bool continuous_dynamic_actuation; // uint16_t SMA_buffer[1<<(SMA_FILTER_SAMPLE_EXPONENT)]; uint8_t SMA_samplesExponent; uint8_t SMA_samples; diff --git a/keyboards/momokai/tap_trio_pro/lut.c b/keyboards/momokai/tap_trio_pro/lut.c index 38f4dbbcaba..5954e2bbac8 100644 --- a/keyboards/momokai/tap_trio_pro/lut.c +++ b/keyboards/momokai/tap_trio_pro/lut.c @@ -13,17 +13,17 @@ SPDX-License-Identifier: GPL-2.0-or-later */ # define MAX(x, y) (((x) > (y)) ? (x) : (y)) #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 */ -const double lut_a = -366.805673399; -const double lut_b = 0.00617870508512; -const double lut_c = -1.49468890703; -const double lut_d = 2094.38794157; +// /* Equation parameters for the sensor-magnet linearity mapping */ +// const double lut_a = -366.805673399; +// const double lut_b = 0.00617870508512; +// const double lut_c = -1.49468890703; +// 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) { double intermediate = lut_a * exp(lut_b * distance + lut_c) + lut_d; diff --git a/keyboards/momokai/tap_trio_pro/matrix.c b/keyboards/momokai/tap_trio_pro/matrix.c index b0e1a59be2a..adfd5479883 100644 --- a/keyboards/momokai/tap_trio_pro/matrix.c +++ b/keyboards/momokai/tap_trio_pro/matrix.c @@ -11,6 +11,8 @@ #include "debounce.h" #include "scanfunctions.h" #include "sma.c" +#include "quantum/matrix.h" + #ifndef MATRIX_INPUT_PRESSED_STATE # 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 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) void matrix_init_pins(void) { for (int row = 0; row < MATRIX_ROWS; row++) { @@ -56,10 +82,6 @@ void matrix_init_custom(void) { 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)); 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); } else { 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; } -__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) {} - diff --git a/keyboards/momokai/tap_trio_pro/psudocode b/keyboards/momokai/tap_trio_pro/psudocode index 27c083297ec..46242d619ac 100644 --- a/keyboards/momokai/tap_trio_pro/psudocode +++ b/keyboards/momokai/tap_trio_pro/psudocode @@ -48,7 +48,7 @@ matrix scanning: 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 - +https://www.desmos.com/calculator/qtbbjbsyvi diff --git a/keyboards/momokai/tap_trio_pro/scanfunctions.c b/keyboards/momokai/tap_trio_pro/scanfunctions.c index 0a0e37a9b7c..e2959d11a9e 100644 --- a/keyboards/momokai/tap_trio_pro/scanfunctions.c +++ b/keyboards/momokai/tap_trio_pro/scanfunctions.c @@ -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) { - if (*current_row & (1 << current_col)) { //if the key is currently pressed - if (key->value < MAX(g_config.actuation_point - g_config.release_hysteresis, 0)) { + if (*current_row & (1 << current_col)) { + if (key->value <= MAX(g_config.actuation_point - g_config.release_hysteresis, 0)) { deregister_key(current_row, current_col); } - } else { //if the key is currently not pressed - if (key->value > MIN(g_config.actuation_point + g_config.press_hysteresis, 255)) { + } else { + if (key->value >= MIN(g_config.actuation_point + g_config.press_hysteresis, CALIBRATION_RANGE)) { 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. */ 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)) { /* Key is pressed Is key still moving down? */ if (key->value > key->extremum) { 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? */ deregister_key(current_row, current_col); 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? */ if (key->value < key->extremum) { 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? */ register_key(current_row, current_col); update_extremum(key); } } - if (key->value < g_config.actuation_point - 5) { - deregister_key(current_row, current_col); + } else { + /* Out of DA zone + Always deregister key */ + deregister_key(current_row, current_col); + if (key->value > key->extremum) { 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) { - if (key->dynamic_actuation_bool) { + if (key->continuous_dynamic_actuation) { if (*current_row & (1 << current_col)) { /* Key is pressed Is key still moving down? */ if (key->value > key->extremum) { 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? */ deregister_key(current_row, current_col); 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? */ if (key->value < key->extremum) { 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? */ register_key(current_row, current_col); update_extremum(key); @@ -113,11 +113,11 @@ void matrix_read_cols_continuous_dynamic_actuation(matrix_row_t *current_row, ui if (key->value == 0) { deregister_key(current_row, current_col); update_extremum(key); - key->dynamic_actuation_bool = false; + key->continuous_dynamic_actuation = false; } } else if (key->value > g_config.actuation_point) { register_key(current_row, current_col); update_extremum(key); - key->dynamic_actuation_bool = true; + key->continuous_dynamic_actuation = true; } } diff --git a/keyboards/momokai/tap_trio_pro/tap_trio_pro.c b/keyboards/momokai/tap_trio_pro/tap_trio_pro.c index 914015fef8b..71864860b51 100644 --- a/keyboards/momokai/tap_trio_pro/tap_trio_pro.c +++ b/keyboards/momokai/tap_trio_pro/tap_trio_pro.c @@ -53,12 +53,12 @@ bool debug_print(void) { // uprintf("%s", buffer); - int raw_analog_value[3]; - for (uint8_t col = 0; col < MATRIX_COLS; col++) { + // int raw_analog_value[3]; + // for (uint8_t col = 0; col < MATRIX_COLS; 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]); + // 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]); return true; } From f959d55ba024b8176820f09cca8147163e7ae38a Mon Sep 17 00:00:00 2001 From: peepeetee Date: Sat, 21 Jun 2025 23:16:48 +0800 Subject: [PATCH 36/43] change one last 400 to 255 --- keyboards/momokai/tap_trio_pro/matrix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/keyboards/momokai/tap_trio_pro/matrix.c b/keyboards/momokai/tap_trio_pro/matrix.c index adfd5479883..4bd9da6cff2 100644 --- a/keyboards/momokai/tap_trio_pro/matrix.c +++ b/keyboards/momokai/tap_trio_pro/matrix.c @@ -76,7 +76,7 @@ void matrix_init_custom(void) { matrix_init_pins(); generate_lut(); - pressedAdcValue = distance_to_adc(400); + pressedAdcValue = distance_to_adc(255); restAdcValue = distance_to_adc(0); wait_ms(100); // Let ADC reach steady state get_sensor_offsets(); From 85b26762ee562a8f20670a8c7a146fdca2bd808b Mon Sep 17 00:00:00 2001 From: peepeetee Date: Sat, 21 Jun 2025 23:29:45 +0800 Subject: [PATCH 37/43] update default values --- keyboards/momokai/tap_trio_pro/matrix.c | 1 + keyboards/momokai/tap_trio_pro/tap_trio_pro.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/keyboards/momokai/tap_trio_pro/matrix.c b/keyboards/momokai/tap_trio_pro/matrix.c index 4bd9da6cff2..0746380af68 100644 --- a/keyboards/momokai/tap_trio_pro/matrix.c +++ b/keyboards/momokai/tap_trio_pro/matrix.c @@ -74,6 +74,7 @@ void matrix_init_custom(void) { // initialize_SMA_filter(&keys[1][i], SMA_FILTER_SAMPLE_EXPONENT); } + // eeconfig_init_kb(); matrix_init_pins(); generate_lut(); pressedAdcValue = distance_to_adc(255); diff --git a/keyboards/momokai/tap_trio_pro/tap_trio_pro.c b/keyboards/momokai/tap_trio_pro/tap_trio_pro.c index 71864860b51..31ab3e2b777 100644 --- a/keyboards/momokai/tap_trio_pro/tap_trio_pro.c +++ b/keyboards/momokai/tap_trio_pro/tap_trio_pro.c @@ -15,10 +15,10 @@ SPDX-License-Identifier: GPL-2.0-or-later */ analog_config g_config = { .mode = dynamic_actuation, - .actuation_point = 32, + .actuation_point = 48, .press_sensitivity = 32, .release_sensitivity = 32, - .press_hysteresis = 5, + .press_hysteresis = 0, .release_hysteresis = 5 }; From 8cdfdc2e10962383e1c0a890241e31383beb48a2 Mon Sep 17 00:00:00 2001 From: peepeetee Date: Sun, 22 Jun 2025 19:16:45 +0800 Subject: [PATCH 38/43] remove my notes --- keyboards/momokai/tap_trio_pro/psudocode | 54 ------------------------ 1 file changed, 54 deletions(-) delete mode 100644 keyboards/momokai/tap_trio_pro/psudocode diff --git a/keyboards/momokai/tap_trio_pro/psudocode b/keyboards/momokai/tap_trio_pro/psudocode deleted file mode 100644 index 46242d619ac..00000000000 --- a/keyboards/momokai/tap_trio_pro/psudocode +++ /dev/null @@ -1,54 +0,0 @@ -matrix scanning: - - scan values - put values in SMA filter: - for each key, there is a sma filter instance - the filter takes in a 2^4=16 values in a circular buffer - 3 variables: 4 -> 2^4 -> uint16_t[2^4] - state variable: is filter initialized for this key? - pointer: where in the circular buffer are we? - sum: sum of values in the circular buffer, so that we don't have to access the whole buffer, just 2 elements. - - special case: initialization - return unfiltered value if the buffer is not filled yet - - get value out, update sensor boundaries only if sma initialized - - on minipad, TRAVEL_DISTANCE_IN_0_01MM is set to 400, which is the range of motion switches have. - i.e. at rest - bottomed out = 4mm - - sensor calibration logic: - on rephlex, the sensors are updated only when they are at their highest, at the start and in a maintaince task that runs periodically: - - - on minipad, the sensors are updated dynamically when they are actuated on an ougoing basis: - There is an up deadzone and a down deadzone - - - - - calebrate key if this is first pass - - - run algos on the key: - regular(look at the methods already implemented) - rapid trigger: - 1. - default boundaries are hysteresis values, reset state once reached - (if continuous rapid trigger, reset state only if fully released) - 2. - when rapid trigger state is false - if value is in rapid trigger zone, press and set rapid trigger state - if state is false && lower than lower hysteresis, press key and set rapid trigger state - 3. - when rapid trigger state is true - if pressed && left rt zone or value is 'sensitivity' above peak, release - if not pressed and key is in trigger zone and value is sensitivity below peak, press - - 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 - -https://www.desmos.com/calculator/qtbbjbsyvi - - - From 161b226675d215b8805be4567b831b0a56027f9c Mon Sep 17 00:00:00 2001 From: peepeetee Date: Sun, 22 Jun 2025 20:36:53 +0800 Subject: [PATCH 39/43] cleanup code --- keyboards/momokai/tap_trio_pro/analogkeys.h | 7 --- keyboards/momokai/tap_trio_pro/config.h | 9 ---- keyboards/momokai/tap_trio_pro/keyboard.json | 3 -- keyboards/momokai/tap_trio_pro/lut.c | 14 +++--- keyboards/momokai/tap_trio_pro/matrix.c | 9 ---- keyboards/momokai/tap_trio_pro/readme.md | 16 +++---- keyboards/momokai/tap_trio_pro/sma.c | 45 -------------------- keyboards/momokai/tap_trio_pro/sma.h | 8 ---- 8 files changed, 13 insertions(+), 98 deletions(-) delete mode 100644 keyboards/momokai/tap_trio_pro/sma.c delete mode 100644 keyboards/momokai/tap_trio_pro/sma.h diff --git a/keyboards/momokai/tap_trio_pro/analogkeys.h b/keyboards/momokai/tap_trio_pro/analogkeys.h index d855a3345ca..75fd4017ca2 100644 --- a/keyboards/momokai/tap_trio_pro/analogkeys.h +++ b/keyboards/momokai/tap_trio_pro/analogkeys.h @@ -36,12 +36,5 @@ typedef struct { int16_t offset; bool is_analog; bool continuous_dynamic_actuation; - // uint16_t SMA_buffer[1<<(SMA_FILTER_SAMPLE_EXPONENT)]; - uint8_t SMA_samplesExponent; - uint8_t SMA_samples; - uint16_t *SMA_buffer; - uint32_t SMA_sum; - uint8_t SMA_index; - bool SMA_filled; } hybrid_key_t; extern hybrid_key_t keys[MATRIX_ROWS][MATRIX_COLS]; diff --git a/keyboards/momokai/tap_trio_pro/config.h b/keyboards/momokai/tap_trio_pro/config.h index e9e0704bf57..738f8935276 100644 --- a/keyboards/momokai/tap_trio_pro/config.h +++ b/keyboards/momokai/tap_trio_pro/config.h @@ -14,12 +14,3 @@ #define CALIBRATION_RANGE 255 -#define DEBOUNCE 16 - -//this configuration for the SMA filter, default is 4 for 2^4 = 16 samples -#define SMA_FILTER_SAMPLE_EXPONENT 4 - -#define I2C1_SCL_PIN GP19 -#define I2C1_SDA_PIN GP18 -#define OLED_BRIGHTNESS 128 -#define OLED_UPDATE_INTERVAL 1000 diff --git a/keyboards/momokai/tap_trio_pro/keyboard.json b/keyboards/momokai/tap_trio_pro/keyboard.json index bdf19928a10..4c58f756451 100644 --- a/keyboards/momokai/tap_trio_pro/keyboard.json +++ b/keyboards/momokai/tap_trio_pro/keyboard.json @@ -19,9 +19,6 @@ "matrix": [1, 0] }, "debounce": 0, - "build": { - "lto": true - }, "matrix_pins": { "direct": [ ["GP28", "GP27", "GP26" ], diff --git a/keyboards/momokai/tap_trio_pro/lut.c b/keyboards/momokai/tap_trio_pro/lut.c index 5954e2bbac8..4271ee5945e 100644 --- a/keyboards/momokai/tap_trio_pro/lut.c +++ b/keyboards/momokai/tap_trio_pro/lut.c @@ -5,21 +5,17 @@ SPDX-License-Identifier: GPL-2.0-or-later */ #include "scanfunctions.h" #include "util.h" -#if !defined(MIN) -# define MIN(x, y) (((x) < (y)) ? (x) : (y)) -#endif - -#if !defined(MAX) -# define MAX(x, y) (((x) > (y)) ? (x) : (y)) -#endif - - // /* Equation parameters for the sensor-magnet linearity mapping */ + +//https://www.desmos.com/calculator/qtbbjbsyvi + +// These are values when there were 400 steps // const double lut_a = -366.805673399; // const double lut_b = 0.00617870508512; // const double lut_c = -1.49468890703; // const double lut_d = 2094.38794157; +//Values for 256 steps const double lut_a = -0.203212; const double lut_b = 0.00955995; const double lut_c = 5.99691; diff --git a/keyboards/momokai/tap_trio_pro/matrix.c b/keyboards/momokai/tap_trio_pro/matrix.c index 0746380af68..252484182b9 100644 --- a/keyboards/momokai/tap_trio_pro/matrix.c +++ b/keyboards/momokai/tap_trio_pro/matrix.c @@ -8,9 +8,7 @@ #include "quantum.h" #include "analog.h" #include "lut.h" -#include "debounce.h" #include "scanfunctions.h" -#include "sma.c" #include "quantum/matrix.h" @@ -121,11 +119,4 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) { return memcmp(previous_matrix, current_matrix, sizeof(previous_matrix)) != 0; } -uint8_t matrix_scan(void) { - bool changed = matrix_scan_custom(raw_matrix); - changed = debounce(raw_matrix, matrix, MATRIX_ROWS, changed); - matrix_scan_kb(); - return (uint8_t)changed; -} - diff --git a/keyboards/momokai/tap_trio_pro/readme.md b/keyboards/momokai/tap_trio_pro/readme.md index 2069f6826fa..c1db565ced5 100644 --- a/keyboards/momokai/tap_trio_pro/readme.md +++ b/keyboards/momokai/tap_trio_pro/readme.md @@ -1,20 +1,20 @@ -# momokai/hall_effect +# momokai/tap_trio_pro -![momokai/hall_effect](imgur.com image replace me!) +![momokai/tap_trio_pro](imgur.com image replace me!) -*A short description of the keyboard/project* +Tap trio pro, a 6 key macropad with 3 hall effect switches * Keyboard Maintainer: [peepeetee](https://github.com/peepeetee) -* Hardware Supported: *The PCBs, controllers supported* +* Hardware Supported: Tap trio pro * Hardware Availability: *Links to where you can find this hardware* Make example for this keyboard (after setting up your build environment): - make momokai/hall_effect:default + make momokai/tap_trio_pro:default Flashing example for this keyboard: - make momokai/hall_effect:default:flash + make momokai/tap_trio_pro:default:flash See the [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) and the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. Brand new to QMK? Start with our [Complete Newbs Guide](https://docs.qmk.fm/#/newbs). @@ -22,6 +22,6 @@ See the [build environment setup](https://docs.qmk.fm/#/getting_started_build_to Enter the bootloader in 3 ways: -* **Bootmagic reset**: Hold down the key at (0,0) in the matrix (usually the top left key or Escape) and plug in the keyboard -* **Physical reset button**: Briefly press the button on the back of the PCB - some may have pads you must short instead +* **Bootmagic reset**: Hold down the key at (1,0) in the matrix (the left most micro switch) and plug in the keyboard +* **Physical reset button**: Hold down the BOOT1 button on the back of the PCB While plugging it in * **Keycode in layout**: Press the key mapped to `QK_BOOT` if it is available diff --git a/keyboards/momokai/tap_trio_pro/sma.c b/keyboards/momokai/tap_trio_pro/sma.c deleted file mode 100644 index eda3d229555..00000000000 --- a/keyboards/momokai/tap_trio_pro/sma.c +++ /dev/null @@ -1,45 +0,0 @@ -/* Copyright 2024 peepeetee (@peepeetee) 2024 minisbett (@minisbett) -SPDX-License-Identifier: GPL-2.0-or-later */ - -#include -#include "analogkeys.h" - - - -void initialize_SMA_filter(hybrid_key_t key, uint8_t samplesExponent) { - key.SMA_samplesExponent = samplesExponent; - key.SMA_samples = 1 << samplesExponent; - key.SMA_buffer = malloc((key.SMA_samples)*sizeof(uint16_t)); - for (int i = 0; i < key.SMA_samples; i++) { - key.SMA_buffer[i] = 0; - } - printf("%s\n", "SMA_buffer test print"); - key.SMA_sum = 0; - key.SMA_index = 0; -} - -uint16_t SMA_filter(hybrid_key_t key, uint16_t value) { - key.SMA_sum = key.SMA_sum - key.SMA_buffer[key.SMA_index] + value; - key.SMA_buffer[key.SMA_index] = value; - key.SMA_index = (key.SMA_index + 1) % key.SMA_samples; - if (!key.SMA_filled) { - if (key.SMA_index == 0) { - key.SMA_filled = true; - } - } - - printf("%s\n", "SMA_filter test print"); - printf("%s\n", "SMA_sum and SMA_index:"); - printf("%lu\n", key.SMA_sum); - printf("%x\n", key.SMA_index); - for(int i = 0; i < key.SMA_samples; i++) { - printf("%u\n", key.SMA_buffer[i]); - } - printf("%s\n", "current value:"); - printf("%x\n", key.SMA_buffer[key.SMA_index]); - return key.SMA_sum >> key.SMA_samplesExponent; -} - - - - diff --git a/keyboards/momokai/tap_trio_pro/sma.h b/keyboards/momokai/tap_trio_pro/sma.h deleted file mode 100644 index b22f5dccf40..00000000000 --- a/keyboards/momokai/tap_trio_pro/sma.h +++ /dev/null @@ -1,8 +0,0 @@ - -#pragma once -#include -#include "analogkeys.h" - -void initialize_SMA_filter(hybrid_key_t key, uint8_t samplesExponent); - -uint16_t SMA_filter(hybrid_key_t key, uint16_t value); From 76ea3c28596d7a5eacf485907e0bc31e458e702b Mon Sep 17 00:00:00 2001 From: peepeetee Date: Sun, 22 Jun 2025 20:54:04 +0800 Subject: [PATCH 40/43] remove keymaps --- .../tap_trio_pro/keymaps/blank/keymap.c | 19 ------------------- .../tap_trio_pro/keymaps/blank/rules.mk | 1 - .../keymaps/blank_hall_effect/keymap.c | 19 ------------------- .../keymaps/blank_hall_effect/rules.mk | 1 - .../tap_trio_pro/keymaps/debug/keymap.c | 18 ------------------ .../tap_trio_pro/keymaps/debug/rules.mk | 1 - .../tap_trio_pro/keymaps/default/rules.mk | 1 - .../momokai/tap_trio_pro/keymaps/via/keymap.c | 11 ----------- .../momokai/tap_trio_pro/keymaps/via/rules.mk | 4 ---- 9 files changed, 75 deletions(-) delete mode 100644 keyboards/momokai/tap_trio_pro/keymaps/blank/keymap.c delete mode 100644 keyboards/momokai/tap_trio_pro/keymaps/blank/rules.mk delete mode 100644 keyboards/momokai/tap_trio_pro/keymaps/blank_hall_effect/keymap.c delete mode 100644 keyboards/momokai/tap_trio_pro/keymaps/blank_hall_effect/rules.mk delete mode 100644 keyboards/momokai/tap_trio_pro/keymaps/debug/keymap.c delete mode 100644 keyboards/momokai/tap_trio_pro/keymaps/debug/rules.mk delete mode 100644 keyboards/momokai/tap_trio_pro/keymaps/default/rules.mk delete mode 100644 keyboards/momokai/tap_trio_pro/keymaps/via/keymap.c delete mode 100644 keyboards/momokai/tap_trio_pro/keymaps/via/rules.mk diff --git a/keyboards/momokai/tap_trio_pro/keymaps/blank/keymap.c b/keyboards/momokai/tap_trio_pro/keymaps/blank/keymap.c deleted file mode 100644 index e1796ecabb9..00000000000 --- a/keyboards/momokai/tap_trio_pro/keymaps/blank/keymap.c +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2023 peepeetee -// SPDX-License-Identifier: GPL-2.0-or-later - -#include QMK_KEYBOARD_H - -const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { - [0] = LAYOUT( - KC_MUTE, - KC_TRNS, KC_TRNS, KC_TRNS, - KC_TRNS, KC_TRNS, KC_TRNS - ) -}; - -#if defined(ENCODER_MAP_ENABLE) -const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = { - [0] = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU) } - -}; -#endif diff --git a/keyboards/momokai/tap_trio_pro/keymaps/blank/rules.mk b/keyboards/momokai/tap_trio_pro/keymaps/blank/rules.mk deleted file mode 100644 index ee325681483..00000000000 --- a/keyboards/momokai/tap_trio_pro/keymaps/blank/rules.mk +++ /dev/null @@ -1 +0,0 @@ -ENCODER_MAP_ENABLE = yes diff --git a/keyboards/momokai/tap_trio_pro/keymaps/blank_hall_effect/keymap.c b/keyboards/momokai/tap_trio_pro/keymaps/blank_hall_effect/keymap.c deleted file mode 100644 index e4ef63117c3..00000000000 --- a/keyboards/momokai/tap_trio_pro/keymaps/blank_hall_effect/keymap.c +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2023 peepeetee -// SPDX-License-Identifier: GPL-2.0-or-later - -#include QMK_KEYBOARD_H - -const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { - [0] = LAYOUT( - KC_MUTE, - KC_TRNS, KC_TRNS, KC_TRNS, - KC_1, KC_2, KC_3 - ) -}; - -#if defined(ENCODER_MAP_ENABLE) -const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = { - [0] = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU) } - -}; -#endif diff --git a/keyboards/momokai/tap_trio_pro/keymaps/blank_hall_effect/rules.mk b/keyboards/momokai/tap_trio_pro/keymaps/blank_hall_effect/rules.mk deleted file mode 100644 index ee325681483..00000000000 --- a/keyboards/momokai/tap_trio_pro/keymaps/blank_hall_effect/rules.mk +++ /dev/null @@ -1 +0,0 @@ -ENCODER_MAP_ENABLE = yes diff --git a/keyboards/momokai/tap_trio_pro/keymaps/debug/keymap.c b/keyboards/momokai/tap_trio_pro/keymaps/debug/keymap.c deleted file mode 100644 index 76958852559..00000000000 --- a/keyboards/momokai/tap_trio_pro/keymaps/debug/keymap.c +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2023 peepeetee -// SPDX-License-Identifier: GPL-2.0-or-later - -#include QMK_KEYBOARD_H - -const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { - [0] = LAYOUT( - KC_1, KC_2, KC_3, - KC_4, KC_5, KC_6 - ) -}; - -#if defined(ENCODER_MAP_ENABLE) -const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = { - [0] = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU) } - -}; -#endif diff --git a/keyboards/momokai/tap_trio_pro/keymaps/debug/rules.mk b/keyboards/momokai/tap_trio_pro/keymaps/debug/rules.mk deleted file mode 100644 index ee325681483..00000000000 --- a/keyboards/momokai/tap_trio_pro/keymaps/debug/rules.mk +++ /dev/null @@ -1 +0,0 @@ -ENCODER_MAP_ENABLE = yes diff --git a/keyboards/momokai/tap_trio_pro/keymaps/default/rules.mk b/keyboards/momokai/tap_trio_pro/keymaps/default/rules.mk deleted file mode 100644 index ee325681483..00000000000 --- a/keyboards/momokai/tap_trio_pro/keymaps/default/rules.mk +++ /dev/null @@ -1 +0,0 @@ -ENCODER_MAP_ENABLE = yes diff --git a/keyboards/momokai/tap_trio_pro/keymaps/via/keymap.c b/keyboards/momokai/tap_trio_pro/keymaps/via/keymap.c deleted file mode 100644 index 84824e214c1..00000000000 --- a/keyboards/momokai/tap_trio_pro/keymaps/via/keymap.c +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2023 peepeetee -// SPDX-License-Identifier: GPL-2.0-or-later - -#include QMK_KEYBOARD_H - -const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { - [0] = LAYOUT( - KC_Z, KC_X, KC_C, - KC_GRV, KC_ESC, KC_F2 - ), -}; diff --git a/keyboards/momokai/tap_trio_pro/keymaps/via/rules.mk b/keyboards/momokai/tap_trio_pro/keymaps/via/rules.mk deleted file mode 100644 index 293c5ffdeb9..00000000000 --- a/keyboards/momokai/tap_trio_pro/keymaps/via/rules.mk +++ /dev/null @@ -1,4 +0,0 @@ -VIA_ENABLE = yes -LTO_ENABLE = yes - -ENCODER_MAP_ENABLE = yes From a4069cefc05fdbd1bdc2c305578d53b97697e47a Mon Sep 17 00:00:00 2001 From: peepeetee Date: Sun, 22 Jun 2025 21:00:15 +0800 Subject: [PATCH 41/43] fill out readme.md --- keyboards/momokai/tap_trio_pro/readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/keyboards/momokai/tap_trio_pro/readme.md b/keyboards/momokai/tap_trio_pro/readme.md index c1db565ced5..8e9207a9d8c 100644 --- a/keyboards/momokai/tap_trio_pro/readme.md +++ b/keyboards/momokai/tap_trio_pro/readme.md @@ -1,12 +1,12 @@ # momokai/tap_trio_pro -![momokai/tap_trio_pro](imgur.com image replace me!) +![momokai/tap_trio_pro](https://i.imgur.com/k6EqTA1.jpeg) Tap trio pro, a 6 key macropad with 3 hall effect switches * Keyboard Maintainer: [peepeetee](https://github.com/peepeetee) * Hardware Supported: Tap trio pro -* Hardware Availability: *Links to where you can find this hardware* +* Hardware Availability: https://momokai.com/ Make example for this keyboard (after setting up your build environment): From 8041da7c0c77def07fdf822ede670e8327d7ff42 Mon Sep 17 00:00:00 2001 From: peepeetee Date: Sun, 22 Jun 2025 21:06:51 +0800 Subject: [PATCH 42/43] fix url and command config --- keyboards/momokai/tap_trio_pro/keyboard.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/keyboards/momokai/tap_trio_pro/keyboard.json b/keyboards/momokai/tap_trio_pro/keyboard.json index 4c58f756451..529ea33c360 100644 --- a/keyboards/momokai/tap_trio_pro/keyboard.json +++ b/keyboards/momokai/tap_trio_pro/keyboard.json @@ -2,10 +2,10 @@ "manufacturer": "momokai", "keyboard_name": "tap_trio_pro", "maintainer": "peepeetee", + "url": "https://momokai.com/", "bootloader": "rp2040", "features": { "bootmagic": true, - "command": false, "console": true, "debug": true, "extrakey": true, @@ -25,10 +25,7 @@ ["GP10", "GP9", "GP8" ] ] }, - - "processor": "RP2040", - "url": "", "usb": { "device_version": "1.0.0", "pid": "0x0016", From b491088d6f8a3a65f19432a754e1bb00d34b7141 Mon Sep 17 00:00:00 2001 From: peepeetee Date: Sun, 22 Jun 2025 21:09:57 +0800 Subject: [PATCH 43/43] use format-json on keyboard.json --- keyboards/momokai/tap_trio_pro/keyboard.json | 149 +++++++++---------- 1 file changed, 73 insertions(+), 76 deletions(-) diff --git a/keyboards/momokai/tap_trio_pro/keyboard.json b/keyboards/momokai/tap_trio_pro/keyboard.json index 529ea33c360..137a8f7e283 100644 --- a/keyboards/momokai/tap_trio_pro/keyboard.json +++ b/keyboards/momokai/tap_trio_pro/keyboard.json @@ -2,96 +2,94 @@ "manufacturer": "momokai", "keyboard_name": "tap_trio_pro", "maintainer": "peepeetee", - "url": "https://momokai.com/", "bootloader": "rp2040", - "features": { - "bootmagic": true, - "console": true, - "debug": true, - "extrakey": true, - "mousekey": true, - "rgb_matrix": true, - "oled": true, - "nkro": true, - "deferred_exec": true - }, "bootmagic": { "matrix": [1, 0] }, "debounce": 0, + "features": { + "bootmagic": true, + "console": true, + "debug": true, + "deferred_exec": true, + "extrakey": true, + "mousekey": true, + "nkro": true, + "oled": true, + "rgb_matrix": true + }, "matrix_pins": { "direct": [ - ["GP28", "GP27", "GP26" ], - ["GP10", "GP9", "GP8" ] + ["GP28", "GP27", "GP26"], + ["GP10", "GP9", "GP8"] ] }, "processor": "RP2040", + "rgb_matrix": { + "animations": { + "alphas_mods": true, + "band_pinwheel_sat": true, + "band_pinwheel_val": true, + "band_sat": true, + "band_spiral_sat": true, + "band_spiral_val": true, + "band_val": true, + "breathing": true, + "cycle_all": true, + "cycle_left_right": true, + "cycle_out_in": true, + "cycle_out_in_dual": true, + "cycle_pinwheel": true, + "cycle_spiral": true, + "cycle_up_down": true, + "digital_rain": true, + "dual_beacon": true, + "gradient_left_right": true, + "gradient_up_down": true, + "hue_breathing": true, + "hue_pendulum": true, + "hue_wave": true, + "jellybean_raindrops": true, + "multisplash": true, + "pixel_flow": true, + "pixel_fractal": true, + "pixel_rain": true, + "rainbow_beacon": true, + "rainbow_moving_chevron": true, + "rainbow_pinwheels": true, + "raindrops": true, + "solid_color": true, + "solid_multisplash": true, + "solid_reactive": true, + "solid_reactive_cross": true, + "solid_reactive_multicross": true, + "solid_reactive_multinexus": true, + "solid_reactive_multiwide": true, + "solid_reactive_nexus": true, + "solid_reactive_simple": true, + "solid_reactive_wide": true, + "solid_splash": true, + "splash": true, + "typing_heatmap": true + }, + "driver": "ws2812", + "layout": [ + {"matrix": [1, 0], "x": 0, "y": 0, "flags": 4}, + {"matrix": [1, 1], "x": 0, "y": 32, "flags": 4}, + {"matrix": [1, 2], "x": 0, "y": 64, "flags": 4} + ], + "led_count": 3, + "sleep": true + }, + "url": "https://momokai.com/", "usb": { "device_version": "1.0.0", "pid": "0x0016", "vid": "0x69F9" }, "ws2812": { - "pin": "GP29", - "driver": "vendor" - }, - "rgb_matrix": { - - "driver": "ws2812", - "led_count": 3, - "sleep": true, - "animations": { - "solid_color": true, - "alphas_mods": true, - "gradient_up_down": true, - "gradient_left_right": true, - "breathing": true, - "band_sat": true, - "band_val": true, - "band_pinwheel_sat": true, - "band_pinwheel_val": true, - "band_spiral_sat": true, - "band_spiral_val": true, - "cycle_all": true, - "cycle_left_right": true, - "cycle_up_down": true, - "cycle_out_in": true, - "cycle_out_in_dual": true, - "rainbow_moving_chevron": true, - "cycle_pinwheel": true, - "cycle_spiral": true, - "dual_beacon": true, - "rainbow_beacon": true, - "rainbow_pinwheels": true, - "raindrops": true, - "jellybean_raindrops": true, - "hue_breathing": true, - "hue_pendulum": true, - "hue_wave": true, - "pixel_fractal": true, - "pixel_flow": true, - "pixel_rain": true, - "typing_heatmap": true, - "digital_rain": true, - "solid_reactive_simple": true, - "solid_reactive": true, - "solid_reactive_wide": true, - "solid_reactive_multiwide": true, - "solid_reactive_cross": true, - "solid_reactive_multicross": true, - "solid_reactive_nexus": true, - "solid_reactive_multinexus": true, - "splash": true, - "multisplash": true, - "solid_splash": true, - "solid_multisplash": true - }, - "layout": [ - {"flags": 4, "matrix": [1, 0], "x": 0, "y": 0}, - {"flags": 4, "matrix": [1, 1], "x": 0, "y": 32}, - {"flags": 4, "matrix": [1, 2], "x": 0, "y": 64} - ] - + "driver": "vendor", + "pin": "GP29" }, "layouts": { "LAYOUT": { @@ -99,11 +97,10 @@ {"matrix": [0, 0], "x": 0, "y": 0}, {"matrix": [0, 1], "x": 1, "y": 0}, {"matrix": [0, 2], "x": 2, "y": 0}, - {"matrix": [1, 0], "x": 0.5, "y": 1.25, "w": 0.5, "h": 0.5}, {"matrix": [1, 1], "x": 1, "y": 1.25, "w": 0.5, "h": 0.5}, {"matrix": [1, 2], "x": 1.5, "y": 1.25, "w": 0.5, "h": 0.5} ] } } -} +} \ No newline at end of file