-
Notifications
You must be signed in to change notification settings - Fork 2k
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
matrix_keypad: Add matrix-style keypad module #18733
Conversation
863a85e
to
e95876c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks neat!
drivers/include/matrix_keypad.h
Outdated
/** | ||
* @brief Device initialization parameters | ||
*/ | ||
matrix_keypad_params_t params; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not
matrix_keypad_params_t params; | |
const matrix_keypad_params_t *params; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with either, afaik this is a memory latency vs ram usage tradeoff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that measurable?
We are also running the code from flash after all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really don't remember the specifics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I'm fine with either here, so just confirm if you prefer it in ROM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It depends on the MCU. E.g. AVRs are clocked so slow so that they do not need to wait for ROM access - it really is the flash that is the bottleneck for CPU clock there. But most other MCUs do implement the logic required to wait on bus accesses. E.g. Cortex M7 have to spend a few cycles waiting for a ROM access, even not every RAM region is accessible in a single CPU cycle. However, Cortex M7 also have quite an elaborate cache system to speed things up.
While I do like a to have an as low latency between the button press and the letter appearing in neovim on the terminal, I am pretty confident that the few CPU cycles spend waiting for the flash (on a cache miss) do not contribute noticeably to that latency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reworked it as suggested above.
drivers/include/matrix_keypad.h
Outdated
/** | ||
* @brief Debounce pattern high to low bits | ||
*/ | ||
#ifndef CONFIG_MATRIX_KEYPAD_DEBOUNCE_PATTERN_BEGIN | ||
#define CONFIG_MATRIX_KEYPAD_DEBOUNCE_PATTERN_BEGIN 0xC0 | ||
#endif | ||
|
||
/** | ||
* @brief Debounce pattern low to high bits | ||
*/ | ||
#ifndef CONFIG_MATRIX_KEYPAD_DEBOUNCE_PATTERN_END | ||
#define CONFIG_MATRIX_KEYPAD_DEBOUNCE_PATTERN_END 0x7 | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would one adjust these?
3 bits set -> 3 cycles of matrix_keypad_scan()
needed to assert state?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, see
RIOT/drivers/include/matrix_keypad.h
Lines 32 to 40 in ef33bd0
* The debouncing algorithm is a pattern style debounce where the switch must be | |
* in one position for a number of samples, then a set of "don't care" samples | |
* and then in the other position for a number of samples. The samples in the | |
* middle allow for a period where the switch can be either low or high without | |
* affecting the transition. The exact pattern is determined by | |
* @ref CONFIG_MATRIX_KEYPAD_DEBOUNCE_PATTERN_BEGIN and | |
* @ref CONFIG_MATRIX_KEYPAD_DEBOUNCE_PATTERN_END. These are used as mask where | |
* the switch must be in a determined state. The bits where neither pattern is | |
* set is used as the "don't care" set of samples. |
It's a bit mask. I would love to use 0b00000111
here, but that's a gnu extension
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's also in C23 - but yea afaik we can't use it yet.
I'd still like to have the number of set bits -> number of required on/off cycles documented just to rule out any ambiguity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I elaborated a bit on the requirements here and tried to remove the ambiguity. Let me know what you think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please squash
dcc987b
to
1d33455
Compare
Murdock results✔️ PASSED 1d33455 matrix_keypad: add test application
ArtifactsThis only reflects a subset of all builds from https://ci-prod.riot-os.org. Please refer to https://ci.riot-os.org for a complete build for now. |
Contribution description
This module implements a simple matrix keypad driver where keys are connected
between GPIO columns and rows. It works best with diodes in series with the
switches to prevent key ghosting, but it can be used without.
For example one of these: https://learn.adafruit.com/matrix-keypad
Testing procedure
Test output with a custom board:
Full Kconfig configuration is provided with the driver (to the best of my ability), I would love it if somebody could sanity check it.
Issues/PRs references
None