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; toggle switch kscan driver #980

Closed
petejohanson opened this issue Oct 15, 2021 · 3 comments
Closed

Feature; toggle switch kscan driver #980

petejohanson opened this issue Oct 15, 2021 · 3 comments
Labels
core Core functionality/behavior of ZMK enhancement New feature or request Hacktoberfest help wanted Extra attention is needed

Comments

@petejohanson
Copy link
Contributor

petejohanson commented Oct 15, 2021

It would be useful to support a single pole, #-throw toggle switch in ZMK in a way that doesn't impact battery life drastically w/ quiescent current from pull up/down on the connected throw line. There's a way to do this by only enabling the pull up/downs on the not selected pin, combined w/ smart interrupts.

For wiring, you'd have the single pole wired to ground, and each of the polls wired to a GPIO pin.

The DT for this would look something like:

toggle_kscan {
    compatible = "zmk,kscan-toggle";
    pull-direction = <GPIO_PULL_UP>;
    input-gpios = <&gpio0 0 GPIO_ACTIVE_LOW &gpio0 1 GPIO_ACTIVE_LOW>;
};

On init, the code should apply the pull direction to each pin, then read each pin to detect which is active LOW.

whichever is active low, should have a kscan event raised for it being pressed, then disable the pull on that pin to stop the quiescent drain.

We should then also configure interrupts for the other pins so the interrupt fires when the toggle is changed.

Once we get an interrrupt, scan other pins, find the new active one, and:

  • Raise release event for old pin.
  • Apply pull to the old pin.
  • Raise press event for new pin.
  • Remove pull from the new pin.

This can then be combined w/ the composite kscan driver, or leveraged as a separate kscan, to do things like switch primary output, or BT profile, etc.

@petejohanson petejohanson added enhancement New feature or request help wanted Extra attention is needed core Core functionality/behavior of ZMK Hacktoberfest labels Oct 15, 2021
@kurtis-lew
Copy link
Contributor

Issue #507 is somewhat related, as the flags associated with the input-gpios could be solely determined by the value of pull-direction. @Nicell suggests in #507 something similar for kscan matrix definitions using diode-direction as the independent variable that sets the necessary flags.

The following links show conversations highlighting initial progress on this feature, which currently assumes all pins are active low and require pins to be pulled up when not in use.
https://discord.com/channels/719497620560543766/719544230497878116/953460939766784000
https://discord.com/channels/719497620560543766/719544230497878116/953744688605720616
https://discord.com/channels/719497620560543766/719544230497878116/953746838769512518
Another implementation of this feature that is being considered in the discussion above is making the toggle_kscan a specific configuration of the direct gpio kscan.

@kurtis-lew
Copy link
Contributor

#1050 could also make use of the pullup resistor disabling solution similar to that implemented here, as to remove the unwanted quiescent current leak.

@kurtis-lew
Copy link
Contributor

This issue should be addressed as of #1305.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core functionality/behavior of ZMK enhancement New feature or request Hacktoberfest help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants