tmc2209_uart/registers/
pwm_auto.rs

1//! PWM_AUTO - Automatic PWM configuration register (0x72)
2
3use super::{Address, ReadableRegister, Register};
4
5/// Automatic PWM configuration register.
6///
7/// Read-only register containing the automatic PWM tuning results.
8/// These values are computed by the auto-tuning algorithm.
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10#[cfg_attr(feature = "defmt", derive(defmt::Format))]
11pub struct PwmAuto(u32);
12
13impl PwmAuto {
14    /// Create with default value (0).
15    pub fn new() -> Self {
16        Self(0)
17    }
18
19    /// Get PWM_OFS_AUTO (0-255).
20    ///
21    /// Automatically determined offset value.
22    /// Result of automatic amplitude calibration.
23    pub fn pwm_ofs_auto(&self) -> u8 {
24        (self.0 & 0xFF) as u8
25    }
26
27    /// Get PWM_GRAD_AUTO (0-255).
28    ///
29    /// Automatically determined gradient value.
30    /// Result of automatic gradient calibration for velocity-dependent current.
31    pub fn pwm_grad_auto(&self) -> u8 {
32        ((self.0 >> 16) & 0xFF) as u8
33    }
34
35    /// Get the raw register value.
36    pub fn raw(&self) -> u32 {
37        self.0
38    }
39
40    /// Create from raw value.
41    pub fn from_raw(value: u32) -> Self {
42        Self(value)
43    }
44}
45
46impl Default for PwmAuto {
47    fn default() -> Self {
48        Self::new()
49    }
50}
51
52impl Register for PwmAuto {
53    const ADDRESS: Address = Address::PwmAuto;
54}
55
56impl ReadableRegister for PwmAuto {}
57
58impl From<u32> for PwmAuto {
59    fn from(value: u32) -> Self {
60        Self(value)
61    }
62}
63
64impl From<PwmAuto> for u32 {
65    fn from(reg: PwmAuto) -> u32 {
66        reg.0
67    }
68}