Reviving InactiveDevice

This commit is contained in:
Ryan Summers 2024-07-03 15:08:19 +02:00 committed by kellerkindt
commit 1c07b969a1
2 changed files with 16 additions and 1 deletions

View file

@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- [breaking] The driver now uses the v1.0 of the `embedded-hal` traits. - [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. `embedded-hal-bus` to facilitate SPI bus sharing.
### Added ### Added

View file

@ -229,4 +229,19 @@ impl<SpiBus: Bus, HostImpl: Host> Device<SpiBus, HostImpl> {
Ok(retry_count_register[0]) Ok(retry_count_register[0])
} }
pub fn deactivate(self) -> (SpiBus, InactiveDevice<HostImpl>) {
(self.bus, InactiveDevice(self.state))
}
}
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct InactiveDevice<HostImpl: Host>(DeviceState<HostImpl>);
impl<HostImpl: Host> InactiveDevice<HostImpl> {
/// Activates the device by taking ownership
pub fn activate<SpiBus: Bus>(self, bus: SpiBus) -> Device<SpiBus, HostImpl> {
Device { bus, state: self.0 }
}
} }