Skip to content

MCPWM Driver Implementation#5344

Open
Alex3404 wants to merge 36 commits intoesp-rs:mainfrom
Alex3404:main
Open

MCPWM Driver Implementation#5344
Alex3404 wants to merge 36 commits intoesp-rs:mainfrom
Alex3404:main

Conversation

@Alex3404
Copy link
Copy Markdown

@Alex3404 Alex3404 commented Apr 10, 2026

Thank you for your contribution!

We appreciate the time and effort you've put into this pull request.
To help us review it efficiently, please ensure you've gone through the following checklist:

Submission Checklist 📝

  • I have updated existing examples or added new ones (if applicable).
  • I have used cargo xtask fmt-packages command to ensure that all changed code is formatted correctly.
  • My changes were added to the CHANGELOG.md in the proper section.
  • I have added necessary changes to user code to the latest Migration Guide.
  • My changes are in accordance to the esp-rs developer guidelines

Extra:

Pull Request Details 📖

Description

I have added support for the capture channels, capture timer, sync events, and some interrupt events for the MCPWM driver. My motivation behind this was that I needed an MCPWM driver for my project, and I wasn't willing to convert my project to esp-idf.

Testing

I have tested the drivers on an ESP32-S3

  • I have used pulse generators for generating sync events, and verified accurate timing through an oscilloscope.
  • Using a pulse generator for verifying capture channel handles events properly
  • Used it in my own project for a triac dimming for measuring us pulse widths of zero crosses, and generating phase shifted gate pulses.

Alex3404 added 16 commits March 28, 2026 12:34
I will be testing these for any issures on my esp32-s3
Cargo was updated to use the new updated pac that I needed to create. Cargo.toml can be reverted once the pac  is in the main branch.
Finished the sync implementation time to test the code!
Forgot to compile with unstable so last commit contained uncompilable code. This compiles with no warnings.
Lastest PAC version
Copilot AI review requested due to automatic review settings April 10, 2026 16:00
@github-actions github-actions Bot added the merge-conflict Merge conflict detected. Automatically added/removed by CI. label Apr 10, 2026
@github-actions
Copy link
Copy Markdown

New commits in main has made this PR unmergable. Please resolve the conflicts.

Comment thread esp-metadata/devices/esp32s3.toml Outdated
Comment thread build_all.ps1 Outdated
Comment thread esp-hal/src/mcpwm/mod.rs Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands the esp-hal MCPWM driver to support additional MCPWM functionality (capture channels + capture timer, sync sources/lines and timer sync-out chaining, plus more interrupt/event handling), and updates device metadata with new MCPWM capability cfgs.

Changes:

  • Add MCPWM capture support (capture timer + capture channels) and new sync abstractions (sync lines + timer sync-out as a sync source).
  • Introduce MCPWM interrupt/event plumbing (timer events, capture events) with a shared per-instance State.
  • Update device metadata / generated cfg lists with new soc_has_mcpwm_* capability symbols.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
esp-metadata/devices/esp32s3.toml Adds MCPWM capability symbol(s) and reformats metadata.
esp-metadata/devices/esp32h2.toml Adds MCPWM capability symbols and reformats metadata.
esp-metadata/devices/esp32c6.toml Adds MCPWM capability symbols and reformats metadata.
esp-metadata/devices/esp32c5.toml Adds MCPWM capability symbols and reformats metadata.
esp-metadata-generated/src/_build_script_utils.rs Emits/validates new soc_has_mcpwm_* cfgs for build scripts and check-cfg.
esp-hal/src/mcpwm/mod.rs Refactors MCPWM instance plumbing; adds capture/sync fields and interrupt/event infrastructure; updates docs.
esp-hal/src/mcpwm/timer.rs Adds sync-in/out configuration, timer events/interrupt helpers, and new timer config fields.
esp-hal/src/mcpwm/operator.rs Adapts operators/pins to new MCPWM Instance abstraction and register access patterns.
esp-hal/src/mcpwm/sync.rs New sync module: SyncLine, SyncOut, and a sealed SyncSource abstraction.
esp-hal/src/mcpwm/capture.rs New capture module: capture timer + capture channels + configuration + interrupt helpers.
esp-hal/Cargo.toml Re-formats and alters dependencies (notably PAC dependency sources/paths).
build_all.ps1 Adds a helper script to build esp-hal for multiple chips.

Comment thread esp-hal/Cargo.toml Outdated
Comment thread esp-hal/src/mcpwm/mod.rs Outdated
Comment thread esp-hal/src/mcpwm/mod.rs Outdated
Comment thread esp-hal/src/mcpwm/timer.rs
Comment thread esp-hal/src/mcpwm/capture.rs
Comment thread esp-hal/src/mcpwm/capture.rs Outdated
Comment thread esp-hal/src/mcpwm/sync.rs
Comment thread esp-hal/src/mcpwm/mod.rs
Comment thread esp-hal/src/mcpwm/mod.rs
Copilot AI review requested due to automatic review settings April 10, 2026 17:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 16 comments.

Comments suppressed due to low confidence (1)

esp-hal/Cargo.toml:313

  • This PR removes the psram feature definition, but the codebase still uses #[cfg(feature = "psram")] (e.g., in esp-hal/src/lib.rs and esp-hal/src/psram/*) and the build script checks cfg!(feature = "psram"). Please restore the psram feature (and its docs/CI feature matrices) or update the codebase to the new intended feature flag, otherwise PSRAM support becomes impossible to enable.
#! ### Unstable APIs
#! Unstable APIs are drivers and features that are not yet ready for general use.
#! They may be incomplete, have bugs, or be subject to change without notice.
#! Unstable APIs are not covered by semver guarantees.

## Enables APIs that are not stable and thus come with no stability guarantees.
## Never enable this feature in a library crate using esp-hal.
unstable = [
    "dep:digest",

Comment thread esp-hal/src/mcpwm/mod.rs Outdated
Comment thread esp-hal/src/mcpwm/mod.rs
Comment thread esp-hal/src/mcpwm/mod.rs
Comment thread esp-hal/src/mcpwm/mod.rs
Comment thread esp-hal/src/mcpwm/timer.rs Outdated
Comment thread esp-metadata/devices/esp32c6.toml Outdated
Comment thread esp-hal/Cargo.toml Outdated
Comment thread esp-hal/src/mcpwm/timer.rs Outdated
Comment thread esp-hal/src/mcpwm/capture.rs Outdated
Comment thread esp-hal/src/mcpwm/mod.rs
Copilot AI review requested due to automatic review settings April 10, 2026 19:59
@github-actions
Copy link
Copy Markdown

New commits in main has made this PR unmergable. Please resolve the conflicts.

@github-actions github-actions Bot added the merge-conflict Merge conflict detected. Automatically added/removed by CI. label Apr 10, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 8 comments.

Comment thread esp-hal/src/mcpwm/mod.rs Outdated
Comment thread esp-hal/src/mcpwm/mod.rs Outdated
Comment thread esp-hal/src/mcpwm/timer.rs
Comment thread esp-hal/src/mcpwm/timer.rs Outdated
Comment thread esp-hal/MIGRATING-1.0.0.md Outdated
Comment thread esp-hal/Cargo.toml Outdated
Comment thread esp-hal/src/mcpwm/capture.rs Outdated
Comment thread esp-hal/src/mcpwm/timer.rs
Copilot AI review requested due to automatic review settings April 10, 2026 20:06
Clarified MCPWM changes regarding Timer methods and configurations.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.

Comment thread esp-hal/src/mcpwm/mod.rs Outdated
Comment thread esp-hal/src/mcpwm/mod.rs Outdated
Comment thread esp-hal/src/mcpwm/mod.rs Outdated
Comment thread esp-hal/Cargo.toml Outdated
Comment thread esp-metadata/devices/esp32c5.toml Outdated
Keeping the int_ena state in a variable is not needed as modify is much better suited.
Copilot AI review requested due to automatic review settings April 10, 2026 21:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.

Comment thread esp-hal/src/mcpwm/mod.rs
Comment thread esp-hal/src/mcpwm/timer.rs Outdated
Comment thread esp-hal/src/mcpwm/capture.rs Outdated
Comment thread esp-hal/CHANGELOG.md Outdated
Added the specific supported configs for mcpwm, as well as added for_each_mcpwm macro for the Instance, and public api
Copilot AI review requested due to automatic review settings April 10, 2026 23:08
Removed mcpwm_swsync_can_propagate since the device.mcpwm generates the configs
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 22 changed files in this pull request and generated 2 comments.

Comment thread esp-hal/src/mcpwm/mod.rs Outdated
Comment thread esp-hal/src/mcpwm/mod.rs Outdated
Copilot AI review requested due to automatic review settings April 10, 2026 23:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 22 changed files in this pull request and generated 1 comment.

Comment thread esp-hal/src/mcpwm/timer.rs
Added an additional check to make sure the sync range provided by the timer config is valid. As well as updated some of the formatting of comments. Renamed functions to better follow the developer guidelines.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-conflict Merge conflict detected. Automatically added/removed by CI.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants