GPIO keypad on tobetter's Ubuntu 21.10

Post Reply
micle
Posts: 2
Joined: Fri Nov 19, 2021 10:18 pm
languages_spoken: english
ODROIDs: Odroid N2+
Has thanked: 0
Been thanked: 0
Contact:

GPIO keypad on tobetter's Ubuntu 21.10

Post by micle »

I'm trying to get GPIO-connected pushbuttons to generate keyboard input on my N2+ running tobetter's Ubuntu, but I'm having trouble.

My setup is:
tobetter's Ubuntu 21.04 server image
-> Upgraded to 21.10 using 'do-release-upgrade'
= Kernel 5.14.0-odroid-arm64

Reading GPIO in sysfs works (switch connected between pins 13 and 14 on the header):

Code: Select all

$ sudo cat /sys/kernel/debug/gpio | grep PIN_13
 gpio-496 (PIN_13              )
$ echo 496 | sudo tee /sys/class/gpio/export
496
$ cat /sys/class/gpio/gpio496/value
0/1   <----- Changes with button press/release

I'm looking at this instruction for inspiration, even though it is for Android: https://wiki.odroid.com/common/applicat ... on_android

Also looking at this, which I successfully used on an RPi-4 before: https://blog.geggus.net/2017/01/setting ... raspberry-

The Odroid wiki page uses the gpio_keys_polled driver, but the RPi instruction uses gpio_keys (i.e. interrupt-driven?).

I noticed that tobetter's kernel has the gpio_keys driver compiled in, but not the gpio_keys_polled driver:

Code: Select all

$ grep KEYBOARD_GPIO /boot/config-5.14.0-odroid-arm64
CONFIG_KEYBOARD_GPIO=y
# CONFIG_KEYBOARD_GPIO_POLLED is not set
So I first tried this devicetree overlay, using gpio-keys (saved as keypad.dts):

Code: Select all

/dts-v1/;
/plugin/;
/ {
    fragment@0 {
        target-path = "/";
        __overlay__ {
            keypad_gpio {
                compatible = "gpio-keys";
                button@0 {
                    label = "GPIO Button Up";
                    linux,code = <103>;
                    gpios = <&gpio 496 1>;
                };
            };
        };
    };
};

Code: Select all

$ sudo dtc -I dts -O dtb -o /boot/dtbs/5.14.0-odroid-arm64/amlogic/overlays/odroidn2/keypad.dtbo keypad.dts
Then updated /boot/config.ini:

Code: Select all

[generic]
...
overlays="keypad"
After rebooting, it seems the devicetree overlay is loaded by the kernel:

Code: Select all

$ ls /sys/firmware/devicetree/base/
...
keypad_gpio
...
But there is no keyboard input when pushing the button, and 'lsinput' lists only the 'meson-ir' device.

I understand from reading online that /sys/class/gpio/gpioX/edge should be present if IRQ is supported on the pin. I do not get an 'edge' file for any of the GPIO pins, so I suspect this might be a problem?
However, this page says GPIO IRQ is supported on the N2: https://wiki.odroid.com/odroid-n2/appli ... e/gpio/irq


Anyway, I also tried building the gpio_keys_polled driver as a module. It loads successfully and shows up in 'lsmod'. I changed to 'compatible = "gpio-keys-polled"' in the devicetree overlay.
But still no keyboard input when pressing the button, and no new input device in 'lsinput'.

1) What should I try next to get either gpio_keys or gpio_keys_polled working?

2) Is there any reason to use gpio_keys_polled, since IRQ should be supported on the N2? E.g. is there a max number of GPIO IRQs available that limits the number of buttons, or something?

micle
Posts: 2
Joined: Fri Nov 19, 2021 10:18 pm
languages_spoken: english
ODROIDs: Odroid N2+
Has thanked: 0
Been thanked: 0
Contact:

Re: GPIO keypad on tobetter's Ubuntu 21.10

Post by micle »

After building the gpio_keys_polled module, the kernel does load it automatically on boot if I have a devicetree overlay with 'compatible = "gpio-keys-polled"':

Code: Select all

$ dmesg | grep gpio_keys
[    3.348650] gpio_keys_polled: loading out-of-tree module taints kernel
[    3.349240] gpio_keys_polled keypad_gpio: missing poll_interval value
[    3.350214] gpio_keys_polled: probe of keypad_gpio failed with error -22
After adding 'poll_interval = <100>;' to my overlay, the last two lines disappear and the module loads fine.

But still no input when pressing the button, and also still no device in 'lsinput'.

Post Reply

Return to “Hardware and peripherals”

Who is online

Users browsing this forum: No registered users and 2 guests