Skip to content

Commit ab23dbb

Browse files
authored
Fixes/fdcan (#45)
* Added has_interrupt to FdCan and FdCanControl. * Made as_raw public instead of pub(crate). * Correctly use a mask in IdReg.to_id().
1 parent 4414f5c commit ab23dbb

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/fdcan.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,12 @@ where
435435
}
436436
}
437437

438+
/// Check if the interrupt is triggered
439+
#[inline]
440+
pub fn has_interrupt(&mut self, interrupt: Interrupt) -> bool {
441+
self.control.has_interrupt(interrupt)
442+
}
443+
438444
/// Clear specified interrupt
439445
#[inline]
440446
pub fn clear_interrupt(&mut self, interrupt: Interrupt) {
@@ -1176,6 +1182,13 @@ where
11761182
self.registers().tscv.read().tsc().bits()
11771183
}
11781184

1185+
/// Check if the interrupt is triggered
1186+
#[inline]
1187+
pub fn has_interrupt(&mut self, interrupt: Interrupt) -> bool {
1188+
let can = self.registers();
1189+
can.ir.read().bits() & (interrupt as u32) > 0
1190+
}
1191+
11791192
/// Clear specified interrupt
11801193
#[inline]
11811194
pub fn clear_interrupt(&mut self, interrupt: Interrupt) {

src/fdcan/id.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl StandardId {
4141

4242
/// Returns this CAN Identifier as a raw 16-bit integer.
4343
#[inline]
44-
pub(crate) fn as_raw(&self) -> u16 {
44+
pub fn as_raw(&self) -> u16 {
4545
self.0
4646
}
4747
}
@@ -88,7 +88,7 @@ impl ExtendedId {
8888

8989
/// Returns this CAN Identifier as a raw 32-bit integer.
9090
#[inline]
91-
pub(crate) fn as_raw(&self) -> u32 {
91+
pub fn as_raw(&self) -> u32 {
9292
self.0
9393
}
9494

@@ -212,10 +212,14 @@ impl IdReg {
212212
/// Returns the identifier.
213213
pub fn to_id(self) -> Id {
214214
if self.is_extended() {
215-
Id::Extended(unsafe { ExtendedId::new_unchecked(self.0 >> Self::EXTENDED_SHIFT) })
215+
Id::Extended(unsafe {
216+
ExtendedId::new_unchecked((self.0 >> Self::EXTENDED_SHIFT) & Self::EXTENDED_MASK)
217+
})
216218
} else {
217219
Id::Standard(unsafe {
218-
StandardId::new_unchecked((self.0 >> Self::STANDARD_SHIFT) as u16)
220+
StandardId::new_unchecked(
221+
((self.0 >> Self::STANDARD_SHIFT) & Self::STANDARD_MASK) as u16,
222+
)
219223
})
220224
}
221225
}

0 commit comments

Comments
 (0)