Added bus model and InactiveW5500 state

This commit is contained in:
Jonah Dahlquist 2019-08-06 21:47:30 -05:00 committed by Jonah Dahlquist
commit a43f86d744
7 changed files with 130 additions and 40 deletions

View file

@ -1,19 +1,30 @@
use embedded_hal::spi::FullDuplex;
use crate::bus::Bus;
use crate::bus::{ActiveBus, Bus};
pub struct ThreeWire {}
impl ThreeWire {
pub fn new() -> Self {
Self { }
Self {}
}
}
impl<Spi: FullDuplex<u8>> Bus<Spi> for ThreeWire {
impl Bus for ThreeWire {}
impl ThreeWire {
pub fn activate<Spi: FullDuplex<u8>>(self, spi: Spi) -> ActiveThreeWire<Spi> {
ActiveThreeWire { spi }
}
}
pub struct ActiveThreeWire<Spi: FullDuplex<u8>> {
spi: Spi,
}
impl<Spi: FullDuplex<u8>> ActiveBus for ActiveThreeWire<Spi> {
type Error = Spi::Error;
fn transfer_frame<'a, 'b>(
spi: &'b mut Spi,
fn transfer_frame<'a>(
address_phase: [u8; 2],
control_phase: u8,
data_phase: &'a mut [u8],
@ -22,3 +33,9 @@ impl<Spi: FullDuplex<u8>> Bus<Spi> for ThreeWire {
Ok(data_phase)
}
}
impl<Spi: FullDuplex<u8>> ActiveThreeWire<Spi> {
pub fn deactivate(self) -> (ThreeWire, Spi) {
(ThreeWire::new(), self.spi)
}
}