diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-05-03 00:44:27 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-05-03 00:52:48 +0200 |
| commit | 71e46d7efdcf903a1493f02ef03d1376fc6bc6df (patch) | |
| tree | 0c1d4a47f33640f3b96c089cd8c6276581f8f6cd | |
| parent | 0be6df168bf8d9121c37118dde5f86e144ec9b37 (diff) | |
stm32/gpio: add EH1.0 trait impls.
| -rw-r--r-- | embassy-stm32/src/gpio.rs | 101 |
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; | |||
| 3 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 4 | use embassy::util::Unborrow; | 4 | use embassy::util::Unborrow; |
| 5 | use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; | 5 | use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; |
| 6 | use embedded_hal_02::digital::v2::{InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin}; | ||
| 7 | 6 | ||
| 8 | use crate::pac; | 7 | use crate::pac; |
| 9 | use crate::pac::gpio::{self, vals}; | 8 | use crate::pac::gpio::{self, vals}; |
| @@ -605,6 +604,9 @@ pub(crate) unsafe fn init() { | |||
| 605 | 604 | ||
| 606 | mod eh02 { | 605 | mod 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")] | ||
| 697 | mod 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")] |
| 695 | pub mod low_level { | 794 | pub mod low_level { |
| 696 | pub use super::sealed::*; | 795 | pub use super::sealed::*; |
