use embedded_hal::can::Id;
use modular_bitfield::prelude::*;
use crate::regs::Register;
#[bitfield]
#[derive(Debug, Clone, Copy, PartialEq, Eq, BitfieldSpecifier)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "ufmt", derive(ufmt::derive::uDebug))]
pub struct RxFilterReg {
pub eid: B18,
#[skip]
__: B1,
pub exide: bool,
#[skip]
__: B1,
pub sid: B11,
}
impl RxFilterReg {
pub fn from_id(id: Id) -> Self {
match id {
Id::Standard(bits) => RxFilterReg::new()
.with_exide(false)
.with_eid(0)
.with_sid(bits.as_raw()),
Id::Extended(bits) => RxFilterReg::new()
.with_exide(true)
.with_eid(bits.as_raw() & 0x3FFFF) .with_sid((bits.as_raw() >> 18) as u16), }
}
}
#[bitfield]
#[derive(Debug, Clone, Copy, PartialEq, Eq, BitfieldSpecifier)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[cfg_attr(feature = "ufmt", derive(ufmt::derive::uDebug))]
pub struct RxMaskReg {
pub eid: B18,
#[skip]
__: B3,
pub sid: B11,
}
impl RxMaskReg {
pub fn from_id(id: Id) -> Self {
match id {
Id::Standard(bits) => RxMaskReg::new().with_eid(0).with_sid(bits.as_raw()),
Id::Extended(bits) => RxMaskReg::new()
.with_eid(bits.as_raw() & 0x3FFFF)
.with_sid((bits.as_raw() >> 18) as u16),
}
}
}
crate::filter_def! {
RxFilter(4) => {
F0 => [Register::RXF0EID0, Register::RXF0EID8, Register::RXF0SIDL, Register::RXF0SIDH],
F1 => [Register::RXF1EID0, Register::RXF1EID8, Register::RXF1SIDL, Register::RXF1SIDH],
F2 => [Register::RXF2EID0, Register::RXF2EID8, Register::RXF2SIDL, Register::RXF2SIDH],
F3 => [Register::RXF3EID0, Register::RXF3EID8, Register::RXF3SIDL, Register::RXF3SIDH],
F4 => [Register::RXF4EID0, Register::RXF4EID8, Register::RXF4SIDL, Register::RXF4SIDH],
F5 => [Register::RXF5EID0, Register::RXF5EID8, Register::RXF5SIDL, Register::RXF5SIDH]
}
}
crate::filter_def! {
RxMask(4) => {
Mask0 => [Register::RXM0EID0, Register::RXM0EID8, Register::RXM0SIDL, Register::RXM0SIDH],
Mask1 => [Register::RXM1EID0, Register::RXM1EID8, Register::RXM1SIDL, Register::RXM1SIDH]
}
}