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
84
85
86
87
88
89
90
91
92
93
use defmt::Format;
#[derive(Debug, Copy, Clone, Eq, PartialEq, Format)]
pub struct StandardId(u16);
impl StandardId {
#[inline]
pub const fn new(raw: u16) -> Option<Self> {
if raw <= 0x7FF {
Some(Self(raw))
} else {
None
}
}
#[inline]
pub(crate) const unsafe fn new_unchecked(raw: u16) -> Self {
Self(raw)
}
#[inline]
pub fn as_raw(&self) -> u16 {
self.0
}
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Format)]
pub struct ExtendedId(u32);
impl ExtendedId {
#[inline]
pub const fn new(raw: u32) -> Option<Self> {
if raw <= 0x1FFF_FFFF {
Some(Self(raw))
} else {
None
}
}
#[inline]
pub(crate) const unsafe fn new_unchecked(raw: u32) -> Self {
Self(raw)
}
#[inline]
pub fn as_raw(&self) -> u32 {
self.0
}
pub fn standard_id(&self) -> StandardId {
StandardId((self.0 >> 18) as u16)
}
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Format)]
pub enum Id {
Standard(StandardId),
Extended(ExtendedId),
}
impl From<StandardId> for Id {
#[inline]
fn from(id: StandardId) -> Self {
Id::Standard(id)
}
}
impl From<ExtendedId> for Id {
#[inline]
fn from(id: ExtendedId) -> Self {
Id::Extended(id)
}
}