esp_hal/gpio/
placeholder.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
//! Placeholder pins/signals.
//!
//! These are useful to pass them into peripheral drivers where you don't want
//! an actual pin but one is required.
// This module also contains peripheral signal impls for `Level` to avoid
// polluting the main module.

use super::*;
use crate::gpio::interconnect::connect_input_signal;

impl crate::peripheral::Peripheral for Level {
    type P = Self;

    unsafe fn clone_unchecked(&self) -> Self::P {
        *self
    }
}

impl Level {
    pub(crate) fn pull_direction(&self, _pull: Pull) {}

    pub(crate) fn input_signals(
        &self,
        _: private::Internal,
    ) -> &'static [(AlternateFunction, InputSignal)] {
        &[]
    }

    pub(crate) fn init_input(&self, _pull: Pull) {}

    pub(crate) fn enable_input(&self, _on: bool) {}

    pub(crate) fn is_input_high(&self) -> bool {
        *self == Level::High
    }

    pub(crate) fn connect_input_to_peripheral(&self, signal: InputSignal) {
        let value = match self {
            Level::High => ONE_INPUT,
            Level::Low => ZERO_INPUT,
        };

        connect_input_signal(signal, value, false, true);
    }

    pub(crate) fn set_to_open_drain_output(&self) {}
    pub(crate) fn set_to_push_pull_output(&self) {}
    pub(crate) fn enable_output(&self, _on: bool) {}
    pub(crate) fn set_output_high(&self, _on: bool) {}
    pub(crate) fn set_drive_strength(&self, _strength: DriveStrength) {}
    pub(crate) fn enable_open_drain(&self, _on: bool) {}

    pub(crate) fn is_set_high(&self) -> bool {
        false
    }

    pub(crate) fn output_signals(
        &self,
        _: private::Internal,
    ) -> &'static [(AlternateFunction, OutputSignal)] {
        &[]
    }

    pub(crate) fn connect_peripheral_to_output(&self, _signal: OutputSignal) {}

    pub(crate) fn disconnect_from_peripheral_output(&self, _signal: OutputSignal) {}
}

/// Placeholder pin, used when no pin is required when using a peripheral.
///
/// When used as a peripheral signal, `NoPin` is equivalent to [`Level::Low`].
#[derive(Default, Clone, Copy)]
pub struct NoPin;

impl crate::peripheral::Peripheral for NoPin {
    type P = Self;

    unsafe fn clone_unchecked(&self) -> Self::P {
        Self
    }
}

impl private::Sealed for NoPin {}

impl embedded_hal::digital::ErrorType for NoPin {
    type Error = core::convert::Infallible;
}

impl embedded_hal::digital::OutputPin for NoPin {
    fn set_low(&mut self) -> Result<(), Self::Error> {
        Ok(())
    }

    fn set_high(&mut self) -> Result<(), Self::Error> {
        Ok(())
    }
}

impl embedded_hal::digital::StatefulOutputPin for NoPin {
    fn is_set_high(&mut self) -> Result<bool, Self::Error> {
        Ok(false)
    }

    fn is_set_low(&mut self) -> Result<bool, Self::Error> {
        Ok(false)
    }
}