Skip to content

Commit 70544ea

Browse files
committed
Fix problems found out by clippy.
1 parent 1de5d30 commit 70544ea

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/can.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use super::pac;
22
use super::pac::can::TX;
33
use crate::gpio::gpiob::{PB8, PB9};
44
use crate::gpio::{Alternate, AF4};
5+
use crate::rcc::Rcc;
56

67
pub struct CANBus {
7-
can: stm32::CAN,
8+
can: pac::CAN,
89
_rx: PB8<Alternate<AF4>>,
910
_tx: PB9<Alternate<AF4>>,
1011
}
@@ -15,17 +16,20 @@ pub enum Event {
1516

1617
impl CANBus {
1718
// TODO add setting of pins the same way as done in other peripherals
18-
pub fn new(can: pac::CAN, rx: PB8<Alternate<AF4>>, tx: PB9<Alternate<AF4>>) -> Self {
19-
unsafe {
20-
let rcc = &(*stm32::RCC::ptr());
21-
rcc.apb1enr.modify(|_, w| w.canen().enabled());
22-
rcc.apb1rstr.modify(|_, w| w.canrst().reset());
23-
rcc.apb1rstr.modify(|_, w| w.canrst().clear_bit());
24-
}
19+
pub fn new(
20+
can: pac::CAN,
21+
rx: PB8<Alternate<AF4>>,
22+
tx: PB9<Alternate<AF4>>,
23+
rcc: &mut Rcc,
24+
) -> Self {
25+
rcc.regs.apb1enr.modify(|_, w| w.canen().enabled());
26+
rcc.regs.apb1rstr.modify(|_, w| w.canrst().reset());
27+
rcc.regs.apb1rstr.modify(|_, w| w.canrst().clear_bit());
2528

2629
can.mcr.write(|w| w.sleep().clear_bit());
2730
can.mcr.modify(|_, w| w.inrq().set_bit());
2831
while !can.msr.read().inak().bit() {}
32+
2933
can.mcr.modify(|_, w| {
3034
w.ttcm()
3135
.clear_bit() // no time triggered communication
@@ -141,8 +145,7 @@ impl CANBus {
141145
pub fn read(&self) -> nb::Result<CANFrame, CANError> {
142146
for (i, rfr) in self.can.rfr.iter().enumerate() {
143147
let pending = rfr.read().fmp().bits();
144-
145-
for _ in 0..pending {
148+
if pending > 0 {
146149
let rx = &self.can.rx[i];
147150
let id = rx.rir.read().stid().bits();
148151
let rtr = rx.rir.read().rtr().bit_is_set();

0 commit comments

Comments
 (0)