Rotary encoder with GPIOs

From ArmadeusWiki
Jump to navigationJump to search

Page under construction... 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 38 (with 4.7k pullup) 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
+                >;
+        };

...
  • you can then replace /boot/imx6ul-opos6uldev.dtb file on your rootfs and reboot
  • Rotary should then be recognized by evtest tool:
# evtest
No device specified, trying to scan all of /dev/input/event*
Available devices:
/dev/input/event0:      iMX6UL Touchscreen Controller
/dev/input/event1:      rotary1
...
Select the device event number [0-6]: 1

Links