w5100-rs/src/inactive_device.rs
Jonah Dahlquist 79b1f52102 Ran cargo fmt
2021-02-18 19:16:16 -08:00

36 lines
1 KiB
Rust

use bus::{ActiveFourWire, ActiveThreeWire, Bus, FourWire, ThreeWire};
use device::Device;
use embedded_hal::digital::v2::OutputPin;
use embedded_hal::spi::FullDuplex;
use network::Network;
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)
}
}