Hello PeteB,
Sure thing.
rune-power-gpio.dts:
- Code: Select all
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";
fragment@0 {
target = <&gpio>;
__overlay__ {
button_pins: button_pins {
brcm,pins = <3>; /* change the 3 here to the gpio where the button is attached */
brcm,function = <0>;
brcm,pull = <2>; /* pull direction: none=0, 1=down, 2=up */
};
};
};
fragment@1 {
target-path = "/soc";
__overlay__ {
keypad: keypad {
compatible = "gpio-keys";
#address-cells = <1>;
#size-cells = <0>;
pinctrl-names = "default";
pinctrl-0 = <&button_pins>;
status = "okay";
button@22 {
label = "pwr_btn";
linux,code = <116>; /* The KEY_POWER defined in include/linux/input.h */
gpios = <&gpio 3 1>; /* Also change the 3 here to the one where the button is attached */
};
};
};
};
};
This is the source code. To compile it, you will need the "dtc-overlay" package: pacman -S dtc-overlay
And the compile command: dtc -@ -I dts -O dtb -o rune-power-gpio.dtb rune-power-gpio.dts
Copy the dtb to /boot/overlay and add the following line to /boot/config: device_tree_overlay=rune-power-gpio
After a reboot, this should create the following entry in your sys-fs: /sys/devices/platform/soc/soc:keypad
And in dev: /dev/input/by-path/platform-soc:keypad-event
If it does not, then something went wrong.
For the shutdown command to work, you have to unmask the systemd-logind daemon: systemctl unmask systemd-logind
Reboot and after that a low-pulse will instantly initiate a shutdown of the system.
Concerning the RUN-Pin. If you are familir with a solderin iron, you could use an OR-gate (something like an
74LV32) to wire the shutdown-pin and the toggle button together:
- OR.png (9.76 KiB) Viewed 3862 times
Pi-Power-off: Input signal for the raspberry to initiate the shutdown
Shutdown-Pin: The pin, which is held high by the raspberry/external circuit
RUN: The Reset signal
With this, the RUN pin will only be pulled low, if both inputs are low, else it'll stay high.