diff options
Diffstat (limited to 'embassy-stm32/src')
| -rw-r--r-- | embassy-stm32/src/exti.rs | 89 | ||||
| -rw-r--r-- | embassy-stm32/src/flash/asynch.rs | 8 | ||||
| -rw-r--r-- | embassy-stm32/src/flash/f4.rs | 2 | ||||
| -rw-r--r-- | embassy-stm32/src/gpio.rs | 439 | ||||
| -rw-r--r-- | embassy-stm32/src/i2c/mod.rs | 142 | ||||
| -rw-r--r-- | embassy-stm32/src/lib.rs | 3 | ||||
| -rw-r--r-- | embassy-stm32/src/spi/mod.rs | 134 | ||||
| -rw-r--r-- | embassy-stm32/src/usart/buffered.rs | 214 | ||||
| -rw-r--r-- | embassy-stm32/src/usart/mod.rs | 191 | ||||
| -rw-r--r-- | embassy-stm32/src/usart/ringbuffered.rs | 38 | ||||
| -rw-r--r-- | embassy-stm32/src/usb/mod.rs | 2 | ||||
| -rw-r--r-- | embassy-stm32/src/usb_otg/mod.rs | 10 |
12 files changed, 560 insertions, 712 deletions
diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs index 07c63a2ef..dbd24804f 100644 --- a/embassy-stm32/src/exti.rs +++ b/embassy-stm32/src/exti.rs | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | use core::convert::Infallible; | ||
| 1 | use core::future::Future; | 2 | use core::future::Future; |
| 2 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 3 | use core::pin::Pin; | 4 | use core::pin::Pin; |
| @@ -137,74 +138,56 @@ impl<'d, T: GpioPin> ExtiInput<'d, T> { | |||
| 137 | } | 138 | } |
| 138 | } | 139 | } |
| 139 | 140 | ||
| 140 | mod eh02 { | 141 | impl<'d, T: GpioPin> embedded_hal_02::digital::v2::InputPin for ExtiInput<'d, T> { |
| 141 | use core::convert::Infallible; | 142 | type Error = Infallible; |
| 142 | 143 | ||
| 143 | use super::*; | 144 | fn is_high(&self) -> Result<bool, Self::Error> { |
| 144 | 145 | Ok(self.is_high()) | |
| 145 | impl<'d, T: GpioPin> embedded_hal_02::digital::v2::InputPin for ExtiInput<'d, T> { | 146 | } |
| 146 | type Error = Infallible; | ||
| 147 | |||
| 148 | fn is_high(&self) -> Result<bool, Self::Error> { | ||
| 149 | Ok(self.is_high()) | ||
| 150 | } | ||
| 151 | 147 | ||
| 152 | fn is_low(&self) -> Result<bool, Self::Error> { | 148 | fn is_low(&self) -> Result<bool, Self::Error> { |
| 153 | Ok(self.is_low()) | 149 | Ok(self.is_low()) |
| 154 | } | ||
| 155 | } | 150 | } |
| 156 | } | 151 | } |
| 157 | 152 | ||
| 158 | #[cfg(feature = "unstable-traits")] | 153 | impl<'d, T: GpioPin> embedded_hal_1::digital::ErrorType for ExtiInput<'d, T> { |
| 159 | mod eh1 { | 154 | type Error = Infallible; |
| 160 | use core::convert::Infallible; | 155 | } |
| 161 | |||
| 162 | use super::*; | ||
| 163 | 156 | ||
| 164 | impl<'d, T: GpioPin> embedded_hal_1::digital::ErrorType for ExtiInput<'d, T> { | 157 | impl<'d, T: GpioPin> embedded_hal_1::digital::InputPin for ExtiInput<'d, T> { |
| 165 | type Error = Infallible; | 158 | fn is_high(&self) -> Result<bool, Self::Error> { |
| 159 | Ok(self.is_high()) | ||
| 166 | } | 160 | } |
| 167 | 161 | ||
| 168 | impl<'d, T: GpioPin> embedded_hal_1::digital::InputPin for ExtiInput<'d, T> { | 162 | fn is_low(&self) -> Result<bool, Self::Error> { |
| 169 | fn is_high(&self) -> Result<bool, Self::Error> { | 163 | Ok(self.is_low()) |
| 170 | Ok(self.is_high()) | ||
| 171 | } | ||
| 172 | |||
| 173 | fn is_low(&self) -> Result<bool, Self::Error> { | ||
| 174 | Ok(self.is_low()) | ||
| 175 | } | ||
| 176 | } | 164 | } |
| 177 | } | 165 | } |
| 178 | #[cfg(all(feature = "unstable-traits", feature = "nightly"))] | ||
| 179 | mod eha { | ||
| 180 | 166 | ||
| 181 | use super::*; | 167 | impl<'d, T: GpioPin> embedded_hal_async::digital::Wait for ExtiInput<'d, T> { |
| 182 | 168 | async fn wait_for_high(&mut self) -> Result<(), Self::Error> { | |
| 183 | impl<'d, T: GpioPin> embedded_hal_async::digital::Wait for ExtiInput<'d, T> { | 169 | self.wait_for_high().await; |
| 184 | async fn wait_for_high(&mut self) -> Result<(), Self::Error> { | 170 | Ok(()) |
| 185 | self.wait_for_high().await; | 171 | } |
| 186 | Ok(()) | ||
| 187 | } | ||
| 188 | 172 | ||
| 189 | async fn wait_for_low(&mut self) -> Result<(), Self::Error> { | 173 | async fn wait_for_low(&mut self) -> Result<(), Self::Error> { |
| 190 | self.wait_for_low().await; | 174 | self.wait_for_low().await; |
| 191 | Ok(()) | 175 | Ok(()) |
| 192 | } | 176 | } |
| 193 | 177 | ||
| 194 | async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> { | 178 | async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> { |
| 195 | self.wait_for_rising_edge().await; | 179 | self.wait_for_rising_edge().await; |
| 196 | Ok(()) | 180 | Ok(()) |
| 197 | } | 181 | } |
| 198 | 182 | ||
| 199 | async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> { | 183 | async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> { |
| 200 | self.wait_for_falling_edge().await; | 184 | self.wait_for_falling_edge().await; |
| 201 | Ok(()) | 185 | Ok(()) |
| 202 | } | 186 | } |
| 203 | 187 | ||
| 204 | async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> { | 188 | async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> { |
| 205 | self.wait_for_any_edge().await; | 189 | self.wait_for_any_edge().await; |
| 206 | Ok(()) | 190 | Ok(()) |
| 207 | } | ||
| 208 | } | 191 | } |
| 209 | } | 192 | } |
| 210 | 193 | ||
diff --git a/embassy-stm32/src/flash/asynch.rs b/embassy-stm32/src/flash/asynch.rs index e966e2a77..eae40c7ec 100644 --- a/embassy-stm32/src/flash/asynch.rs +++ b/embassy-stm32/src/flash/asynch.rs | |||
| @@ -55,7 +55,6 @@ impl interrupt::typelevel::Handler<crate::interrupt::typelevel::FLASH> for Inter | |||
| 55 | } | 55 | } |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | #[cfg(feature = "nightly")] | ||
| 59 | impl embedded_storage_async::nor_flash::ReadNorFlash for Flash<'_, Async> { | 58 | impl embedded_storage_async::nor_flash::ReadNorFlash for Flash<'_, Async> { |
| 60 | const READ_SIZE: usize = super::READ_SIZE; | 59 | const READ_SIZE: usize = super::READ_SIZE; |
| 61 | 60 | ||
| @@ -68,7 +67,6 @@ impl embedded_storage_async::nor_flash::ReadNorFlash for Flash<'_, Async> { | |||
| 68 | } | 67 | } |
| 69 | } | 68 | } |
| 70 | 69 | ||
| 71 | #[cfg(feature = "nightly")] | ||
| 72 | impl embedded_storage_async::nor_flash::NorFlash for Flash<'_, Async> { | 70 | impl embedded_storage_async::nor_flash::NorFlash for Flash<'_, Async> { |
| 73 | const WRITE_SIZE: usize = WRITE_SIZE; | 71 | const WRITE_SIZE: usize = WRITE_SIZE; |
| 74 | const ERASE_SIZE: usize = super::MAX_ERASE_SIZE; | 72 | const ERASE_SIZE: usize = super::MAX_ERASE_SIZE; |
| @@ -158,8 +156,7 @@ foreach_flash_region! { | |||
| 158 | } | 156 | } |
| 159 | } | 157 | } |
| 160 | 158 | ||
| 161 | #[cfg(feature = "nightly")] | 159 | impl embedded_storage_async::nor_flash::ReadNorFlash for crate::_generated::flash_regions::$type_name<'_, Async> { |
| 162 | impl embedded_storage_async::nor_flash::ReadNorFlash for crate::_generated::flash_regions::$type_name<'_, Async> { | ||
| 163 | const READ_SIZE: usize = super::READ_SIZE; | 160 | const READ_SIZE: usize = super::READ_SIZE; |
| 164 | 161 | ||
| 165 | async fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error> { | 162 | async fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error> { |
| @@ -171,8 +168,7 @@ foreach_flash_region! { | |||
| 171 | } | 168 | } |
| 172 | } | 169 | } |
| 173 | 170 | ||
| 174 | #[cfg(feature = "nightly")] | 171 | impl embedded_storage_async::nor_flash::NorFlash for crate::_generated::flash_regions::$type_name<'_, Async> { |
| 175 | impl embedded_storage_async::nor_flash::NorFlash for crate::_generated::flash_regions::$type_name<'_, Async> { | ||
| 176 | const WRITE_SIZE: usize = $write_size; | 172 | const WRITE_SIZE: usize = $write_size; |
| 177 | const ERASE_SIZE: usize = $erase_size; | 173 | const ERASE_SIZE: usize = $erase_size; |
| 178 | 174 | ||
diff --git a/embassy-stm32/src/flash/f4.rs b/embassy-stm32/src/flash/f4.rs index 3e5959ddb..5d07020ce 100644 --- a/embassy-stm32/src/flash/f4.rs +++ b/embassy-stm32/src/flash/f4.rs | |||
| @@ -142,7 +142,6 @@ mod alt_regions { | |||
| 142 | } | 142 | } |
| 143 | } | 143 | } |
| 144 | 144 | ||
| 145 | #[cfg(feature = "nightly")] | ||
| 146 | impl embedded_storage_async::nor_flash::ReadNorFlash for $type_name<'_, Async> { | 145 | impl embedded_storage_async::nor_flash::ReadNorFlash for $type_name<'_, Async> { |
| 147 | const READ_SIZE: usize = crate::flash::READ_SIZE; | 146 | const READ_SIZE: usize = crate::flash::READ_SIZE; |
| 148 | 147 | ||
| @@ -155,7 +154,6 @@ mod alt_regions { | |||
| 155 | } | 154 | } |
| 156 | } | 155 | } |
| 157 | 156 | ||
| 158 | #[cfg(feature = "nightly")] | ||
| 159 | impl embedded_storage_async::nor_flash::NorFlash for $type_name<'_, Async> { | 157 | impl embedded_storage_async::nor_flash::NorFlash for $type_name<'_, Async> { |
| 160 | const WRITE_SIZE: usize = $region.write_size as usize; | 158 | const WRITE_SIZE: usize = $region.write_size as usize; |
| 161 | const ERASE_SIZE: usize = $region.erase_size as usize; | 159 | const ERASE_SIZE: usize = $region.erase_size as usize; |
diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs index 011f4c07a..b863c4ffe 100644 --- a/embassy-stm32/src/gpio.rs +++ b/embassy-stm32/src/gpio.rs | |||
| @@ -772,306 +772,293 @@ pub(crate) unsafe fn init(_cs: CriticalSection) { | |||
| 772 | }); | 772 | }); |
| 773 | } | 773 | } |
| 774 | 774 | ||
| 775 | mod eh02 { | 775 | impl<'d, T: Pin> embedded_hal_02::digital::v2::InputPin for Input<'d, T> { |
| 776 | use embedded_hal_02::digital::v2::{InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin}; | 776 | type Error = Infallible; |
| 777 | 777 | ||
| 778 | use super::*; | 778 | #[inline] |
| 779 | 779 | fn is_high(&self) -> Result<bool, Self::Error> { | |
| 780 | impl<'d, T: Pin> InputPin for Input<'d, T> { | 780 | Ok(self.is_high()) |
| 781 | type Error = Infallible; | ||
| 782 | |||
| 783 | #[inline] | ||
| 784 | fn is_high(&self) -> Result<bool, Self::Error> { | ||
| 785 | Ok(self.is_high()) | ||
| 786 | } | ||
| 787 | |||
| 788 | #[inline] | ||
| 789 | fn is_low(&self) -> Result<bool, Self::Error> { | ||
| 790 | Ok(self.is_low()) | ||
| 791 | } | ||
| 792 | } | 781 | } |
| 793 | 782 | ||
| 794 | impl<'d, T: Pin> OutputPin for Output<'d, T> { | 783 | #[inline] |
| 795 | type Error = Infallible; | 784 | fn is_low(&self) -> Result<bool, Self::Error> { |
| 796 | 785 | Ok(self.is_low()) | |
| 797 | #[inline] | ||
| 798 | fn set_high(&mut self) -> Result<(), Self::Error> { | ||
| 799 | self.set_high(); | ||
| 800 | Ok(()) | ||
| 801 | } | ||
| 802 | |||
| 803 | #[inline] | ||
| 804 | fn set_low(&mut self) -> Result<(), Self::Error> { | ||
| 805 | self.set_low(); | ||
| 806 | Ok(()) | ||
| 807 | } | ||
| 808 | } | 786 | } |
| 787 | } | ||
| 809 | 788 | ||
| 810 | impl<'d, T: Pin> StatefulOutputPin for Output<'d, T> { | 789 | impl<'d, T: Pin> embedded_hal_02::digital::v2::OutputPin for Output<'d, T> { |
| 811 | #[inline] | 790 | type Error = Infallible; |
| 812 | fn is_set_high(&self) -> Result<bool, Self::Error> { | ||
| 813 | Ok(self.is_set_high()) | ||
| 814 | } | ||
| 815 | 791 | ||
| 816 | /// Is the output pin set as low? | 792 | #[inline] |
| 817 | #[inline] | 793 | fn set_high(&mut self) -> Result<(), Self::Error> { |
| 818 | fn is_set_low(&self) -> Result<bool, Self::Error> { | 794 | self.set_high(); |
| 819 | Ok(self.is_set_low()) | 795 | Ok(()) |
| 820 | } | ||
| 821 | } | 796 | } |
| 822 | 797 | ||
| 823 | impl<'d, T: Pin> ToggleableOutputPin for Output<'d, T> { | 798 | #[inline] |
| 824 | type Error = Infallible; | 799 | fn set_low(&mut self) -> Result<(), Self::Error> { |
| 825 | #[inline] | 800 | self.set_low(); |
| 826 | fn toggle(&mut self) -> Result<(), Self::Error> { | 801 | Ok(()) |
| 827 | self.toggle(); | ||
| 828 | Ok(()) | ||
| 829 | } | ||
| 830 | } | 802 | } |
| 803 | } | ||
| 831 | 804 | ||
| 832 | impl<'d, T: Pin> OutputPin for OutputOpenDrain<'d, T> { | 805 | impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for Output<'d, T> { |
| 833 | type Error = Infallible; | 806 | #[inline] |
| 807 | fn is_set_high(&self) -> Result<bool, Self::Error> { | ||
| 808 | Ok(self.is_set_high()) | ||
| 809 | } | ||
| 834 | 810 | ||
| 835 | #[inline] | 811 | /// Is the output pin set as low? |
| 836 | fn set_high(&mut self) -> Result<(), Self::Error> { | 812 | #[inline] |
| 837 | self.set_high(); | 813 | fn is_set_low(&self) -> Result<bool, Self::Error> { |
| 838 | Ok(()) | 814 | Ok(self.is_set_low()) |
| 839 | } | 815 | } |
| 816 | } | ||
| 840 | 817 | ||
| 841 | #[inline] | 818 | impl<'d, T: Pin> embedded_hal_02::digital::v2::ToggleableOutputPin for Output<'d, T> { |
| 842 | fn set_low(&mut self) -> Result<(), Self::Error> { | 819 | type Error = Infallible; |
| 843 | self.set_low(); | 820 | #[inline] |
| 844 | Ok(()) | 821 | fn toggle(&mut self) -> Result<(), Self::Error> { |
| 845 | } | 822 | self.toggle(); |
| 823 | Ok(()) | ||
| 846 | } | 824 | } |
| 825 | } | ||
| 847 | 826 | ||
| 848 | impl<'d, T: Pin> StatefulOutputPin for OutputOpenDrain<'d, T> { | 827 | impl<'d, T: Pin> embedded_hal_02::digital::v2::OutputPin for OutputOpenDrain<'d, T> { |
| 849 | #[inline] | 828 | type Error = Infallible; |
| 850 | fn is_set_high(&self) -> Result<bool, Self::Error> { | ||
| 851 | Ok(self.is_set_high()) | ||
| 852 | } | ||
| 853 | 829 | ||
| 854 | /// Is the output pin set as low? | 830 | #[inline] |
| 855 | #[inline] | 831 | fn set_high(&mut self) -> Result<(), Self::Error> { |
| 856 | fn is_set_low(&self) -> Result<bool, Self::Error> { | 832 | self.set_high(); |
| 857 | Ok(self.is_set_low()) | 833 | Ok(()) |
| 858 | } | ||
| 859 | } | 834 | } |
| 860 | 835 | ||
| 861 | impl<'d, T: Pin> ToggleableOutputPin for OutputOpenDrain<'d, T> { | 836 | #[inline] |
| 862 | type Error = Infallible; | 837 | fn set_low(&mut self) -> Result<(), Self::Error> { |
| 863 | #[inline] | 838 | self.set_low(); |
| 864 | fn toggle(&mut self) -> Result<(), Self::Error> { | 839 | Ok(()) |
| 865 | self.toggle(); | ||
| 866 | Ok(()) | ||
| 867 | } | ||
| 868 | } | 840 | } |
| 841 | } | ||
| 869 | 842 | ||
| 870 | impl<'d, T: Pin> InputPin for Flex<'d, T> { | 843 | impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for OutputOpenDrain<'d, T> { |
| 871 | type Error = Infallible; | 844 | #[inline] |
| 845 | fn is_set_high(&self) -> Result<bool, Self::Error> { | ||
| 846 | Ok(self.is_set_high()) | ||
| 847 | } | ||
| 872 | 848 | ||
| 873 | #[inline] | 849 | /// Is the output pin set as low? |
| 874 | fn is_high(&self) -> Result<bool, Self::Error> { | 850 | #[inline] |
| 875 | Ok(self.is_high()) | 851 | fn is_set_low(&self) -> Result<bool, Self::Error> { |
| 876 | } | 852 | Ok(self.is_set_low()) |
| 853 | } | ||
| 854 | } | ||
| 877 | 855 | ||
| 878 | #[inline] | 856 | impl<'d, T: Pin> embedded_hal_02::digital::v2::ToggleableOutputPin for OutputOpenDrain<'d, T> { |
| 879 | fn is_low(&self) -> Result<bool, Self::Error> { | 857 | type Error = Infallible; |
| 880 | Ok(self.is_low()) | 858 | #[inline] |
| 881 | } | 859 | fn toggle(&mut self) -> Result<(), Self::Error> { |
| 860 | self.toggle(); | ||
| 861 | Ok(()) | ||
| 882 | } | 862 | } |
| 863 | } | ||
| 883 | 864 | ||
| 884 | impl<'d, T: Pin> OutputPin for Flex<'d, T> { | 865 | impl<'d, T: Pin> embedded_hal_02::digital::v2::InputPin for Flex<'d, T> { |
| 885 | type Error = Infallible; | 866 | type Error = Infallible; |
| 886 | 867 | ||
| 887 | #[inline] | 868 | #[inline] |
| 888 | fn set_high(&mut self) -> Result<(), Self::Error> { | 869 | fn is_high(&self) -> Result<bool, Self::Error> { |
| 889 | self.set_high(); | 870 | Ok(self.is_high()) |
| 890 | Ok(()) | 871 | } |
| 891 | } | ||
| 892 | 872 | ||
| 893 | #[inline] | 873 | #[inline] |
| 894 | fn set_low(&mut self) -> Result<(), Self::Error> { | 874 | fn is_low(&self) -> Result<bool, Self::Error> { |
| 895 | self.set_low(); | 875 | Ok(self.is_low()) |
| 896 | Ok(()) | ||
| 897 | } | ||
| 898 | } | 876 | } |
| 877 | } | ||
| 899 | 878 | ||
| 900 | impl<'d, T: Pin> StatefulOutputPin for Flex<'d, T> { | 879 | impl<'d, T: Pin> embedded_hal_02::digital::v2::OutputPin for Flex<'d, T> { |
| 901 | #[inline] | 880 | type Error = Infallible; |
| 902 | fn is_set_high(&self) -> Result<bool, Self::Error> { | ||
| 903 | Ok(self.is_set_high()) | ||
| 904 | } | ||
| 905 | 881 | ||
| 906 | /// Is the output pin set as low? | 882 | #[inline] |
| 907 | #[inline] | 883 | fn set_high(&mut self) -> Result<(), Self::Error> { |
| 908 | fn is_set_low(&self) -> Result<bool, Self::Error> { | 884 | self.set_high(); |
| 909 | Ok(self.is_set_low()) | 885 | Ok(()) |
| 910 | } | ||
| 911 | } | 886 | } |
| 912 | 887 | ||
| 913 | impl<'d, T: Pin> ToggleableOutputPin for Flex<'d, T> { | 888 | #[inline] |
| 914 | type Error = Infallible; | 889 | fn set_low(&mut self) -> Result<(), Self::Error> { |
| 915 | #[inline] | 890 | self.set_low(); |
| 916 | fn toggle(&mut self) -> Result<(), Self::Error> { | 891 | Ok(()) |
| 917 | self.toggle(); | ||
| 918 | Ok(()) | ||
| 919 | } | ||
| 920 | } | 892 | } |
| 921 | } | 893 | } |
| 922 | 894 | ||
| 923 | #[cfg(feature = "unstable-traits")] | 895 | impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for Flex<'d, T> { |
| 924 | mod eh1 { | 896 | #[inline] |
| 925 | use embedded_hal_1::digital::{ErrorType, InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin}; | 897 | fn is_set_high(&self) -> Result<bool, Self::Error> { |
| 898 | Ok(self.is_set_high()) | ||
| 899 | } | ||
| 926 | 900 | ||
| 927 | use super::*; | 901 | /// Is the output pin set as low? |
| 902 | #[inline] | ||
| 903 | fn is_set_low(&self) -> Result<bool, Self::Error> { | ||
| 904 | Ok(self.is_set_low()) | ||
| 905 | } | ||
| 906 | } | ||
| 928 | 907 | ||
| 929 | impl<'d, T: Pin> ErrorType for Input<'d, T> { | 908 | impl<'d, T: Pin> embedded_hal_02::digital::v2::ToggleableOutputPin for Flex<'d, T> { |
| 930 | type Error = Infallible; | 909 | type Error = Infallible; |
| 910 | #[inline] | ||
| 911 | fn toggle(&mut self) -> Result<(), Self::Error> { | ||
| 912 | self.toggle(); | ||
| 913 | Ok(()) | ||
| 931 | } | 914 | } |
| 915 | } | ||
| 932 | 916 | ||
| 933 | impl<'d, T: Pin> InputPin for Input<'d, T> { | 917 | impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Input<'d, T> { |
| 934 | #[inline] | 918 | type Error = Infallible; |
| 935 | fn is_high(&self) -> Result<bool, Self::Error> { | 919 | } |
| 936 | Ok(self.is_high()) | ||
| 937 | } | ||
| 938 | 920 | ||
| 939 | #[inline] | 921 | impl<'d, T: Pin> embedded_hal_1::digital::InputPin for Input<'d, T> { |
| 940 | fn is_low(&self) -> Result<bool, Self::Error> { | 922 | #[inline] |
| 941 | Ok(self.is_low()) | 923 | fn is_high(&self) -> Result<bool, Self::Error> { |
| 942 | } | 924 | Ok(self.is_high()) |
| 943 | } | 925 | } |
| 944 | 926 | ||
| 945 | impl<'d, T: Pin> ErrorType for Output<'d, T> { | 927 | #[inline] |
| 946 | type Error = Infallible; | 928 | fn is_low(&self) -> Result<bool, Self::Error> { |
| 929 | Ok(self.is_low()) | ||
| 947 | } | 930 | } |
| 931 | } | ||
| 948 | 932 | ||
| 949 | impl<'d, T: Pin> OutputPin for Output<'d, T> { | 933 | impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Output<'d, T> { |
| 950 | #[inline] | 934 | type Error = Infallible; |
| 951 | fn set_high(&mut self) -> Result<(), Self::Error> { | 935 | } |
| 952 | Ok(self.set_high()) | ||
| 953 | } | ||
| 954 | 936 | ||
| 955 | #[inline] | 937 | impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for Output<'d, T> { |
| 956 | fn set_low(&mut self) -> Result<(), Self::Error> { | 938 | #[inline] |
| 957 | Ok(self.set_low()) | 939 | fn set_high(&mut self) -> Result<(), Self::Error> { |
| 958 | } | 940 | Ok(self.set_high()) |
| 959 | } | 941 | } |
| 960 | 942 | ||
| 961 | impl<'d, T: Pin> StatefulOutputPin for Output<'d, T> { | 943 | #[inline] |
| 962 | #[inline] | 944 | fn set_low(&mut self) -> Result<(), Self::Error> { |
| 963 | fn is_set_high(&self) -> Result<bool, Self::Error> { | 945 | Ok(self.set_low()) |
| 964 | Ok(self.is_set_high()) | 946 | } |
| 965 | } | 947 | } |
| 966 | 948 | ||
| 967 | /// Is the output pin set as low? | 949 | impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for Output<'d, T> { |
| 968 | #[inline] | 950 | #[inline] |
| 969 | fn is_set_low(&self) -> Result<bool, Self::Error> { | 951 | fn is_set_high(&self) -> Result<bool, Self::Error> { |
| 970 | Ok(self.is_set_low()) | 952 | Ok(self.is_set_high()) |
| 971 | } | ||
| 972 | } | 953 | } |
| 973 | 954 | ||
| 974 | impl<'d, T: Pin> ToggleableOutputPin for Output<'d, T> { | 955 | /// Is the output pin set as low? |
| 975 | #[inline] | 956 | #[inline] |
| 976 | fn toggle(&mut self) -> Result<(), Self::Error> { | 957 | fn is_set_low(&self) -> Result<bool, Self::Error> { |
| 977 | Ok(self.toggle()) | 958 | Ok(self.is_set_low()) |
| 978 | } | ||
| 979 | } | 959 | } |
| 960 | } | ||
| 980 | 961 | ||
| 981 | impl<'d, T: Pin> ErrorType for OutputOpenDrain<'d, T> { | 962 | impl<'d, T: Pin> embedded_hal_1::digital::ToggleableOutputPin for Output<'d, T> { |
| 982 | type Error = Infallible; | 963 | #[inline] |
| 964 | fn toggle(&mut self) -> Result<(), Self::Error> { | ||
| 965 | Ok(self.toggle()) | ||
| 983 | } | 966 | } |
| 967 | } | ||
| 984 | 968 | ||
| 985 | impl<'d, T: Pin> InputPin for OutputOpenDrain<'d, T> { | 969 | impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for OutputOpenDrain<'d, T> { |
| 986 | #[inline] | 970 | type Error = Infallible; |
| 987 | fn is_high(&self) -> Result<bool, Self::Error> { | 971 | } |
| 988 | Ok(self.is_high()) | ||
| 989 | } | ||
| 990 | 972 | ||
| 991 | #[inline] | 973 | impl<'d, T: Pin> embedded_hal_1::digital::InputPin for OutputOpenDrain<'d, T> { |
| 992 | fn is_low(&self) -> Result<bool, Self::Error> { | 974 | #[inline] |
| 993 | Ok(self.is_low()) | 975 | fn is_high(&self) -> Result<bool, Self::Error> { |
| 994 | } | 976 | Ok(self.is_high()) |
| 995 | } | 977 | } |
| 996 | 978 | ||
| 997 | impl<'d, T: Pin> OutputPin for OutputOpenDrain<'d, T> { | 979 | #[inline] |
| 998 | #[inline] | 980 | fn is_low(&self) -> Result<bool, Self::Error> { |
| 999 | fn set_high(&mut self) -> Result<(), Self::Error> { | 981 | Ok(self.is_low()) |
| 1000 | Ok(self.set_high()) | 982 | } |
| 1001 | } | 983 | } |
| 1002 | 984 | ||
| 1003 | #[inline] | 985 | impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for OutputOpenDrain<'d, T> { |
| 1004 | fn set_low(&mut self) -> Result<(), Self::Error> { | 986 | #[inline] |
| 1005 | Ok(self.set_low()) | 987 | fn set_high(&mut self) -> Result<(), Self::Error> { |
| 1006 | } | 988 | Ok(self.set_high()) |
| 1007 | } | 989 | } |
| 1008 | 990 | ||
| 1009 | impl<'d, T: Pin> StatefulOutputPin for OutputOpenDrain<'d, T> { | 991 | #[inline] |
| 1010 | #[inline] | 992 | fn set_low(&mut self) -> Result<(), Self::Error> { |
| 1011 | fn is_set_high(&self) -> Result<bool, Self::Error> { | 993 | Ok(self.set_low()) |
| 1012 | Ok(self.is_set_high()) | 994 | } |
| 1013 | } | 995 | } |
| 1014 | 996 | ||
| 1015 | /// Is the output pin set as low? | 997 | impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for OutputOpenDrain<'d, T> { |
| 1016 | #[inline] | 998 | #[inline] |
| 1017 | fn is_set_low(&self) -> Result<bool, Self::Error> { | 999 | fn is_set_high(&self) -> Result<bool, Self::Error> { |
| 1018 | Ok(self.is_set_low()) | 1000 | Ok(self.is_set_high()) |
| 1019 | } | ||
| 1020 | } | 1001 | } |
| 1021 | 1002 | ||
| 1022 | impl<'d, T: Pin> ToggleableOutputPin for OutputOpenDrain<'d, T> { | 1003 | /// Is the output pin set as low? |
| 1023 | #[inline] | 1004 | #[inline] |
| 1024 | fn toggle(&mut self) -> Result<(), Self::Error> { | 1005 | fn is_set_low(&self) -> Result<bool, Self::Error> { |
| 1025 | Ok(self.toggle()) | 1006 | Ok(self.is_set_low()) |
| 1026 | } | ||
| 1027 | } | 1007 | } |
| 1008 | } | ||
| 1028 | 1009 | ||
| 1029 | impl<'d, T: Pin> InputPin for Flex<'d, T> { | 1010 | impl<'d, T: Pin> embedded_hal_1::digital::ToggleableOutputPin for OutputOpenDrain<'d, T> { |
| 1030 | #[inline] | 1011 | #[inline] |
| 1031 | fn is_high(&self) -> Result<bool, Self::Error> { | 1012 | fn toggle(&mut self) -> Result<(), Self::Error> { |
| 1032 | Ok(self.is_high()) | 1013 | Ok(self.toggle()) |
| 1033 | } | 1014 | } |
| 1015 | } | ||
| 1034 | 1016 | ||
| 1035 | #[inline] | 1017 | impl<'d, T: Pin> embedded_hal_1::digital::InputPin for Flex<'d, T> { |
| 1036 | fn is_low(&self) -> Result<bool, Self::Error> { | 1018 | #[inline] |
| 1037 | Ok(self.is_low()) | 1019 | fn is_high(&self) -> Result<bool, Self::Error> { |
| 1038 | } | 1020 | Ok(self.is_high()) |
| 1039 | } | 1021 | } |
| 1040 | 1022 | ||
| 1041 | impl<'d, T: Pin> OutputPin for Flex<'d, T> { | 1023 | #[inline] |
| 1042 | #[inline] | 1024 | fn is_low(&self) -> Result<bool, Self::Error> { |
| 1043 | fn set_high(&mut self) -> Result<(), Self::Error> { | 1025 | Ok(self.is_low()) |
| 1044 | Ok(self.set_high()) | 1026 | } |
| 1045 | } | 1027 | } |
| 1046 | 1028 | ||
| 1047 | #[inline] | 1029 | impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for Flex<'d, T> { |
| 1048 | fn set_low(&mut self) -> Result<(), Self::Error> { | 1030 | #[inline] |
| 1049 | Ok(self.set_low()) | 1031 | fn set_high(&mut self) -> Result<(), Self::Error> { |
| 1050 | } | 1032 | Ok(self.set_high()) |
| 1051 | } | 1033 | } |
| 1052 | 1034 | ||
| 1053 | impl<'d, T: Pin> ToggleableOutputPin for Flex<'d, T> { | 1035 | #[inline] |
| 1054 | #[inline] | 1036 | fn set_low(&mut self) -> Result<(), Self::Error> { |
| 1055 | fn toggle(&mut self) -> Result<(), Self::Error> { | 1037 | Ok(self.set_low()) |
| 1056 | Ok(self.toggle()) | ||
| 1057 | } | ||
| 1058 | } | 1038 | } |
| 1039 | } | ||
| 1059 | 1040 | ||
| 1060 | impl<'d, T: Pin> ErrorType for Flex<'d, T> { | 1041 | impl<'d, T: Pin> embedded_hal_1::digital::ToggleableOutputPin for Flex<'d, T> { |
| 1061 | type Error = Infallible; | 1042 | #[inline] |
| 1043 | fn toggle(&mut self) -> Result<(), Self::Error> { | ||
| 1044 | Ok(self.toggle()) | ||
| 1062 | } | 1045 | } |
| 1046 | } | ||
| 1063 | 1047 | ||
| 1064 | impl<'d, T: Pin> StatefulOutputPin for Flex<'d, T> { | 1048 | impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Flex<'d, T> { |
| 1065 | #[inline] | 1049 | type Error = Infallible; |
| 1066 | fn is_set_high(&self) -> Result<bool, Self::Error> { | 1050 | } |
| 1067 | Ok(self.is_set_high()) | ||
| 1068 | } | ||
| 1069 | 1051 | ||
| 1070 | /// Is the output pin set as low? | 1052 | impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for Flex<'d, T> { |
| 1071 | #[inline] | 1053 | #[inline] |
| 1072 | fn is_set_low(&self) -> Result<bool, Self::Error> { | 1054 | fn is_set_high(&self) -> Result<bool, Self::Error> { |
| 1073 | Ok(self.is_set_low()) | 1055 | Ok(self.is_set_high()) |
| 1074 | } | 1056 | } |
| 1057 | |||
| 1058 | /// Is the output pin set as low? | ||
| 1059 | #[inline] | ||
| 1060 | fn is_set_low(&self) -> Result<bool, Self::Error> { | ||
| 1061 | Ok(self.is_set_low()) | ||
| 1075 | } | 1062 | } |
| 1076 | } | 1063 | } |
| 1077 | 1064 | ||
diff --git a/embassy-stm32/src/i2c/mod.rs b/embassy-stm32/src/i2c/mod.rs index 19346d707..d2a50cf7e 100644 --- a/embassy-stm32/src/i2c/mod.rs +++ b/embassy-stm32/src/i2c/mod.rs | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 4 | 4 | ||
| 5 | use crate::dma::NoDma; | ||
| 5 | use crate::interrupt; | 6 | use crate::interrupt; |
| 6 | 7 | ||
| 7 | #[cfg_attr(i2c_v1, path = "v1.rs")] | 8 | #[cfg_attr(i2c_v1, path = "v1.rs")] |
| @@ -97,107 +98,92 @@ foreach_peripheral!( | |||
| 97 | }; | 98 | }; |
| 98 | ); | 99 | ); |
| 99 | 100 | ||
| 100 | mod eh02 { | 101 | impl<'d, T: Instance> embedded_hal_02::blocking::i2c::Read for I2c<'d, T> { |
| 101 | use super::*; | 102 | type Error = Error; |
| 102 | |||
| 103 | impl<'d, T: Instance> embedded_hal_02::blocking::i2c::Read for I2c<'d, T> { | ||
| 104 | type Error = Error; | ||
| 105 | 103 | ||
| 106 | fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Self::Error> { | 104 | fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Self::Error> { |
| 107 | self.blocking_read(address, buffer) | 105 | self.blocking_read(address, buffer) |
| 108 | } | ||
| 109 | } | 106 | } |
| 107 | } | ||
| 110 | 108 | ||
| 111 | impl<'d, T: Instance> embedded_hal_02::blocking::i2c::Write for I2c<'d, T> { | 109 | impl<'d, T: Instance> embedded_hal_02::blocking::i2c::Write for I2c<'d, T> { |
| 112 | type Error = Error; | 110 | type Error = Error; |
| 113 | 111 | ||
| 114 | fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error> { | 112 | fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error> { |
| 115 | self.blocking_write(address, write) | 113 | self.blocking_write(address, write) |
| 116 | } | ||
| 117 | } | 114 | } |
| 115 | } | ||
| 118 | 116 | ||
| 119 | impl<'d, T: Instance> embedded_hal_02::blocking::i2c::WriteRead for I2c<'d, T> { | 117 | impl<'d, T: Instance> embedded_hal_02::blocking::i2c::WriteRead for I2c<'d, T> { |
| 120 | type Error = Error; | 118 | type Error = Error; |
| 121 | 119 | ||
| 122 | fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> { | 120 | fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> { |
| 123 | self.blocking_write_read(address, write, read) | 121 | self.blocking_write_read(address, write, read) |
| 124 | } | ||
| 125 | } | 122 | } |
| 126 | } | 123 | } |
| 127 | 124 | ||
| 128 | #[cfg(feature = "unstable-traits")] | 125 | impl embedded_hal_1::i2c::Error for Error { |
| 129 | mod eh1 { | 126 | fn kind(&self) -> embedded_hal_1::i2c::ErrorKind { |
| 130 | use super::*; | 127 | match *self { |
| 131 | use crate::dma::NoDma; | 128 | Self::Bus => embedded_hal_1::i2c::ErrorKind::Bus, |
| 132 | 129 | Self::Arbitration => embedded_hal_1::i2c::ErrorKind::ArbitrationLoss, | |
| 133 | impl embedded_hal_1::i2c::Error for Error { | 130 | Self::Nack => { |
| 134 | fn kind(&self) -> embedded_hal_1::i2c::ErrorKind { | 131 | embedded_hal_1::i2c::ErrorKind::NoAcknowledge(embedded_hal_1::i2c::NoAcknowledgeSource::Unknown) |
| 135 | match *self { | ||
| 136 | Self::Bus => embedded_hal_1::i2c::ErrorKind::Bus, | ||
| 137 | Self::Arbitration => embedded_hal_1::i2c::ErrorKind::ArbitrationLoss, | ||
| 138 | Self::Nack => { | ||
| 139 | embedded_hal_1::i2c::ErrorKind::NoAcknowledge(embedded_hal_1::i2c::NoAcknowledgeSource::Unknown) | ||
| 140 | } | ||
| 141 | Self::Timeout => embedded_hal_1::i2c::ErrorKind::Other, | ||
| 142 | Self::Crc => embedded_hal_1::i2c::ErrorKind::Other, | ||
| 143 | Self::Overrun => embedded_hal_1::i2c::ErrorKind::Overrun, | ||
| 144 | Self::ZeroLengthTransfer => embedded_hal_1::i2c::ErrorKind::Other, | ||
| 145 | } | 132 | } |
| 133 | Self::Timeout => embedded_hal_1::i2c::ErrorKind::Other, | ||
| 134 | Self::Crc => embedded_hal_1::i2c::ErrorKind::Other, | ||
| 135 | Self::Overrun => embedded_hal_1::i2c::ErrorKind::Overrun, | ||
| 136 | Self::ZeroLengthTransfer => embedded_hal_1::i2c::ErrorKind::Other, | ||
| 146 | } | 137 | } |
| 147 | } | 138 | } |
| 139 | } | ||
| 148 | 140 | ||
| 149 | impl<'d, T: Instance, TXDMA, RXDMA> embedded_hal_1::i2c::ErrorType for I2c<'d, T, TXDMA, RXDMA> { | 141 | impl<'d, T: Instance, TXDMA, RXDMA> embedded_hal_1::i2c::ErrorType for I2c<'d, T, TXDMA, RXDMA> { |
| 150 | type Error = Error; | 142 | type Error = Error; |
| 151 | } | 143 | } |
| 152 | 144 | ||
| 153 | impl<'d, T: Instance> embedded_hal_1::i2c::I2c for I2c<'d, T, NoDma, NoDma> { | 145 | impl<'d, T: Instance> embedded_hal_1::i2c::I2c for I2c<'d, T, NoDma, NoDma> { |
| 154 | fn read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Self::Error> { | 146 | fn read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Self::Error> { |
| 155 | self.blocking_read(address, read) | 147 | self.blocking_read(address, read) |
| 156 | } | 148 | } |
| 157 | 149 | ||
| 158 | fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error> { | 150 | fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error> { |
| 159 | self.blocking_write(address, write) | 151 | self.blocking_write(address, write) |
| 160 | } | 152 | } |
| 161 | 153 | ||
| 162 | fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> { | 154 | fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> { |
| 163 | self.blocking_write_read(address, write, read) | 155 | self.blocking_write_read(address, write, read) |
| 164 | } | 156 | } |
| 165 | 157 | ||
| 166 | fn transaction( | 158 | fn transaction( |
| 167 | &mut self, | 159 | &mut self, |
| 168 | _address: u8, | 160 | _address: u8, |
| 169 | _operations: &mut [embedded_hal_1::i2c::Operation<'_>], | 161 | _operations: &mut [embedded_hal_1::i2c::Operation<'_>], |
| 170 | ) -> Result<(), Self::Error> { | 162 | ) -> Result<(), Self::Error> { |
| 171 | todo!(); | 163 | todo!(); |
| 172 | } | ||
| 173 | } | 164 | } |
| 174 | } | 165 | } |
| 175 | 166 | ||
| 176 | #[cfg(all(feature = "unstable-traits", feature = "nightly"))] | 167 | impl<'d, T: Instance, TXDMA: TxDma<T>, RXDMA: RxDma<T>> embedded_hal_async::i2c::I2c for I2c<'d, T, TXDMA, RXDMA> { |
| 177 | mod eha { | 168 | async fn read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Self::Error> { |
| 178 | use super::*; | 169 | self.read(address, read).await |
| 179 | 170 | } | |
| 180 | impl<'d, T: Instance, TXDMA: TxDma<T>, RXDMA: RxDma<T>> embedded_hal_async::i2c::I2c for I2c<'d, T, TXDMA, RXDMA> { | ||
| 181 | async fn read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Self::Error> { | ||
| 182 | self.read(address, read).await | ||
| 183 | } | ||
| 184 | 171 | ||
| 185 | async fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error> { | 172 | async fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error> { |
| 186 | self.write(address, write).await | 173 | self.write(address, write).await |
| 187 | } | 174 | } |
| 188 | 175 | ||
| 189 | async fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> { | 176 | async fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> { |
| 190 | self.write_read(address, write, read).await | 177 | self.write_read(address, write, read).await |
| 191 | } | 178 | } |
| 192 | 179 | ||
| 193 | async fn transaction( | 180 | async fn transaction( |
| 194 | &mut self, | 181 | &mut self, |
| 195 | address: u8, | 182 | address: u8, |
| 196 | operations: &mut [embedded_hal_1::i2c::Operation<'_>], | 183 | operations: &mut [embedded_hal_1::i2c::Operation<'_>], |
| 197 | ) -> Result<(), Self::Error> { | 184 | ) -> Result<(), Self::Error> { |
| 198 | let _ = address; | 185 | let _ = address; |
| 199 | let _ = operations; | 186 | let _ = operations; |
| 200 | todo!() | 187 | todo!() |
| 201 | } | ||
| 202 | } | 188 | } |
| 203 | } | 189 | } |
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index 511da9179..7ce801a0a 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | #![cfg_attr(not(test), no_std)] | 1 | #![cfg_attr(not(test), no_std)] |
| 2 | #![cfg_attr(feature = "nightly", feature(async_fn_in_trait, impl_trait_projections))] | 2 | #![allow(async_fn_in_trait)] |
| 3 | #![cfg_attr(feature = "nightly", allow(stable_features, unknown_lints, async_fn_in_trait))] | ||
| 4 | 3 | ||
| 5 | //! ## Feature flags | 4 | //! ## Feature flags |
| 6 | #![doc = document_features::document_features!(feature_label = r#"<span class="stab portability"><code>{feature}</code></span>"#)] | 5 | #![doc = document_features::document_features!(feature_label = r#"<span class="stab portability"><code>{feature}</code></span>"#)] |
diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index c391e0a5a..92599c75e 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs | |||
| @@ -848,102 +848,88 @@ fn transfer_word<W: Word>(regs: Regs, tx_word: W) -> Result<W, Error> { | |||
| 848 | Ok(rx_word) | 848 | Ok(rx_word) |
| 849 | } | 849 | } |
| 850 | 850 | ||
| 851 | mod eh02 { | 851 | // Note: It is not possible to impl these traits generically in embedded-hal 0.2 due to a conflict with |
| 852 | use super::*; | 852 | // some marker traits. For details, see https://github.com/rust-embedded/embedded-hal/pull/289 |
| 853 | 853 | macro_rules! impl_blocking { | |
| 854 | // Note: It is not possible to impl these traits generically in embedded-hal 0.2 due to a conflict with | 854 | ($w:ident) => { |
| 855 | // some marker traits. For details, see https://github.com/rust-embedded/embedded-hal/pull/289 | 855 | impl<'d, T: Instance, Tx, Rx> embedded_hal_02::blocking::spi::Write<$w> for Spi<'d, T, Tx, Rx> { |
| 856 | macro_rules! impl_blocking { | 856 | type Error = Error; |
| 857 | ($w:ident) => { | 857 | |
| 858 | impl<'d, T: Instance, Tx, Rx> embedded_hal_02::blocking::spi::Write<$w> for Spi<'d, T, Tx, Rx> { | 858 | fn write(&mut self, words: &[$w]) -> Result<(), Self::Error> { |
| 859 | type Error = Error; | 859 | self.blocking_write(words) |
| 860 | |||
| 861 | fn write(&mut self, words: &[$w]) -> Result<(), Self::Error> { | ||
| 862 | self.blocking_write(words) | ||
| 863 | } | ||
| 864 | } | 860 | } |
| 861 | } | ||
| 865 | 862 | ||
| 866 | impl<'d, T: Instance, Tx, Rx> embedded_hal_02::blocking::spi::Transfer<$w> for Spi<'d, T, Tx, Rx> { | 863 | impl<'d, T: Instance, Tx, Rx> embedded_hal_02::blocking::spi::Transfer<$w> for Spi<'d, T, Tx, Rx> { |
| 867 | type Error = Error; | 864 | type Error = Error; |
| 868 | 865 | ||
| 869 | fn transfer<'w>(&mut self, words: &'w mut [$w]) -> Result<&'w [$w], Self::Error> { | 866 | fn transfer<'w>(&mut self, words: &'w mut [$w]) -> Result<&'w [$w], Self::Error> { |
| 870 | self.blocking_transfer_in_place(words)?; | 867 | self.blocking_transfer_in_place(words)?; |
| 871 | Ok(words) | 868 | Ok(words) |
| 872 | } | ||
| 873 | } | 869 | } |
| 874 | }; | 870 | } |
| 875 | } | 871 | }; |
| 876 | |||
| 877 | impl_blocking!(u8); | ||
| 878 | impl_blocking!(u16); | ||
| 879 | } | 872 | } |
| 880 | 873 | ||
| 881 | #[cfg(feature = "unstable-traits")] | 874 | impl_blocking!(u8); |
| 882 | mod eh1 { | 875 | impl_blocking!(u16); |
| 883 | use super::*; | ||
| 884 | 876 | ||
| 885 | impl<'d, T: Instance, Tx, Rx> embedded_hal_1::spi::ErrorType for Spi<'d, T, Tx, Rx> { | 877 | impl<'d, T: Instance, Tx, Rx> embedded_hal_1::spi::ErrorType for Spi<'d, T, Tx, Rx> { |
| 886 | type Error = Error; | 878 | type Error = Error; |
| 887 | } | 879 | } |
| 888 | 880 | ||
| 889 | impl<'d, T: Instance, W: Word, Tx, Rx> embedded_hal_1::spi::SpiBus<W> for Spi<'d, T, Tx, Rx> { | 881 | impl<'d, T: Instance, W: Word, Tx, Rx> embedded_hal_1::spi::SpiBus<W> for Spi<'d, T, Tx, Rx> { |
| 890 | fn flush(&mut self) -> Result<(), Self::Error> { | 882 | fn flush(&mut self) -> Result<(), Self::Error> { |
| 891 | Ok(()) | 883 | Ok(()) |
| 892 | } | 884 | } |
| 893 | 885 | ||
| 894 | fn read(&mut self, words: &mut [W]) -> Result<(), Self::Error> { | 886 | fn read(&mut self, words: &mut [W]) -> Result<(), Self::Error> { |
| 895 | self.blocking_read(words) | 887 | self.blocking_read(words) |
| 896 | } | 888 | } |
| 897 | 889 | ||
| 898 | fn write(&mut self, words: &[W]) -> Result<(), Self::Error> { | 890 | fn write(&mut self, words: &[W]) -> Result<(), Self::Error> { |
| 899 | self.blocking_write(words) | 891 | self.blocking_write(words) |
| 900 | } | 892 | } |
| 901 | 893 | ||
| 902 | fn transfer(&mut self, read: &mut [W], write: &[W]) -> Result<(), Self::Error> { | 894 | fn transfer(&mut self, read: &mut [W], write: &[W]) -> Result<(), Self::Error> { |
| 903 | self.blocking_transfer(read, write) | 895 | self.blocking_transfer(read, write) |
| 904 | } | 896 | } |
| 905 | 897 | ||
| 906 | fn transfer_in_place(&mut self, words: &mut [W]) -> Result<(), Self::Error> { | 898 | fn transfer_in_place(&mut self, words: &mut [W]) -> Result<(), Self::Error> { |
| 907 | self.blocking_transfer_in_place(words) | 899 | self.blocking_transfer_in_place(words) |
| 908 | } | ||
| 909 | } | 900 | } |
| 901 | } | ||
| 910 | 902 | ||
| 911 | impl embedded_hal_1::spi::Error for Error { | 903 | impl embedded_hal_1::spi::Error for Error { |
| 912 | fn kind(&self) -> embedded_hal_1::spi::ErrorKind { | 904 | fn kind(&self) -> embedded_hal_1::spi::ErrorKind { |
| 913 | match *self { | 905 | match *self { |
| 914 | Self::Framing => embedded_hal_1::spi::ErrorKind::FrameFormat, | 906 | Self::Framing => embedded_hal_1::spi::ErrorKind::FrameFormat, |
| 915 | Self::Crc => embedded_hal_1::spi::ErrorKind::Other, | 907 | Self::Crc => embedded_hal_1::spi::ErrorKind::Other, |
| 916 | Self::ModeFault => embedded_hal_1::spi::ErrorKind::ModeFault, | 908 | Self::ModeFault => embedded_hal_1::spi::ErrorKind::ModeFault, |
| 917 | Self::Overrun => embedded_hal_1::spi::ErrorKind::Overrun, | 909 | Self::Overrun => embedded_hal_1::spi::ErrorKind::Overrun, |
| 918 | } | ||
| 919 | } | 910 | } |
| 920 | } | 911 | } |
| 921 | } | 912 | } |
| 922 | 913 | ||
| 923 | #[cfg(all(feature = "unstable-traits", feature = "nightly"))] | 914 | impl<'d, T: Instance, Tx: TxDma<T>, Rx: RxDma<T>, W: Word> embedded_hal_async::spi::SpiBus<W> for Spi<'d, T, Tx, Rx> { |
| 924 | mod eha { | 915 | async fn flush(&mut self) -> Result<(), Self::Error> { |
| 925 | use super::*; | 916 | Ok(()) |
| 926 | 917 | } | |
| 927 | impl<'d, T: Instance, Tx: TxDma<T>, Rx: RxDma<T>, W: Word> embedded_hal_async::spi::SpiBus<W> for Spi<'d, T, Tx, Rx> { | ||
| 928 | async fn flush(&mut self) -> Result<(), Self::Error> { | ||
| 929 | Ok(()) | ||
| 930 | } | ||
| 931 | 918 | ||
| 932 | async fn write(&mut self, words: &[W]) -> Result<(), Self::Error> { | 919 | async fn write(&mut self, words: &[W]) -> Result<(), Self::Error> { |
| 933 | self.write(words).await | 920 | self.write(words).await |
| 934 | } | 921 | } |
| 935 | 922 | ||
| 936 | async fn read(&mut self, words: &mut [W]) -> Result<(), Self::Error> { | 923 | async fn read(&mut self, words: &mut [W]) -> Result<(), Self::Error> { |
| 937 | self.read(words).await | 924 | self.read(words).await |
| 938 | } | 925 | } |
| 939 | 926 | ||
| 940 | async fn transfer(&mut self, read: &mut [W], write: &[W]) -> Result<(), Self::Error> { | 927 | async fn transfer(&mut self, read: &mut [W], write: &[W]) -> Result<(), Self::Error> { |
| 941 | self.transfer(read, write).await | 928 | self.transfer(read, write).await |
| 942 | } | 929 | } |
| 943 | 930 | ||
| 944 | async fn transfer_in_place(&mut self, words: &mut [W]) -> Result<(), Self::Error> { | 931 | async fn transfer_in_place(&mut self, words: &mut [W]) -> Result<(), Self::Error> { |
| 945 | self.transfer_in_place(words).await | 932 | self.transfer_in_place(words).await |
| 946 | } | ||
| 947 | } | 933 | } |
| 948 | } | 934 | } |
| 949 | 935 | ||
diff --git a/embassy-stm32/src/usart/buffered.rs b/embassy-stm32/src/usart/buffered.rs index 4daddfe91..a2e4ceaae 100644 --- a/embassy-stm32/src/usart/buffered.rs +++ b/embassy-stm32/src/usart/buffered.rs | |||
| @@ -560,172 +560,120 @@ impl<'d, T: BasicInstance> embedded_io::Write for BufferedUartTx<'d, T> { | |||
| 560 | } | 560 | } |
| 561 | } | 561 | } |
| 562 | 562 | ||
| 563 | mod eh02 { | 563 | impl<'d, T: BasicInstance> embedded_hal_02::serial::Read<u8> for BufferedUartRx<'d, T> { |
| 564 | use super::*; | 564 | type Error = Error; |
| 565 | 565 | ||
| 566 | impl<'d, T: BasicInstance> embedded_hal_02::serial::Read<u8> for BufferedUartRx<'d, T> { | 566 | fn read(&mut self) -> Result<u8, nb::Error<Self::Error>> { |
| 567 | type Error = Error; | 567 | let r = T::regs(); |
| 568 | 568 | unsafe { | |
| 569 | fn read(&mut self) -> Result<u8, nb::Error<Self::Error>> { | 569 | let sr = sr(r).read(); |
| 570 | let r = T::regs(); | 570 | if sr.pe() { |
| 571 | unsafe { | 571 | rdr(r).read_volatile(); |
| 572 | let sr = sr(r).read(); | 572 | Err(nb::Error::Other(Error::Parity)) |
| 573 | if sr.pe() { | 573 | } else if sr.fe() { |
| 574 | rdr(r).read_volatile(); | 574 | rdr(r).read_volatile(); |
| 575 | Err(nb::Error::Other(Error::Parity)) | 575 | Err(nb::Error::Other(Error::Framing)) |
| 576 | } else if sr.fe() { | 576 | } else if sr.ne() { |
| 577 | rdr(r).read_volatile(); | 577 | rdr(r).read_volatile(); |
| 578 | Err(nb::Error::Other(Error::Framing)) | 578 | Err(nb::Error::Other(Error::Noise)) |
| 579 | } else if sr.ne() { | 579 | } else if sr.ore() { |
| 580 | rdr(r).read_volatile(); | 580 | rdr(r).read_volatile(); |
| 581 | Err(nb::Error::Other(Error::Noise)) | 581 | Err(nb::Error::Other(Error::Overrun)) |
| 582 | } else if sr.ore() { | 582 | } else if sr.rxne() { |
| 583 | rdr(r).read_volatile(); | 583 | Ok(rdr(r).read_volatile()) |
| 584 | Err(nb::Error::Other(Error::Overrun)) | 584 | } else { |
| 585 | } else if sr.rxne() { | 585 | Err(nb::Error::WouldBlock) |
| 586 | Ok(rdr(r).read_volatile()) | ||
| 587 | } else { | ||
| 588 | Err(nb::Error::WouldBlock) | ||
| 589 | } | ||
| 590 | } | 586 | } |
| 591 | } | 587 | } |
| 592 | } | 588 | } |
| 589 | } | ||
| 593 | 590 | ||
| 594 | impl<'d, T: BasicInstance> embedded_hal_02::blocking::serial::Write<u8> for BufferedUartTx<'d, T> { | 591 | impl<'d, T: BasicInstance> embedded_hal_02::blocking::serial::Write<u8> for BufferedUartTx<'d, T> { |
| 595 | type Error = Error; | 592 | type Error = Error; |
| 596 | 593 | ||
| 597 | fn bwrite_all(&mut self, mut buffer: &[u8]) -> Result<(), Self::Error> { | 594 | fn bwrite_all(&mut self, mut buffer: &[u8]) -> Result<(), Self::Error> { |
| 598 | while !buffer.is_empty() { | 595 | while !buffer.is_empty() { |
| 599 | match self.blocking_write(buffer) { | 596 | match self.blocking_write(buffer) { |
| 600 | Ok(0) => panic!("zero-length write."), | 597 | Ok(0) => panic!("zero-length write."), |
| 601 | Ok(n) => buffer = &buffer[n..], | 598 | Ok(n) => buffer = &buffer[n..], |
| 602 | Err(e) => return Err(e), | 599 | Err(e) => return Err(e), |
| 603 | } | ||
| 604 | } | 600 | } |
| 605 | Ok(()) | ||
| 606 | } | ||
| 607 | |||
| 608 | fn bflush(&mut self) -> Result<(), Self::Error> { | ||
| 609 | self.blocking_flush() | ||
| 610 | } | 601 | } |
| 602 | Ok(()) | ||
| 611 | } | 603 | } |
| 612 | 604 | ||
| 613 | impl<'d, T: BasicInstance> embedded_hal_02::serial::Read<u8> for BufferedUart<'d, T> { | 605 | fn bflush(&mut self) -> Result<(), Self::Error> { |
| 614 | type Error = Error; | 606 | self.blocking_flush() |
| 615 | |||
| 616 | fn read(&mut self) -> Result<u8, nb::Error<Self::Error>> { | ||
| 617 | embedded_hal_02::serial::Read::read(&mut self.rx) | ||
| 618 | } | ||
| 619 | } | 607 | } |
| 608 | } | ||
| 620 | 609 | ||
| 621 | impl<'d, T: BasicInstance> embedded_hal_02::blocking::serial::Write<u8> for BufferedUart<'d, T> { | 610 | impl<'d, T: BasicInstance> embedded_hal_02::serial::Read<u8> for BufferedUart<'d, T> { |
| 622 | type Error = Error; | 611 | type Error = Error; |
| 623 | |||
| 624 | fn bwrite_all(&mut self, mut buffer: &[u8]) -> Result<(), Self::Error> { | ||
| 625 | while !buffer.is_empty() { | ||
| 626 | match self.tx.blocking_write(buffer) { | ||
| 627 | Ok(0) => panic!("zero-length write."), | ||
| 628 | Ok(n) => buffer = &buffer[n..], | ||
| 629 | Err(e) => return Err(e), | ||
| 630 | } | ||
| 631 | } | ||
| 632 | Ok(()) | ||
| 633 | } | ||
| 634 | 612 | ||
| 635 | fn bflush(&mut self) -> Result<(), Self::Error> { | 613 | fn read(&mut self) -> Result<u8, nb::Error<Self::Error>> { |
| 636 | self.tx.blocking_flush() | 614 | embedded_hal_02::serial::Read::read(&mut self.rx) |
| 637 | } | ||
| 638 | } | 615 | } |
| 639 | } | 616 | } |
| 640 | 617 | ||
| 641 | #[cfg(feature = "unstable-traits")] | 618 | impl<'d, T: BasicInstance> embedded_hal_02::blocking::serial::Write<u8> for BufferedUart<'d, T> { |
| 642 | mod eh1 { | 619 | type Error = Error; |
| 643 | use super::*; | ||
| 644 | 620 | ||
| 645 | impl<'d, T: BasicInstance> embedded_hal_nb::serial::ErrorType for BufferedUart<'d, T> { | 621 | fn bwrite_all(&mut self, mut buffer: &[u8]) -> Result<(), Self::Error> { |
| 646 | type Error = Error; | 622 | while !buffer.is_empty() { |
| 623 | match self.tx.blocking_write(buffer) { | ||
| 624 | Ok(0) => panic!("zero-length write."), | ||
| 625 | Ok(n) => buffer = &buffer[n..], | ||
| 626 | Err(e) => return Err(e), | ||
| 627 | } | ||
| 628 | } | ||
| 629 | Ok(()) | ||
| 647 | } | 630 | } |
| 648 | 631 | ||
| 649 | impl<'d, T: BasicInstance> embedded_hal_nb::serial::ErrorType for BufferedUartTx<'d, T> { | 632 | fn bflush(&mut self) -> Result<(), Self::Error> { |
| 650 | type Error = Error; | 633 | self.tx.blocking_flush() |
| 651 | } | 634 | } |
| 635 | } | ||
| 652 | 636 | ||
| 653 | impl<'d, T: BasicInstance> embedded_hal_nb::serial::ErrorType for BufferedUartRx<'d, T> { | 637 | impl<'d, T: BasicInstance> embedded_hal_nb::serial::ErrorType for BufferedUart<'d, T> { |
| 654 | type Error = Error; | 638 | type Error = Error; |
| 655 | } | 639 | } |
| 656 | 640 | ||
| 657 | impl<'d, T: BasicInstance> embedded_hal_nb::serial::Read for BufferedUartRx<'d, T> { | 641 | impl<'d, T: BasicInstance> embedded_hal_nb::serial::ErrorType for BufferedUartTx<'d, T> { |
| 658 | fn read(&mut self) -> nb::Result<u8, Self::Error> { | 642 | type Error = Error; |
| 659 | embedded_hal_02::serial::Read::read(self) | 643 | } |
| 660 | } | ||
| 661 | } | ||
| 662 | 644 | ||
| 663 | impl<'d, T: BasicInstance> embedded_hal_nb::serial::Write for BufferedUartTx<'d, T> { | 645 | impl<'d, T: BasicInstance> embedded_hal_nb::serial::ErrorType for BufferedUartRx<'d, T> { |
| 664 | fn write(&mut self, char: u8) -> nb::Result<(), Self::Error> { | 646 | type Error = Error; |
| 665 | self.blocking_write(&[char]).map(drop).map_err(nb::Error::Other) | 647 | } |
| 666 | } | ||
| 667 | 648 | ||
| 668 | fn flush(&mut self) -> nb::Result<(), Self::Error> { | 649 | impl<'d, T: BasicInstance> embedded_hal_nb::serial::Read for BufferedUartRx<'d, T> { |
| 669 | self.blocking_flush().map_err(nb::Error::Other) | 650 | fn read(&mut self) -> nb::Result<u8, Self::Error> { |
| 670 | } | 651 | embedded_hal_02::serial::Read::read(self) |
| 671 | } | 652 | } |
| 653 | } | ||
| 672 | 654 | ||
| 673 | impl<'d, T: BasicInstance> embedded_hal_nb::serial::Read for BufferedUart<'d, T> { | 655 | impl<'d, T: BasicInstance> embedded_hal_nb::serial::Write for BufferedUartTx<'d, T> { |
| 674 | fn read(&mut self) -> Result<u8, nb::Error<Self::Error>> { | 656 | fn write(&mut self, char: u8) -> nb::Result<(), Self::Error> { |
| 675 | embedded_hal_02::serial::Read::read(&mut self.rx) | 657 | self.blocking_write(&[char]).map(drop).map_err(nb::Error::Other) |
| 676 | } | ||
| 677 | } | 658 | } |
| 678 | 659 | ||
| 679 | impl<'d, T: BasicInstance> embedded_hal_nb::serial::Write for BufferedUart<'d, T> { | 660 | fn flush(&mut self) -> nb::Result<(), Self::Error> { |
| 680 | fn write(&mut self, char: u8) -> nb::Result<(), Self::Error> { | 661 | self.blocking_flush().map_err(nb::Error::Other) |
| 681 | self.tx.blocking_write(&[char]).map(drop).map_err(nb::Error::Other) | ||
| 682 | } | ||
| 683 | |||
| 684 | fn flush(&mut self) -> nb::Result<(), Self::Error> { | ||
| 685 | self.tx.blocking_flush().map_err(nb::Error::Other) | ||
| 686 | } | ||
| 687 | } | 662 | } |
| 688 | } | 663 | } |
| 689 | 664 | ||
| 690 | #[cfg(all( | 665 | impl<'d, T: BasicInstance> embedded_hal_nb::serial::Read for BufferedUart<'d, T> { |
| 691 | feature = "unstable-traits", | 666 | fn read(&mut self) -> Result<u8, nb::Error<Self::Error>> { |
| 692 | feature = "nightly", | 667 | embedded_hal_02::serial::Read::read(&mut self.rx) |
| 693 | feature = "_todo_embedded_hal_serial" | ||
| 694 | ))] | ||
| 695 | mod eha { | ||
| 696 | use core::future::Future; | ||
| 697 | |||
| 698 | use super::*; | ||
| 699 | |||
| 700 | impl<'d, T: BasicInstance> embedded_hal_async::serial::Write for BufferedUartTx<'d, T> { | ||
| 701 | async fn write(&mut self, buf: &[u8]) -> Result<(), Self::Error> { | ||
| 702 | Self::write(buf) | ||
| 703 | } | ||
| 704 | |||
| 705 | async fn flush(&mut self) -> Result<(), Self::Error> { | ||
| 706 | Self::flush() | ||
| 707 | } | ||
| 708 | } | ||
| 709 | |||
| 710 | impl<'d, T: BasicInstance> embedded_hal_async::serial::Read for BufferedUartRx<'d, T> { | ||
| 711 | async fn read(&mut self, buf: &mut [u8]) -> Result<(), Self::Error> { | ||
| 712 | Self::read(buf) | ||
| 713 | } | ||
| 714 | } | 668 | } |
| 669 | } | ||
| 715 | 670 | ||
| 716 | impl<'d, T: BasicInstance> embedded_hal_async::serial::Write for BufferedUart<'d, T> { | 671 | impl<'d, T: BasicInstance> embedded_hal_nb::serial::Write for BufferedUart<'d, T> { |
| 717 | async fn write(&mut self, buf: &[u8]) -> Result<(), Self::Error> { | 672 | fn write(&mut self, char: u8) -> nb::Result<(), Self::Error> { |
| 718 | self.tx.write(buf) | 673 | self.tx.blocking_write(&[char]).map(drop).map_err(nb::Error::Other) |
| 719 | } | ||
| 720 | |||
| 721 | async fn flush(&mut self) -> Result<(), Self::Error> { | ||
| 722 | self.tx.flush() | ||
| 723 | } | ||
| 724 | } | 674 | } |
| 725 | 675 | ||
| 726 | impl<'d, T: BasicInstance> embedded_hal_async::serial::Read for BufferedUart<'d, T> { | 676 | fn flush(&mut self) -> nb::Result<(), Self::Error> { |
| 727 | async fn read(&mut self, buf: &mut [u8]) -> Result<(), Self::Error> { | 677 | self.tx.blocking_flush().map_err(nb::Error::Other) |
| 728 | self.rx.read(buf) | ||
| 729 | } | ||
| 730 | } | 678 | } |
| 731 | } | 679 | } |
diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index ea127e7f7..d5828a492 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs | |||
| @@ -1010,102 +1010,93 @@ fn configure( | |||
| 1010 | Ok(()) | 1010 | Ok(()) |
| 1011 | } | 1011 | } |
| 1012 | 1012 | ||
| 1013 | mod eh02 { | 1013 | impl<'d, T: BasicInstance, RxDma> embedded_hal_02::serial::Read<u8> for UartRx<'d, T, RxDma> { |
| 1014 | use super::*; | 1014 | type Error = Error; |
| 1015 | fn read(&mut self) -> Result<u8, nb::Error<Self::Error>> { | ||
| 1016 | self.nb_read() | ||
| 1017 | } | ||
| 1018 | } | ||
| 1015 | 1019 | ||
| 1016 | impl<'d, T: BasicInstance, RxDma> embedded_hal_02::serial::Read<u8> for UartRx<'d, T, RxDma> { | 1020 | impl<'d, T: BasicInstance, TxDma> embedded_hal_02::blocking::serial::Write<u8> for UartTx<'d, T, TxDma> { |
| 1017 | type Error = Error; | 1021 | type Error = Error; |
| 1018 | fn read(&mut self) -> Result<u8, nb::Error<Self::Error>> { | 1022 | fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> { |
| 1019 | self.nb_read() | 1023 | self.blocking_write(buffer) |
| 1020 | } | 1024 | } |
| 1025 | fn bflush(&mut self) -> Result<(), Self::Error> { | ||
| 1026 | self.blocking_flush() | ||
| 1021 | } | 1027 | } |
| 1028 | } | ||
| 1022 | 1029 | ||
| 1023 | impl<'d, T: BasicInstance, TxDma> embedded_hal_02::blocking::serial::Write<u8> for UartTx<'d, T, TxDma> { | 1030 | impl<'d, T: BasicInstance, TxDma, RxDma> embedded_hal_02::serial::Read<u8> for Uart<'d, T, TxDma, RxDma> { |
| 1024 | type Error = Error; | 1031 | type Error = Error; |
| 1025 | fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> { | 1032 | fn read(&mut self) -> Result<u8, nb::Error<Self::Error>> { |
| 1026 | self.blocking_write(buffer) | 1033 | self.nb_read() |
| 1027 | } | ||
| 1028 | fn bflush(&mut self) -> Result<(), Self::Error> { | ||
| 1029 | self.blocking_flush() | ||
| 1030 | } | ||
| 1031 | } | 1034 | } |
| 1035 | } | ||
| 1032 | 1036 | ||
| 1033 | impl<'d, T: BasicInstance, TxDma, RxDma> embedded_hal_02::serial::Read<u8> for Uart<'d, T, TxDma, RxDma> { | 1037 | impl<'d, T: BasicInstance, TxDma, RxDma> embedded_hal_02::blocking::serial::Write<u8> for Uart<'d, T, TxDma, RxDma> { |
| 1034 | type Error = Error; | 1038 | type Error = Error; |
| 1035 | fn read(&mut self) -> Result<u8, nb::Error<Self::Error>> { | 1039 | fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> { |
| 1036 | self.nb_read() | 1040 | self.blocking_write(buffer) |
| 1037 | } | 1041 | } |
| 1042 | fn bflush(&mut self) -> Result<(), Self::Error> { | ||
| 1043 | self.blocking_flush() | ||
| 1038 | } | 1044 | } |
| 1045 | } | ||
| 1039 | 1046 | ||
| 1040 | impl<'d, T: BasicInstance, TxDma, RxDma> embedded_hal_02::blocking::serial::Write<u8> for Uart<'d, T, TxDma, RxDma> { | 1047 | impl embedded_hal_nb::serial::Error for Error { |
| 1041 | type Error = Error; | 1048 | fn kind(&self) -> embedded_hal_nb::serial::ErrorKind { |
| 1042 | fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> { | 1049 | match *self { |
| 1043 | self.blocking_write(buffer) | 1050 | Self::Framing => embedded_hal_nb::serial::ErrorKind::FrameFormat, |
| 1044 | } | 1051 | Self::Noise => embedded_hal_nb::serial::ErrorKind::Noise, |
| 1045 | fn bflush(&mut self) -> Result<(), Self::Error> { | 1052 | Self::Overrun => embedded_hal_nb::serial::ErrorKind::Overrun, |
| 1046 | self.blocking_flush() | 1053 | Self::Parity => embedded_hal_nb::serial::ErrorKind::Parity, |
| 1054 | Self::BufferTooLong => embedded_hal_nb::serial::ErrorKind::Other, | ||
| 1047 | } | 1055 | } |
| 1048 | } | 1056 | } |
| 1049 | } | 1057 | } |
| 1050 | 1058 | ||
| 1051 | #[cfg(feature = "unstable-traits")] | 1059 | impl<'d, T: BasicInstance, TxDma, RxDma> embedded_hal_nb::serial::ErrorType for Uart<'d, T, TxDma, RxDma> { |
| 1052 | mod eh1 { | 1060 | type Error = Error; |
| 1053 | use super::*; | 1061 | } |
| 1054 | 1062 | ||
| 1055 | impl embedded_hal_nb::serial::Error for Error { | 1063 | impl<'d, T: BasicInstance, TxDma> embedded_hal_nb::serial::ErrorType for UartTx<'d, T, TxDma> { |
| 1056 | fn kind(&self) -> embedded_hal_nb::serial::ErrorKind { | 1064 | type Error = Error; |
| 1057 | match *self { | 1065 | } |
| 1058 | Self::Framing => embedded_hal_nb::serial::ErrorKind::FrameFormat, | ||
| 1059 | Self::Noise => embedded_hal_nb::serial::ErrorKind::Noise, | ||
| 1060 | Self::Overrun => embedded_hal_nb::serial::ErrorKind::Overrun, | ||
| 1061 | Self::Parity => embedded_hal_nb::serial::ErrorKind::Parity, | ||
| 1062 | Self::BufferTooLong => embedded_hal_nb::serial::ErrorKind::Other, | ||
| 1063 | } | ||
| 1064 | } | ||
| 1065 | } | ||
| 1066 | 1066 | ||
| 1067 | impl<'d, T: BasicInstance, TxDma, RxDma> embedded_hal_nb::serial::ErrorType for Uart<'d, T, TxDma, RxDma> { | 1067 | impl<'d, T: BasicInstance, RxDma> embedded_hal_nb::serial::ErrorType for UartRx<'d, T, RxDma> { |
| 1068 | type Error = Error; | 1068 | type Error = Error; |
| 1069 | } | 1069 | } |
| 1070 | 1070 | ||
| 1071 | impl<'d, T: BasicInstance, TxDma> embedded_hal_nb::serial::ErrorType for UartTx<'d, T, TxDma> { | 1071 | impl<'d, T: BasicInstance, RxDma> embedded_hal_nb::serial::Read for UartRx<'d, T, RxDma> { |
| 1072 | type Error = Error; | 1072 | fn read(&mut self) -> nb::Result<u8, Self::Error> { |
| 1073 | self.nb_read() | ||
| 1073 | } | 1074 | } |
| 1075 | } | ||
| 1074 | 1076 | ||
| 1075 | impl<'d, T: BasicInstance, RxDma> embedded_hal_nb::serial::ErrorType for UartRx<'d, T, RxDma> { | 1077 | impl<'d, T: BasicInstance, TxDma> embedded_hal_nb::serial::Write for UartTx<'d, T, TxDma> { |
| 1076 | type Error = Error; | 1078 | fn write(&mut self, char: u8) -> nb::Result<(), Self::Error> { |
| 1079 | self.blocking_write(&[char]).map_err(nb::Error::Other) | ||
| 1077 | } | 1080 | } |
| 1078 | 1081 | ||
| 1079 | impl<'d, T: BasicInstance, RxDma> embedded_hal_nb::serial::Read for UartRx<'d, T, RxDma> { | 1082 | fn flush(&mut self) -> nb::Result<(), Self::Error> { |
| 1080 | fn read(&mut self) -> nb::Result<u8, Self::Error> { | 1083 | self.blocking_flush().map_err(nb::Error::Other) |
| 1081 | self.nb_read() | ||
| 1082 | } | ||
| 1083 | } | 1084 | } |
| 1085 | } | ||
| 1084 | 1086 | ||
| 1085 | impl<'d, T: BasicInstance, TxDma> embedded_hal_nb::serial::Write for UartTx<'d, T, TxDma> { | 1087 | impl<'d, T: BasicInstance, TxDma, RxDma> embedded_hal_nb::serial::Read for Uart<'d, T, TxDma, RxDma> { |
| 1086 | fn write(&mut self, char: u8) -> nb::Result<(), Self::Error> { | 1088 | fn read(&mut self) -> Result<u8, nb::Error<Self::Error>> { |
| 1087 | self.blocking_write(&[char]).map_err(nb::Error::Other) | 1089 | self.nb_read() |
| 1088 | } | ||
| 1089 | |||
| 1090 | fn flush(&mut self) -> nb::Result<(), Self::Error> { | ||
| 1091 | self.blocking_flush().map_err(nb::Error::Other) | ||
| 1092 | } | ||
| 1093 | } | 1090 | } |
| 1091 | } | ||
| 1094 | 1092 | ||
| 1095 | impl<'d, T: BasicInstance, TxDma, RxDma> embedded_hal_nb::serial::Read for Uart<'d, T, TxDma, RxDma> { | 1093 | impl<'d, T: BasicInstance, TxDma, RxDma> embedded_hal_nb::serial::Write for Uart<'d, T, TxDma, RxDma> { |
| 1096 | fn read(&mut self) -> Result<u8, nb::Error<Self::Error>> { | 1094 | fn write(&mut self, char: u8) -> nb::Result<(), Self::Error> { |
| 1097 | self.nb_read() | 1095 | self.blocking_write(&[char]).map_err(nb::Error::Other) |
| 1098 | } | ||
| 1099 | } | 1096 | } |
| 1100 | 1097 | ||
| 1101 | impl<'d, T: BasicInstance, TxDma, RxDma> embedded_hal_nb::serial::Write for Uart<'d, T, TxDma, RxDma> { | 1098 | fn flush(&mut self) -> nb::Result<(), Self::Error> { |
| 1102 | fn write(&mut self, char: u8) -> nb::Result<(), Self::Error> { | 1099 | self.blocking_flush().map_err(nb::Error::Other) |
| 1103 | self.blocking_write(&[char]).map_err(nb::Error::Other) | ||
| 1104 | } | ||
| 1105 | |||
| 1106 | fn flush(&mut self) -> nb::Result<(), Self::Error> { | ||
| 1107 | self.blocking_flush().map_err(nb::Error::Other) | ||
| 1108 | } | ||
| 1109 | } | 1100 | } |
| 1110 | } | 1101 | } |
| 1111 | 1102 | ||
| @@ -1159,47 +1150,39 @@ where | |||
| 1159 | } | 1150 | } |
| 1160 | } | 1151 | } |
| 1161 | 1152 | ||
| 1162 | #[cfg(all(feature = "unstable-traits", feature = "nightly"))] | 1153 | impl<T, TxDma, RxDma> embedded_io_async::Write for Uart<'_, T, TxDma, RxDma> |
| 1163 | mod eio { | 1154 | where |
| 1164 | use super::*; | 1155 | T: BasicInstance, |
| 1165 | 1156 | TxDma: self::TxDma<T>, | |
| 1166 | impl<T, TxDma, RxDma> embedded_io_async::Write for Uart<'_, T, TxDma, RxDma> | 1157 | { |
| 1167 | where | 1158 | async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> { |
| 1168 | T: BasicInstance, | 1159 | self.write(buf).await?; |
| 1169 | TxDma: super::TxDma<T>, | 1160 | Ok(buf.len()) |
| 1170 | { | 1161 | } |
| 1171 | async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> { | ||
| 1172 | self.write(buf).await?; | ||
| 1173 | Ok(buf.len()) | ||
| 1174 | } | ||
| 1175 | 1162 | ||
| 1176 | async fn flush(&mut self) -> Result<(), Self::Error> { | 1163 | async fn flush(&mut self) -> Result<(), Self::Error> { |
| 1177 | self.blocking_flush() | 1164 | self.blocking_flush() |
| 1178 | } | ||
| 1179 | } | 1165 | } |
| 1166 | } | ||
| 1180 | 1167 | ||
| 1181 | impl<T, TxDma> embedded_io_async::Write for UartTx<'_, T, TxDma> | 1168 | impl<T, TxDma> embedded_io_async::Write for UartTx<'_, T, TxDma> |
| 1182 | where | 1169 | where |
| 1183 | T: BasicInstance, | 1170 | T: BasicInstance, |
| 1184 | TxDma: super::TxDma<T>, | 1171 | TxDma: self::TxDma<T>, |
| 1185 | { | 1172 | { |
| 1186 | async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> { | 1173 | async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> { |
| 1187 | self.write(buf).await?; | 1174 | self.write(buf).await?; |
| 1188 | Ok(buf.len()) | 1175 | Ok(buf.len()) |
| 1189 | } | 1176 | } |
| 1190 | 1177 | ||
| 1191 | async fn flush(&mut self) -> Result<(), Self::Error> { | 1178 | async fn flush(&mut self) -> Result<(), Self::Error> { |
| 1192 | self.blocking_flush() | 1179 | self.blocking_flush() |
| 1193 | } | ||
| 1194 | } | 1180 | } |
| 1195 | } | 1181 | } |
| 1196 | 1182 | ||
| 1197 | #[cfg(feature = "nightly")] | ||
| 1198 | pub use buffered::*; | 1183 | pub use buffered::*; |
| 1199 | 1184 | ||
| 1200 | #[cfg(feature = "nightly")] | ||
| 1201 | pub use crate::usart::buffered::InterruptHandler as BufferedInterruptHandler; | 1185 | pub use crate::usart::buffered::InterruptHandler as BufferedInterruptHandler; |
| 1202 | #[cfg(feature = "nightly")] | ||
| 1203 | mod buffered; | 1186 | mod buffered; |
| 1204 | 1187 | ||
| 1205 | #[cfg(not(gpdma))] | 1188 | #[cfg(not(gpdma))] |
| @@ -1284,7 +1267,6 @@ pub(crate) mod sealed { | |||
| 1284 | fn regs() -> Regs; | 1267 | fn regs() -> Regs; |
| 1285 | fn state() -> &'static State; | 1268 | fn state() -> &'static State; |
| 1286 | 1269 | ||
| 1287 | #[cfg(feature = "nightly")] | ||
| 1288 | fn buffered_state() -> &'static buffered::State; | 1270 | fn buffered_state() -> &'static buffered::State; |
| 1289 | } | 1271 | } |
| 1290 | 1272 | ||
| @@ -1322,7 +1304,6 @@ macro_rules! impl_usart { | |||
| 1322 | &STATE | 1304 | &STATE |
| 1323 | } | 1305 | } |
| 1324 | 1306 | ||
| 1325 | #[cfg(feature = "nightly")] | ||
| 1326 | fn buffered_state() -> &'static buffered::State { | 1307 | fn buffered_state() -> &'static buffered::State { |
| 1327 | static STATE: buffered::State = buffered::State::new(); | 1308 | static STATE: buffered::State = buffered::State::new(); |
| 1328 | &STATE | 1309 | &STATE |
diff --git a/embassy-stm32/src/usart/ringbuffered.rs b/embassy-stm32/src/usart/ringbuffered.rs index eceabbe9a..b8d17e4e4 100644 --- a/embassy-stm32/src/usart/ringbuffered.rs +++ b/embassy-stm32/src/usart/ringbuffered.rs | |||
| @@ -7,7 +7,7 @@ use embassy_embedded_hal::SetConfig; | |||
| 7 | use embassy_hal_internal::PeripheralRef; | 7 | use embassy_hal_internal::PeripheralRef; |
| 8 | use futures::future::{select, Either}; | 8 | use futures::future::{select, Either}; |
| 9 | 9 | ||
| 10 | use super::{clear_interrupt_flags, rdr, reconfigure, sr, BasicInstance, Config, ConfigError, Error, UartRx}; | 10 | use super::{clear_interrupt_flags, rdr, reconfigure, sr, BasicInstance, Config, ConfigError, Error, RxDma, UartRx}; |
| 11 | use crate::dma::ReadableRingBuffer; | 11 | use crate::dma::ReadableRingBuffer; |
| 12 | use crate::usart::{Regs, Sr}; | 12 | use crate::usart::{Regs, Sr}; |
| 13 | 13 | ||
| @@ -240,28 +240,20 @@ fn clear_idle_flag(r: Regs) -> Sr { | |||
| 240 | sr | 240 | sr |
| 241 | } | 241 | } |
| 242 | 242 | ||
| 243 | #[cfg(all(feature = "unstable-traits", feature = "nightly"))] | 243 | impl<T, Rx> embedded_io_async::ErrorType for RingBufferedUartRx<'_, T, Rx> |
| 244 | mod eio { | 244 | where |
| 245 | use embedded_io_async::{ErrorType, Read}; | 245 | T: BasicInstance, |
| 246 | 246 | Rx: RxDma<T>, | |
| 247 | use super::RingBufferedUartRx; | 247 | { |
| 248 | use crate::usart::{BasicInstance, Error, RxDma}; | 248 | type Error = Error; |
| 249 | 249 | } | |
| 250 | impl<T, Rx> ErrorType for RingBufferedUartRx<'_, T, Rx> | ||
| 251 | where | ||
| 252 | T: BasicInstance, | ||
| 253 | Rx: RxDma<T>, | ||
| 254 | { | ||
| 255 | type Error = Error; | ||
| 256 | } | ||
| 257 | 250 | ||
| 258 | impl<T, Rx> Read for RingBufferedUartRx<'_, T, Rx> | 251 | impl<T, Rx> embedded_io_async::Read for RingBufferedUartRx<'_, T, Rx> |
| 259 | where | 252 | where |
| 260 | T: BasicInstance, | 253 | T: BasicInstance, |
| 261 | Rx: RxDma<T>, | 254 | Rx: RxDma<T>, |
| 262 | { | 255 | { |
| 263 | async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> { | 256 | async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> { |
| 264 | self.read(buf).await | 257 | self.read(buf).await |
| 265 | } | ||
| 266 | } | 258 | } |
| 267 | } | 259 | } |
diff --git a/embassy-stm32/src/usb/mod.rs b/embassy-stm32/src/usb/mod.rs index bee287fe6..d0b289462 100644 --- a/embassy-stm32/src/usb/mod.rs +++ b/embassy-stm32/src/usb/mod.rs | |||
| @@ -1,9 +1,7 @@ | |||
| 1 | use crate::interrupt; | 1 | use crate::interrupt; |
| 2 | use crate::rcc::RccPeripheral; | 2 | use crate::rcc::RccPeripheral; |
| 3 | 3 | ||
| 4 | #[cfg(feature = "nightly")] | ||
| 5 | mod usb; | 4 | mod usb; |
| 6 | #[cfg(feature = "nightly")] | ||
| 7 | pub use usb::*; | 5 | pub use usb::*; |
| 8 | 6 | ||
| 9 | pub(crate) mod sealed { | 7 | pub(crate) mod sealed { |
diff --git a/embassy-stm32/src/usb_otg/mod.rs b/embassy-stm32/src/usb_otg/mod.rs index 12e5f0e60..be54a3d10 100644 --- a/embassy-stm32/src/usb_otg/mod.rs +++ b/embassy-stm32/src/usb_otg/mod.rs | |||
| @@ -1,13 +1,10 @@ | |||
| 1 | use crate::rcc::RccPeripheral; | 1 | use crate::rcc::RccPeripheral; |
| 2 | use crate::{interrupt, peripherals}; | 2 | use crate::{interrupt, peripherals}; |
| 3 | 3 | ||
| 4 | #[cfg(feature = "nightly")] | ||
| 5 | mod usb; | 4 | mod usb; |
| 6 | #[cfg(feature = "nightly")] | ||
| 7 | pub use usb::*; | 5 | pub use usb::*; |
| 8 | 6 | ||
| 9 | // Using Instance::ENDPOINT_COUNT requires feature(const_generic_expr) so just define maximum eps | 7 | // Using Instance::ENDPOINT_COUNT requires feature(const_generic_expr) so just define maximum eps |
| 10 | #[cfg(feature = "nightly")] | ||
| 11 | const MAX_EP_COUNT: usize = 9; | 8 | const MAX_EP_COUNT: usize = 9; |
| 12 | 9 | ||
| 13 | pub(crate) mod sealed { | 10 | pub(crate) mod sealed { |
| @@ -17,7 +14,6 @@ pub(crate) mod sealed { | |||
| 17 | const ENDPOINT_COUNT: usize; | 14 | const ENDPOINT_COUNT: usize; |
| 18 | 15 | ||
| 19 | fn regs() -> crate::pac::otg::Otg; | 16 | fn regs() -> crate::pac::otg::Otg; |
| 20 | #[cfg(feature = "nightly")] | ||
| 21 | fn state() -> &'static super::State<{ super::MAX_EP_COUNT }>; | 17 | fn state() -> &'static super::State<{ super::MAX_EP_COUNT }>; |
| 22 | } | 18 | } |
| 23 | } | 19 | } |
| @@ -99,8 +95,7 @@ foreach_interrupt!( | |||
| 99 | crate::pac::USB_OTG_FS | 95 | crate::pac::USB_OTG_FS |
| 100 | } | 96 | } |
| 101 | 97 | ||
| 102 | #[cfg(feature = "nightly")] | 98 | fn state() -> &'static State<MAX_EP_COUNT> { |
| 103 | fn state() -> &'static State<MAX_EP_COUNT> { | ||
| 104 | static STATE: State<MAX_EP_COUNT> = State::new(); | 99 | static STATE: State<MAX_EP_COUNT> = State::new(); |
| 105 | &STATE | 100 | &STATE |
| 106 | } | 101 | } |
| @@ -151,8 +146,7 @@ foreach_interrupt!( | |||
| 151 | unsafe { crate::pac::otg::Otg::from_ptr(crate::pac::USB_OTG_HS.as_ptr()) } | 146 | unsafe { crate::pac::otg::Otg::from_ptr(crate::pac::USB_OTG_HS.as_ptr()) } |
| 152 | } | 147 | } |
| 153 | 148 | ||
| 154 | #[cfg(feature = "nightly")] | 149 | fn state() -> &'static State<MAX_EP_COUNT> { |
| 155 | fn state() -> &'static State<MAX_EP_COUNT> { | ||
| 156 | static STATE: State<MAX_EP_COUNT> = State::new(); | 150 | static STATE: State<MAX_EP_COUNT> = State::new(); |
| 157 | &STATE | 151 | &STATE |
| 158 | } | 152 | } |
