1

I have an external board with some buttons that are attached to gpio 20 and 21 which connects these pins to ground when pressed:

schematic

simulate this circuit – Schematic created using CircuitLab

I'd like to emit the keys x (fire_left) and o (fire_right) when the buttons are pressed.

I used the following dts file (joystick.dts):

/dts-v1/;
/plugin/;
/ {
   compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709", "brcm,bcm2710";

   fragment@0 {
      target-path = <&gpio>;
      __overlay__ {

         butt_pins: butt_pins {
             brcm,pins = <20 21>;    // gpio no.
             brcm,function = <0 0>;  // 0:in, 1:out
             brcm,pull = <2 2>;      // 2:up 1:down 0:none
         };
      };
   };

   fragment@1 {
      target-path = "/";
      __overlay__ {
         pinctrl-names = "default";
         pinctrl-0 = <&butt_pins>;

         keypad: joystick {
            compatible = "gpio-keys";
            #address-cells = <1>;
            #size-cells = <0>;
            autorepeat;
            button@21 {
               label = "fire_right";
               linux,code = <24>;  // o
               gpios = <&gpio 21 1>;
            };

            button@20 {
               label = "fire_left";
               linux,code = <45>;  // x
               gpios = <&gpio 20 1>;
            };
         };
      };
   };
};

I compiled it with:

 dtc -Idts -O dtb -o joystick.dtbo joystick.dts -W no-unit_address_vs_reg

and used the following command to load it:

sudo dtoverlay joystick.dtbo

My problem is, that, although I configured in fragment@0 pullups for the gpios, the Raspberry pi ignored this setting and doesn't set the pullups.

The output of sudo grep gpio /sys/kernel/debug/gpio (buttons are not pressed!):

gpiochip0: GPIOs 0-53, parent: platform/3f200000.gpio, pinctrl-bcm2835:
 gpio-20  (                    |fire_left           ) in  lo
 gpio-21  (                    |fire_right          ) in  lo
gpiochip2: GPIOs 100-101, brcmvirt-gpio, can sleep:
 gpio-100 (                    |?                   ) out hi
gpiochip1: GPIOs 128-135, brcmexp-gpio, can sleep:
 gpio-135 (                    |?                   ) in  hi

As you can see, gpio-20 and gpio-21 got the correct lable and are set as input. Unfortunately the input value is low and not hight as it would be expected if the pullups where set correctly.

1 Answer 1

0

I found it!

In fragment@0 you have to use target=<&gpio>; instead of target-path = <&gpio>.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.