Closed burrbull closed 2 years ago
I see. Thanks for the detailed insight. I agree with your analysis and would merge this once the CI passes.
For embedded-hal
itself, I think we need some kind of generic bounds, though, so that different time representations can be used but that is a topic for embedded-hal
.
Those problem was related to interacting
RateExt32
trait withInto
. Looks like it works fine now.But I'm still insist don't use
Into
there as it complicate creating other high-level things which dependent fromPwm
orCountDown
. As we useHertz
almost everywhere (or time units), but I never seen usingKilohertz
orMegahertz
for such traits it's much better create/convertHertz
inplace before passing topwm
. WithRateExt32
(which converts to requested) or like instm32g0xx-hal
where calling10.mhz()
just createsHertz(10_000_000)
instead of creatingMegahertz(10)
and then callingInto
to convert toHertz
. Yes, withoutInto
we need to convert obviously when passingcore::Duration
for example. But I don't think adding.into()
or.to_rate()
makes code worse. Furthermore if we plan to support different time types (with different ranges) onCountDown
for example, it is better to make different implementations which can use different prescaler/reload formulas for those types. As automatic conversions can overflow/underflow/zero_div in unpredictable places. In my view usingFrom/Into
as generics for time/rate creates more problems then solves.