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

input: gpio_qdec: add optical encoder support #66121

Merged
merged 2 commits into from Jan 23, 2024

Conversation

fabiobaltieri
Copy link
Member

@fabiobaltieri fabiobaltieri commented Dec 4, 2023

Change the gpio_qdec driver to support optical encoders.

Add a property to use for defining an arbitrary number of GPIOs for the sensing devices (typically infrared LEDs, but could also be the biasing for the phototransistor), and one for adding a delay between turning those on and reading the pin status.

The infrared LEDs typically consume a non negligible amount of power, so there's also a new idle-poll-time-us property that enables two possible modes of operation:

  • if idle-poll-time-us is zero (default) the LEDs are enabled all the time and the driver enters polling mode using the GPIO interrupt as with mechanical encoders. This is usable for mains powered devices and has the lowest overhead on the CPU.

  • if idle-poll-time-us is non zero, then the driver polls the encoder all the time, turning on the LEDs just before reading the state and shutting them off immediately after, but when the encoder is idle it switches the polling rate to idle-poll-time-us to save power, and only polls at sample-time-us when some movement is detected.

@fabiobaltieri fabiobaltieri force-pushed the input-qdec-sense branch 2 times, most recently from 00d161c to 4c22e4c Compare December 8, 2023 21:29
@fabiobaltieri fabiobaltieri marked this pull request as ready for review December 13, 2023 22:38
@zephyrbot zephyrbot added area: Devicetree Binding PR modifies or adds a Device Tree binding area: Input Input Subsystem and Drivers labels Dec 13, 2023
@zephyrbot zephyrbot requested a review from galak December 13, 2023 22:38
gmarull
gmarull previously approved these changes Jan 2, 2024
Rename gpio to ab_gpio, this is in preparation for adding another gpio
pointer.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
@fabiobaltieri
Copy link
Member Author

Merge conflict, rebased.

gmarull
gmarull previously approved these changes Jan 12, 2024
Change the gpio_qdec driver to support optical encoders.

Add a property to use for defining an arbitrary number of GPIOs for the
sensing devices (typically infrared LEDs, but could also be the
biasing for the phototransistor), and one for adding a delay between
turning those on and reading the pin status.

The infrared LEDs typically consume a non negligible amount of power, so
there's also a new idle-poll-time-us property that enables two possible
modes of operation:

- if idle-poll-time-us is zero (default) the LEDs are enabled all the
  time and the driver enters polling mode using the GPIO interrupt as
  with mechanical encoders. This is usable for mains powered devices and
  has the lowest overhead on the CPU.

- if idle-poll-time-us is non zero, then the driver polls the encoder
  all the time, turning on the LEDs just before reading the state and
  shutting them off immediately after, but when the encoder is idle it
  switches the polling rate to idle-poll-time-us to save power, and only
  polls at sample-time-us when some movement is detected.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
@fabiobaltieri
Copy link
Member Author

@kartben ping

@fabiobaltieri fabiobaltieri added this to the v3.6.0 milestone Jan 22, 2024
@nashif nashif merged commit 1dd2307 into zephyrproject-rtos:main Jan 23, 2024
18 checks passed
@fabiobaltieri fabiobaltieri deleted the input-qdec-sense branch January 23, 2024 15:17
@kartben
Copy link
Collaborator

kartben commented Feb 20, 2024

@fabiobaltieri Just tested this on an ESP32 today and it crashes unless INPUT_STACK_SIZE is 1024. Would it make sense to change the default stack size of the input thread to a more conservative value? I am guessing 768 would be an option too :P

@fabiobaltieri
Copy link
Member Author

@fabiobaltieri Just tested this on an ESP32 today and it crashes unless INPUT_STACK_SIZE is 1024. Would it make sense to change the default stack size of the input thread to a more conservative value? I am guessing 768 would be an option too :P

Yeah not a bad idea, found myself changing it for some applications as well, 512 may have been optimistic. Can you send a PR? If you set it to 1024 (which sounds good to me) you can drop the override from tests/subsys/input/api/testcase.yaml as well

@kartben
Copy link
Collaborator

kartben commented Feb 20, 2024

@fabiobaltieri Just tested this on an ESP32 today and it crashes unless INPUT_STACK_SIZE is 1024. Would it make sense to change the default stack size of the input thread to a more conservative value? I am guessing 768 would be an option too :P

Yeah not a bad idea, found myself changing it for some applications as well, 512 may have been optimistic. Can you send a PR? If you set it to 1024 (which sounds good to me) you can drop the override from tests/subsys/input/api/testcase.yaml as well

Sounds good. Will probably have to wait after 3.6 -- still wrapping up all the demos I want to videotape, which this driver will apparently be a part of :)

@fabiobaltieri
Copy link
Member Author

Sounds good. Will probably have to wait after 3.6 -- still wrapping up all the demos I want to videotape, which this driver will apparently be a part of :)

Yeah no sense pushing it for 3.6, I'll just file it myself then not a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Devicetree Binding PR modifies or adds a Device Tree binding area: Input Input Subsystem and Drivers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants