aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/exti.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2021-04-14 16:25:54 +0200
committerDario Nieuwenhuis <[email protected]>2021-04-14 17:04:40 +0200
commit8b1ffb2cb7bd2e0c0f50eefb2391c15ae3050e73 (patch)
tree7c76e7e3e6f2729b4cef85b99abaa6a4040db231 /embassy-stm32/src/exti.rs
parent59ccc45f280e05a9d2a0ece2bb1e01debadb2f7e (diff)
Remove Pin from GPIO traits
Diffstat (limited to 'embassy-stm32/src/exti.rs')
-rw-r--r--embassy-stm32/src/exti.rs41
1 files changed, 16 insertions, 25 deletions
diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs
index 8d70defe6..9a12f8115 100644
--- a/embassy-stm32/src/exti.rs
+++ b/embassy-stm32/src/exti.rs
@@ -1,6 +1,5 @@
1use core::future::Future; 1use core::future::Future;
2use core::mem; 2use core::mem;
3use core::pin::Pin;
4use cortex_m; 3use cortex_m;
5 4
6use crate::hal::gpio; 5use crate::hal::gpio;
@@ -96,13 +95,10 @@ impl<T: Instance + digital::InputPin> digital::InputPin for ExtiPin<T> {
96} 95}
97 96
98impl<T: Instance + digital::InputPin + 'static> ExtiPin<T> { 97impl<T: Instance + digital::InputPin + 'static> ExtiPin<T> {
99 fn wait_for_state<'a>(self: Pin<&'a mut Self>, state: bool) -> impl Future<Output = ()> + 'a { 98 fn wait_for_state<'a>(&'a mut self, state: bool) -> impl Future<Output = ()> + 'a {
100 let s = unsafe { self.get_unchecked_mut() };
101
102 s.pin.clear_pending_bit();
103 async move { 99 async move {
104 let fut = InterruptFuture::new(&mut s.interrupt); 100 let fut = InterruptFuture::new(&mut self.interrupt);
105 let pin = &mut s.pin; 101 let pin = &mut self.pin;
106 cortex_m::interrupt::free(|_| { 102 cortex_m::interrupt::free(|_| {
107 pin.trigger_edge(if state { 103 pin.trigger_edge(if state {
108 EdgeOption::Rising 104 EdgeOption::Rising
@@ -111,37 +107,32 @@ impl<T: Instance + digital::InputPin + 'static> ExtiPin<T> {
111 }); 107 });
112 }); 108 });
113 109
114 if (state && s.pin.is_high().unwrap_or(false)) 110 if (state && self.pin.is_high().unwrap_or(false))
115 || (!state && s.pin.is_low().unwrap_or(false)) 111 || (!state && self.pin.is_low().unwrap_or(false))
116 { 112 {
117 return; 113 return;
118 } 114 }
119 115
120 fut.await; 116 fut.await;
121 117
122 s.pin.clear_pending_bit(); 118 self.pin.clear_pending_bit();
123 } 119 }
124 } 120 }
125} 121}
126 122
127impl<T: Instance + 'static> ExtiPin<T> { 123impl<T: Instance + 'static> ExtiPin<T> {
128 fn wait_for_edge<'a>( 124 fn wait_for_edge<'a>(&'a mut self, state: EdgeOption) -> impl Future<Output = ()> + 'a {
129 self: Pin<&'a mut Self>, 125 self.pin.clear_pending_bit();
130 state: EdgeOption,
131 ) -> impl Future<Output = ()> + 'a {
132 let s = unsafe { self.get_unchecked_mut() };
133
134 s.pin.clear_pending_bit();
135 async move { 126 async move {
136 let fut = InterruptFuture::new(&mut s.interrupt); 127 let fut = InterruptFuture::new(&mut self.interrupt);
137 let pin = &mut s.pin; 128 let pin = &mut self.pin;
138 cortex_m::interrupt::free(|_| { 129 cortex_m::interrupt::free(|_| {
139 pin.trigger_edge(state); 130 pin.trigger_edge(state);
140 }); 131 });
141 132
142 fut.await; 133 fut.await;
143 134
144 s.pin.clear_pending_bit(); 135 self.pin.clear_pending_bit();
145 } 136 }
146 } 137 }
147} 138}
@@ -149,7 +140,7 @@ impl<T: Instance + 'static> ExtiPin<T> {
149impl<T: Instance + digital::InputPin + 'static> WaitForHigh for ExtiPin<T> { 140impl<T: Instance + digital::InputPin + 'static> WaitForHigh for ExtiPin<T> {
150 type Future<'a> = impl Future<Output = ()> + 'a; 141 type Future<'a> = impl Future<Output = ()> + 'a;
151 142
152 fn wait_for_high<'a>(self: Pin<&'a mut Self>) -> Self::Future<'a> { 143 fn wait_for_high<'a>(&'a mut self) -> Self::Future<'a> {
153 self.wait_for_state(true) 144 self.wait_for_state(true)
154 } 145 }
155} 146}
@@ -157,7 +148,7 @@ impl<T: Instance + digital::InputPin + 'static> WaitForHigh for ExtiPin<T> {
157impl<T: Instance + digital::InputPin + 'static> WaitForLow for ExtiPin<T> { 148impl<T: Instance + digital::InputPin + 'static> WaitForLow for ExtiPin<T> {
158 type Future<'a> = impl Future<Output = ()> + 'a; 149 type Future<'a> = impl Future<Output = ()> + 'a;
159 150
160 fn wait_for_low<'a>(self: Pin<&'a mut Self>) -> Self::Future<'a> { 151 fn wait_for_low<'a>(&'a mut self) -> Self::Future<'a> {
161 self.wait_for_state(false) 152 self.wait_for_state(false)
162 } 153 }
163} 154}
@@ -176,7 +167,7 @@ impl<T: Instance + digital::InputPin + 'static> WaitForLow for ExtiPin<T> {
176impl<T: Instance + 'static> WaitForRisingEdge for ExtiPin<T> { 167impl<T: Instance + 'static> WaitForRisingEdge for ExtiPin<T> {
177 type Future<'a> = impl Future<Output = ()> + 'a; 168 type Future<'a> = impl Future<Output = ()> + 'a;
178 169
179 fn wait_for_rising_edge<'a>(self: Pin<&'a mut Self>) -> Self::Future<'a> { 170 fn wait_for_rising_edge<'a>(&'a mut self) -> Self::Future<'a> {
180 self.wait_for_edge(EdgeOption::Rising) 171 self.wait_for_edge(EdgeOption::Rising)
181 } 172 }
182} 173}
@@ -184,7 +175,7 @@ impl<T: Instance + 'static> WaitForRisingEdge for ExtiPin<T> {
184impl<T: Instance + 'static> WaitForFallingEdge for ExtiPin<T> { 175impl<T: Instance + 'static> WaitForFallingEdge for ExtiPin<T> {
185 type Future<'a> = impl Future<Output = ()> + 'a; 176 type Future<'a> = impl Future<Output = ()> + 'a;
186 177
187 fn wait_for_falling_edge<'a>(self: Pin<&'a mut Self>) -> Self::Future<'a> { 178 fn wait_for_falling_edge<'a>(&'a mut self) -> Self::Future<'a> {
188 self.wait_for_edge(EdgeOption::Falling) 179 self.wait_for_edge(EdgeOption::Falling)
189 } 180 }
190} 181}
@@ -192,7 +183,7 @@ impl<T: Instance + 'static> WaitForFallingEdge for ExtiPin<T> {
192impl<T: Instance + 'static> WaitForAnyEdge for ExtiPin<T> { 183impl<T: Instance + 'static> WaitForAnyEdge for ExtiPin<T> {
193 type Future<'a> = impl Future<Output = ()> + 'a; 184 type Future<'a> = impl Future<Output = ()> + 'a;
194 185
195 fn wait_for_any_edge<'a>(self: Pin<&'a mut Self>) -> Self::Future<'a> { 186 fn wait_for_any_edge<'a>(&'a mut self) -> Self::Future<'a> {
196 self.wait_for_edge(EdgeOption::RisingFalling) 187 self.wait_for_edge(EdgeOption::RisingFalling)
197 } 188 }
198} 189}