stm32f4xx_hal/gpio/
hal_1.rs1use core::convert::Infallible;
2
3use super::{dynamic::PinModeError, marker, AnyPin, DynamicPin, Output, PartiallyErasedPin, Pin};
4
5use embedded_hal::digital::{ErrorType, InputPin, OutputPin, StatefulOutputPin};
6
7impl<const P: char, const N: u8, MODE> ErrorType for Pin<P, N, MODE> {
9 type Error = Infallible;
10}
11
12impl<const P: char, const N: u8, MODE> OutputPin for Pin<P, N, Output<MODE>> {
13 #[inline(always)]
14 fn set_high(&mut self) -> Result<(), Self::Error> {
15 self.set_high();
16 Ok(())
17 }
18
19 #[inline(always)]
20 fn set_low(&mut self) -> Result<(), Self::Error> {
21 self.set_low();
22 Ok(())
23 }
24}
25
26impl<const P: char, const N: u8, MODE> StatefulOutputPin for Pin<P, N, Output<MODE>> {
27 #[inline(always)]
28 fn is_set_high(&mut self) -> Result<bool, Self::Error> {
29 Ok(Self::is_set_high(self))
30 }
31
32 #[inline(always)]
33 fn is_set_low(&mut self) -> Result<bool, Self::Error> {
34 Ok(Self::is_set_low(self))
35 }
36}
37
38impl<const P: char, const N: u8, MODE> InputPin for Pin<P, N, MODE>
39where
40 MODE: marker::Readable,
41{
42 #[inline(always)]
43 fn is_high(&mut self) -> Result<bool, Self::Error> {
44 Ok(Self::is_high(self))
45 }
46
47 #[inline(always)]
48 fn is_low(&mut self) -> Result<bool, Self::Error> {
49 Ok(Self::is_low(self))
50 }
51}
52
53impl<MODE> ErrorType for AnyPin<MODE> {
55 type Error = core::convert::Infallible;
56}
57
58impl<MODE> OutputPin for AnyPin<Output<MODE>> {
59 #[inline(always)]
60 fn set_high(&mut self) -> Result<(), Self::Error> {
61 self.set_high();
62 Ok(())
63 }
64
65 #[inline(always)]
66 fn set_low(&mut self) -> Result<(), Self::Error> {
67 self.set_low();
68 Ok(())
69 }
70}
71
72impl<MODE> StatefulOutputPin for AnyPin<Output<MODE>> {
73 #[inline(always)]
74 fn is_set_high(&mut self) -> Result<bool, Self::Error> {
75 Ok(Self::is_set_high(self))
76 }
77
78 #[inline(always)]
79 fn is_set_low(&mut self) -> Result<bool, Self::Error> {
80 Ok(Self::is_set_low(self))
81 }
82}
83
84impl<MODE> InputPin for AnyPin<MODE>
85where
86 MODE: marker::Readable,
87{
88 #[inline(always)]
89 fn is_high(&mut self) -> Result<bool, Self::Error> {
90 Ok(Self::is_high(self))
91 }
92
93 #[inline(always)]
94 fn is_low(&mut self) -> Result<bool, Self::Error> {
95 Ok(Self::is_low(self))
96 }
97}
98
99impl<const P: char, MODE> ErrorType for PartiallyErasedPin<P, MODE> {
101 type Error = Infallible;
102}
103
104impl<const P: char, MODE> OutputPin for PartiallyErasedPin<P, Output<MODE>> {
105 #[inline(always)]
106 fn set_high(&mut self) -> Result<(), Self::Error> {
107 self.set_high();
108 Ok(())
109 }
110
111 #[inline(always)]
112 fn set_low(&mut self) -> Result<(), Self::Error> {
113 self.set_low();
114 Ok(())
115 }
116}
117
118impl<const P: char, MODE> StatefulOutputPin for PartiallyErasedPin<P, Output<MODE>> {
119 #[inline(always)]
120 fn is_set_high(&mut self) -> Result<bool, Self::Error> {
121 Ok(Self::is_set_high(self))
122 }
123
124 #[inline(always)]
125 fn is_set_low(&mut self) -> Result<bool, Self::Error> {
126 Ok(Self::is_set_low(self))
127 }
128}
129
130impl<const P: char, MODE> InputPin for PartiallyErasedPin<P, MODE>
131where
132 MODE: marker::Readable,
133{
134 #[inline(always)]
135 fn is_high(&mut self) -> Result<bool, Self::Error> {
136 Ok(Self::is_high(self))
137 }
138
139 #[inline(always)]
140 fn is_low(&mut self) -> Result<bool, Self::Error> {
141 Ok(Self::is_low(self))
142 }
143}
144
145impl<const P: char, const N: u8> ErrorType for DynamicPin<P, N> {
147 type Error = PinModeError;
148}
149
150impl<const P: char, const N: u8> OutputPin for DynamicPin<P, N> {
151 fn set_high(&mut self) -> Result<(), Self::Error> {
152 self.set_high()
153 }
154 fn set_low(&mut self) -> Result<(), Self::Error> {
155 self.set_low()
156 }
157}
158
159impl<const P: char, const N: u8> InputPin for DynamicPin<P, N> {
160 fn is_high(&mut self) -> Result<bool, Self::Error> {
161 Self::is_high(self)
162 }
163 fn is_low(&mut self) -> Result<bool, Self::Error> {
164 Self::is_low(self)
165 }
166}