embedded_interfaces/commands/
i2c.rs1use crate::{TransportError, commands::Command};
2
3#[maybe_async_cfg::maybe(
4 idents(hal(sync = "embedded_hal", async = "embedded_hal_async"), I2cBoundBus),
5 sync(feature = "sync"),
6 async(feature = "async")
7)]
8#[allow(async_fn_in_trait)]
9#[allow(clippy::type_complexity)]
10pub trait Executor: crate::commands::r#Executor {
11 async fn execute<D, I, A>(
13 delay: &mut D,
14 bound_bus: &mut crate::i2c::I2cBoundBus<I, A>,
15 input: <Self::Command as Command>::In,
16 ) -> Result<<Self::Command as Command>::Out, TransportError<Self::Error, I::Error>>
17 where
18 D: hal::delay::DelayNs,
19 I: hal::i2c::I2c<A> + hal::i2c::ErrorType,
20 A: hal::i2c::AddressMode + Copy + core::fmt::Debug;
21}
22
23#[maybe_async_cfg::maybe(
24 idents(hal(sync = "embedded_hal", async = "embedded_hal_async"), Executor, CommandInterface),
25 sync(feature = "sync"),
26 async(feature = "async")
27)]
28impl<I, A> crate::commands::CommandInterface for crate::i2c::I2cDevice<I, A>
29where
30 I: hal::i2c::I2c<A> + hal::i2c::ErrorType,
31 A: hal::i2c::AddressMode + Copy + core::fmt::Debug,
32{
33 type BusError = I::Error;
34
35 #[inline]
37 async fn execute<C, D>(
38 &mut self,
39 delay: &mut D,
40 input: C::In,
41 ) -> Result<C::Out, TransportError<C::ExecutorError, Self::BusError>>
42 where
43 D: hal::delay::DelayNs,
44 C: Command,
45 {
46 <C::I2cExecutor as Executor>::execute::<D, I, A>(delay, &mut self.bound_bus, input).await
47 }
48}