From 1c07b969a142840bcf40dd5c01c87299cc6229bd Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Wed, 3 Jul 2024 15:08:19 +0200 Subject: [PATCH] Reviving InactiveDevice --- CHANGELOG.md | 2 +- src/device.rs | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9248b6a..94fe2ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - [breaking] The driver now uses the v1.0 of the `embedded-hal` traits. -- [breaking] The `FourWireRef` bus, `InactiveDevice`, and `DeviceRefMut` have been removed in favor of using +- [breaking] The `FourWireRef` bus and `DeviceRefMut` have been removed in favor of using `embedded-hal-bus` to facilitate SPI bus sharing. ### Added diff --git a/src/device.rs b/src/device.rs index 9ee966b..0807899 100644 --- a/src/device.rs +++ b/src/device.rs @@ -229,4 +229,19 @@ impl Device { Ok(retry_count_register[0]) } + + pub fn deactivate(self) -> (SpiBus, InactiveDevice) { + (self.bus, InactiveDevice(self.state)) + } +} + +#[derive(Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] +pub struct InactiveDevice(DeviceState); + +impl InactiveDevice { + /// Activates the device by taking ownership + pub fn activate(self, bus: SpiBus) -> Device { + Device { bus, state: self.0 } + } }