Skip to content

Commit 590da9a

Browse files
author
Cor Peters
committed
clippy +fmt
1 parent a7cd23e commit 590da9a

14 files changed

+115
-94
lines changed

examples/can-echo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn main() -> ! {
4949
let rx = gpioa.pa11.into_alternate();
5050
let tx = gpioa.pa12.into_alternate();
5151

52-
let can = crate::hal::can::FdCan::new(dp.FDCAN1, (tx, rx), &mut rcc);
52+
let can = crate::hal::can::FdCan::new(dp.FDCAN1, (tx, rx), &rcc);
5353
let mut can = FdCan::new(can).into_config_mode();
5454

5555
can.set_nominal_bit_timing(btr);
@@ -65,7 +65,7 @@ fn main() -> ! {
6565
let rx = gpiob.pb5.into_alternate();
6666
let tx = gpiob.pb6.into_alternate();
6767

68-
let can = crate::hal::can::FdCan::new(dp.FDCAN2, (tx, rx), &mut rcc);
68+
let can = crate::hal::can::FdCan::new(dp.FDCAN2, (tx, rx), &rcc);
6969
let mut can = FdCan::new(can).into_config_mode();
7070

7171
can.set_nominal_bit_timing(btr);

src/fdcan.rs

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ where
190190

191191
#[inline]
192192
fn msg_ram_mut(&mut self) -> &mut message_ram::RegisterBlock {
193-
unsafe { &mut *I::MSG_RAM }
193+
self.instance().msg_ram_mut()
194194
}
195195

196196
#[inline]
@@ -358,6 +358,7 @@ where
358358

359359
/// Splits this `FdCan` instance into transmitting and receiving halves, by reference.
360360
#[inline]
361+
#[allow(clippy::type_complexity)]
361362
fn split_by_ref_generic(
362363
&mut self,
363364
) -> (
@@ -375,6 +376,7 @@ where
375376

376377
/// Consumes this `FdCan` instance and splits it into transmitting and receiving halves.
377378
#[inline]
379+
#[allow(clippy::type_complexity)]
378380
fn split_generic(
379381
self,
380382
) -> (
@@ -389,6 +391,7 @@ where
389391

390392
/// Combines an FdCanControl, Tx and the two Rx instances back into an FdCan instance
391393
#[inline]
394+
#[allow(clippy::type_complexity)]
392395
pub fn combine(
393396
t: (
394397
FdCanControl<I, MODE>,
@@ -799,6 +802,7 @@ where
799802
{
800803
/// Splits this `FdCan` instance into transmitting and receiving halves, by reference.
801804
#[inline]
805+
#[allow(clippy::type_complexity)]
802806
pub fn split_by_ref(
803807
&mut self,
804808
) -> (
@@ -811,6 +815,7 @@ where
811815
}
812816

813817
/// Consumes this `FdCan` instance and splits it into transmitting and receiving halves.
818+
#[allow(clippy::type_complexity)]
814819
pub fn split(
815820
self,
816821
) -> (
@@ -985,6 +990,7 @@ where
985990
#[inline]
986991
unsafe fn conjure_by_ref<'a>() -> &'a mut Self {
987992
// Cause out of bounds access when `Self` is not zero-sized.
993+
#[allow(clippy::unnecessary_operation)]
988994
[()][core::mem::size_of::<Self>()];
989995

990996
// Any aligned pointer is valid for ZSTs.
@@ -998,12 +1004,12 @@ where
9981004

9991005
#[inline]
10001006
fn tx_msg_ram(&self) -> &message_ram::Transmit {
1001-
unsafe { &(&*I::MSG_RAM).transmit }
1007+
unsafe { &(*I::MSG_RAM).transmit }
10021008
}
10031009

10041010
#[inline]
10051011
fn tx_msg_ram_mut(&mut self) -> &mut message_ram::Transmit {
1006-
unsafe { &mut (&mut *I::MSG_RAM).transmit }
1012+
unsafe { &mut (*I::MSG_RAM).transmit }
10071013
}
10081014

10091015
/// Puts a CAN frame in a transmit mailbox for transmission on the bus.
@@ -1140,11 +1146,7 @@ where
11401146
let header: TxFrameHeader = (&self.tx_msg_ram().tbsa[idx as usize].header).into();
11411147
let old_id: IdReg = header.into();
11421148

1143-
if id <= old_id {
1144-
false
1145-
} else {
1146-
true
1147-
}
1149+
id > old_id
11481150
} else {
11491151
true
11501152
}
@@ -1174,29 +1176,25 @@ where
11741176
result
11751177
}
11761178

1177-
#[inline]
1178-
fn abort_pending_mailbox<PTX, R>(&mut self, idx: Mailbox, pending: Option<PTX>) -> Option<R>
1179-
where
1180-
PTX: FnOnce(Mailbox, TxFrameHeader, &[u32]) -> R,
1181-
{
1182-
if self.abort(idx) {
1183-
let tx_ram = self.tx_msg_ram();
1179+
// #[inline]
1180+
// fn abort_pending_mailbox<PTX, R>(&mut self, idx: Mailbox, pending: Option<PTX>) -> Option<R>
1181+
// where
1182+
// PTX: FnOnce(Mailbox, TxFrameHeader, &[u32]) -> R,
1183+
// {
1184+
// if self.abort(idx) {
1185+
// let tx_ram = self.tx_msg_ram();
11841186

1185-
//read back header section
1186-
let header = (&tx_ram.tbsa[idx as usize].header).into();
1187-
if let Some(pending) = pending {
1188-
Some(pending(idx, header, &tx_ram.tbsa[idx as usize].data))
1189-
} else {
1190-
None
1191-
}
1192-
} else {
1193-
// Abort request failed because the frame was already sent (or being sent) on
1194-
// the bus. All mailboxes are now free. This can happen for small prescaler
1195-
// values (e.g. 1MBit/s bit timing with a source clock of 8MHz) or when an ISR
1196-
// has preempted the execution.
1197-
None
1198-
}
1199-
}
1187+
// //read back header section
1188+
// let header = (&tx_ram.tbsa[idx as usize].header).into();
1189+
// pending.map(|pending| pending(idx, header, &tx_ram.tbsa[idx as usize].data))
1190+
// } else {
1191+
// // Abort request failed because the frame was already sent (or being sent) on
1192+
// // the bus. All mailboxes are now free. This can happen for small prescaler
1193+
// // values (e.g. 1MBit/s bit timing with a source clock of 8MHz) or when an ISR
1194+
// // has preempted the execution.
1195+
// None
1196+
// }
1197+
// }
12001198

12011199
/// Attempts to abort the sending of a frame that is pending in a mailbox.
12021200
///
@@ -1233,11 +1231,7 @@ where
12331231
let can = self.registers();
12341232
let idx: u8 = idx.into();
12351233

1236-
if can.txbrp.read().trp().bits() & idx != 0 {
1237-
true
1238-
} else {
1239-
false
1240-
}
1234+
can.txbrp.read().trp().bits() & idx != 0
12411235
}
12421236

12431237
/// Returns `true` if no frame is pending for transmission.
@@ -1326,6 +1320,7 @@ where
13261320
#[inline]
13271321
unsafe fn conjure_by_ref<'a>() -> &'a mut Self {
13281322
// Cause out of bounds access when `Self` is not zero-sized.
1323+
#[allow(clippy::unnecessary_operation)]
13291324
[()][core::mem::size_of::<Self>()];
13301325

13311326
// Any aligned pointer is valid for ZSTs.
@@ -1352,9 +1347,9 @@ where
13521347
self.release_mailbox(mbox);
13531348

13541349
if self.has_overrun() {
1355-
result.map(|r| ReceiveOverrun::NoOverrun(r))
1350+
result.map(ReceiveOverrun::NoOverrun)
13561351
} else {
1357-
result.map(|r| ReceiveOverrun::Overrun(r))
1352+
result.map(ReceiveOverrun::Overrun)
13581353
}
13591354
} else {
13601355
Err(nb::Error::WouldBlock)
@@ -1368,7 +1363,7 @@ where
13681363

13691364
#[inline]
13701365
fn rx_msg_ram(&self) -> &message_ram::Receive {
1371-
unsafe { &(&(&*I::MSG_RAM).receive)[FIFONR::NR] }
1366+
unsafe { &(&(*I::MSG_RAM).receive)[FIFONR::NR] }
13721367
}
13731368

13741369
#[inline]

src/fdcan/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl NominalBitTiming {
3737
}
3838
#[inline]
3939
pub(crate) fn ntseg1(&self) -> u8 {
40-
self.seg1 & 0xFF
40+
self.seg1
4141
}
4242
#[inline]
4343
pub(crate) fn ntseg2(&self) -> u8 {

src/fdcan/filter.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl StandardFilter {
2929
action: Action::StoreInFifo0,
3030
}
3131
}
32-
32+
3333
/// Accept all messages in FIFO 1
3434
pub fn accept_all_into_fifo1() -> StandardFilter {
3535
StandardFilter {
@@ -40,7 +40,7 @@ impl StandardFilter {
4040
action: Action::StoreInFifo0,
4141
}
4242
}
43-
43+
4444
/// Reject all messages
4545
pub fn reject_all() -> StandardFilter {
4646
StandardFilter {
@@ -51,7 +51,7 @@ impl StandardFilter {
5151
action: Action::Reject,
5252
}
5353
}
54-
54+
5555
/// Disable the filter
5656
pub fn disable() -> StandardFilter {
5757
StandardFilter {
@@ -72,7 +72,7 @@ impl ExtendedFilter {
7272
action: Action::StoreInFifo0,
7373
}
7474
}
75-
75+
7676
/// Accept all messages in FIFO 1
7777
pub fn accept_all_into_fifo1() -> ExtendedFilter {
7878
ExtendedFilter {
@@ -83,7 +83,7 @@ impl ExtendedFilter {
8383
action: Action::StoreInFifo0,
8484
}
8585
}
86-
86+
8787
/// Reject all messages
8888
pub fn reject_all() -> ExtendedFilter {
8989
ExtendedFilter {
@@ -94,7 +94,7 @@ impl ExtendedFilter {
9494
action: Action::Reject,
9595
}
9696
}
97-
97+
9898
/// Disable the filter
9999
pub fn disable() -> ExtendedFilter {
100100
ExtendedFilter {

src/fdcan/frame.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@ pub enum FrameFormat {
1818
/// Frame used by Classic CAN
1919
Standard = 0,
2020
/// New frame format used by FdCan
21-
FDCAN = 1,
21+
Fdcan = 1,
2222
}
2323
impl From<FrameFormat> for PacFrameFormat {
2424
fn from(ff: FrameFormat) -> Self {
2525
match ff {
2626
FrameFormat::Standard => PacFrameFormat::Standard,
27-
FrameFormat::FDCAN => PacFrameFormat::FDCAN,
27+
FrameFormat::Fdcan => PacFrameFormat::Fdcan,
2828
}
2929
}
3030
}
3131
impl From<PacFrameFormat> for FrameFormat {
3232
fn from(ff: PacFrameFormat) -> Self {
3333
match ff {
3434
PacFrameFormat::Standard => FrameFormat::Standard,
35-
PacFrameFormat::FDCAN => FrameFormat::FDCAN,
35+
PacFrameFormat::Fdcan => FrameFormat::Fdcan,
3636
}
3737
}
3838
}

src/fdcan/message_ram.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ impl generic::Writable for TxBufferElementHeader {}
8787
/// Accessor for the FdCan Message Ram Area
8888
pub unsafe trait MsgRamExt {
8989
const MSG_RAM: *mut RegisterBlock;
90-
fn msg_ram(&self) -> &mut RegisterBlock {
90+
fn msg_ram(&self) -> &RegisterBlock {
91+
unsafe { &*Self::MSG_RAM }
92+
}
93+
fn msg_ram_mut(&mut self) -> &mut RegisterBlock {
9194
unsafe { &mut *Self::MSG_RAM }
9295
}
9396
}

src/fdcan/message_ram/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@ impl FDF_R {
8484
pub fn frame_format(&self) -> FrameFormat {
8585
match self.bits() {
8686
false => FrameFormat::Standard,
87-
true => FrameFormat::FDCAN,
87+
true => FrameFormat::Fdcan,
8888
}
8989
}
9090
pub fn is_standard_format(&self) -> bool {
9191
*self == FrameFormat::Standard
9292
}
9393
pub fn is_fdcan_format(&self) -> bool {
94-
*self == FrameFormat::FDCAN
94+
*self == FrameFormat::Fdcan
9595
}
9696
}
9797

src/fdcan/message_ram/enums.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#[cfg_attr(feature = "unstable-defmt", derive(defmt::Format))]
55
pub enum DataLength {
66
Standard(u8),
7-
FDCAN(u8),
7+
Fdcan(u8),
88
}
99
impl DataLength {
1010
/// Creates a DataLength type
@@ -16,8 +16,8 @@ impl DataLength {
1616
0..=8 => DataLength::Standard(len),
1717
_ => panic!("DataLength > 8"),
1818
},
19-
FrameFormat::FDCAN => match len {
20-
0..=64 => DataLength::FDCAN(len),
19+
FrameFormat::Fdcan => match len {
20+
0..=64 => DataLength::Fdcan(len),
2121
_ => panic!("DataLength > 64"),
2222
},
2323
}
@@ -28,20 +28,20 @@ impl DataLength {
2828
}
2929
/// Specialised function to create FDCAN frames
3030
pub fn new_fdcan(len: u8) -> DataLength {
31-
Self::new(len, FrameFormat::FDCAN)
31+
Self::new(len, FrameFormat::Fdcan)
3232
}
3333

3434
/// returns the length in bytes
3535
pub fn len(&self) -> u8 {
3636
match self {
37-
DataLength::Standard(l) | DataLength::FDCAN(l) => *l,
37+
DataLength::Standard(l) | DataLength::Fdcan(l) => *l,
3838
}
3939
}
4040

4141
pub(crate) fn dlc(&self) -> u8 {
4242
match self {
4343
DataLength::Standard(l) => *l,
44-
DataLength::FDCAN(l) => match l {
44+
DataLength::Fdcan(l) => match l {
4545
0..=8 => *l,
4646
9..=12 => 12,
4747
13..=16 => 16,
@@ -59,7 +59,7 @@ impl From<DataLength> for FrameFormat {
5959
fn from(dl: DataLength) -> FrameFormat {
6060
match dl {
6161
DataLength::Standard(_) => FrameFormat::Standard,
62-
DataLength::FDCAN(_) => FrameFormat::FDCAN,
62+
DataLength::Fdcan(_) => FrameFormat::Fdcan,
6363
}
6464
}
6565
}
@@ -122,7 +122,7 @@ impl From<ErrorStateIndicator> for bool {
122122
#[cfg_attr(feature = "unstable-defmt", derive(defmt::Format))]
123123
pub enum FrameFormat {
124124
Standard = 0,
125-
FDCAN = 1,
125+
Fdcan = 1,
126126
}
127127
impl From<FrameFormat> for bool {
128128
#[inline(always)]

0 commit comments

Comments
 (0)