stm32: i2c: Clean up conditional code a bit
By moving conditional code inside the functions, we can reduce duplication and in one case we can even eliminate one...
This commit is contained in:
parent
565ed78f91
commit
f993344b19
@ -148,31 +148,20 @@ struct Timeout {
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl Timeout {
|
||||
#[cfg(not(feature = "time"))]
|
||||
#[inline]
|
||||
fn check(self) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "time")]
|
||||
#[inline]
|
||||
fn check(self) -> Result<(), Error> {
|
||||
if Instant::now() > self.deadline {
|
||||
Err(Error::Timeout)
|
||||
} else {
|
||||
return Err(Error::Timeout);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "time"))]
|
||||
#[inline]
|
||||
fn with<R>(self, fut: impl Future<Output = Result<R, Error>>) -> impl Future<Output = Result<R, Error>> {
|
||||
fut
|
||||
}
|
||||
|
||||
#[cfg(feature = "time")]
|
||||
#[inline]
|
||||
fn with<R>(self, fut: impl Future<Output = Result<R, Error>>) -> impl Future<Output = Result<R, Error>> {
|
||||
{
|
||||
use futures::FutureExt;
|
||||
|
||||
embassy_futures::select::select(embassy_time::Timer::at(self.deadline), fut).map(|r| match r {
|
||||
@ -180,6 +169,10 @@ impl Timeout {
|
||||
embassy_futures::select::Either::Second(r) => r,
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "time"))]
|
||||
fut
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) mod sealed {
|
||||
|
Loading…
Reference in New Issue
Block a user