1 ============================================== 2 rotary-encoder - a generic driver for GPIO con 3 ============================================== 4 5 :Author: Daniel Mack <daniel@caiaq.de>, Feb 200 6 7 Function 8 -------- 9 10 Rotary encoders are devices which are connecte 11 peripherals with two wires. The outputs are ph 12 and by triggering on falling and rising edges, 13 be determined. 14 15 Some encoders have both outputs low in stable 16 a stable state with both outputs high (half-pe 17 a stable state in all steps (quarter-period mo 18 19 The phase diagram of these two outputs look li 20 21 _____ _____ ____ 22 | | | | | 23 Channel A ____| |_____| |_____| 24 25 : : : : : : : : : : 26 __ _____ _____ _ 27 | | | | | | 28 Channel B |_____| |_____| |_____| 29 30 : : : : : : : : : : 31 Event a b c d a b c d a b 32 33 |<-------->| 34 one step 35 36 |<-->| 37 one step (half-period mode) 38 39 |<>| 40 one step (quarter-period mod 41 42 For more information, please see 43 https://en.wikipedia.org/wiki/Rotary_e 44 45 46 Events / state machine 47 ---------------------- 48 49 In half-period mode, state a) and c) above are 50 rotational direction based on the last stable 51 states b) and d) given that the new stable sta 52 (i.e. the rotation was not reversed half-way). 53 54 Otherwise, the following apply: 55 56 a) Rising edge on channel A, channel B in low 57 This state is used to recognize a cloc 58 59 b) Rising edge on channel B, channel A in high 60 When entering this state, the encoder 61 meaning that there it has seen half th 62 63 c) Falling edge on channel A, channel B in hig 64 This state is used to recognize a coun 65 66 d) Falling edge on channel B, channel A in low 67 Parking position. If the encoder enter 68 should have happened, unless it flippe 69 'armed' state tells us about that. 70 71 Platform requirements 72 --------------------- 73 74 As there is no hardware dependent call in this 75 used with must support gpiolib. Another requir 76 able to fire on both edges. 77 78 79 Board integration 80 ----------------- 81 82 To use this driver in your system, register a 83 name 'rotary-encoder' and associate the IRQs a 84 data with it. Because the driver uses generic 85 be done either via device tree, ACPI, or using 86 example below: 87 88 :: 89 90 /* board support file example */ 91 92 #include <linux/input.h> 93 #include <linux/gpio/machine.h> 94 #include <linux/property.h> 95 96 #define GPIO_ROTARY_A 1 97 #define GPIO_ROTARY_B 2 98 99 static struct gpiod_lookup_table rotar 100 .dev_id = "rotary-encoder.0", 101 .table = { 102 GPIO_LOOKUP_IDX("gpio- 103 GPIO_R 104 GPIO_LOOKUP_IDX("gpio- 105 GPIO_R 106 { }, 107 }, 108 }; 109 110 static const struct property_entry rot 111 PROPERTY_ENTRY_U32("rotary-enc 112 PROPERTY_ENTRY_U32("linux,axis 113 PROPERTY_ENTRY_U32("rotary-enc 114 { }, 115 }; 116 117 static const struct software_node rota 118 .properties = rotary_encoder_p 119 }; 120 121 static struct platform_device rotary_e 122 .name = "rotary-enco 123 .id = 0, 124 }; 125 126 ... 127 128 gpiod_add_lookup_table(&rotary_encoder 129 device_add_software_node(&rotary_encod 130 platform_device_register(&rotary_encod 131 132 ... 133 134 Please consult device tree binding documentati 135 supported by the driver.
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.