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

Adaptive debounce logic #4454

Merged
merged 1 commit into from
Nov 22, 2018
Merged

Adaptive debounce logic #4454

merged 1 commit into from
Nov 22, 2018

Conversation

trunneml
Copy link

About

I extended the current debounce logic with an adaptive by switch debouncing. This way a bad switch gets a higher debouncing as a good switch.

How it works

The debounce filtering reports a key/switch change directly as before, without any extra delay. The new thing is that the debounce logic will filter all further changes, until the key/switch reports the same state for the given count of scans. As long as the switch toggles the internal debounce counter of the switch will set to DEBOUNCE from config.h. The counter is decreased every scan where the switch didn't changed it's state.
So a perfect switch will get a short debounce period (min. DEBOUNCE) and a bad key will get a much longer debounce period. The result is an adaptive debouncing period for each switch.
In other words this gives an adaptive debouncing period for each switch / keypress.

Background

I've got an ergodox with kailh cooper switches. I love this switches but the operation point and the reset point are very close together, directly on the pressure point. So a slightly wobbling of the key creates a double key press, when you type slowly without bottoming out. With the old debouncing (before #1279) this wasn't a problem. But since then, some of my keys needed a debouncing value of 35. With this patch I could reduce DEBOUNCE scan count to 10 without any problems, even super fast double key presses are correctly detected with out bouncing. Slow-mo typing without bottoming out, which means I hold the key directly between operation and reset point, is no longer a problem. So with this patch the ergodox-ez should be faster (DEBOUNCE is now 10) and more robust against bouncing.

@ezuk Do you see any problems with this? I think this should reduce the bounce problem of the mentioned ergodox-ez batches in the comment.

The debounce filtering reports a key/switch change directly, without any extra delay. After that the debounce logic will filter all further changes, until the key/switch reports the same state for the given count of scans.
So a perfect switch will get a short debounce period and a bad key will get a much longer debounce period. The result is an adaptive debouncing period for each switch.

This value defines how often the same key/switch state has to be detected in successive reads until the next key state can be reported.
In other words this value defines the minimum debouncing period for a switch.
@ezuk
Copy link
Contributor

ezuk commented Nov 20, 2018

interesting! @fdidron thoughts?

@fdidron
Copy link
Contributor

fdidron commented Nov 22, 2018

@ezuk @trunneml I tested this intensively on the Shine and the Glow. It works perfectly, awesome contribution. The new #define DEBOUNCE 10 is a good sensible default value.

@trunneml
Copy link
Author

@ezuk @trunneml I tested this intensively on the Shine and the Glow. It works perfectly, awesome contribution. The new #define DEBOUNCE 10 is a good sensible default value.

I think 5 should also work fine. But I couldn't test it. Is there a way to test one of the ergodox-ez that really needes 15?

@ezuk
Copy link
Contributor

ezuk commented Nov 22, 2018

@trunneml awesome stuff! Merging, thank you for contributing! 😍

@ezuk ezuk merged commit 48262bd into qmk:master Nov 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants