MCPWM Driver Implementation#5344
Open
Alex3404 wants to merge 36 commits intoesp-rs:mainfrom
Open
Conversation
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
…pecifly set config
|
New commits in main has made this PR unmergable. Please resolve the conflicts. |
bugadani
reviewed
Apr 10, 2026
bugadani
reviewed
Apr 10, 2026
bugadani
reviewed
Apr 10, 2026
Contributor
There was a problem hiding this comment.
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. |
Perfer to use cargo xtask check-packages esp-hal instead
Contributor
There was a problem hiding this comment.
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
psramfeature definition, but the codebase still uses#[cfg(feature = "psram")](e.g., inesp-hal/src/lib.rsandesp-hal/src/psram/*) and the build script checkscfg!(feature = "psram"). Please restore thepsramfeature (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",
|
New commits in main has made this PR unmergable. Please resolve the conflicts. |
Clarified MCPWM changes regarding Timer methods and configurations.
bugadani
reviewed
Apr 10, 2026
Keeping the int_ena state in a variable is not needed as modify is much better suited.
Added the specific supported configs for mcpwm, as well as added for_each_mcpwm macro for the Instance, and public api
Removed mcpwm_swsync_can_propagate since the device.mcpwm generates the configs
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 📝
cargo xtask fmt-packagescommand to ensure that all changed code is formatted correctly.CHANGELOG.mdin the proper section.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