Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Extended per-key debouncing #24658

Open
1 of 4 tasks
boessu opened this issue Nov 29, 2024 · 1 comment
Open
1 of 4 tasks

[Feature Request] Extended per-key debouncing #24658

boessu opened this issue Nov 29, 2024 · 1 comment

Comments

@boessu
Copy link

boessu commented Nov 29, 2024

Feature Request Type

  • Core functionality
  • Add-on hardware support (eg. audio, RGB, OLED screen, etc.)
  • Alteration (enhancement/optimization) of existing feature(s)
  • New behavior

Description

Problem: Alot of people do complain about spacebar-chattering on their keyboards while the rest of the keys do work fine (me too ;-). It seems as this is a specific problem on brown switches, and it seems as it is not only one keyboard brand which is affected (search for reddit discussions. You'll find them), It also happens on brand-new keyboards.

Solution/Feature request: I would like to enhance the per-key debouncing with the option of an extended debounce time for specific keys like the spacebar.

Example code in sym_defer_pk.c

// Extended debounce for specific keys (e.g. spacebar)
#ifndef DEBOUNCE_EXTENDED
#    define DEBOUNCE_EXTENDED 5
#endif

// Maximum debounce: 255ms
#if DEBOUNCE_EXTENDED > UINT8_MAX
#    undef DEBOUNCE_EXTENDED
#    define DEBOUNCE_EXTENDED UINT8_MAX
#endif

// Extended debounce on specific keys (default: false)
// Example: debouncing keys in matrix row 0, column 0 and row 1, column 1:
// # define DEBOUNCE_EXTENDED_KEYS(row, col) ((row == 0 && col == 0) || (row == 1 && col == 1))
#ifndef DEBOUNCE_EXTENDED_KEYS
    # define DEBOUNCE_EXTENDED_KEYS(row, col) (false)
#endif

the operation start_debounce_counters has to be enhanced with a if-statement:

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) {
                    // enhanced debouncing for specific keys
                    if (DEBOUNCE_EXTENDED_KEYS(row, col)) {
                        *debounce_pointer    = DEBOUNCE_EXTENDED;
                    } else {
                        *debounce_pointer    = DEBOUNCE;
                    }
                    counters_need_update = true;
                }
            } else {
                *debounce_pointer = DEBOUNCE_ELAPSED;
            }
            debounce_pointer++;
        }
    }
}

I guess the compiler will remove the "dead parts" in the case if it is statically set to false.
It can be used in sym_eager_pk.c too. I'm not sure if it makes sense in asym_eager_defer_pk.c though.

@filterpaper
Copy link
Contributor

An actual user function like bool extended_debounce(uint8_t row, uint8_t col) (instead of DEBOUNCE_EXTENDED_KEYS(row, col)) will be safer while avoiding the pitfalls of a complex preprocessor macro. Proper preprocessor guards like the examples in PR 24560 will avoid any code bloat when the feature is not activated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants