2022-12-31 11:52:38 +01:00
|
|
|
{ config, lib, ... }:
|
2021-12-11 02:26:21 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.hardware.raspberry-pi."4";
|
2022-08-02 20:32:29 +02:00
|
|
|
optionalProperty = name: value: lib.optionalString (value != null) "${name} = <${builtins.toString value}>;";
|
|
|
|
simple-overlay = { target, status, frequency }: {
|
2021-12-11 02:26:21 +01:00
|
|
|
name = "${target}-${status}-overlay";
|
|
|
|
dtsText = ''
|
|
|
|
/dts-v1/;
|
|
|
|
/plugin/;
|
|
|
|
/ {
|
|
|
|
compatible = "brcm,bcm2711";
|
|
|
|
fragment@0 {
|
|
|
|
target = <&${target}>;
|
|
|
|
__overlay__ {
|
|
|
|
status = "${status}";
|
2022-08-02 20:32:29 +02:00
|
|
|
${optionalProperty "clock-frequency" frequency}
|
2021-12-11 02:26:21 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.hardware.raspberry-pi."4" = {
|
2022-08-02 20:32:29 +02:00
|
|
|
i2c0 = {
|
|
|
|
enable = lib.mkEnableOption ''
|
|
|
|
Turn on the VideoCore I2C bus (maps to /dev/i2c-22) and enable access from the i2c group.
|
|
|
|
After a reboot, i2c-tools (e.g. i2cdetect -F 22) should work for root or any user in i2c.
|
|
|
|
'';
|
|
|
|
frequency = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.int;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
interface clock-frequency
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
i2c1 = {
|
|
|
|
enable = lib.mkEnableOption ''
|
|
|
|
Turn on the ARM I2C bus (/dev/i2c-1 on GPIO pins 3 and 5) and enable access from the i2c group.
|
|
|
|
After a reboot, i2c-tools (e.g. i2cdetect -F 1) should work for root or any user in i2c.
|
|
|
|
'';
|
|
|
|
frequency = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.int;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
interface clock-frequency
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2021-12-11 02:26:21 +01:00
|
|
|
};
|
|
|
|
config.hardware = lib.mkMerge [
|
|
|
|
(lib.mkIf cfg.i2c0.enable {
|
|
|
|
i2c.enable = lib.mkDefault true;
|
|
|
|
deviceTree = {
|
2022-08-02 20:32:29 +02:00
|
|
|
overlays = [ (simple-overlay {
|
|
|
|
target = "i2c0if";
|
|
|
|
status = "okay";
|
2022-12-31 11:52:38 +01:00
|
|
|
inherit (cfg.i2c0) frequency;
|
2022-08-02 20:32:29 +02:00
|
|
|
}) ];
|
2021-12-11 02:26:21 +01:00
|
|
|
};
|
|
|
|
})
|
|
|
|
(lib.mkIf cfg.i2c1.enable {
|
|
|
|
i2c.enable = lib.mkDefault true;
|
|
|
|
deviceTree = {
|
2022-08-02 20:32:29 +02:00
|
|
|
overlays = [ (simple-overlay {
|
|
|
|
target = "i2c1";
|
|
|
|
status = "okay";
|
2022-12-31 11:52:38 +01:00
|
|
|
inherit (cfg.i2c1) frequency;
|
2022-08-02 20:32:29 +02:00
|
|
|
}) ];
|
2021-12-11 02:26:21 +01:00
|
|
|
};
|
|
|
|
})
|
|
|
|
];
|
|
|
|
}
|