* [libgpiod] How can I use PWM
@ 2022-08-05 11:14 Robert Baumgartner
2022-08-06 10:12 ` Andy Shevchenko
0 siblings, 1 reply; 6+ messages in thread
From: Robert Baumgartner @ 2022-08-05 11:14 UTC (permalink / raw)
To: linux-gpio
Hi team,
I try to migrate some python scripts for my Raspberry from RPi.GPIO to
libgpiod, but I miss PWM features.
Do I miss something? Or is it not available?
Some details: https://www.electronicwings.com/raspberry-pi/raspberry-pi-pwm-generation-using-python-and-c
Any help would be appreciated.
Mit freundlichen Grüßen / Kind regards
Robert Baumgartner
Senior Solution Architect OpenShift
Red Hat Austria GmbH, Firmenbuch Nr.: FN 479668w, Handelsgericht Wien
Millenniumtower 26. Stock
Handelskai 94-96
A-1200 Wien
robert.baumgartner@redhat.com
M: +43-660-5913883
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [libgpiod] How can I use PWM
2022-08-05 11:14 [libgpiod] How can I use PWM Robert Baumgartner
@ 2022-08-06 10:12 ` Andy Shevchenko
2022-08-06 13:40 ` Kent Gibson
0 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2022-08-06 10:12 UTC (permalink / raw)
To: Robert Baumgartner, Thierry Reding, Thierry Reding
Cc: open list:GPIO SUBSYSTEM, linux-pwm
On Fri, Aug 5, 2022 at 1:17 PM Robert Baumgartner <rbaumgar@redhat.com> wrote:
>
> Hi team,
>
> I try to migrate some python scripts for my Raspberry from RPi.GPIO to
> libgpiod,
This is great and everyone should be encouraged to follow your example!
> but I miss PWM features.
> Do I miss something? Or is it not available?
No, you haven't missed anything except Unix ideology. That ideology is
telling us that one tool for one thing, and in very featurable mode.
That said, lingpiod is exclusively for GPIO ABI between kernel and
user space. For PWM you need to access the PWM ABI in a way how it's
represented by the Linux kernel. I believe there are plenty of
libraries more or less okayish for that purpose, but I never heard
about any official library and/or Python bindings for it.
Thierry, any suggestion here?
> Some details: https://www.electronicwings.com/raspberry-pi/raspberry-pi-pwm-generation-using-python-and-c
>
> Any help would be appreciated.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [libgpiod] How can I use PWM
2022-08-06 10:12 ` Andy Shevchenko
@ 2022-08-06 13:40 ` Kent Gibson
2022-08-06 14:04 ` Andy Shevchenko
0 siblings, 1 reply; 6+ messages in thread
From: Kent Gibson @ 2022-08-06 13:40 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Robert Baumgartner, Thierry Reding, Thierry Reding,
open list:GPIO SUBSYSTEM, Bartosz Golaszewski
On Sat, Aug 06, 2022 at 12:12:31PM +0200, Andy Shevchenko wrote:
> On Fri, Aug 5, 2022 at 1:17 PM Robert Baumgartner <rbaumgar@redhat.com> wrote:
> >
> > Hi team,
> >
> > I try to migrate some python scripts for my Raspberry from RPi.GPIO to
> > libgpiod,
>
> This is great and everyone should be encouraged to follow your example!
>
> > but I miss PWM features.
> > Do I miss something? Or is it not available?
>
> No, you haven't missed anything except Unix ideology. That ideology is
> telling us that one tool for one thing, and in very featurable mode.
> That said, lingpiod is exclusively for GPIO ABI between kernel and
> user space. For PWM you need to access the PWM ABI in a way how it's
> represented by the Linux kernel. I believe there are plenty of
> libraries more or less okayish for that purpose, but I never heard
> about any official library and/or Python bindings for it.
>
I'm assuming Robert is refering to software PWM. AFAIAA Rpi.GPIO doesn't
support hardware PWM, and the referenced article also refers to software
PWM for the Python case.
libgpiod doesn't directly support software PWM, but it is fairly
straight forward to implement yourself using libgpiod.
Separate from Andy's point on Unix ideology, adding it to libgpiod would
involve threading or async, which in C would open cans of worms that are
best left to the specific application to decide on. So I don't see it
ever going into the core libgpiod.
Not such an issue for Python with its included batteries, so I would
personally consider adding something along those lines to the Python
bindings, and possibly the Rust as well. OTOH I suspect Bart's
preference is for the bindings to idiomatically wrap, not extend, the
libgpiod API.
Cheers,
Kent.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [libgpiod] How can I use PWM
2022-08-06 13:40 ` Kent Gibson
@ 2022-08-06 14:04 ` Andy Shevchenko
2022-08-07 13:20 ` Robert Baumgartner
0 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2022-08-06 14:04 UTC (permalink / raw)
To: Kent Gibson
Cc: Robert Baumgartner, Thierry Reding, Thierry Reding,
open list:GPIO SUBSYSTEM, Bartosz Golaszewski
On Sat, Aug 6, 2022 at 3:40 PM Kent Gibson <warthog618@gmail.com> wrote:
> On Sat, Aug 06, 2022 at 12:12:31PM +0200, Andy Shevchenko wrote:
> > On Fri, Aug 5, 2022 at 1:17 PM Robert Baumgartner <rbaumgar@redhat.com> wrote:
...
> > No, you haven't missed anything except Unix ideology. That ideology is
> > telling us that one tool for one thing, and in very featurable mode.
> > That said, lingpiod is exclusively for GPIO ABI between kernel and
> > user space. For PWM you need to access the PWM ABI in a way how it's
> > represented by the Linux kernel. I believe there are plenty of
> > libraries more or less okayish for that purpose, but I never heard
> > about any official library and/or Python bindings for it.
>
> I'm assuming Robert is refering to software PWM.
I don't think so. The article he referenced clearly tells about two
(hardware!) PWMs.
> AFAIAA Rpi.GPIO doesn't
> support hardware PWM, and the referenced article also refers to software
> PWM for the Python case.
>
> libgpiod doesn't directly support software PWM, but it is fairly
> straight forward to implement yourself using libgpiod.
Hmm... I was under the impression that we have pwm-gpio in the
kernel... Can't find quickly if there is one.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [libgpiod] How can I use PWM
2022-08-06 14:04 ` Andy Shevchenko
@ 2022-08-07 13:20 ` Robert Baumgartner
2022-08-07 14:41 ` Kent Gibson
0 siblings, 1 reply; 6+ messages in thread
From: Robert Baumgartner @ 2022-08-07 13:20 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Kent Gibson, Thierry Reding, Thierry Reding,
open list:GPIO SUBSYSTEM, Bartosz Golaszewski
Andy, Kent,
I believe I am on the right track.
I added following line to my config.txt
# enable pwm on pin 18
dtoverlay=pwm,pin=18,func=2
Now I have
# ls /sys/class/pwm/pwmchip0
device export npwm power subsystem uevent unexport
# lsmod|grep pwm
pwm_bcm2835 16384 0
and an example I found is working
https://github.com/jdimpson/syspw
Kind regards
Robert
On Sat, Aug 6, 2022 at 4:04 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
>
> On Sat, Aug 6, 2022 at 3:40 PM Kent Gibson <warthog618@gmail.com> wrote:
> > On Sat, Aug 06, 2022 at 12:12:31PM +0200, Andy Shevchenko wrote:
> > > On Fri, Aug 5, 2022 at 1:17 PM Robert Baumgartner <rbaumgar@redhat.com> wrote:
>
> ...
>
> > > No, you haven't missed anything except Unix ideology. That ideology is
> > > telling us that one tool for one thing, and in very featurable mode.
> > > That said, lingpiod is exclusively for GPIO ABI between kernel and
> > > user space. For PWM you need to access the PWM ABI in a way how it's
> > > represented by the Linux kernel. I believe there are plenty of
> > > libraries more or less okayish for that purpose, but I never heard
> > > about any official library and/or Python bindings for it.
> >
> > I'm assuming Robert is refering to software PWM.
>
> I don't think so. The article he referenced clearly tells about two
> (hardware!) PWMs.
>
> > AFAIAA Rpi.GPIO doesn't
> > support hardware PWM, and the referenced article also refers to software
> > PWM for the Python case.
> >
> > libgpiod doesn't directly support software PWM, but it is fairly
> > straight forward to implement yourself using libgpiod.
>
> Hmm... I was under the impression that we have pwm-gpio in the
> kernel... Can't find quickly if there is one.
>
> --
> With Best Regards,
> Andy Shevchenko
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [libgpiod] How can I use PWM
2022-08-07 13:20 ` Robert Baumgartner
@ 2022-08-07 14:41 ` Kent Gibson
0 siblings, 0 replies; 6+ messages in thread
From: Kent Gibson @ 2022-08-07 14:41 UTC (permalink / raw)
To: Robert Baumgartner
Cc: Andy Shevchenko, Thierry Reding, Thierry Reding,
open list:GPIO SUBSYSTEM, Bartosz Golaszewski
On Sun, Aug 07, 2022 at 03:20:33PM +0200, Robert Baumgartner wrote:
> Andy, Kent,
>
> I believe I am on the right track.
>
> I added following line to my config.txt
> # enable pwm on pin 18
> dtoverlay=pwm,pin=18,func=2
>
> Now I have
> # ls /sys/class/pwm/pwmchip0
> device export npwm power subsystem uevent unexport
> # lsmod|grep pwm
> pwm_bcm2835 16384 0
>
Excellent - if the hardware PWMs cover the lines you are interested in
then that is certainly the way to go.
> and an example I found is working
> https://github.com/jdimpson/syspw
>
I believe that should be syspwm.
Cheers,
Kent.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-08-07 14:42 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-05 11:14 [libgpiod] How can I use PWM Robert Baumgartner
2022-08-06 10:12 ` Andy Shevchenko
2022-08-06 13:40 ` Kent Gibson
2022-08-06 14:04 ` Andy Shevchenko
2022-08-07 13:20 ` Robert Baumgartner
2022-08-07 14:41 ` Kent Gibson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).