From 10bbe9958264d5d152e6a46c34fd90309a413a4b Mon Sep 17 00:00:00 2001 From: Michael Watzko Date: Tue, 23 Mar 2021 23:31:51 +0100 Subject: [PATCH] Add Device::deactivate and InactiveDevice::activate --- src/device.rs | 25 +++++++++++++++++++++++++ src/lib.rs | 33 ++++++++++++++++----------------- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/device.rs b/src/device.rs index 92d9a1f..c0271fd 100644 --- a/src/device.rs +++ b/src/device.rs @@ -75,4 +75,29 @@ impl Device { pub fn release(self) -> (SpiBus, HostImpl) { (self.bus, self.host) } + + pub fn deactivate(self) -> (SpiBus, InactiveDevice) { + ( + self.bus, + InactiveDevice { + host: self.host, + sockets: self.sockets, + }, + ) + } +} + +pub struct InactiveDevice { + host: HostImpl, + sockets: [u8; 1], +} + +impl InactiveDevice { + pub fn activate(self, bus: SpiBus) -> Device { + Device { + bus, + host: self.host, + sockets: self.sockets, + } + } } diff --git a/src/lib.rs b/src/lib.rs index 7c956b1..6d4b0f8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,22 @@ #![no_std] #![allow(unused)] #![deny(broken_intra_doc_links)] -#[macro_use(block)] + +pub mod bus; +mod device; +mod host; +pub mod net; +pub mod register; +mod socket; +pub mod udp; +mod uninitialized_device; + +pub use device::{Device, InactiveDevice}; +pub use host::{Dhcp, HostConfig, Manual}; +pub use net::MacAddress; +pub use uninitialized_device::UninitializedDevice; + +// TODO add better docs to all public items, add unit tests. /// Settings for wake on LAN. Allows the W5500 to optionally emit an interrupt upon receiving a packet #[repr(u8)] @@ -53,19 +68,3 @@ impl Default for Mode { } } } - -// TODO add better docs to all public items, add unit tests. - -pub mod bus; -mod device; -mod host; -pub mod net; -pub mod register; -mod socket; -mod udp; -mod uninitialized_device; - -pub use device::Device; -pub use host::{Dhcp, HostConfig, Manual}; -pub use net::MacAddress; -pub use uninitialized_device::UninitializedDevice;