MCPWM Driver Implementation - #5344
Conversation
|
New commits in main has made this PR unmergable. Please resolve the conflicts. |
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. |
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 have made this PR unmergeable. Please resolve the conflicts. |
…gs or errors Switched from regs to ptr method for the mcpwm peripheral
|
New commits in main have made this PR unmergeable. Please resolve the conflicts. |
Fix new line ending
|
I've just looked at the PR description but this needs to be changed: -McPwm::new(peripherals.MCPWM0, clock_cfg);
+McPwm::new(AnyMcPwm::from(peripherals.MCPWM0), clock_cfg);Take the peripehral as it is, convert to AnyMcPwm in the constructor, like other drivers do. |
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
Changelog
esp-hal
esp-hal/MCPWM Driver
esp_hal::mcpwm::timer::Timer::apply_configto apply a config to a timer.esp_hal::mcpwm::timer::Timer::startis now parameterless. Instead, useesp_hal::mcpwm::timer::Timer::apply_configto apply a config to a timer.PeripheralClockConfig::timer_clock_default().McPwm::new.Timer::startstarts with the configuredStopConditionrather than being restricted to running tillTimer::stopis called.Migration guide
esp-hal/MCPWM driver
Timer::startsignature changedThe
Timer::startmethod is now parameter less and doesn't take in aTimerClockConfig. Instead, useTimer::apply_configmethod to set the config for themcpwm::Timer.TimerClockConfigcreated bytimer_clock_with_frequencyandtimer_clock_with_prescalerwill still default to
StopCondition::RunContinuously. So, any existing code will only needa simple change.
Mcpwmremoved genericsTimerremoved genericsOperatorremoved genericsLinkedPinsremoved genericsPwmPingenerics reducedMcpwm::newsignature changedThe
Mcpwm::newnow takes aAnyMcpwmtype please useAnyMcpwm::from(mcpwm_peripheral)to construct the MCPWM driver.