mirror of
https://github.com/NixOS/nixos-hardware.git
synced 2025-11-05 01:37:24 +08:00
add optional config that makes lgpio and pigpio work
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
./cpu-revision.nix
|
||||
./digi-amp-plus.nix
|
||||
./dwc2.nix
|
||||
./gpio.nix
|
||||
./i2c.nix
|
||||
./leds.nix
|
||||
./modesetting.nix
|
||||
|
||||
36
raspberry-pi/4/gpio.nix
Normal file
36
raspberry-pi/4/gpio.nix
Normal file
@@ -0,0 +1,36 @@
|
||||
{ pkgs, lib, config, ... }:
|
||||
{
|
||||
options.hardware.raspberry-pi."4".gpio = {
|
||||
enable = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
description =
|
||||
"Enable udev rules and kernelParams that make lgpio and pigpio work";
|
||||
default = false;
|
||||
};
|
||||
};
|
||||
config = let
|
||||
cfg = config.hardware.raspberry-pi."4".gpio;
|
||||
in
|
||||
lib.mkIf cfg.enable {
|
||||
users.groups.gpio = lib.mkDefault { };
|
||||
|
||||
# the bit that matters to lgpio here is
|
||||
# "${pkgs.coreutils}/bin/chgrp gpio /dev/%k && chmod 660 /dev/%k"
|
||||
# see https://github.com/NixOS/nixpkgs/pull/352308
|
||||
|
||||
# sudo udevadm test --action=add /dev/gpiochip0 to test
|
||||
|
||||
# import lgpio; lgpio.gpiochip_open(0) should show "1" and not raise
|
||||
# an exception
|
||||
|
||||
services.udev.extraRules = lib.mkBefore ''
|
||||
KERNEL=="gpiomem", GROUP="gpio", MODE="0660"
|
||||
SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", PROGRAM="${pkgs.bash}/bin/bash -c '${pkgs.coreutils}/bin/chgrp gpio /dev/%k && chmod 660 /dev/%k && ${pkgs.coreutils}/bin/chgrp -R gpio /sys/class/gpio && ${pkgs.coreutils}/bin/chmod -R g=u /sys/class/gpio'"
|
||||
SUBSYSTEM=="gpio", ACTION=="add", PROGRAM="${pkgs.bash}/bin/bash -c '${pkgs.coreutils}/bin/chgrp -R gpio /sys%p && ${pkgs.coreutils}/bin/chmod -R g=u /sys%p'"
|
||||
'';
|
||||
|
||||
boot.kernelParams = [
|
||||
"iomem=relaxed" # for pigpiod
|
||||
];
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user