Debounce 2 GPIOs via devicetree overlay

Dear all,
for our project we need to debounce two Gpio Inputs from the imx6ull-emmc v1.1 module.
so i think it is possible with a device tree overlay. i found this option here from another topic

debounce-interval = <10>;

but it is only used in gpio-keys. so does anybody knows how i could add this to the pin SODIMM_102 and SODIMM_104?

Thank you very much for any help!

Florian

Hi, I’m the Toradex AI Assistant. I’m in early beta, and I would appreciate your feedback.
The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


Hello Florian,

To debounce GPIO inputs on the iMX6ULL module using a device tree overlay, you indeed can use the debounce-interval property, similar to how it’s used within the gpio-keys node. However, this property is specific to the gpio-keys driver, which means it’s not directly applicable to general GPIO pin configuration outside of a gpio-keys context.

If your application allows treating these GPIOs as input keys, you could define them within a gpio-keys node in your device tree overlay. Here’s how you could approach it for SODIMM_102 and SODIMM_104:

/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/gpio.h>
#include "imx6ull-pinfunc.h"

/ {
    compatible = "toradex,colibri-imx6ull-emmc";

    fragment@0 {
        target-path = "/";
        __overlay__ {
            debounce-keys {
                compatible = "gpio-keys";
                pinctrl-names = "default";
                pinctrl-0 = <&pinctrl_debounce_keys>;

                sodimm_102_key {
                    label = "sodimm_102_key";
                    gpios = <&gpio1 10 GPIO_ACTIVE_HIGH>; // Adjust GPIO number as per SODIMM_102 mapping
                    linux,code = <KEY_RESERVED>; // Use appropriate keycode
                    debounce-interval = <10>;
                };

                sodimm_104_key {
                    label = "sodimm_104_key";
                    gpios = <&gpio1 12 GPIO_ACTIVE_HIGH>; // Adjust GPIO number as per SODIMM_104 mapping
                    linux,code = <KEY_RESERVED>; // Use appropriate keycode
                    debounce-interval = <10>;
                };
            };
        };
    };

    fragment@1 {
        target = <&iomuxc>;
        __overlay__ {
            pinctrl_debounce_keys: debouncekeysgrp {
                fsl,pins = <
                    MX6UL_PAD_..._GPIO1_IO10 0x... // Configure pin SODIMM_102
                    MX6UL_PAD_..._GPIO1_IO12 0x... // Configure pin SODIMM_104
                >;
            };
        };
    };
};

Please adjust the gpios property according to the actual GPIO number mapping for SODIMM_102 and SODIMM_104 on the

Please, also check if these links can help you solve your problem:

GPIO (Linux) | Toradex Developer Center.

Dear @toraflo,

Thank you for contacting us. May I ask what specific use you will have for the gpios? Will you be using them for buttons?

Probably the easiest way to debounce them in that case would be a hardware debounce through capacitors.
Should you want to use wakeup, there is an example in this link.

Best regards
Collin

Capacitor discharge current, which is limited only by closed contacts resistance, I fear may lead to premature button failure. Adding extra current limiting resistor may further complicate input circuit, for the best you would need comparator… The easiest, I believe, is software debouncing. Once you (de)press the button (input edge interrupt), you signal button event and start debounce timer. Once timer expires, you reread input, and if new readout value doesn’t agree with last valid edge (button got (de)released during debounce period), you signal new event and start debounce timer again. Worst buttons and switches have 50ms or longer bouncing time, so something like 50ms should be your debouncing timer expiration value. New switches may be better, but it so annoying to see rotary knob heavily misbehaving on few years old device, so you should keep as high as suitable for your application.