1# Copyright 2023 Google LLC 2# SPDX-License-Identifier: Apache-2.0 3 4description: | 5 GPIO based QDEC input device 6 7 Implement an input device generating relative axis event reports for a rotary 8 encoder connected to two GPIOs. The driver is normally idling until it sees a 9 transition on any of the encoder signal lines, then switches to polling mode 10 and samples the two signal lines periodically to track the encoder position, 11 and goes back to idling after the specified timeout. 12 13 Example configuration: 14 15 #include <zephyr/dt-bindings/input/input-event-codes.h> 16 17 qdec { 18 compatible = "gpio-qdec"; 19 gpios = <&gpio0 14 (GPIO_PULL_UP | GPIO_ACTIVE_HIGH)>, 20 <&gpio0 13 (GPIO_PULL_UP | GPIO_ACTIVE_HIGH)>; 21 steps-per-period = <4>; 22 zephyr,axis = <INPUT_REL_WHEEL>; 23 sample-time-us = <2000>; 24 idle-timeout-ms = <200>; 25 }; 26 27compatible: "gpio-qdec" 28 29include: base.yaml 30 31properties: 32 gpios: 33 type: phandle-array 34 required: true 35 description: | 36 GPIO for the A and B encoder signals. 37 38 led-gpios: 39 type: phandle-array 40 description: | 41 GPIOs for LED or other components needed for sensing the AB signals. 42 43 led-pre-us: 44 type: int 45 description: | 46 Time between enabling the led-gpios output pins and reading the encoder 47 state on the input pins, meant to give the state detector (such a 48 phototransistor) time to settle to right state. Required if led-gpios and 49 idle-poll-time-us are specified, can be explicitly set to 0 for no delay. 50 51 steps-per-period: 52 type: int 53 required: true 54 description: | 55 How many steps to count before reporting an input event. 56 57 zephyr,axis: 58 type: int 59 required: true 60 description: | 61 The input code for the axis to report for the device, typically any of 62 INPUT_REL_*. 63 64 sample-time-us: 65 type: int 66 required: true 67 description: | 68 How often to sample the A and B signal lines when tracking the encoder 69 movement. 70 71 idle-poll-time-us: 72 type: int 73 description: | 74 How often to sample the A and B signal while idling. If unset then the 75 driver will use the GPIO interrupt to exit idle state, and any GPIO 76 specified in led-gpios will be enabled all the time. If non zero, then 77 the driver will poll every idle-poll-time-us microseconds while idle, and 78 only activate led-gpios before sampling the encoder state. 79 80 idle-timeout-ms: 81 type: int 82 required: true 83 description: | 84 Timeout for the last detected transition before stopping the sampling 85 timer and going back to idle state. 86