aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/spi/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-stm32/src/spi/mod.rs')
-rw-r--r--embassy-stm32/src/spi/mod.rs134
1 files changed, 60 insertions, 74 deletions
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
851mod 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 853macro_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")] 874impl_blocking!(u8);
882mod eh1 { 875impl_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> { 877impl<'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> { 881impl<'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 { 903impl 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"))] 914impl<'d, T: Instance, Tx: TxDma<T>, Rx: RxDma<T>, W: Word> embedded_hal_async::spi::SpiBus<W> for Spi<'d, T, Tx, Rx> {
924mod 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