aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Mcguigan <[email protected]>2023-02-02 21:42:42 -0800
committerJosh Mcguigan <[email protected]>2023-02-02 21:42:42 -0800
commit0bb6000e5cab0a2f2dbbb95a4a2d69a2536de88b (patch)
treeec637a0bff329f6d7b9cf6161aea43896245b54f
parent9af25c3396423036d0092a5f32f2d09b05a4e910 (diff)
stm32 gpio implement degrade to AnyPin
-rw-r--r--embassy-stm32/src/gpio.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs
index 5e3346754..3024f1ffa 100644
--- a/embassy-stm32/src/gpio.rs
+++ b/embassy-stm32/src/gpio.rs
@@ -28,6 +28,21 @@ impl<'d, T: Pin> Flex<'d, T> {
28 Self { pin } 28 Self { pin }
29 } 29 }
30 30
31 #[inline]
32 pub fn degrade(mut self) -> Flex<'d, AnyPin> {
33 // Safety: We are about to drop the other copy of this pin, so
34 // this clone is safe.
35 let pin = unsafe { self.pin.clone_unchecked() };
36
37 // We don't want to run the destructor here, because that would
38 // deconfigure the pin.
39 core::mem::forget(self);
40
41 Flex {
42 pin: pin.map_into::<AnyPin>(),
43 }
44 }
45
31 /// Put the pin into input mode. 46 /// Put the pin into input mode.
32 #[inline] 47 #[inline]
33 pub fn set_as_input(&mut self, pull: Pull) { 48 pub fn set_as_input(&mut self, pull: Pull) {
@@ -287,6 +302,13 @@ impl<'d, T: Pin> Input<'d, T> {
287 } 302 }
288 303
289 #[inline] 304 #[inline]
305 pub fn degrade(self) -> Input<'d, AnyPin> {
306 Input {
307 pin: self.pin.degrade(),
308 }
309 }
310
311 #[inline]
290 pub fn is_high(&self) -> bool { 312 pub fn is_high(&self) -> bool {
291 self.pin.is_high() 313 self.pin.is_high()
292 } 314 }
@@ -345,6 +367,13 @@ impl<'d, T: Pin> Output<'d, T> {
345 Self { pin } 367 Self { pin }
346 } 368 }
347 369
370 #[inline]
371 pub fn degrade(self) -> Output<'d, AnyPin> {
372 Output {
373 pin: self.pin.degrade(),
374 }
375 }
376
348 /// Set the output as high. 377 /// Set the output as high.
349 #[inline] 378 #[inline]
350 pub fn set_high(&mut self) { 379 pub fn set_high(&mut self) {
@@ -408,6 +437,13 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> {
408 } 437 }
409 438
410 #[inline] 439 #[inline]
440 pub fn degrade(self) -> Output<'d, AnyPin> {
441 Output {
442 pin: self.pin.degrade(),
443 }
444 }
445
446 #[inline]
411 pub fn is_high(&self) -> bool { 447 pub fn is_high(&self) -> bool {
412 !self.pin.is_low() 448 !self.pin.is_low()
413 } 449 }