Skip to content

WIP New module: Esp32HardwarePwm#3015

Open
pljakobs wants to merge 4 commits intoSmingHub:developfrom
pljakobs:develop
Open

WIP New module: Esp32HardwarePwm#3015
pljakobs wants to merge 4 commits intoSmingHub:developfrom
pljakobs:develop

Conversation

@pljakobs
Copy link
Copy Markdown
Contributor

@pljakobs pljakobs commented Apr 17, 2026

Summary

This PR adds Esp32HardwarePwm, a comprehensive C++ wrapper for the ESP32 LEDC PWM peripheral, to Arch/Esp32/Components

Motivation

The ESP32 LEDC hardware is significantly more capable than the ESP8266 PWM — it supports up to 20-bit resolution, frequencies up to 40 MHz, hardware-accelerated linear fading, and phase shifting across multiple independent timer+channel groups. The pre-existing HardwarePWM API surface does not expose these capabilities on Esp32. This component provides a native Esp32-specific driver that takes full advantage of the hardware.

Features

  • Multiple independent instances — each with its own timer configuration (frequency, resolution, speed mode, timer index); multiple instances coexist by using non-overlapping channel ranges
  • Flexible duty cycle control — both channel-indexed and legacy pin-indexed analogWrite API; configurable 1–20-bit resolution
  • Phase shifting — OFF, AUTO (evenly distributed), or MANUAL (per-pin hpoint values) to reduce inrush current spikes and EMI
  • Spread spectrum — optional frequency dithering around the base frequency for EMI reduction
  • Hardware fade — hardware-accelerated linear transitions via the LEDC fade engine; ISR installed lazily on first use
  • Per-channel fade queue — chain multiple fades per channel without application polling:
    • FIFO mode: plays entries once in order, auto-starts on first enqueue, fires onQueueEmpty callback when drained
      CYCLIC mode: loops the entry set endlessly, fires onCyclicWrap each loop, requires explicit startQueue() after seeding
    • Per-channel configurable queue depth (default 10, uint16_t); runtime resize while queue is empty
    • Three callback slots: onFadeDone, onQueueEmpty, onCyclicWrap — dispatched via System.queueCallback (task context, ISR-safe)

@what-the-diff
Copy link
Copy Markdown

what-the-diff bot commented Apr 17, 2026

PR Summary

  • Introduction of "Esp32HardwarePwm" Submodule
    A new module named "Esp32HardwarePwm" has been added to further enhance the project functionalities. This new component will be incorporated from another repository as a submodule.

  • Establishment of "Esp32HardwarePwm" Submodule Directory
    This refers to the creation of a dedicated space or directory for the "Esp32HardwarePwm" submodule. It helps to organize different modules effectively. This specific initialization is linked to a particular update or change noted as a "commit".

@pljakobs pljakobs marked this pull request as draft April 17, 2026 20:15
@pljakobs pljakobs changed the title New module: Esp32HardwarePwm WIP New module: Esp32HardwarePwm Apr 17, 2026
@pljakobs pljakobs marked this pull request as ready for review April 20, 2026 13:51
@pljakobs
Copy link
Copy Markdown
Contributor Author

This has become pretty massive but it's also now very functionally complete.
It covers the minimal functionality of configuring a set of channels for PWM and sentting both percentage and absolute value.
It also allows to leverage the Esp32 ledc's functionality to set a variety of PWM frequencies and bit widths (tested to 64kHz and 8Bit).
Additional features:

  • automatic or manual hpoint setting to allow phase shifting channels
  • spread spectrum to reduce the peak spectral load and "smear" it out
  • CIE 1931 curve to allow for linear perception brightness fading
  • hardware fade support
  • queued fade support with Sming native callbacks
  • experimental timing correction support with companion application to calculate SOC specific timing parameters

@pljakobs
Copy link
Copy Markdown
Contributor Author

the build errors are changed function names int he sample app. I'll fix these in ab it.

Picks up refactor/api-rename merge (PR SmingHub#14): unify fade API to fadeChan/fadePercentChan with queue and cie boolean params.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant