Skip to content

Commit

Permalink
resolve PR Issues
Browse files Browse the repository at this point in the history
artifacts of non-existent feature: imxrt-rs#122 (comment)

remove constrain function and use core::cmp::Ordering::clamp trait: imxrt-rs#122 (comment)
  • Loading branch information
dstric-aqueduct committed Dec 12, 2022
1 parent 081d027 commit 68677eb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 23 deletions.
7 changes: 0 additions & 7 deletions imxrt-hal/src/can/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,13 +430,6 @@ impl PartialEq for Data {

impl Eq for Data {}

#[cfg(feature = "unstable-defmt")]
impl defmt::Format for Data {
fn format(&self, fmt: defmt::Formatter<'_>) {
self.as_ref().format(fmt)
}
}

macro_rules! data_from_array {
( $($len:literal),+ ) => {
$(
Expand Down
22 changes: 6 additions & 16 deletions imxrt-hal/src/can/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use core::marker::PhantomData;

/// Error that indicates that an incoming message has been lost due to buffer overrun.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "unstable-defmt", derive(defmt::Format))]
pub struct OverrunError {
_priv: (),
}
Expand Down Expand Up @@ -127,15 +126,6 @@ pub struct MailboxData {
pub mailbox_number: u8,
}

#[inline]
fn constrain<T: PartialOrd>(value: T, min: T, max: T) -> T {
match value {
v if v < min => min,
v if v > max => max,
_ => value,
}
}

impl<M> CAN<M>
where
M: Unsigned,
Expand Down Expand Up @@ -498,7 +488,7 @@ where
}

pub fn set_max_mailbox(&mut self, last: u8) {
let last = constrain(last, 1, 64) - 1;
let last = last.clamp(1, 64) - 1;
self.while_frozen(|this| {
let fifo_cleared = this.fifo_enabled();
this.disable_fifo();
Expand Down Expand Up @@ -643,7 +633,7 @@ where
let offset = this.mailbox_offset();
for i in 0..max_fifo_filters {
this.write_mailbox_idflt_tab(i as u8, Some(0x00));
if i < constrain(offset as usize, 0, 32) as u32 {
if i < offset.clamp(0, 32) as u32 {
this.write_mailbox_rximr(i as u8, Some(0x00));
}
}
Expand All @@ -654,7 +644,7 @@ where
let offset = this.mailbox_offset();
for i in 0..max_fifo_filters {
this.write_mailbox_idflt_tab(i as u8, Some(0xFFFFFFFF));
if i < constrain(offset, 0, 32) as u32 {
if i < offset.clamp(0, 32) as u32 {
this.write_mailbox_rximr(i as u8, Some(0x3FFFFFFF));
}
}
Expand All @@ -664,7 +654,7 @@ where
let offset = this.mailbox_offset();
for i in 0..max_fifo_filters {
this.write_mailbox_idflt_tab(i as u8, Some(0xFFFFFFFF));
if i < constrain(offset as usize, 0, 32) as u32 {
if i < offset.clamp(0, 32) as u32 {
this.write_mailbox_rximr(i as u8, Some(0x7FFF7FFF));
}
}
Expand Down Expand Up @@ -715,7 +705,7 @@ where
};
this.write_mailbox_idflt_tab(filter_id, Some(filter));
let offset = this.mailbox_offset();
if filter_id < constrain(offset, 0, 32) as u8 {
if filter_id < offset.clamp(0, 32) as u8 {
this.write_mailbox_rximr(filter_id, Some(mask));
}
write_reg!(ral::can, this.reg, RXFGMASK, 0x3FFFFFFF);
Expand Down Expand Up @@ -764,7 +754,7 @@ where
});
this.write_mailbox_idflt_tab(filter_id, Some(filter));
let offset = this.mailbox_offset();
if filter_id < constrain(offset as usize, 0, 32) as u8 {
if filter_id < offset.clamp(0, 32) as u8 {
this.write_mailbox_rximr(filter_id, Some(mask));
}
write_reg!(ral::can, this.reg, RXFGMASK, 0x7FFF7FFF);
Expand Down
10 changes: 10 additions & 0 deletions imxrt-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub mod iomuxc {
}

pub mod adc;
pub mod can;
pub mod ccm;
pub mod dma;
pub mod gpio;
Expand Down Expand Up @@ -55,6 +56,7 @@ pub mod dcdc {
pub struct Peripherals {
pub adc: adc::Unclocked,
pub iomuxc: iomuxc::Pads,
pub can: can::Unclocked,
pub ccm: ccm::CCM,
pub pit: pit::UnclockedPIT,
pub dcdc: dcdc::DCDC,
Expand Down Expand Up @@ -89,6 +91,10 @@ impl Peripherals {
adc2: ral::adc::ADC2::steal(),
},
iomuxc: iomuxc::pads(ral::iomuxc::IOMUXC::steal()),
can: can::Unclocked {
can1: ral::can::CAN1::steal(),
can2: ral::can::CAN2::steal(),
},
ccm: ccm::CCM::new(ral::ccm::CCM::steal(), ral::ccm_analog::CCM_ANALOG::steal()),
pit: pit::UnclockedPIT::new(ral::pit::PIT::steal()),
dcdc: dcdc::DCDC(ral::dcdc::DCDC::steal()),
Expand Down Expand Up @@ -139,6 +145,10 @@ impl Peripherals {
adc2: ral::adc::ADC2::take()?,
},
iomuxc: iomuxc::pads(ral::iomuxc::IOMUXC::take()?),
can: can::Unclocked {
can1: ral::can::CAN1::take()?,
can2: ral::can::CAN2::take()?,
},
ccm: ccm::CCM::new(ral::ccm::CCM::take()?, ral::ccm_analog::CCM_ANALOG::take()?),
pit: pit::UnclockedPIT::new(ral::pit::PIT::take()?),
dcdc: dcdc::DCDC(ral::dcdc::DCDC::take()?),
Expand Down

0 comments on commit 68677eb

Please sign in to comment.