GPIOKEYS(4)

πŸ’– GPIOKEYS πŸ’–

okay bestie, so this is a kernel interfaces manual page for gpiokeys β€” the GPIO keys device driver. yes we're in the kernel, yes it's giving embedded systems main character energy, and yes you're gonna understand it. let's go πŸ¦‹


✨ NAME ✨

gpiokeys β€” GPIO keys device driver πŸ’…


🌸 SYNOPSIS 🌸

so if you wanna compile this driver into the kernel, you drop these lines into your kernel configuration file:

options FDT
device gpio
device gpiokeys

or β€” alternate route, bestie β€” if you'd rather load it as a module at boot time, you put this line in loader.conf(5):

gpiokeys_load="YES"

slay, either way works ✨


πŸŽ€ DESCRIPTION πŸŽ€

k so here's the vibe: the gpiokeys driver gives you a way to represent a set of general purpose inputs as a keyboard(4) device. cute, right?

ngl though β€” at the moment the driver supports only FDT(4) based systems. no cap. the DTS is the one that decides which pins get mapped to buttons and what key codes get generated for each virtual button. then you can use that keyboard(4) device from userland to monitor for input changes. obsessed with the flexibility fr fr πŸ‘‘

on an FDT(4) based system, the DTS part for a gpiokeys device usually looks like this:

/ {

        ...

        gpio_keys {
                compatible = "gpio-keys";

                btn1 {
                        label = "button1";
                        linux,code = <KEY_1>;
                        gpios = <&gpio 0 3 GPIO_ACTIVE_LOW>
                };

                btn2 {
                        label = "button2";
                        linux,code = <KEY_2>;
                        gpios = <&gpio 0 4 GPIO_ACTIVE_LOW>
                };
        };
};

for more deets about the gpios property, please go consult /usr/src/sys/dts/bindings-gpio.txt β€” it's literally right there, iykyk πŸ’œ


πŸ”₯ the key code properties πŸ”₯

the gpiokeys driver supports two properties for specifying a key code:

  • the property freebsd,code specifies a FreeBSD native scancode compatible with kbdmap(5) keyboard maps πŸŽ€
  • the property linux,code specifies an evdev scancode. that scancode gets internally translated to a native scancode. heads up though: not all evdev scancodes have corresponding native scancodes. if a scancode can't be translated, then a diagnostic message is printed and the input is ignored. 😭
okay important side note, bestie β€” that "input is ignored" part is real. like, silently-ish dropped. not a crash, just a little shrug and a log line. don't come for me, i'm just the messenger πŸ’€

🫢 the other properties 🫢

  • the property label is a descriptive name of a button. it is used for diagnostic messages only. this property is optional. if it's not set, the node name is used in its place. periodt πŸ’…
  • the property autorepeat determines whether autorepeat is enabled for a button. ⭐
  • the property debounce-interval defines debouncing interval time in milliseconds. if not specified, the interval defaults to 5. 🌸

🌈 SEE ALSO 🌈

fdt(4), gpio(4), keyboard(4), kbdmap(5)

go read them, they're all iconic in their own way πŸ¦‹


πŸ‘‘ HISTORY πŸ‘‘

the gpiokeys manual page first appeared in FreeBSD 12.2. vintage-ish, but make it embedded πŸ’–


πŸ’œ AUTHORS πŸ’œ

the gpiokeys driver was written by Oleksandr Tymoshenko <gonzo@FreeBSD.org>.

this manual page was written by Andriy Gapon <avg@FreeBSD.org>.

absolute legends, we stan 🫢


and that's the whole page bestie!! this one's a Debian production, dated August 5, 2020, sitting pretty as part of the Kernel Interfaces Manual. ty for coming to my ted talk, go press a button πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from