Why does the `Clock` Trait require the user to define `const SCALING_FACTOR`?
seanybaggins opened this issue · comments
Why does the Clock
Trait require the user to define...
const SCALING_FACTOR: Fraction
?
Would it be better if const SCALING_FACTOR
was instead
fn frequency(&self) -> Rate;
The rational
Suppose I am writing some hal
or driver and I would like to implement the Clock
trait so the user of my hal
or driver doesn't need to. Its possible when writing these hal
's or drivers that I cannot determine the frequency of hardware I am interfacing with at compile time but can determine the frequency at runtime.
Example of how this may be implemented for a hal
or driver
struct StopWatch {
inner: Hardware
}
impl Clock for StopWatch {
...
fn frequency(&self) -> Rate {
self.hardware.get_clock_frequency().MHz()
}
...
}
I am still somewhat new to rust in an embedded context so my apologies if this is a horribly misguided suggestion/question.
Hi this is to get compile time generation and optimization of the conversion math.
To set the speed of a HAL timer at compile time you can see an example here: https://github.com/rtic-rs/dwt-systick-monotonic/blob/master/src/lib.rs
Thanks for the explanation. Closed the issue.