-
Notifications
You must be signed in to change notification settings - Fork 220
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
Swap PWM channel argument to pass by reference #246
Conversation
r? @therealprof (rust_highfive has picked a reviewer for you, use r? to override) |
Makes sense to me but I'd second @eldruin comment (#244 (comment)) that it would be great to see a converted example. |
yeah absolutely, just figured i'd get the ball rolling on this one |
This PR changes the channel arguments into shared references, not mutable ones. I think this is a mistake. The only method where taking a shared reference makes sense, in my opinion, is
|
i would pose the argument that the associated channel types are only index into the
|
I would totally agree with that reasoning, if You don't have to do it that way, of course. Now that I've written all of this, I'm thinking that the whole design may be sub-optimal. It's likely I'll provide a more detailed proposal later, but for now, how about this idea:
Then implementations can mix and match, to suit the hardware capabilities and their own design. They can implement all those traits for a single timer type, or additionally decide to provide the applicable implementations for each channel type too (with |
all good points! i think the split i am unsure about dropping |
First, a quick note: You'd typically want to implement such splitting by consuming the Otherwise, I do agree with that paragraph, except that it made me realize another weirdness: If acquiring the Maybe I'm just not seeing how this API is meant to be implemented, but the more I think about it, the more I believe it needs a thorough redesign.
Yes, good point. Maybe it would be best to just drop I have an ongoing project that will need PWM traits soon (soon being relative; it's a side project and I'm busy with paying work). I'm currently thinking that, if I can't make the current traits work for my needs, it might be best if I create an embedded-pwm crate to replace the traits in embedded-hal. That would allow for some rapid iteration and eventually, everything could be merged back into embedded-hal. |
I now believe that most of what I said has been wrong. I've summarized my insights for everyone who's interested, but as far as this PR is concerned, I now believe this should be merged as-is (and ideally released as @therealprof To be clear, by "converted example" you're referring to a HAL implementation that is updated to use these modified traits? |
i had a quick go at modifying @eldruin's pwm-pca9685-rs but, this doesn't currently use the pwm traits, it's p difficult to map them to the operation of this particular device, and patching to e-h |
Yeah, sorry about that. I have been meaning to implement the pwm traits in the pwm-pca9685-rs crate but did not find time yet. |
I implemented the modified trait in LPC8xx HAL: lpc-rs/lpc8xx-hal#292 Implementations (very ugly, for reasons unrelated to this PR): https://github.com/braun-embedded/lpc8xx-hal/blob/pwm-ryankurte/src/ctimer/peripheral.rs#L569-L768 Usage example: https://github.com/braun-embedded/lpc8xx-hal/blob/pwm-ryankurte/examples/ctimer_blink.rs#L55-L84 I don't have a generic driver that uses these traits yet, and won't have for at least a few weeks. |
ahhh also i wonder whether it important that we're eliding phase at the moment? often you setup a PWM with a specific on and off count (across multiple channels), rather than just a period, for things like BLDC control |
Setting the phase is actually the way to configure the PWM for the PCA9685. There you just configure for each channel channel when it goes on and when it goes off with numbers in the range of [0-4096] (4095 + full on, actually). |
Good point about the phase. I suggest handling that in a follow-up PR though. This one already is a clear improvement as-is and I'd like to see it merged rather sooner than later. |
@therealprof are you happy with @hannobraun's implementations of this? worth note that we've gone for a shared reference rather than a mutable one (following a bunch of discussion on #256) |
I haven't checked. I trust @eldruin expertise here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is fine as-is. Sorry for the delay! I would be happy to approve it but it seems this needs to be rebased first.
Just a ping from this week's meeting, it looks like this PR could probably be merged after a rebase, @ryankurte ? |
924e3bb
to
8e52003
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
bors r+
Ach, @ryankurte could you run |
266: Fix code formatting + check it on bors r=therealprof a=eldruin This was missed in #246. Co-authored-by: Diego Barrios Romero <[email protected]>
266: Fix code formatting + check it on bors r=therealprof a=eldruin This was missed in #246. Co-authored-by: Diego Barrios Romero <[email protected]>
266: Fix code formatting + check it on bors r=therealprof a=eldruin This was missed in #246. Co-authored-by: Diego Barrios Romero <[email protected]>
Swap PWM channel arguments to be passed by reference to alleviate need for cloning / reconstructing channel objects per #244