1+ ============================================================
12rotary-encoder - a generic driver for GPIO connected devices
2- Daniel Mack <daniel@caiaq.de>, Feb 2009
3+ ============================================================
34
4- 0. Function
5- -----------
5+ :Author: Daniel Mack <daniel@caiaq.de>, Feb 2009
6+
7+ Function
8+ --------
69
710Rotary encoders are devices which are connected to the CPU or other
811peripherals with two wires. The outputs are phase-shifted by 90 degrees
@@ -13,7 +16,7 @@ Some encoders have both outputs low in stable states, others also have
1316a stable state with both outputs high (half-period mode) and some have
1417a stable state in all steps (quarter-period mode).
1518
16- The phase diagram of these two outputs look like this:
19+ The phase diagram of these two outputs look like this::
1720
1821 _____ _____ _____
1922 | | | | | |
@@ -40,8 +43,8 @@ For more information, please see
4043 https://en.wikipedia.org/wiki/Rotary_encoder
4144
4245
43- 1. Events / state machine
44- -------------------------
46+ Events / state machine
47+ ----------------------
4548
4649In half-period mode, state a) and c) above are used to determine the
4750rotational direction based on the last stable state. Events are reported in
@@ -65,16 +68,16 @@ d) Falling edge on channel B, channel A in low state
6568 should have happened, unless it flipped back on half the way. The
6669 'armed' state tells us about that.
6770
68- 2. Platform requirements
69- ------------------------
71+ Platform requirements
72+ ---------------------
7073
7174As there is no hardware dependent call in this driver, the platform it is
7275used with must support gpiolib. Another requirement is that IRQs must be
7376able to fire on both edges.
7477
7578
76- 3. Board integration
77- --------------------
79+ Board integration
80+ -----------------
7881
7982To use this driver in your system, register a platform_device with the
8083name 'rotary-encoder' and associate the IRQs and some specific platform
@@ -93,34 +96,33 @@ the configuration.
9396Because GPIO to IRQ mapping is platform specific, this information must
9497be given in separately to the driver. See the example below.
9598
96- ---------<snip>---------
97-
98- /* board support file example */
99-
100- #include <linux/input.h>
101- #include <linux/rotary_encoder.h>
102-
103- #define GPIO_ROTARY_A 1
104- #define GPIO_ROTARY_B 2
105-
106- static struct rotary_encoder_platform_data my_rotary_encoder_info = {
107- .steps = 24,
108- .axis = ABS_X,
109- .relative_axis = false,
110- .rollover = false,
111- .gpio_a = GPIO_ROTARY_A,
112- .gpio_b = GPIO_ROTARY_B,
113- .inverted_a = 0,
114- .inverted_b = 0,
115- .half_period = false,
116- .wakeup_source = false,
117- };
118-
119- static struct platform_device rotary_encoder_device = {
120- .name = "rotary-encoder",
121- .id = 0,
122- .dev = {
123- .platform_data = &my_rotary_encoder_info,
124- }
125- };
126-
99+ ::
100+
101+ /* board support file example */
102+
103+ #include <linux/input.h>
104+ #include <linux/rotary_encoder.h>
105+
106+ #define GPIO_ROTARY_A 1
107+ #define GPIO_ROTARY_B 2
108+
109+ static struct rotary_encoder_platform_data my_rotary_encoder_info = {
110+ .steps = 24,
111+ .axis = ABS_X,
112+ .relative_axis = false,
113+ .rollover = false,
114+ .gpio_a = GPIO_ROTARY_A,
115+ .gpio_b = GPIO_ROTARY_B,
116+ .inverted_a = 0,
117+ .inverted_b = 0,
118+ .half_period = false,
119+ .wakeup_source = false,
120+ };
121+
122+ static struct platform_device rotary_encoder_device = {
123+ .name = "rotary-encoder",
124+ .id = 0,
125+ .dev = {
126+ .platform_data = &my_rotary_encoder_info,
127+ }
128+ };
0 commit comments