tmc2209_uart/registers/
tstep.rs

1//! TSTEP - Measured step time register (0x12)
2
3use super::{Address, ReadableRegister, Register};
4
5/// Measured step time register.
6///
7/// Actual measured time between two 1/256 microsteps derived from step input frequency.
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
9#[cfg_attr(feature = "defmt", derive(defmt::Format))]
10pub struct Tstep(u32);
11
12impl Tstep {
13    /// Maximum value indicating overflow or standstill.
14    pub const MAX_VALUE: u32 = 0xFFFFF;
15
16    /// Get the measured step time value (0 to 2^20 - 1).
17    ///
18    /// In units of 1/f_CLK (typically 1/12MHz ≈ 83.3ns).
19    /// Value of 0xFFFFF indicates overflow or standstill.
20    pub fn value(&self) -> u32 {
21        self.0 & 0xFFFFF
22    }
23
24    /// Alias for `value()` - get the TSTEP value.
25    pub fn tstep(&self) -> u32 {
26        self.value()
27    }
28
29    /// Check if the motor is in standstill or overflow condition.
30    pub fn is_standstill(&self) -> bool {
31        self.value() == Self::MAX_VALUE
32    }
33
34    /// Get the raw register value.
35    pub fn raw(&self) -> u32 {
36        self.0
37    }
38
39    /// Create from raw value.
40    pub fn from_raw(value: u32) -> Self {
41        Self(value)
42    }
43}
44
45impl Register for Tstep {
46    const ADDRESS: Address = Address::Tstep;
47}
48
49impl ReadableRegister for Tstep {}
50
51impl From<u32> for Tstep {
52    fn from(value: u32) -> Self {
53        Self(value)
54    }
55}
56
57impl From<Tstep> for u32 {
58    fn from(reg: Tstep) -> u32 {
59        reg.0
60    }
61}