-
Notifications
You must be signed in to change notification settings - Fork 201
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
Creating abstractions over Pwm trait is not ideal #244
Comments
huh this can be frustrating! while we don't currently require |
Have you tried |
Thanks to both of you for getting back to me. The closure approach got too noisy, so I gave up and settled on using |
Thank you @amiraeva. |
Possibly related: It's not always ideal to represent PWM as a pin. For example, in STM32, PWM is controlled by timer peripherals. In F3, the PWM module used raw pointers so it could make it fit with the channel paradigm. I ended up adding PWM functionality to the timer struct, and was unable to make it work with the channel-based EH traits. |
interesting experience, are you able to share this code? it's an interesting use case, in my experience with PWM / timers it is not uncommon to run 2+ channels of PWM from a single timer but, the configuration changes between them tend to be somewhat restricted. |
Discussion in there is also relevant; has comments from me and the original, EH/channel-based PWM module author. You'll see the crux of the issue is that the trait is channel-based, while most of the settings for STM32 MCUs are not. Eg, compare the code in that PR to the |
246: Swap PWM channel argument to pass by reference r=eldruin a=ryankurte Swap PWM channel arguments to be passed by reference to alleviate need for cloning / reconstructing channel objects per #244 Co-authored-by: ryan <ryan@kurte.nz> Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
Fixed in #246 |
I'm working on a project in which I've defined an
ActuatorMotor
which wraps aPwm
channel on my device. As I'm refactoring to makeActuatorMotor
generic over the specificPwm
hardware, I've found it annoying that allPwm
functions takePwm::Channel
by move.Here's an example:
A workaround that seems to work for now is to make
channel
store a closure which spits out instances ofPwm::Channel
i.e.Fn() -> P::Channel
. At a first glance, requiring aClone
and/orCopy
bound onPwm::Channel
would solve my problem, or altering the method signatures inPwm
to instead take&mut Pwm::Channel
instead of by move.The text was updated successfully, but these errors were encountered: