An eternity later I’ve been able to confirm those two helper libraries working on hardware (see Configuring PWM channel outputs on the Allwinner D1 (MangoPi MQ Pro) - #10 by Lucassifoni ) . Well, dts_buddy was already confirmed working, but pwmx was bothering me because of a pinmux issue.
Here is a sample of an iex session with both dts_buddy loading a runtime configfs overlay, and pwmx managing output pwm channels :
iex(livebook@nerves.local)1> import DtsBuddy.Sigil
DtsBuddy.Sigil
iex(livebook@nerves.local)2> DtsBuddy.enable_overlays
:ok
iex(livebook@nerves.local)3> DtsBuddy.overlays_enabled?
true
iex(livebook@nerves.local)4> compiled =
~DTS"""
/dts-v1/;
/plugin/;
&{/soc/pinctrl@2000000} {
pwm0_pb5: pwm0-pb5 { pins = "PB5"; function = "pwm0"; };
pwm1_pb6: pwm1-pb6 { pins = "PB6"; function = "pwm1"; };
pwm2_pb11: pwm2-pb11 { pins = "PB11"; function = "pwm2"; };
pwm3_pb0: pwm3-pb0 { pins = "PB0"; function = "pwm3"; };
pwm4_pb1: pwm4-pb1 { pins = "PB1"; function = "pwm4"; };
pwm5_pd21: pwm5-pd21 { pins = "PD21"; function = "pwm5"; };
pwm7_pb10: pwm7-pb10 { pins = "PB10"; function = "pwm7"; };
};
&{/soc/pwm@2000c00} {
pinctrl-names = "default";
pinctrl-0 = <&pwm0_pb5>, <&pwm1_pb6>, <&pwm2_pb11>, <&pwm3_pb0>,
<&pwm4_pb1>, <&pwm5_pd21>, <&pwm7_pb10>;
status = "okay";
};
"""pwm7ch
{:ok, "/data/pwm7ch.dtbo", "pwm7ch"}
iex(livebook@nerves.local)5> DtsBuddy.load(compiled)
:ok
iex(livebook@nerves.local)6> DtsBuddy.status("pwm7ch")
:applied
iex(livebook@nerves.local)7> Pwmx.list_available_outputs()
[
{"pwmchip0", 0},
{"pwmchip0", 1},
{"pwmchip0", 2},
{"pwmchip0", 3},
{"pwmchip0", 4},
{"pwmchip0", 5},
{"pwmchip0", 6},
{"pwmchip0", 7}
]
iex(livebook@nerves.local)8>
outs = for ch <- [0, 1, 2, 3, 4, 5, 7], into: %{}
{:ok, pid} = Pwmx.Output.start_link({"pwmchip0", ch})
pid |> Pwmx.Output.set_period(500_000, :us) |> Pwmx.Output.set_duty_cycle_absolute(250_000, :us) |> Pwmx.Output.enable()
{ch, pid}
end
I will now take the time to clean them up and publish them.























