Tasmota icon indicating copy to clipboard operation
Tasmota copied to clipboard

Allow mapping of one PWM channel to multiple GPIOs

Open sudden6 opened this issue 1 year ago • 1 comments

Description:

Allow same PWM channel on multiple GPIO pins on ESP32.

This implementation seems to work, but it has one drawback. It will use a a new PWM hardware channel per configured PWM output, so you can never have more than 16 PWM outputs even if all of them are configured as PWM1. Also, the PWM signal is not guaranteed to be exactly the same only that it has the same duty cycle. The hardware PWM channels are reconfigured at different times and phasing is applied on all outputs. This is no problem for light strips though.

A proper implementation would use the ESP32 GPIO_MUX to route the same LEDC PWM channels to multiple GPIO pins, but this would be more complicated to implement with the current framework of Tasmota.

Related issue (if applicable): https://github.com/arendst/Tasmota/discussions/10884

Checklist:

  • [x] The pull request is done against the latest development branch
  • [x] Only relevant files were touched
  • [] Only one feature/fix was added per PR and the code change compiles without warnings
  • [ ] The code change is tested and works with Tasmota core ESP8266 V.2.7.6
  • [x] The code change is tested and works with Tasmota core ESP32 V.2.0.14
  • [x] I accept the CLA.

I don't have any ESP8266 devices for testing, but the changes are only in regions that won't affect it. I also took the liberty of adding some documentation in doxygen format, let me know if that's ok.

sudden6 avatar Feb 18 '24 19:02 sudden6

Without testing if and how it affects the esp8266, there is no merge possible.

Jason2866 avatar Feb 19 '24 10:02 Jason2866

I will review it

s-hadinger avatar Feb 19 '24 17:02 s-hadinger

I'm favorable to have this special semantics: if two GPIO have the same PWM<x> then they are replicating the same behavior. Actually it would make sense to have the same with RELAY<x>

I looked at esp-idf api, it should be possible to use the Mux to have only one timer driving 2 GPIOs, but I'm afraid this would be too specific, and fragile whenever esp-idf evolves again. The need is still a niche, so having this limitation of consuming one timer per actual GPIO should be ok.

s-hadinger avatar Feb 28 '24 11:02 s-hadinger

I just need to test on ESP8266 before merging

s-hadinger avatar Feb 28 '24 11:02 s-hadinger

I tested on ESP8266, but it does not expose the same behavior. I.e. the duplication of PWM does not work on ESP8266.

I'm annoyed to not have a consistent behavior on ESP8266 and ESP32. If you want this feature integrated, you need to backport it to ESP8266 as well. Thanks

s-hadinger avatar Feb 29 '24 12:02 s-hadinger

@s-hadinger I don't have any ESP8266 device and I don't think the PWM generators are similar enough that I could do a blind port.

sudden6 avatar Feb 29 '24 18:02 sudden6

This PR has been automatically marked as stale because it hasn't any activity in last few weeks. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Mar 25 '24 19:03 github-actions[bot]

This PR was automatically closed because of being stale.

github-actions[bot] avatar Mar 30 '24 19:03 github-actions[bot]