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,