Add Interface trait

This commit is contained in:
Vadim Kaushan 2020-01-28 19:45:23 +03:00
parent 1956825a8e
commit f09403d092
No known key found for this signature in database
GPG key ID: A501C5DF67C05C4E

View file

@ -13,6 +13,24 @@ use hal::spi::{Mode, Phase, Polarity};
use core::fmt::Debug; use core::fmt::Debug;
use core::iter::IntoIterator; use core::iter::IntoIterator;
/// Trait representing the interface to the hardware.
///
/// Intended to abstract the various buses (SPI, MPU 8/9/16-bit) from the Controller code.
pub trait Interface {
type Error;
/// Sends a command with a sequence of 8-bit arguments
///
/// Mostly used for sending configuration commands
fn write(&mut self, command: u8, data: &[u8]) -> Result<(), Self::Error>;
/// Sends a command with a sequence of 16-bit data words
///
/// Mostly used for sending MemoryWrite command and other commands
/// with 16-bit arguments
fn write_iter(&mut self, command: u8, data: impl IntoIterator<Item = u16>) -> Result<(), Self::Error>;
}
/// SPI mode /// SPI mode
pub const MODE: Mode = Mode { pub const MODE: Mode = Mode {
polarity: Polarity::IdleLow, polarity: Polarity::IdleLow,