dbc_rs/bit_timing/
impls.rs

1use super::BitTiming;
2
3impl BitTiming {
4    /// Creates a new empty BitTiming (most common case).
5    #[must_use]
6    pub(crate) const fn new() -> Self {
7        Self {
8            baudrate: None,
9            btr1: None,
10            btr2: None,
11        }
12    }
13
14    /// Creates a new BitTiming with baudrate only.
15    #[must_use]
16    pub const fn with_baudrate(baudrate: u32) -> Self {
17        Self {
18            baudrate: Some(baudrate),
19            btr1: None,
20            btr2: None,
21        }
22    }
23
24    /// Creates a new BitTiming with all parameters.
25    #[must_use]
26    pub const fn with_btr(baudrate: u32, btr1: u32, btr2: u32) -> Self {
27        Self {
28            baudrate: Some(baudrate),
29            btr1: Some(btr1),
30            btr2: Some(btr2),
31        }
32    }
33
34    /// Returns the baudrate in kbps, if specified.
35    #[must_use]
36    pub const fn baudrate(&self) -> Option<u32> {
37        self.baudrate
38    }
39
40    /// Returns the BTR1 (Bus Timing Register 1) value, if specified.
41    #[must_use]
42    pub const fn btr1(&self) -> Option<u32> {
43        self.btr1
44    }
45
46    /// Returns the BTR2 (Bus Timing Register 2) value, if specified.
47    #[must_use]
48    pub const fn btr2(&self) -> Option<u32> {
49        self.btr2
50    }
51
52    /// Returns true if the bit timing section is empty (no values).
53    #[must_use]
54    pub const fn is_empty(&self) -> bool {
55        self.baudrate.is_none()
56    }
57}