NixOS on ARM/Raspberry Pi 4: Difference between revisions
imported>Jooooscha Add explaination on why applying the GPIO code works |
imported>Jooooscha Add section for enabling the SPI device |
||
Line 210: | Line 210: | ||
}; | }; | ||
</syntaxHighlight> | </syntaxHighlight> | ||
=== Enabling the SPI === | |||
To enable the SPI, you would normally add <code>dtparam=spi=on</code> to <code>/boot/config.txt</code>. | |||
This is not possbible on NixOS, and instead you have to apply a device tree overlay. | |||
For this we use the <code>hardware.deviceTree.overlays</code> option. | |||
After applying the overlay, we add an <code>spi</code> group and change the owner of the <code>spidev</code> device to it, similarly to [[#Using GPIO pins as non root |GPIO]]. | |||
<syntaxHighlight lang="nix"> | |||
hardware.raspberry-pi."4".apply-overlays-dtmerge.enable = true; | |||
hardware.deviceTree = { | |||
enable = true; | |||
filter = "*-rpi-*.dtb"; | |||
overlays = [ | |||
{ | |||
name = "spi"; | |||
dtsoFile = ./spi0-0cd.dtso; | |||
} | |||
]; | |||
}; | |||
users.groups.spi = {}; | |||
services.udev.extraRules = '' | |||
SUBSYSTEM=="spidev", KERNEL=="spidev0.0", GROUP="spi", MODE="0660" | |||
''; | |||
</syntaxHighlight> | |||
The the <code>spi0-0cd.dtso</code> file can be downlaoded [https://github.com/raspberrypi/firmware/blob/master/boot/overlays/spi0-0cs.dtbo here]. | |||
You might have to change the <code>compatible</code> field to "raspberrypi" in the dtbo file. | |||
=== HDMI-CEC === | === HDMI-CEC === |