Rotary encoder with GPIOs

From ArmadeusWiki
Revision as of 18:17, 3 March 2017 by JulienB (Talk | contribs) (Hardware)

Jump to: navigation, search

Page under construction... Construction.png Informations on this page are not guaranteed !!

Introduction

This page will explain you how to drive a rotary encoder connected to GPIOs of your APF/OPOS.

Hardware

The instructions were tested on OPOS6ULDev where rotary encoder is connected to GPIOs on RPi compatible connector:

Encoder Pin number
on RPi connector
Function
+ 1 Power
GND 6 GND
SW Key press
DT 32
CLK 40

Software

Device Tree need to be adapted:

        gpio-keys {
                compatible = "gpio-keys";
                pinctrl-names = "default";
                pinctrl-0 = <&pinctrl_gpio_keys>;

                user-button {
                        label = "User button";
                        gpios = <&gpio2 11 GPIO_ACTIVE_LOW>;
                        linux,code = <BTN_MISC>;
                        wakeup-source;
                };

+                rotary1_button {
+                        label = "rotary1_button";
+                        gpios = <&gpio5 2 GPIO_ACTIVE_LOW>;
+                        debounce-interval = <10>;
+                        linux,code = <28>;
+                };
        }

+        rotary1 {
+                compatible = "rotary-encoder";
+                pinctrl-names = "default";
+                pinctrl-0 = <&pinctrl_rotary1>;
+                gpios = <&gpio5 0 1>, <&gpio5 1 1>;
+                linux,axis = <1>; /* REL_Y */
+                rotary-encoder,relative-axis;
+        };

...
&iomuxc {
        pinctrl-names = "default";
        pinctrl-0 = <&pinctrl_gpios>;

...

+        pinctrl_rotary1: rotary1grp {
+                fsl,pins = <
+                        MX6UL_PAD_SNVS_TAMPER0__GPIO5_IO00      0x0b0b0
+                        MX6UL_PAD_SNVS_TAMPER1__GPIO5_IO01      0x0b0b0
+                >;
+        };

...

Links