1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use crate::avr::config;
#[derive(Copy, Clone)]
pub struct ClockMask(pub u8);
impl ClockMask {
pub fn with_clock(spi_clock: u32) -> ClockMask {
let mut divider_bits = if spi_clock >= config::CPU_FREQUENCY_HZ / 2 {
0
} else if spi_clock >= config::CPU_FREQUENCY_HZ / 4 {
1
} else if spi_clock >= config::CPU_FREQUENCY_HZ / 8 {
2
} else if spi_clock >= config::CPU_FREQUENCY_HZ / 16 {
3
} else if spi_clock >= config::CPU_FREQUENCY_HZ / 32 {
4
} else if spi_clock >= config::CPU_FREQUENCY_HZ / 64 {
5
} else {
6
};
divider_bits ^= 0x1;
if divider_bits == 6 {
divider_bits = 7;
}
ClockMask(divider_bits)
}
pub fn control_register_mask(self) -> u8 {
(self.0 & 0b110) >> 1
}
pub fn status_register_mask(self) -> u8 {
self.0 & 0b1
}
}