-
-
Notifications
You must be signed in to change notification settings - Fork 40k
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
Conversation
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 would be better to have something like ENCODER_PIN_CFG
and have that set to the different types.
Much like the col2row stuff. This way, we can check to see if it's defined or not, and default to pullup.
However, ENCODER_PIN_CFG
is probably a horrible name, and something better should be used.
Also, ideally, this should probably be targeting develop. |
alright so i basically combined your suggestions and it looks much cleaner now, thank you both. how can i redirect it to develop, or should i close this and open a new one? |
Ok slight problem it doesnt work now lol. getting on discord |
To redirect it to develop, edit the title. That should let you choose what branch to target. |
for (int i = 0; i < NUMBER_OF_ENCODERS; i++) { | ||
setEncPinInput(encoders_pad_a[i]); | ||
setEncPinInput(encoders_pad_b[i]); | ||
|
||
encoder_state[i] = (readPin(encoders_pad_a[i]) << 0) | (readPin(encoders_pad_b[i]) << 1); | ||
} |
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.
clang-format
for (int i = 0; i < NUMBER_OF_ENCODERS; i++) { | |
setEncPinInput(encoders_pad_a[i]); | |
setEncPinInput(encoders_pad_b[i]); | |
encoder_state[i] = (readPin(encoders_pad_a[i]) << 0) | (readPin(encoders_pad_b[i]) << 1); | |
} | |
for (int i = 0; i < NUMBER_OF_ENCODERS; i++) { | |
setEncPinInput(encoders_pad_a[i]); | |
setEncPinInput(encoders_pad_b[i]); | |
encoder_state[i] = (readPin(encoders_pad_a[i]) << 0) | (readPin(encoders_pad_b[i]) << 1); | |
} |
for (int i = 0; i < NUMBER_OF_ENCODERS; i++) { | ||
setPinInputHigh(encoders_pad_a[i]); | ||
setPinInputHigh(encoders_pad_b[i]); | ||
#ifdef ENCODER_PINS |
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.
Naming things is difficult, however i'm cautious of too much crossover to existing setting, eg BACKLIGHT_PINS
. While docs exists, it leads to questions like "why doesn't #define ENCODER_PINS {A1, B2}
work?"
I cant find an existing setting to align to, but the closest thing that come to mind would be ENCODER_PIN_MODE
, maybe ENCODER_PAD_MODE
.
Sorry about that, GitHub decided to delete the |
Thank you for your contribution! |
Thank you for your contribution! |
Thank you for your contribution! |
Description
Added 3 toggles: ENC_PUP, ENC_PDOWN, and ENC_FLOAT. When ENC_PUP is defined, it sets the internal resistor on the encoder pins to be pulled up, and the same sort of behavior for the others. If none of these are defined, then it defaults to the current behavior of having the internal pull-up.
My optical encoder needs a pull down on these pins to work right, and the values also need to be finely tuned which might be possible even with an internal pull-up, but it's way easier if I can just set the pin to be floating.
I'm not much of a coder, so while I did test it and it works on my hardware, it looks super inelegant and I'm sure theres like a billion ways to optimize the code. I'm also not married to the names of those toggle things.
I also tried my hand at putting in some documentation based on existing docs.
Types of Changes
Issues Fixed or Closed by This PR
Checklist