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

Add option to set the encoder A and B pins on the MCU to use internal pull-down, pull-up, or leave floating #11706

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/feature_encoders.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ If you are using different pinouts for the encoders on each half of a split keyb
#define ENCODER_RESOLUTIONS_RIGHT { 2, 4 }
```

## Configuring Input Pins

Rarely, you may want to set the MCU pin hooked up to the encoder to use its internal pull-down or be left floating, instead of the default which is to use an internal pull-up. This is mainly relevant for non-mechanical encoders, such as optical or hall effect. These options can be configured by placing these `#define`s in your `config.h`:

|Define |Description |
|---------------|---------------------------------------------------------------------------------------------------------|
|`ENC_PUP` |Toggles on the internal pull-up |
|`ENC_PDOWN ` |Toggles on the internal pull-down |
|`ENC_FLOAT` |Leaves the pin as floating |

## Callbacks

The callback functions can be inserted into your `<keyboard>.c`:
Expand Down
23 changes: 23 additions & 0 deletions quantum/encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,35 @@ void encoder_init(void) {
}
#endif

#ifdef ENC_PUP
for (int i = 0; i < NUMBER_OF_ENCODERS; i++) {
setPinInputHigh(encoders_pad_a[i]);
setPinInputHigh(encoders_pad_b[i]);

encoder_state[i] = (readPin(encoders_pad_a[i]) << 0) | (readPin(encoders_pad_b[i]) << 1);
}
#elif ENC_PDOWN
for (int i = 0; i < NUMBER_OF_ENCODERS; i++) {
setPinInputLow(encoders_pad_a[i]);
setPinInputLow(encoders_pad_b[i]);

encoder_state[i] = (readPin(encoders_pad_a[i]) << 0) | (readPin(encoders_pad_b[i]) << 1);
}
#elif ENC_FLOAT
for (int i = 0; i < NUMBER_OF_ENCODERS; i++) {
setPinInput(encoders_pad_a[i]);
setPinInput(encoders_pad_b[i]);

encoder_state[i] = (readPin(encoders_pad_a[i]) << 0) | (readPin(encoders_pad_b[i]) << 1);
}
#else
for (int i = 0; i < NUMBER_OF_ENCODERS; i++) {
setPinInputHigh(encoders_pad_a[i]);
setPinInputHigh(encoders_pad_b[i]);

encoder_state[i] = (readPin(encoders_pad_a[i]) << 0) | (readPin(encoders_pad_b[i]) << 1);
}
drashna marked this conversation as resolved.
Show resolved Hide resolved
#endif
drashna marked this conversation as resolved.
Show resolved Hide resolved

#ifdef SPLIT_KEYBOARD
thisHand = isLeftHand ? 0 : NUMBER_OF_ENCODERS;
Expand Down