aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32/src/gpio.rs101
1 files changed, 100 insertions, 1 deletions
diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs
index 1ac6f3952..30f900316 100644
--- a/embassy-stm32/src/gpio.rs
+++ b/embassy-stm32/src/gpio.rs
@@ -3,7 +3,6 @@ use core::convert::Infallible;
3use core::marker::PhantomData; 3use core::marker::PhantomData;
4use embassy::util::Unborrow; 4use embassy::util::Unborrow;
5use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; 5use embassy_hal_common::{unborrow, unsafe_impl_unborrow};
6use embedded_hal_02::digital::v2::{InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin};
7 6
8use crate::pac; 7use crate::pac;
9use crate::pac::gpio::{self, vals}; 8use crate::pac::gpio::{self, vals};
@@ -605,6 +604,9 @@ pub(crate) unsafe fn init() {
605 604
606mod eh02 { 605mod eh02 {
607 use super::*; 606 use super::*;
607 use embedded_hal_02::digital::v2::{
608 InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin,
609 };
608 610
609 impl<'d, T: Pin> InputPin for Input<'d, T> { 611 impl<'d, T: Pin> InputPin for Input<'d, T> {
610 type Error = Infallible; 612 type Error = Infallible;
@@ -691,6 +693,103 @@ mod eh02 {
691 } 693 }
692} 694}
693 695
696#[cfg(feature = "unstable-traits")]
697mod eh1 {
698 use super::*;
699 use embedded_hal_1::digital::blocking::{
700 InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin,
701 };
702 use embedded_hal_1::digital::ErrorType;
703
704 impl<'d, T: Pin> ErrorType for Input<'d, T> {
705 type Error = Infallible;
706 }
707
708 impl<'d, T: Pin> InputPin for Input<'d, T> {
709 #[inline]
710 fn is_high(&self) -> Result<bool, Self::Error> {
711 Ok(self.is_high())
712 }
713
714 #[inline]
715 fn is_low(&self) -> Result<bool, Self::Error> {
716 Ok(self.is_low())
717 }
718 }
719
720 impl<'d, T: Pin> ErrorType for Output<'d, T> {
721 type Error = Infallible;
722 }
723
724 impl<'d, T: Pin> OutputPin for Output<'d, T> {
725 #[inline]
726 fn set_high(&mut self) -> Result<(), Self::Error> {
727 Ok(self.set_high())
728 }
729
730 #[inline]
731 fn set_low(&mut self) -> Result<(), Self::Error> {
732 Ok(self.set_low())
733 }
734 }
735
736 impl<'d, T: Pin> StatefulOutputPin for Output<'d, T> {
737 #[inline]
738 fn is_set_high(&self) -> Result<bool, Self::Error> {
739 Ok(self.is_set_high())
740 }
741
742 /// Is the output pin set as low?
743 #[inline]
744 fn is_set_low(&self) -> Result<bool, Self::Error> {
745 Ok(self.is_set_low())
746 }
747 }
748
749 impl<'d, T: Pin> ToggleableOutputPin for Output<'d, T> {
750 #[inline]
751 fn toggle(&mut self) -> Result<(), Self::Error> {
752 Ok(self.toggle())
753 }
754 }
755
756 impl<'d, T: Pin> ErrorType for OutputOpenDrain<'d, T> {
757 type Error = Infallible;
758 }
759
760 impl<'d, T: Pin> OutputPin for OutputOpenDrain<'d, T> {
761 #[inline]
762 fn set_high(&mut self) -> Result<(), Self::Error> {
763 Ok(self.set_high())
764 }
765
766 #[inline]
767 fn set_low(&mut self) -> Result<(), Self::Error> {
768 Ok(self.set_low())
769 }
770 }
771
772 impl<'d, T: Pin> StatefulOutputPin for OutputOpenDrain<'d, T> {
773 #[inline]
774 fn is_set_high(&self) -> Result<bool, Self::Error> {
775 Ok(self.is_set_high())
776 }
777
778 /// Is the output pin set as low?
779 #[inline]
780 fn is_set_low(&self) -> Result<bool, Self::Error> {
781 Ok(self.is_set_low())
782 }
783 }
784
785 impl<'d, T: Pin> ToggleableOutputPin for OutputOpenDrain<'d, T> {
786 #[inline]
787 fn toggle(&mut self) -> Result<(), Self::Error> {
788 Ok(self.toggle())
789 }
790 }
791}
792
694#[cfg(feature = "unstable-pac")] 793#[cfg(feature = "unstable-pac")]
695pub mod low_level { 794pub mod low_level {
696 pub use super::sealed::*; 795 pub use super::sealed::*;