Skip to content

Commit f9270cb

Browse files
zklapowSh3Rm4n
authored andcommitted
clippy
1 parent 0eb802f commit f9270cb

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/can.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,44 @@ const MAX_EXTENDED_ID: u32 = 0x1FFF_FFFF;
3030
///
3131
/// Use `CanOpts::default()` to get 250kbps at 32mhz system clock
3232
pub struct CanOpts {
33-
pub brp: u16,
34-
pub sjw: u8,
35-
pub ts1: u8,
36-
pub ts2: u8,
37-
pub lbkm: LBKM_A,
33+
brp: u16,
34+
sjw: u8,
35+
ts1: u8,
36+
ts2: u8,
37+
lbkm: LBKM_A,
3838
}
3939

4040
impl CanOpts {
41+
/// Create new `CanOpts` using the default settings from `CanOpts::default()` to get 250kbps at 32mhz system clock.
4142
pub fn new() -> CanOpts {
4243
CanOpts::default()
4344
}
4445

46+
/// Set the Baud Rate Prescaler. See http://www.bittiming.can-wiki.info/#bxCAN for generating the timing parameters for different baud rates and clocks.
4547
pub fn brp(mut self, brp: u16) -> Self {
4648
self.brp = brp;
4749
self
4850
}
4951

52+
/// Set the Resynchronisation Jump Width. See http://www.bittiming.can-wiki.info/#bxCAN for generating the timing parameters for different baud rates and clocks.
5053
pub fn sjw(mut self, sjw: u8) -> Self {
5154
self.sjw = sjw;
5255
self
5356
}
5457

58+
/// Set Time Segment One. See http://www.bittiming.can-wiki.info/#bxCAN for generating the timing parameters for different baud rates and clocks.
5559
pub fn ts1(mut self, ts1: u8) -> Self {
5660
self.ts1 = ts1;
5761
self
5862
}
5963

64+
/// Set Time Segment Two. See http://www.bittiming.can-wiki.info/#bxCAN for generating the timing parameters for different baud rates and clocks.
6065
pub fn ts2(mut self, ts2: u8) -> Self {
6166
self.ts2 = ts2;
6267
self
6368
}
6469

70+
/// Enable or disable loopback mode on the CAN device. This is useful for debugging.
6571
pub fn lbkm(mut self, lbkm: LBKM_A) -> Self {
6672
self.lbkm = lbkm;
6773
self
@@ -308,6 +314,7 @@ impl CanFilterData {
308314
}
309315

310316
impl Can {
317+
/// Initialize the CAN peripheral using the options specified by `opts`.
311318
pub fn new_with_opts(
312319
can: stm32::CAN,
313320
rx: gpioa::PA11<AF9>,
@@ -619,7 +626,7 @@ impl CanFrame {
619626
///
620627
/// # Panics
621628
///
622-
/// This function will panic if `dlc` is not inside the vliad range `0..=8`.
629+
/// This function will panic if `dlc` is not inside the valid range `0..=8`.
623630
pub fn new_remote(id: CanId, dlc: usize) -> CanFrame {
624631
assert!((0..=8).contains(&dlc));
625632

@@ -630,7 +637,13 @@ impl CanFrame {
630637
}
631638
}
632639

640+
/// Length of the frame data
633641
pub fn len(&self) -> usize {
634642
self.dlc
635643
}
644+
645+
/// Is this frame empty. This usually indicates a remote frame.
646+
pub fn is_empty(&self) -> bool {
647+
self.dlc == 0
648+
}
636649
}

0 commit comments

Comments
 (0)