diff options
| author | Andres Oliva <[email protected]> | 2023-10-11 23:39:24 +0200 |
|---|---|---|
| committer | Andres Oliva <[email protected]> | 2023-10-11 23:39:24 +0200 |
| commit | f76d50e837cab098cd255c15ee0655c8d3ffb55b (patch) | |
| tree | dbe9c9a5b85e80aa79fe6112238a3d31b25da74b /embassy-stm32 | |
| parent | ee5ea7aa06491a2bbd523ac054604977cb0c9e33 (diff) | |
cfg! macro didn't work, had to duplicate functions with different guards
Diffstat (limited to 'embassy-stm32')
| -rw-r--r-- | embassy-stm32/src/i2c/v2.rs | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs index 093b960d8..926a3f7a1 100644 --- a/embassy-stm32/src/i2c/v2.rs +++ b/embassy-stm32/src/i2c/v2.rs | |||
| @@ -7,6 +7,7 @@ use embassy_embedded_hal::SetConfig; | |||
| 7 | use embassy_hal_internal::drop::OnDrop; | 7 | use embassy_hal_internal::drop::OnDrop; |
| 8 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 8 | use embassy_hal_internal::{into_ref, PeripheralRef}; |
| 9 | use embassy_sync::waitqueue::AtomicWaker; | 9 | use embassy_sync::waitqueue::AtomicWaker; |
| 10 | #[cfg(feature = "time")] | ||
| 10 | use embassy_time::{Duration, Instant}; | 11 | use embassy_time::{Duration, Instant}; |
| 11 | 12 | ||
| 12 | use crate::dma::{NoDma, Transfer}; | 13 | use crate::dma::{NoDma, Transfer}; |
| @@ -759,12 +760,14 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { | |||
| 759 | // Automatic Stop | 760 | // Automatic Stop |
| 760 | } | 761 | } |
| 761 | 762 | ||
| 763 | #[cfg(feature = "time")] | ||
| 762 | pub fn blocking_read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Error> { | 764 | pub fn blocking_read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Error> { |
| 763 | if cfg!(feature = "time") { | 765 | self.blocking_read_timeout(address, read, self.timeout) |
| 764 | self.blocking_read_timeout(address, read, self.timeout) | 766 | } |
| 765 | } else { | 767 | |
| 766 | self.blocking_read_timeout(address, read, || Ok(())) | 768 | #[cfg(not(feature = "time"))] |
| 767 | } | 769 | pub fn blocking_read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Error> { |
| 770 | self.blocking_read_timeout(address, read, || Ok(())) | ||
| 768 | } | 771 | } |
| 769 | 772 | ||
| 770 | #[cfg(feature = "time")] | 773 | #[cfg(feature = "time")] |
| @@ -782,12 +785,14 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { | |||
| 782 | self.write_internal(address, write, true, check_timeout) | 785 | self.write_internal(address, write, true, check_timeout) |
| 783 | } | 786 | } |
| 784 | 787 | ||
| 788 | #[cfg(feature = "time")] | ||
| 785 | pub fn blocking_write(&mut self, address: u8, write: &[u8]) -> Result<(), Error> { | 789 | pub fn blocking_write(&mut self, address: u8, write: &[u8]) -> Result<(), Error> { |
| 786 | if cfg!(feature = "time") { | 790 | self.blocking_write_timeout(address, write, self.timeout) |
| 787 | self.blocking_write_timeout(address, write, self.timeout) | 791 | } |
| 788 | } else { | 792 | |
| 789 | self.blocking_write_timeout(address, write, || Ok(())) | 793 | #[cfg(not(feature = "time"))] |
| 790 | } | 794 | pub fn blocking_write(&mut self, address: u8, write: &[u8]) -> Result<(), Error> { |
| 795 | self.blocking_write_timeout(address, write, || Ok(())) | ||
| 791 | } | 796 | } |
| 792 | 797 | ||
| 793 | #[cfg(feature = "time")] | 798 | #[cfg(feature = "time")] |
| @@ -812,18 +817,19 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { | |||
| 812 | read: &mut [u8], | 817 | read: &mut [u8], |
| 813 | check_timeout: impl Fn() -> Result<(), Error>, | 818 | check_timeout: impl Fn() -> Result<(), Error>, |
| 814 | ) -> Result<(), Error> { | 819 | ) -> Result<(), Error> { |
| 815 | let check_timeout = timeout_fn(timeout); | ||
| 816 | self.write_internal(address, write, false, &check_timeout)?; | 820 | self.write_internal(address, write, false, &check_timeout)?; |
| 817 | self.read_internal(address, read, true, &check_timeout) | 821 | self.read_internal(address, read, true, &check_timeout) |
| 818 | // Automatic Stop | 822 | // Automatic Stop |
| 819 | } | 823 | } |
| 820 | 824 | ||
| 825 | #[cfg(feature = "time")] | ||
| 821 | pub fn blocking_write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Error> { | 826 | pub fn blocking_write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Error> { |
| 822 | if cfg!(feature = "time") { | 827 | self.blocking_write_read_timeout(address, write, read, self.timeout) |
| 823 | self.blocking_write_read_timeout(address, write, read, self.timeout) | 828 | } |
| 824 | } else { | 829 | |
| 825 | self.blocking_write_read_timeout(address, write, read, || Ok(())) | 830 | #[cfg(not(feature = "time"))] |
| 826 | } | 831 | pub fn blocking_write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Error> { |
| 832 | self.blocking_write_read_timeout(address, write, read, || Ok(())) | ||
| 827 | } | 833 | } |
| 828 | 834 | ||
| 829 | fn blocking_write_vectored_with_timeout( | 835 | fn blocking_write_vectored_with_timeout( |
| @@ -925,12 +931,14 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { | |||
| 925 | self.blocking_write_vectored_with_timeout(address, write, check_timeout) | 931 | self.blocking_write_vectored_with_timeout(address, write, check_timeout) |
| 926 | } | 932 | } |
| 927 | 933 | ||
| 934 | #[cfg(feature = "time")] | ||
| 928 | pub fn blocking_write_vectored(&mut self, address: u8, write: &[&[u8]]) -> Result<(), Error> { | 935 | pub fn blocking_write_vectored(&mut self, address: u8, write: &[&[u8]]) -> Result<(), Error> { |
| 929 | if cfg!(feature = "time") { | 936 | self.blocking_write_vectored_timeout(address, write, self.timeout) |
| 930 | self.blocking_write_vectored_timeout(address, write, self.timeout) | 937 | } |
| 931 | } else { | 938 | |
| 932 | self.blocking_write_vectored_timeout(address, write, || Ok(())) | 939 | #[cfg(not(feature = "time"))] |
| 933 | } | 940 | pub fn blocking_write_vectored(&mut self, address: u8, write: &[&[u8]]) -> Result<(), Error> { |
| 941 | self.blocking_write_vectored_timeout(address, write, || Ok(())) | ||
| 934 | } | 942 | } |
| 935 | } | 943 | } |
| 936 | 944 | ||
