fn calculate_timeout_ticks_register_values(ticks: u32) -> (u16, u16) {
    // Note (unwrap): Never panics because 32-bit value is shifted right by 16 bits,
    // resulting in a value that always fits in 16 bits.
    let psc = u16(ticks / (1 << 16)).unwrap();
    // Note (unwrap): Never panics because the divisor is always such that the result fits in 16 bits.
    let arr = u16(ticks / (u32(psc) + 1)).unwrap();
    (psc, arr)
}
/// We want to have `ticks` amount of timer ticks before it reloads.
/// But `ticks` may have a higher value than what the timer can hold directly.
/// So we'll use the prescaler to extend the range.
///
/// To know how many times we would overflow with a prescaler of 1, we divide `ticks` by 2^16 (the max amount of ticks per overflow).
/// If the result is e.g. 3, then we need to increase our range by 4 times to fit all the ticks.
/// We can increase the range enough by setting the prescaler to 3 (which will divide the clock freq by 4).
/// Because every tick is now 4x as long, we need to divide `ticks` by 4 to keep the same timeout.
///
/// This function returns the prescaler register value and auto reload register value.
We want to have `ticks` amount of timer ticks before it reloads.
But `ticks` may have a higher value than what the timer can hold directly.
So we'll use the prescaler to extend the range.

To know how many times we would overflow with a prescaler of 1, we divide `ticks` by 2^16 (the max amount of ticks per overflow).
If the result is e.g. 3, then we need to increase our range by 4 times to fit all the ticks.
We can increase the range enough by setting the prescaler to 3 (which will divide the clock freq by 4).
Because every tick is now 4x as long, we need to divide `ticks` by 4 to keep the same timeout.

This function returns the prescaler register value and auto reload register value.
We want to have ` ticks ` amount of timer ticks before it reloads . But ` ticks ` may have a higher value than what the timer can hold directly . So we ' ll use the prescaler to extend the range . To know how many times we would overflow with a prescaler of 1 we divide ` ticks ` by 2^16 ( the max amount of ticks per overflow ) . If the result is e . g . 3 then we need to increase our range by 4 times to fit all the ticks . We can increase the range enough by setting the prescaler to 3 ( which will divide the clock freq by 4 ) . Because every tick is now 4x as long we need to divide ` ticks ` by 4 to keep the same timeout . This function returns the prescaler register value and auto reload register value .
fn calculate_timeout_ticks_register_values(ticks: u32) -> (u16, u16) {
    // Note (unwrap): Never panics because 32-bit value is shifted right by 16 bits,
    // resulting in a value that always fits in 16 bits.
    let psc = u16(ticks / (1 << 16)).unwrap();
    // Note (unwrap): Never panics because the divisor is always such that the result fits in 16 bits.
    let arr = u16(ticks / (u32(psc) + 1)).unwrap();
    (psc, arr)
}
fn calculate_timeout_ticks_register_values ( ticks : u32 ) -> ( u16 , u16 ) { // Note (unwrap): Never panics because 32-bit value is shifted right by 16 bits, // resulting in a value that always fits in 16 bits. let psc = u16 ( ticks / ( 1 << 16 ) ) . unwrap ( ) ; // Note (unwrap): Never panics because the divisor is always such that the result fits in 16 bits. let arr = u16 ( ticks / ( u32 ( psc ) + 1 ) ) . unwrap ( ) ; ( psc , arr ) }
We want to have `ticks` amount of timer ticks before it reloads.
We want to have ` ticks ` amount of timer ticks before it reloads .
ticks
u32
ticks
u32