use crate::{MaybeBitdumpFormattable, TransportError};
pub mod i2c;
pub mod spi;
pub mod unsupported_executor;
pub trait Executor {
type Command: Command;
type Error: core::fmt::Debug;
}
pub trait Command {
type In: bytemuck::Pod + MaybeBitdumpFormattable;
type Out: bytemuck::Pod + bytemuck::Zeroable + MaybeBitdumpFormattable;
type ExecutorError: core::fmt::Debug;
#[cfg(all(feature = "sync", not(feature = "async")))]
type SpiExecutor: spi::ExecutorSync<Command = Self, Error = Self::ExecutorError>;
#[cfg(all(not(feature = "sync"), feature = "async"))]
type SpiExecutor: spi::ExecutorAsync<Command = Self, Error = Self::ExecutorError>;
#[cfg(all(feature = "sync", feature = "async"))]
type SpiExecutor: spi::ExecutorSync<Command = Self, Error = Self::ExecutorError>
+ spi::ExecutorAsync<Command = Self, Error = Self::ExecutorError>;
#[cfg(all(feature = "sync", not(feature = "async")))]
type I2cExecutor: i2c::ExecutorSync<Command = Self, Error = Self::ExecutorError>;
#[cfg(all(not(feature = "sync"), feature = "async"))]
type I2cExecutor: i2c::ExecutorAsync<Command = Self, Error = Self::ExecutorError>;
#[cfg(all(feature = "sync", feature = "async"))]
type I2cExecutor: i2c::ExecutorSync<Command = Self, Error = Self::ExecutorError>
+ i2c::ExecutorAsync<Command = Self, Error = Self::ExecutorError>;
}
#[maybe_async_cfg::maybe(
idents(hal(sync = "embedded_hal", async = "embedded_hal_async")),
sync(feature = "sync"),
async(feature = "async")
)]
#[allow(async_fn_in_trait)]
pub trait CommandInterface {
type BusError: core::fmt::Debug;
async fn execute<C, D>(
&mut self,
delay: &mut D,
input: C::In,
) -> Result<C::Out, TransportError<C::ExecutorError, Self::BusError>>
where
D: hal::delay::DelayNs,
C: Command;
}
#[macro_export]
macro_rules! define_executor {
($executor:ident, $command_trait:ident, $error_type:ty) => {
#[doc = "The executor for any [`"]
#[doc = stringify!($command_trait)]
#[doc = "`]"]
pub struct $executor<C: $command_trait + ?Sized> {
_marker: PhantomData<C>,
}
impl<C: $command_trait> embedded_interfaces::commands::Executor for $executor<C> {
type Error = $error_type;
type Command = C;
}
};
}