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
// Traits used across the library. Could be used more generally than in this lib.

/// Is a set of speeds valid?
#[derive(Clone, Copy)]
#[repr(u8)]
pub enum ClocksValid {
    Valid,
    NotValid,
}

/// This trait allows you to return information about a common's speeds.
/// It's used for configuring peripherals.
pub trait ClockCfg {
    /// System clock speed, in Hz.
    fn sysclk(&self) -> u32;

    /// HCLK speed, in Hz. Ie AHB bus, core, memory, and DMA.
    fn hclk(&self) -> u32;

    /// Cortex System timer speed, in Hz.
    fn systick(&self) -> u32;

    /// USB speed, in Hz.
    fn usb(&self) -> u32;

    /// APB1 peripheral common speed, in Hz.
    fn apb1(&self) -> u32;

    /// APB1 timer common speed, in Hz.
    fn apb1_timer(&self) -> u32;

    /// APB2 timer common speed, in Hz.
    fn apb2(&self) -> u32;

    /// APB2 peripheral common speed, in Hz.
    fn apb2_timer(&self) -> u32;

    // Todo: Optional APB3, APB4, AHB2, AHB4, HCLK3. These are for H7.

    /// Validate that the clocks speeds are all within the acceptable range
    /// for the MCU
    /// // todo Separate USB validation? back to `Validation enum`, or keep it simple?
    fn validate_speeds(&self) -> ClocksValid;
}

pub trait OpenDrain {}

pub trait SdaPin {}

pub trait SclPin {}

/// Trait representing a single-channel digital-to-analog converter (DAC).
pub trait SingleChannelDac<Word> {
    /// Error type returned by DAC methods
    type Error;

    /// Output a constant signal, given a bit word.
    fn try_set_value(&mut self, value: Word) -> Result<(), Self::Error>;

    // todo: Enable and disable? set voltage?
}