use crate::inactive_w5500::InactiveW5500; use crate::uninitialized_w5500::UninitializedW5500; use bus::{ActiveBus, ActiveFourWire, ActiveThreeWire, FourWire, ThreeWire}; use embedded_hal::digital::v2::OutputPin; use embedded_hal::spi::FullDuplex; use network::Network; use register; pub struct W5500 { bus: SpiBus, network: NetworkImpl, } impl W5500 { pub fn new(bus: SpiBus, network: NetworkImpl) -> Self { W5500 { bus, network } } pub fn reset(mut self) -> Result, SpiBus::Error> { // TODO accept all sockets back self.clear_mode()?; Ok(UninitializedW5500::new(self.bus)) } fn clear_mode(&mut self) -> Result<(), SpiBus::Error> { // reset bit let mut mode = [0b10000000]; block!(self .bus .transfer_frame(register::COMMON, register::common::MODE, true, &mut mode))?; Ok(()) } //TODO open_udp_socket } impl, ChipSelect: OutputPin, NetworkImpl: Network> W5500, NetworkImpl> { pub fn deactivate(self) -> (InactiveW5500, NetworkImpl>, Spi) { let (bus, spi) = self.bus.deactivate(); (InactiveW5500::new(bus, self.network), spi) } } impl, NetworkImpl: Network> W5500, NetworkImpl> { pub fn deactivate(self) -> (InactiveW5500, Spi) { let (bus, spi) = self.bus.deactivate(); (InactiveW5500::new(bus, self.network), spi) } }