Renamed W5500 -> Device, added an Interface struct that should implement the embedded-nal traits, used it to internalize the mutability of the device

This commit is contained in:
Jonah Dahlquist 2020-11-19 19:28:12 -08:00
commit 3cad9cac57
7 changed files with 113 additions and 83 deletions

34
src/inactive_device.rs Normal file
View file

@ -0,0 +1,34 @@
use bus::{ActiveFourWire, ActiveThreeWire, Bus, FourWire, ThreeWire};
use embedded_hal::digital::v2::OutputPin;
use embedded_hal::spi::FullDuplex;
use network::Network;
use device::Device;
pub struct InactiveDevice<SpiBus: Bus, NetworkImpl: Network> {
bus: SpiBus,
network: NetworkImpl,
}
impl<SpiBus: Bus, NetworkImpl: Network> InactiveDevice<SpiBus, NetworkImpl> {
pub fn new(bus: SpiBus, network: NetworkImpl) -> Self {
Self { bus, network }
}
}
impl<ChipSelect: OutputPin, NetworkImpl: Network> InactiveDevice<FourWire<ChipSelect>, NetworkImpl> {
pub fn activate<Spi: FullDuplex<u8>>(
self,
spi: Spi,
) -> Device<ActiveFourWire<Spi, ChipSelect>, NetworkImpl> {
Device::new(self.bus.activate(spi), self.network)
}
}
impl<NetworkImpl: Network> InactiveDevice<ThreeWire, NetworkImpl> {
pub fn activate<Spi: FullDuplex<u8>>(
self,
spi: Spi,
) -> Device<ActiveThreeWire<Spi>, NetworkImpl> {
Device::new(self.bus.activate(spi), self.network)
}
}