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