Skip to main content

Rate

Trait Rate 

Source
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§

Source

const CLOCK: TimerClock

The input clock the hardware counts at.

Source

const DIVISOR: u16

What that clock is divided by, 1..=256.

Provided Associated Constants§

Source

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.

Source

const MODULO: u8 = _

What the hardware reloads the counter with.

Source

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.

Source

const MS_SHIFT: u32 = _

What the product is shifted by to reach milliseconds.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl Rate for Hz32

Source§

const CLOCK: TimerClock = TimerClock::Hz4096

Source§

const DIVISOR: u16 = 256

Source§

impl Rate for Hz64

Source§

const CLOCK: TimerClock = TimerClock::Hz4096

Source§

const DIVISOR: u16 = 128

Source§

impl Rate for Hz128

Source§

const CLOCK: TimerClock = TimerClock::Hz16384

Source§

const DIVISOR: u16 = 256

Source§

impl Rate for Hz256

Source§

const CLOCK: TimerClock = TimerClock::Hz16384

Source§

const DIVISOR: u16 = 128

Source§

impl Rate for Hz512

Source§

const CLOCK: TimerClock = TimerClock::Hz65536

Source§

const DIVISOR: u16 = 256

Source§

impl Rate for Hz1024

Source§

const CLOCK: TimerClock = TimerClock::Hz65536

Source§

const DIVISOR: u16 = 128

Source§

impl Rate for Hz2048

Source§

const CLOCK: TimerClock = TimerClock::Hz262144

Source§

const DIVISOR: u16 = 256

Source§

impl Rate for Hz4096

Source§

const CLOCK: TimerClock = TimerClock::Hz262144

Source§

const DIVISOR: u16 = 128

Source§

impl Rate for Hz8192

Source§

const CLOCK: TimerClock = TimerClock::Hz262144

Source§

const DIVISOR: u16 = 64

Source§

impl Rate for Hz16384

Source§

const CLOCK: TimerClock = TimerClock::Hz262144

Source§

const DIVISOR: u16 = 32