Interesting discussion! I want to make my own keyboard firmware, so I looked at how some existing community firmwares do debouncing and then I searched and found this thread.
If I got it right...
* Hasu's tmk_firmware does debouncing on all keys as a block. Polling the matrix in an idle loop until it finds a possible key-press. Then it enters "debouncing mode", where it waits 1 ms between sampling. 5 ms debounce interval on both press and release.
* bpiphany's AVR-Keyboard does no debouncing on press, but 3.9 ms on release, per key. 0.48 ms between advancing the key's debouncing counter, but sampling continuously.
* The ErgoDox firmware does no debouncing at all, waiting 5 ms between samples.
I wonder if anyone has experienced spurious keys or chattering on the Phantom or ErgoDox...
I have a chattering switch on my Phantom/AVR-Keyboard, but that switch also feels different so it must have been damaged when I lubed it.
If I understand it right, you would need debouncing on at least key press
or key release to avoid chattering, but you would need it on both if you also need to avoid EMI problems.
I think I'll do the sliding window method, with each generation a bitfield (array of bitfields, really).
Bitfields because using bitfields are the direct result datatypes from scanning and the deghosting routine (if I would need to use it) is simpler with bitfields that it would be otherwise. The complexity is instead laid on the debouncing routine. Vertical counters would use less memory - but they are more complex, especially if you want to allow different intervals for press and release, but then they wouldn't save
that much memory anyway.
I am thinking of putting the scanning into a 1 KHz timer interrupt, but the debouncing (and deghosting) in the main loop. That way, if the main loop takes longer than 1 ms (because of various keyboard features
), then it would still debounce recent samples.