-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add espressif rotaryio divisor support. #6207
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
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.
I had to change the order in
shared-bindings/rotaryio/IncrementalEncoder.c
as the divisor value needs to be known before configuring the peripheral. I don't think this will cause issues for other ports as the set_divisor function only sets a value on a struct, so the order of operations shouldn't matter.
Rather than change the order, let's add the divisor
argument to _construct
, and change the other ports to handle that. Then we are not dependent on the order happening to work for all ports.
6918a95
to
3d66332
Compare
I've realised the |
We might consider making that attribute read-only, since as you say, it's not clear why you'd want to change it. We could make it read-only just on espressif, but we try to avoid chip-specific idiosyncrasies if they are avoidable. This is an incompatible API change so we we might make it read-only on espressif now and then read-only on all ports in 8.0.0. @jepler do you have an opinion about this? |
I don't mind if you do this. I can't think of any super plausible reasons to change it at runtime (but https://hackaday.com/2022/03/13/haptic-smart-knob-does-several-jobs/ is cool! and probably not something you'd implement in CircuitPython) The alternative is to always use the "count every quadrature transition" mode and slightly refactor It's worth noting there IS a slight bug in that code if |
3d66332
to
319ca85
Compare
@domdfcoding you pushed 319ca85 after our discussions of making |
Sorry @dhalbert, I thought I had replied. @jepler's suggestion to "count every quadrature transition" was the missing piece. By always configuring the second PCNT channel and counting every transition the code becomes much simpler, and allows the The same approach could be used with the other ports, which would mean I did find a bug in my current code if the |
Thanks for the reply. Does it still make sense to pass the initial divisor in? I think that makes sense, because then you don't have to worry about the order of the calls. |
With the current code the constructor doesn't need to know the divisor anymore, so the order is back how it was before this PR. |
I think it depends what you think should happen when the divisor is changed. Given that I don't know the real world reason for dynamically changing the encoder divisor, I don't feel confident stating how it should work. I see three possibilities:
Again, given that there's no particular scenario that we have in mind for changing this dynamically, I would probably take the simplest alternative: position is free to jump when changing divisor, the code can set the value (E.g., reset to zero) if it needs to. |
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.
If this passes your testing with divisors of 1 and 4, it's good enough for me. I didn't do any testing on HW myself.
Follow up to #5468, which don't include espressif support.
I have tested this on a QT Py ESP32-S2 with this type of rotary encoder, which requires
divisor=1
. I've also tested withdivisor=2
anddivisor=4
, and a pulse is registered every 2 and 4 detents respectively as expected.I had to change the order in
shared-bindings/rotaryio/IncrementalEncoder.c
as the divisor value needs to be known before configuring the peripheral. I don't think this will cause issues for other ports as the set_divisor function only sets a value on a struct, so the order of operations shouldn't matter.