NixOS on ARM/Raspberry Pi 4: Difference between revisions
imported>Lassulus mNo edit summary |
imported>Fstuess No edit summary |
||
Line 224: | Line 224: | ||
''; | ''; | ||
</nowiki>}} | </nowiki>}} | ||
==== Gpio and 1-wire ==== | |||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | |||
# add gpio group | |||
users.groups.gpio = {}; | |||
# udev rule for gpio | |||
services.udev.extraRules = '' | |||
SUBSYSTEM=="bcm2835-gpiomem", KERNEL=="gpiomem", GROUP="gpio",MODE="0660" | |||
SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", RUN+="${pkgs.bash}/bin/bash -c 'chown root:gpio /sys/class/gpio/export /sys/class/gpio/unexport ; chmod 220 /sys/class/gpio/export /sys/class/gpio/unexport'" | |||
SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add",RUN+="${pkgs.bash}/bin/bash -c 'chown root:gpio /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value ; chmod 660 /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value'" | |||
''; | |||
# add user with gpio group | |||
users = { | |||
mutableUsers = false; | |||
users.mygpiouser = { | |||
isNormalUser = true; | |||
password = "mygpiouserpasswd"; | |||
extraGroups = [ "wheel" "gpio" ]; | |||
}; | |||
}; | |||
# insert device tree snippet for 1-wire | |||
hardware.deviceTree = { | |||
enable = true; | |||
overlays = [ | |||
{ | |||
name = "w1-gpio-overlay"; | |||
dtsText = '' | |||
/dts-v1/; | |||
/plugin/; | |||
/ { | |||
compatible = "brcm,bcm2711"; | |||
fragment@0 { | |||
target-path = "/"; | |||
__overlay__ { | |||
w1: onewire@0 { | |||
compatible = "w1-gpio"; | |||
pinctrl-names = "default"; | |||
pinctrl-0 = <&w1_pins>; | |||
gpios = <&gpio 4 0>; | |||
rpi,parasitic-power = <0>; | |||
status = "okay"; | |||
}; | |||
}; | |||
}; | |||
fragment@1 { | |||
target = <&gpio>; | |||
__overlay__ { | |||
w1_pins: w1_pins { | |||
brcm,pins = <4>; | |||
brcm,function = <0>; // in (initially) | |||
brcm,pull = <0>; // off | |||
}; | |||
}; | |||
}; | |||
__overrides__ { | |||
gpiopin = <&w1>,"4", | |||
<&w1_pins>,"brcm,pins:0"; | |||
pullup = <&w1>,"rpi,parasitic-power:0"; | |||
}; | |||
}; | |||
''; | |||
} | |||
]; | |||
}; | |||
</nowiki>}} | |||
== Troubleshooting == | == Troubleshooting == | ||