Try using cfg! macro

This commit is contained in:
Andres Oliva 2023-10-11 23:32:40 +02:00
parent cd68f85501
commit 251d004708

View File

@ -755,11 +755,12 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
}
pub fn blocking_read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Error> {
#[cfg(feature = "time")]
if cfg!(feature = "time") {
self.blocking_read_timeout(address, read, self.timeout)
#[cfg(not(feature = "time"))]
} else {
self.blocking_read_timeout(address, read, || Ok(()))
}
}
#[cfg(feature = "time")]
pub fn blocking_write_timeout(&mut self, address: u8, write: &[u8], timeout: Duration) -> Result<(), Error> {
@ -772,11 +773,12 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
}
pub fn blocking_write(&mut self, address: u8, write: &[u8]) -> Result<(), Error> {
#[cfg(feature = "time")]
if cfg!(feature = "time") {
self.blocking_write_timeout(address, write, self.timeout)
#[cfg(not(feature = "time"))]
} else {
self.blocking_write_timeout(address, write, || Ok(()))
}
}
#[cfg(feature = "time")]
pub fn blocking_write_read_timeout(
@ -807,11 +809,12 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
}
pub fn blocking_write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Error> {
#[cfg(feature = "time")]
if cfg!(feature = "time") {
self.blocking_write_read_timeout(address, write, read, self.timeout)
#[cfg(not(feature = "time"))]
} else {
self.blocking_write_read_timeout(address, write, read, || Ok(()))
}
}
fn blocking_write_vectored_with_timeout(
&mut self,
@ -913,12 +916,13 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
}
pub fn blocking_write_vectored(&mut self, address: u8, write: &[&[u8]]) -> Result<(), Error> {
#[cfg(feature = "time")]
if cfg!(feature = "time") {
self.blocking_write_vectored_timeout(address, write, self.timeout)
#[cfg(not(feature = "time"))]
} else {
self.blocking_write_vectored_timeout(address, write, || Ok(()))
}
}
}
impl<'d, T: Instance, TXDMA, RXDMA> Drop for I2c<'d, T, TXDMA, RXDMA> {
fn drop(&mut self) {