feat: get device state and more derives
Signed-off-by: Lachezar Lechev <elpiel93@gmail.com>
This commit is contained in:
parent
6ff773d5ed
commit
c6e5c58845
1 changed files with 7 additions and 1 deletions
|
|
@ -8,6 +8,8 @@ use crate::socket::Socket;
|
|||
use crate::uninitialized_device::UninitializedDevice;
|
||||
use crate::{register, MacAddress};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
pub enum ResetError<E> {
|
||||
SocketsNotReleased,
|
||||
Other(E),
|
||||
|
|
@ -21,7 +23,7 @@ impl<E> From<E> for ResetError<E> {
|
|||
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
pub(crate) struct DeviceState<HostImpl: Host> {
|
||||
pub struct DeviceState<HostImpl: Host> {
|
||||
host: HostImpl,
|
||||
sockets: [u8; 1],
|
||||
}
|
||||
|
|
@ -42,6 +44,10 @@ impl<SpiBus: Bus, HostImpl: Host> Device<SpiBus, HostImpl> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_state(&self) -> &DeviceState<HostImpl> {
|
||||
&self.state
|
||||
}
|
||||
|
||||
pub fn reset(mut self) -> Result<UninitializedDevice<SpiBus>, ResetError<SpiBus::Error>> {
|
||||
if self.state.sockets != [0b11111111] {
|
||||
Err(ResetError::SocketsNotReleased)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue