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
60
61
use crate::target::CLOCK;
use crate::time::{Hertz, U32Ext};

pub trait ClocksExt {
    fn constrain(self) -> ClocksCfg;
}

pub struct ClocksCfg {
    pub hfclk: HFCLK,
    pub lfclk: LFCLK,
}

pub struct HFCLK {
    _0: ()
}

pub struct LFCLK {
    _0: ()
}

pub struct Clocks {
    hfclk: Hertz,
    lfclk: Hertz,
}

impl HFCLK {
    // TODO: allow external clock selection?
}

impl LFCLK {
    // TODO: allow external clock selection? Calibration?
}

impl ClocksExt for CLOCK {
    fn constrain(self) -> ClocksCfg {
        ClocksCfg {
            hfclk: HFCLK { _0: () },
            lfclk: LFCLK { _0: () },
        }
    }
}

impl ClocksCfg {
    pub fn freeze(self) -> Clocks {
        // TODO - this isn't very useful, can you actually change internal clock speeds?
        Clocks {
            hfclk: 64_000_000.hz(),
            lfclk: 32_768.hz(),
        }
    }
}

impl Clocks {
    pub fn hfclk(&self) -> Hertz {
        self.hfclk
    }

    pub fn lfclk(&self) -> Hertz {
        self.lfclk
    }
}