Ledc rewrite - #5937
Conversation
|
I'm not sure why we should accept this - a lot of change, but it doesn't solve the fundamental useability issues - timers and channels are tied in such a way that makes using LEDC in a real application rather difficult. Sure, the driver itself is a little better than how it was - but if we're going to change it, we might as well spend the time to actually design the driver into a shape that we consider good enough for the long term. I'm also not sure this was written by a human, and maintaining something generated by an LLM will be difficult if you won't be around to be able to answer questions about the code in the future. |
|
The Regarding the AI comment: I used an LLM to research how other drivers are written. I wrote the code myself, only sometimes asking the LLM for small code snippets which I reviewed and edited. |
Submission Checklist 📝
cargo xtask fmt-packagescommand to ensure that all changed code is formatted correctly.skip-changelogormanual-changeloglabel as appropriate.Extra:
Pull Request Details 📖
Description
This pull request refactors the
LEDCdriver to be in par withesp-haldeveloper guidelines.Key changes:
Testing
cargo xtask lint-packagesandcargo xtask fmt-packages.hil-testto verify PWM signal generation, timer reconfiguration, and automated hardware duty cycle fading.Changelog
esp-hal
LSGlobalClkSourcetoLowSpeedGlobalClockSource.LSClockSourcetoClockSource.Migration guide
esp-hal/LEDC driver
LEDC API refactored to use creator pattern
The LEDC driver API has been restructured.
Ledc::new()now returns an instance containing dedicated creator fields for each timer and channel (e.g.,timer0,channel0) instead of using.timer()and.channel()methods.LSGlobalClkSourcehas been renamed toLowSpeedGlobalClockSourceReplace all uses of
LSGlobalClkSourcewithLowSpeedGlobalClockSource.LSClockSourceandHSClockSourcewere merged and renamed toClockSource.Replace all uses of
LSClockSourceandHSClockSourcewithClockSource.Timer and Channel creation has been moved to
TimerCreatorandChannelCreator.Change all usages of the
.timer()and.channel()methods inside theLedcdriver to use the new creator fields:ledc.timer0.configure()orledc.channel0.configure().Output pin is assignment moved to
with_pin()method.Move all pin assignments from the Config struct to
with_pin()method on the configuredChannel.Duty Cycles are now absolute
u32values.Change all
set_duty()method usages toset_duty_cycle()and make sure the argument is an absolute value. A simple way to do this would be to changepercentagetochannel.max_duty_cycle() / percentage * 100.Example migration: