-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Add charliplex keyscan #1694
Add charliplex keyscan #1694
Conversation
ba396a2
to
3bff73e
Compare
3bff73e
to
87f60fe
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.
Thanks for this! A few thoughts on the details.
app/drivers/zephyr/dts/bindings/kscan/zmk,kscan-gpio-round-robin.yaml
Outdated
Show resolved
Hide resolved
Also, I'd love to have a feature that allows me to reverse the columns and rows. Currently, I'm working with a circuit that looks like this: (source: https://jpskenn.github.io/blog/2020/12/05/first-year-of-my-self-made-keyboard-activity) This is merely a request. If the implementation is difficult or if this proposal does not align with your thoughts, please feel free to disregard it. |
The column/row don't actually matter with the round robin. If you consider In your transform, you would just have:
(note that this is how the switches are labeled anyway, so that helps keep your hardware and software aligned) It's not really rows and columns, just out/in pairings. Also note that flipping all the diode directions (but no position) gives you the same capability, but with the out/in reversed, and you keep the same picture. |
@HookyKB Thank you for your response. it seems that my understanding was not enough. |
@petejohanson auto polling config added. See #1694 (comment) regarding the wait config. |
1ea01f2
to
695d15a
Compare
I find that "charlieplex" would be a proper name for this type of key scan. |
It is, but Round Robin is equally proper, and less ambiguous IMO. |
While some people may be familiar with the term "round-robin tournament," it still does not accurately reflect the underlying technique used in the keyscan, which relies on diodes being forward biased. What's more important is that the keyscan is entirely based on charlieplexing, so there's no reason to come up with a new term for it. Let's just use the already established term. It's less confusing and way more straightforward. |
@nguyendown I don't see a problem. No-one is 'confused', you would just prefer a different name. I didn't come up with the name, I used the title of the reference document, and in there you'll see that the author was also unaware of the name you're suggesting. Also, with the additional interrupt handler, it is now its own entity, so, I'm pretty happy calling it not charliplexing. You'll may also like to note that charlieplexing was a term assigned to a long pre-existing circuit structure, so 🤷. (And thus named for someone who didn't come up with it, and I like that even less.) |
Code looks good. Can you please rebase one more time to pick up the pre-commit check work, to be sure the MD files all pass? Thanks! |
Can we put this pull request on hold? Because of the naming convention? I am currently messaging the author of the article about the proper name. |
I'm happy to discuss more. Regardless of technicalities, the term "round robin matrix" has become pervasive. At a minimum, if we do want to merge this with a different name, then the docs should clearly identify this as being the same design known as "round robin matrix" by many. |
I'll bring it here so that we can have an open discussion. There are three names in the article: Charlieplexing, Round Robin Matrix, and Square Matrix. I immediately knew that "Square Matrix" would not work well. The term is not unique, and people may ask, "square matrix? Is it linear algebra?" You'd have to explain "square means N-square keys" every time you mention it. You'd also need to tell them "it's not exactly N-square, but like N-square minus N." Not to mention that "square matrix" could also refer to a normal matrix with four cols, and four rows. Zephyr
Zephyr also refers to "round robin" as "round robin scheduling" KeyscanI'll explain why I insist on using the term "Charlieplex" for the keyscan. Here's the original Charlieplex (1). (2) and (3) are the same as the original, but the switches are arranged in a grid. (4) and (5) have an additional diode per pin to prevent ghosting. (6) and (7) use an interrupt pin to detect key press from sleep. All the variants use the same scanning technique as the original, which is why the keyscan should be named "Charlieplex." VariantsTrying to name every possible variation or arrangement is not practical. Not only is it not feasible, but it also creates even more confusion. My suggestion is to simply describe any additional features. We can refer to (1), (2), and (3) as the Charlieplex. (4) and (5) can be called the Anti-Ghosting Charlieplex, while (6) and (7) can be referred to as the Low-Power Anti-Ghosting Charlieplex. |
Hmmmm, is it really now the case, that because of differences in the name of a feature, it is not being merged and users are not able to make use of the feature? I honestly couldn't care less if the feature is called "Low-Power Anti-Ghosting Charlieplex in Round-Robin, Square-Matrix Fashion with superpowers" or just "Matrix Connection Variant #7"... Please: who can make a decision to merge a feature here? Thank you for considering your users and preventing further forks just to implement already submitted feature branches... |
To be honest... I was fairly "round robin matrix" camp, until doing a bit of googling for the terms "keyboard round robin matrix" and "charliplex keyboard matrix". The later brings up several authoritative articles, including the KBD News one, such as:
To name a few. The first search term mostly returns non-keyboard related articles, with only a smattering, including the same KBD News article and an Atreus GitHub link actually being what we're talking about. Given that... I actually am convinced, and suggest we use "charliplex" as the authoritative term, with alternative terms included in the documentation. @HookyKB I know you've worked very hard on this, for which I'm grateful. Any major objections to adjusting the naming on this before we merge? |
@petejohanson Yep, no problems. I'll do the rename & rebase this weekend. Two devs in disagreement meant nothing IMO, but once the repo owner rolls in, I'm generally happy with what they decide. 👍 |
695d15a
to
c2c73c1
Compare
58b3bf5
to
c1b979d
Compare
c1b979d
to
76d4882
Compare
@petejohanson all yours. Tested with my |
@HookyKB Here is a fork of your repo with the changes I made. Checkout kscan/round_robin and refer to board/shield/011 contents to see the config I have for the board. It does work, though I will note what you mentioned about ghosting: I did try doing it without (edit, forgot mention) |
@ReSummit Nice to know it works. Hopefully this can be a solution for duplex as well. You might need to disable the console for it to work. I had a problem with console enabled as it was trying to set a pin high when something else was using it. app/boards/shields/intro/intro.dtsi L14-15:
And set serial to disable at the bottom. |
This is probably because the SAM0 GPIO driver in Zephyr enforces some checks that the nrfx one doesn't:
Your fix seems so-so, I wonder if perhaps we should only be specifying the active high/low in the DTS, and then inferring the pull flag to add whenever setting a pin as in input. |
@HookyKB Unfortunately this doesn't change anything. Just recompiled and no keys are detected being pressed. I actually needed those properties enabled to even get a USB serial debug and get the error messages.
@petejohanson This was actually what I was looking for when I saw the error code that was returned from Inferring the pull flag sounds like a good idea, but part of me wonders if there should be another parameter for that. Probably a later problem though...? |
@ReSummit I just push an additional commit:
Can you please test? |
Testing at the moment but uh, it doesn't compile... This error shows up: <zmk-path>/app/module/drivers/kscan/kscan_gpio_charlieplex.c:398:52: error: expected expression before ',' token
398 | LISTIFY(INST_LEN(n), KSCAN_GPIO_CFG_INIT, (, ), n)}; \
| I changed the GPIO flags to now include |
@ReSummit Seems to compile here fine, but I've identified a small fix that likely was the issue. Please try again? |
Looking back through the code that was added and I think it has to do with the set_as_output function as I think the flags are still there (because in my code modifications, I filtered out all PULLUP / PULLDOWN flags that were causing problems). |
It doesn't work after removing the pull flag from your DTS/overlay? |
Whoops, forgot to take out the flags, uploaded again and am now seeing a different logged output, but none of the keys work. The logs seem to show a debug log about sending events:
|
Looks like my bit checking logic was errant. Just pushed another fix for testing. Thanks! |
Just compiled and uploaded. The keys are working now! Just in case anything looks weird, I attached a keypress debug but it looks good!
|
Multiplex handler (all->all) with single pin for interrupt handling. For wired boards/shields, the interrupt can be ignored to simplify the electronics greatly.
Per the other docs, this lays out how to implement it in the settings files, not how to implement it in hardware.
The _used_ size was correct, but the addressing requires n*n.
If the interrupt pin is set, use the interrupt code, else poll. This change results in a slightly larger executable in both cases, with unreachable code. More so in the case of polling, bet the difference is not great.
I'd dropped the `e` from `charlieplex` everywhere. Bring it back to make the world a safe place again.
* To avoid issues with platforms that enforce no pull flags when pins are used as outputs, infer the pull flags in code instead of setting them in the DTS for charlieplex kscan driver. * Use `LISTIFY` macro instead of deprecated `UTIL_LISTIFY`.
* Check against `GPIO_ACTIVE_LOW` properly which has a non-zero value.
f9ffa17
to
c85b75e
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.
Rebased this and removed the deprecated label
property. LGTM, will merge once the tests pass. Thanks @HookyKB !
Adds support for https://kbd.news/Square-or-round-robin-matrix-1400.html with addition of an extra interrupt pin for low power support.
Implementation of this matrix in hardware is left as an exercise for the user. Ensure all lines to the interrupt pin are not able to re-feed the matrix or it will surely fail.
Example:
Shields implementing this scan setup may not be suitable for all boards (see the referenced document above).
It is expected that, with proper design, (compared to a matrix kscan) an additional 2*n diodes will be required, where n is the number of input pins in use. One for the line to the input pin (this may not be required for some controllers), and one for each 'column' to the interrupt pin. Note that not all of the charliplex matrix pins need to be used as input to the controller.
eg. An 8 pin charliplex kscan matrix may use all 8 pins for output, but only use 5 for input.
See HookyKB@40221a4 for example usage.