fn calculate_frequency_16bit(
    base_freq: Hertz,
    freq: Hertz,
    alignment: Alignment,
) -> (u32, u16) {
    let ideal_period =
        calculate_frequency_32bit(base_freq, freq, alignment).0 + 1;

    // Division factor is (PSC + 1)
    let prescale = (ideal_period - 1) / (1 << 16);

    // This will always fit in a 16-bit value because u32::MAX / (1 << 16) fits in a 16 bit

    // Round to the nearest period
    let period = (ideal_period + (prescale >> 1)) / (prescale + 1) - 1;

    // It should be impossible to fail these asserts
    assert!(period <= 0xFFFF);
    assert!(prescale <= 0xFFFF);

    (period, prescale as u16)
}
// Period and prescaler calculator for 16-bit timers
// Returns (arr, psc)
// Returns as (u32, u16) to be compatible but arr will always be a valid u16
Period and prescaler calculator for 16-bit timers
Returns (arr, psc)
Returns as (u32, u16) to be compatible but arr will always be a valid u16
Period and prescaler calculator for 16 - bit timers Returns ( arr psc ) Returns as ( u32 u16 ) to be compatible but arr will always be a valid u16
fn calculate_frequency_16bit(
    base_freq: Hertz,
    freq: Hertz,
    alignment: Alignment,
) -> (u32, u16) {
    let ideal_period =
        calculate_frequency_32bit(base_freq, freq, alignment).0 + 1;
    // Division factor is (PSC + 1)
    let prescale = (ideal_period - 1) / (1 << 16);
    // This will always fit in a 16-bit value because u32::MAX / (1 << 16) fits in a 16 bit
    // Round to the nearest period
    let period = (ideal_period + (prescale >> 1)) / (prescale + 1) - 1;
    // It should be impossible to fail these asserts
    assert!(period <= 0xFFFF);
    assert!(prescale <= 0xFFFF);
    (period, prescale as u16)
}
fn calculate_frequency_16bit ( base_freq : Hertz , freq : Hertz , alignment : Alignment , ) -> ( u32 , u16 ) { let ideal_period = calculate_frequency_32bit ( base_freq , freq , alignment ) . 0 + 1 ; // Division factor is (PSC + 1) let prescale = ( ideal_period - 1 ) / ( 1 << 16 ) ; // This will always fit in a 16-bit value because u32::MAX / (1 << 16) fits in a 16 bit // Round to the nearest period let period = ( ideal_period + ( prescale >> 1 ) ) / ( prescale + 1 ) - 1 ; // It should be impossible to fail these asserts assert ! ( period 0xFFFF ) ; assert ! ( prescale 0xFFFF ) ; ( period , prescale as u16 ) }
Period and prescaler calculator for 16-bit timers
Returns (arr, psc)
Returns as (u32, u16) to be compatible but arr will always be a valid u16
Period and prescaler calculator for 16 - bit timers Returns ( arr psc ) Returns as ( u32 u16 ) to be compatible but arr will always be a valid u16
base_freq
Hertz
freq
Hertz
alignment
Alignment
base_freq
Hertz
freq
Hertz
alignment
Alignment