Open dr-apple opened 7 years ago
I certainly can. I'll have a think about how to implement it and get it done when I've got a little time to spare.
Perfectly thank you, you can also times times whether you can speed up the input of an input? It takes about 1 second until the change is recognized :-( This is too slow at a pushbutton ....
Yep, it's on the list - see #5 :)
Hi, Great job @flyte Is PWM implemented already?
Hey @Gr4ffy thanks!
It's currently not implemented I'm afraid. There's no technical reason why it couldn't be, just not enough time in the day 😊
Got it, thanks for the feedback.
no pwm yet?
I am also in need of PWM, so I was looking at implementing this, but I'm not sure what the best approach is. I'm not sure if I'll be able to find the time to actually implement this, but in the interest of moving this forward, here are some considerations I had while looking at the code for this. Feedback is welcome.
/dev/gpiochipx
has no way to configure PWM output. There is a /sys/class/pwm/pwmchipx
interface, but that does require devicetree configuration to let the PWM driver take control of pins rather than runtime configuration. Of course, it can be acceptable that PWM output is supported only by some modules, and there could mabye even be a pwmchip-sysfs gpio module that only supports PWM output (to be used together with the gpiod module for regular GPIO for example).supports_pwm
or enable_pwm
directive needs to be added. I guess PWM-enabled pins can still also be controlled as regular digital pins (e.g. by passing on_payload
as value instead of a PWM value), so all regular values can still apply as normal. digital_output_loop()
(that converts on_payload/off_payload
to a bool) and set_digital_output()
(that logs and passes the value to the right gpio module). The easiest approach would be to generalize these methods to just pass either booleans or numbers, and let the gpio module call the right output method based on the type of value.set_pwm_output()
next to set_digital_output()
and add a set_pwm_pin()
to gpio modules, letting digital_output_loop()
call the right method based on the type of value.<topic_prefix>/output/<name>/set_pwm
(which saves the "look at the content to decide whether to do PWM or on/off", which is a bit fragile). This would probably be implemented by letting _handle_digital_output_msg
match the set_pwm
topic and if so, adding a different kind of message to the gpio queue (maybe adding a type flag or so) so digital_output_loop()
(which processes the loop) can dispatch to the right method. This approach is probably the most explicit and most appropriate, without needing much extra boilerplate code._handle_digital_output_msg()
and digital_output_loop()
. The former looks at the topic and handles set_on_ms
and set_off_ms
directly by dispatching a task, and puts regular pin updates in a queue that is handled by digital_output_loop()
(which also matches the payload against on_payload
/off_payload
config). For the set_on/off_ms
handling, the comments say this is done in a task to prevent blocking digital_output_loop()
, but the latter also handles the timed_set_ms
configuration by also dispatching a task, essentially duplicating the set_on_ms
code in a different place. I suspect these different timed features might have been introduced over time, but looking at them now, it seems this code could be refactored to be simpler.I think the /sys/class/pwm
interface makes the most sense (instead of trying to write several drivers for specific hardware when there is already a common API in the kernel), and to be a dedicated module that doesn't try to figure out things like mappings that may not even exist between regular GPIO pins and PWM pins. Just rely on the user to determine which PWM chip and line they want to use and have the driver loaded. I've used this interface from C before, all you have to do it write the pin number to the export
file (like the old sysfs gpio), set the frequency/period with period
, write 1 to enable
, and write a number to duty_cycle
to set the pulse length.
Hello,
it works all very good, thanks for your script...
Could you still install PWM for all GPIO?