pub trait Rate: Copy {
const CLOCK: TimerClock;
const DIVISOR: u16;
const HZ: u32 = _;
const MODULO: u8 = _;
const MS_NUM: u32 = _;
const MS_SHIFT: u32 = _;
}Expand description
How often the timer overflows, as a type.
An implementation names an input clock and what to divide it by, which is
what the hardware takes; everything else follows. rate has the eleven a
program can usually afford, and an implementation of one’s own is how to
reach a rate between them: a music driver wanting a particular tempo would
write it out rather than round to a power of two.
#[derive(Clone, Copy)]
struct Tempo;
impl Rate for Tempo {
const CLOCK: TimerClock = TimerClock::Hz65536;
const DIVISOR: u16 = 66; // 992.96 Hz, the closest to a millisecond
}Required Associated Constants§
Sourceconst CLOCK: TimerClock
const CLOCK: TimerClock
The input clock the hardware counts at.
Provided Associated Constants§
Sourceconst HZ: u32 = _
const HZ: u32 = _
Overflows per second, rounded down.
The clock over the divisor is the exact answer; this one loses the fraction, so 992.96 Hz reads as 992.
Sourceconst MS_NUM: u32 = _
const MS_NUM: u32 = _
What ticks are multiplied by to reach milliseconds, before
MS_SHIFT.
A tick is 1000 * divisor / clock ms. 1000 is 8 * 125 and the clock is
a power of two, so the division comes out as a shift; the twos the
divisor brings are cancelled here rather than left to make this larger
than it need be.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".