ariel_os_stm32/
gpio.rs

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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//! Provides GPIO access.

pub mod input {
    //! Input-specific types.

    use embassy_stm32::{
        gpio::{Level, Pull},
        Peripheral,
    };

    #[doc(hidden)]
    pub use embassy_stm32::gpio::{Input, Pin as InputPin};

    #[cfg(feature = "external-interrupts")]
    #[doc(hidden)]
    pub use embassy_stm32::exti::ExtiInput as IntEnabledInput;

    /// Whether inputs support configuring whether a Schmitt trigger is enabled.
    pub const SCHMITT_TRIGGER_CONFIGURABLE: bool = false;

    #[doc(hidden)]
    pub fn new(
        pin: impl Peripheral<P: InputPin> + 'static,
        pull: ariel_os_embassy_common::gpio::Pull,
        _schmitt_trigger: bool, // Not supported by this hardware
    ) -> Result<Input<'static>, ariel_os_embassy_common::gpio::input::Error> {
        let pull = from_pull(pull);
        Ok(Input::new(pin, pull))
    }

    #[cfg(feature = "external-interrupts")]
    #[doc(hidden)]
    pub fn new_int_enabled<P: Peripheral<P = T> + 'static, T: InputPin>(
        pin: P,
        pull: ariel_os_embassy_common::gpio::Pull,
        _schmitt_trigger: bool, // Not supported by this hardware
    ) -> Result<IntEnabledInput<'static>, ariel_os_embassy_common::gpio::input::Error> {
        let pull = from_pull(pull);
        let mut pin = pin.into_ref();
        let ch = crate::extint_registry::EXTINT_REGISTRY.get_interrupt_channel_for_pin(&mut pin)?;
        let pin = pin.into_ref().map_into();
        Ok(IntEnabledInput::new(pin, ch, pull))
    }

    ariel_os_embassy_common::define_from_pull!();
    ariel_os_embassy_common::define_into_level!();
}

pub mod output {
    //! Output-specific types.

    use embassy_stm32::{gpio::Level, Peripheral};

    #[doc(hidden)]
    pub use embassy_stm32::gpio::{Output, Pin as OutputPin};

    /// Whether outputs support configuring their drive strength.
    pub const DRIVE_STRENGTH_CONFIGURABLE: bool = false;
    /// Whether outputs support configuring their speed/slew rate.
    pub const SPEED_CONFIGURABLE: bool = true;

    #[doc(hidden)]
    pub fn new(
        pin: impl Peripheral<P: OutputPin> + 'static,
        initial_level: ariel_os_embassy_common::gpio::Level,
        _drive_strength: super::DriveStrength, // Not supported by hardware
        speed: super::Speed,
    ) -> Output<'static> {
        let initial_level = match initial_level {
            ariel_os_embassy_common::gpio::Level::Low => Level::Low,
            ariel_os_embassy_common::gpio::Level::High => Level::High,
        };
        Output::new(pin, initial_level, speed.into())
    }
}

pub use ariel_os_embassy_common::gpio::UnsupportedDriveStrength as DriveStrength;

/// Available output speed/slew rate settings.
#[derive(Copy, Clone, PartialEq, Eq)]
pub enum Speed {
    /// Low.
    Low,
    /// Medium.
    Medium,
    /// High.
    High,
    /// Very high.
    VeryHigh,
}

impl From<Speed> for embassy_stm32::gpio::Speed {
    fn from(speed: Speed) -> Self {
        match speed {
            Speed::Low => Self::Low,
            Speed::Medium => Self::Medium,
            Speed::High => Self::High,
            Speed::VeryHigh => Self::VeryHigh,
        }
    }
}

impl ariel_os_embassy_common::gpio::FromSpeed for Speed {
    fn from(speed: ariel_os_embassy_common::gpio::Speed<Self>) -> Self {
        use ariel_os_embassy_common::gpio::Speed::*;

        match speed {
            Hal(speed) => speed,
            Low => Self::Low,
            Medium => Self::Medium,
            High => Self::High,
            VeryHigh => Self::VeryHigh,
        }
    }
}