-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't change PWM frequency after instanciating a Pwm struct #172
Comments
Hey @azerupi, thank you for bringing this up!
I think this is sound, as far as Rust's
Definitely! The only hurdles are coming up with an acceptable design, and someone doing the implementation work.
I share your concern, but I think this would be fine (although far from ideal), as long as this is properly documented. It would be great if someone came up with a better design, but this seems like a low-effort change that would allow you to get rid of your
I don't know either. I'm sure an elegant design is hiding in there somewhere, but that will probably take some effort and experimentation to find. I'm happy to provide feedback if anyone comes up with something, but for now, I think think adding a |
Thanks for your reply!
In that case I might give it a try and send a pull-request for that when I have some time 🙂 |
Thank you, @azerupi, that would be great! |
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 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. See stm32-rs#172 for more information
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 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. See stm32-rs#172 for more information
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 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. See stm32-rs#172 for more information
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 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. See stm32-rs#172 for more information
Hi,
I'm trying to change the frequency of a PWM pin dynamically. This is impossible with the currant API because the method to change the frequency is on the timer, but the timer contains all the pwm channels and when you 'associate' a pwm channel to a pin it is moved out of the timer struct. When you then try to configure the pwm frequency you get a 'borrow of partially moved value' error.
Example:
Resulting in the following error:
Workaround
I discussed this on the matrix channel a bit and I currently have two workarounds requiring unsafe:
Change the registers directly
This works but you loose the niceties provided by the
set_frequency
function (e.g. provide a frequency in Hz).Make a raw pointer to the timer object to bypass Rust's ownership
This also compiles, however I'm not sure what the implications are. Is this "safe"? I guess it is as long as I don't try to associate the channel with another pin?
HAL crate
Would it be possible to support this use case in the HAL library to avoid the need to use
unsafe
?Pwm
instance? Although it would probably be very strange to have one Pwm instance change the frequency for all the other channels remotely. 🤔What are your thoughts about this?
The text was updated successfully, but these errors were encountered: