1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//! GSTAT - Global status register (0x01)
use super::{Address, ReadableRegister, Register, WritableRegister};
/// Global status register.
///
/// Contains status flags that indicate reset, driver errors, and undervoltage.
/// Flags can be cleared by writing `1` to the corresponding bit.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Gstat(u32);
impl Gstat {
/// Reset flag.
///
/// Indicates that the IC has been reset since the last read.
/// All registers have been cleared to reset values.
pub fn reset(&self) -> bool {
self.0 & (1 << 0) != 0
}
/// Clear the reset flag by setting it to 1.
pub fn clear_reset(&mut self) -> &mut Self {
self.0 |= 1 << 0;
self
}
/// Driver error flag.
///
/// Indicates the driver has been shut down due to overtemperature
/// or short circuit detection. Read DRV_STATUS for details.
pub fn drv_err(&self) -> bool {
self.0 & (1 << 1) != 0
}
/// Clear the driver error flag by setting it to 1.
pub fn clear_drv_err(&mut self) -> &mut Self {
self.0 |= 1 << 1;
self
}
/// Undervoltage on charge pump.
///
/// Indicates an undervoltage condition. The driver is disabled.
/// This flag is not latched and clears automatically.
pub fn uv_cp(&self) -> bool {
self.0 & (1 << 2) != 0
}
/// Check if any error flags are set.
pub fn has_errors(&self) -> bool {
self.drv_err() || self.uv_cp()
}
/// Get the raw register value.
pub fn raw(&self) -> u32 {
self.0
}
/// Create from raw value.
pub fn from_raw(value: u32) -> Self {
Self(value)
}
}
impl Register for Gstat {
const ADDRESS: Address = Address::Gstat;
}
impl ReadableRegister for Gstat {}
impl WritableRegister for Gstat {} // Write-clear register
impl From<u32> for Gstat {
fn from(value: u32) -> Self {
Self(value)
}
}
impl From<Gstat> for u32 {
fn from(reg: Gstat) -> u32 {
reg.0
}
}