embedded_interfaces/commands/
spi.rs

1use crate::{TransportError, commands::Command};
2
3#[maybe_async_cfg::maybe(
4    idents(hal(sync = "embedded_hal", async = "embedded_hal_async")),
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    /// Execute the given command through the given SPI interface
12    async fn execute<D, I>(
13        delay: &mut D,
14        interface: &mut I,
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::spi::r#SpiDevice;
20}
21
22#[maybe_async_cfg::maybe(
23    idents(hal(sync = "embedded_hal", async = "embedded_hal_async"), Executor, CommandInterface),
24    sync(feature = "sync"),
25    async(feature = "async")
26)]
27impl<I> crate::commands::CommandInterface for crate::spi::SpiDevice<I>
28where
29    I: hal::spi::r#SpiDevice,
30{
31    type BusError = I::Error;
32
33    /// Executes the given command through this interface
34    #[inline]
35    async fn execute<C, D>(
36        &mut self,
37        delay: &mut D,
38        input: C::In,
39    ) -> Result<C::Out, TransportError<C::ExecutorError, Self::BusError>>
40    where
41        D: hal::delay::DelayNs,
42        C: Command,
43    {
44        <C::SpiExecutor as Executor>::execute::<D, I>(delay, &mut self.interface, input).await
45    }
46}