use crate::{private, Error};
use embedded_hal::spi::SpiDevice;
#[derive(Debug, Default)]
pub struct SpiInterface<SPI> {
pub(crate) spi: SPI,
}
pub trait WriteCommand: private::Sealed {
type Error;
fn write_command(&mut self, command: u8, data: u8) -> Result<(), Self::Error>;
}
impl<SPI, E> WriteCommand for SpiInterface<SPI>
where
SPI: SpiDevice<Error = E>,
{
type Error = Error<E>;
fn write_command(&mut self, command: u8, data: u8) -> Result<(), Error<E>> {
let payload: [u8; 2] = [command, data];
self.spi.write(&payload).map_err(Error::Comm)
}
}