~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/Documentation/input/devices/rotary-encoder.rst

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /Documentation/input/devices/rotary-encoder.rst (Version linux-6.11.5) and /Documentation/input/devices/rotary-encoder.rst (Version linux-5.18.19)


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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php