Add set_frequency method on PWM channels #174
Merged
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.
Following discussion in #172 this adds a method to PWM channels to change the underlying timer's frequency. This allows to dynamically change the PWM frequency when we have already associated a channel with a pin. Otherwise this required unsafe to work around a partial move error because the channel was moved out of the timer struct.
In the implementation I changed
clock_frequency
on theInstance
to not take&self
. This allows it to be used in the channels. But this is not required, we could access the RCC register directly to avoid making a breaking change?Compared to the timer's implementation we don't stop and start the timer before changing the frequency. I tested it on my project and it seems to work flawlessly. I'm not sure why that was required in the timer's implementation? If it needs to be added, is there a way to reuse the timer's implementation without copy-pasting?
Let me know if anything can be improved! 🙂