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

Conversation

Croktopus
Copy link
Contributor

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

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Keyboard (addition or update)
  • Keymap/layout/userspace (addition or update)
  • Documentation

Issues Fixed or Closed by This PR

Checklist

  • My code follows the code style of this project: C, Python
  • I have read the PR Checklist document and have made the appropriate changes.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

Copy link
Member

@drashna drashna left a 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.

quantum/encoder.c Outdated Show resolved Hide resolved
quantum/encoder.c Outdated Show resolved Hide resolved
@drashna
Copy link
Member

drashna commented Feb 5, 2021

Also, ideally, this should probably be targeting develop.

@Croktopus
Copy link
Contributor Author

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?

@Croktopus
Copy link
Contributor Author

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

@drashna
Copy link
Member

drashna commented Feb 11, 2021

To redirect it to develop, edit the title. That should let you choose what branch to target.

@Croktopus Croktopus changed the base branch from master to develop February 11, 2021 18:35
@mtei mtei requested a review from a team February 18, 2021 16:46
Comment on lines +105 to +110
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);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-format

Suggested change
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
Copy link
Member

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.

@tzarc tzarc closed this Feb 27, 2021
@tzarc tzarc deleted the branch qmk:develop February 27, 2021 20:28
@tzarc
Copy link
Member

tzarc commented Feb 27, 2021

Sorry about that, GitHub decided to delete the develop branch from upstream when we merged it, despite being told otherwise. Reopened.

@stale
Copy link

stale bot commented Apr 18, 2021

Thank you for your contribution!
This pull request has been automatically marked as stale because it has not had activity in the last 45 days. It will be closed in 30 days if no further activity occurs. Please feel free to give a status update now, or re-open when it's ready.
For maintainers: Please label with awaiting review, breaking_change, in progress, or on hold to prevent the issue from being re-flagged.

@drashna drashna self-requested a review April 19, 2021 03:39
@stale stale bot removed the awaiting changes label Apr 19, 2021
@stale
Copy link

stale bot commented Jun 3, 2021

Thank you for your contribution!
This pull request has been automatically marked as stale because it has not had activity in the last 45 days. It will be closed in 30 days if no further activity occurs. Please feel free to give a status update now, or re-open when it's ready.
For maintainers: Please label with awaiting review, breaking_change, in progress, or on hold to prevent the issue from being re-flagged.

@stale
Copy link

stale bot commented Jul 8, 2021

Thank you for your contribution!
This pull request has been automatically closed because it has not had activity in the last 30 days. Please feel free to give a status update now, ping for review, or re-open when it's ready.

@stale stale bot closed this Jul 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants