embassy_stm32_plus/traits/gpio/
mod.rs

1#[cfg(feature = "exti")]
2use embassy_stm32::exti::ExtiInput;
3use embassy_stm32::gpio::{Input, Level, Output, Pin, Pull, Speed};
4#[cfg(feature = "exti")]
5use embassy_stm32::Peripheral;
6
7/// gpio trait
8pub trait GpioTrait: Pin {
9    /// Create GPIO input driver, default Pull is [Pull::Up]<br />
10    /// more see [Self::input_with_pull] or [Input::new]
11    #[inline]
12    fn input(self) -> Input<'static> {
13        self.input_with_pull(Pull::Up)
14    }
15
16    /// Create GPIO input driver, more see [Input::new]
17    #[inline]
18    fn input_with_pull(self, pull: Pull) -> Input<'static> {
19        Input::new(self, pull)
20    }
21
22    /// Create GPIO output driver, default level is [Level::High] and default speed is [Speed::Low]<br />
23    /// more see [Self::output_with_level_speed] or [Output::new]
24    #[inline]
25    fn output(self) -> Output<'static> {
26        self.output_with_level_speed(Level::High, Speed::Low)
27    }
28
29    /// Create GPIO output driver, more see [Output::new]
30    #[inline]
31    fn output_with_level_speed(self, level: Level, speed: Speed) -> Output<'static> {
32        Output::new(self, level, speed)
33    }
34
35    /// Create an EXTI input, default pull is [Pull::Up]<br />
36    /// more see [Self::exti_input_with_pull] or [ExtiInput::new]
37    #[cfg(feature = "exti")]
38    #[inline]
39    fn exti_input(self, exti: impl Peripheral<P=Self::ExtiChannel> + 'static) -> ExtiInput<'static> {
40        self.exti_input_with_pull(exti, Pull::Up)
41    }
42
43    /// Create an EXTI input, more see [ExtiInput::new]
44    #[cfg(feature = "exti")]
45    #[inline]
46    fn exti_input_with_pull(self, exti: impl Peripheral<P=Self::ExtiChannel> + 'static, pull: Pull) -> ExtiInput<'static> {
47        ExtiInput::new(self, exti, pull)
48    }
49}
50
51/// any pin support gpio trait
52impl<T: Pin> GpioTrait for T {}