FluenTech / embedded-time

Time(ing) library (Instant/Duration/Clock/Timer/Period/Frequency) for bare-metal embedded systems
Apache License 2.0
87 stars 17 forks source link

Fixed-point Duration with Clock::SCALING_FACTOR #85

Open Piroro-hs opened 3 years ago

Piroro-hs commented 3 years ago

It's convenient to have fixed-point Durations whose time unit is same as Clock's.

It could be useful for use-case like below.

// assume clock rate is multiple of 3
// this periodic timer runs at exactly 3Hz
let timer = clock.new_timer(3_u32.Hz().to_duration::<ClockDuration<Clock>>().unwrap()).into_periodic();
// while this is not
let timer = clock.new_timer(3_u32.Hz().to_duration::<Milliseconds>().unwrap()).into_periodic();
PTaylor-us commented 2 years ago

First, thank you for the suggestion. Second, I'm very sorry for the delay. I do see the value of this. It would, however, need to be a Generic duration which is less efficient, but if needs must.

I will definitely look into this.