use core::fmt::Debug;
pub use crate::i2c::{I2CInterface, SlaveAddr};
pub use crate::spi::{SPIBusInterface, SPIInterface};
#[cfg(feature = "async")]
#[allow(async_fn_in_trait)]
pub trait Interface {
type Error: Debug;
async fn write_read(&mut self, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error>;
async fn write(&mut self, data: &[u8]) -> Result<(), Self::Error>;
}
#[cfg(feature = "async")]
impl<I: Interface> Interface for &mut I {
type Error = I::Error;
async fn write_read(&mut self, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> {
I::write_read(self, write, read).await
}
async fn write(&mut self, data: &[u8]) -> Result<(), Self::Error> {
I::write(self, data).await
}
}
#[cfg(feature = "blocking")]
pub trait Interface {
type Error: Debug;
fn write_read(&mut self, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error>;
fn write(&mut self, data: &[u8]) -> Result<(), Self::Error>;
}
#[cfg(feature = "blocking")]
impl<I: Interface> Interface for &mut I {
type Error = I::Error;
fn write_read(&mut self, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> {
I::write_read(self, write, read)
}
fn write(&mut self, data: &[u8]) -> Result<(), Self::Error> {
I::write(self, data)
}
}