joan2937 / lg

Linux C libraries and Python modules for manipulating GPIO
The Unlicense
57 stars 20 forks source link

Hardware PWM #11

Open scottwillmoore opened 2 years ago

scottwillmoore commented 2 years ago

First off, thank you for your work this is an awesome project.

I ask mostly out of curiosity, but would it be possible to support hardware PWM using the /dev/gpiochip interface?

Also, do you know if the software PWM has much of an impact on the performance of the CPU? I assume the CPU frequency is so high that the software PWM is has a mostly negligible impact on performance anyway, but would love to hear your opinion.

joan2937 commented 2 years ago

The /dev/gpiochip API has no support for PWM. Of course that may change in the future.

Note that PWM is usually implemented by a separate hardware block whose outputs are multiplexed to the pin outputs. I.e. like the typical SPI/I2C/serial implementations. These do not fall within the scope of /dev/gpiochip.

lg makes use of SPI, I2C, serial as Linux has exposed an API for these blocks. lg will be extended to support PWM If and when PWM support is added to Linux at the same level.

danfrist commented 4 months ago

It would be great to add hardware PWM, even though it uses a different interface. I've built my own solution, but I can't find a way to switch back and forth between using PWM pins as GPIOs and PWMs. Currently, if you use them as a GPIO through lgpio, they cannot be used as hardware PWM until after rebooting. It seems the kernel is reserving them for one or the other, or lgpio is not releasing them fully.

https://github.com/Sttark/linux_GPIO_scope/blob/main/pigpio_lgpio.py#L121

I know this is an old topic, but I had to switch over to using lg instead of pigpio because the new Pi 5 doesn't seem to support pigpio.