#![allow(clippy::identity_op)]
use modular_bitfield::prelude::*;
pub trait Register: From<u8> + Into<u8> {
const ADDRESS: u8;
}
pub trait Modify {}
#[bitfield]
#[repr(u8)]
#[derive(Copy, Clone, Debug, Default)]
pub struct RXB0CTRL {
#[skip(setters)]
pub filhit: B1,
#[skip(setters)]
pub bukt1: bool,
pub bukt: bool,
#[skip(setters)]
pub rxrtr: bool,
#[skip]
__: B1,
pub rxm: RXM,
#[skip]
__: B1,
}
#[bitfield]
#[repr(u8)]
#[derive(Copy, Clone, Debug, Default)]
pub struct RXB1CTRL {
#[skip(setters)]
pub filhit: B3,
#[skip(setters)]
pub rxrtr: bool,
#[skip]
__: B1,
pub rxm: RXM,
#[skip]
__: B1,
}
#[cfg(not(any(feature = "mcp2515", feature = "mcp25625")))]
#[derive(BitfieldSpecifier, Copy, Clone, Debug)]
#[bits = 2]
pub enum RXM {
Filter = 0b00,
FilterStandard = 0b01,
FilterExtended = 0b10,
ReceiveAny = 0b11,
}
#[cfg(any(feature = "mcp2515", feature = "mcp25625"))]
#[derive(BitfieldSpecifier, Copy, Clone, Debug)]
#[bits = 2]
pub enum RXM {
Filter = 0b00,
Reserved1 = 0b01,
Reserved2 = 0b10,
ReceiveAny = 0b11,
}
#[cfg(any(feature = "mcp2515", feature = "mcp25625"))]
#[bitfield]
#[repr(u8)]
#[derive(Copy, Clone, Debug)]
pub struct CANCTRL {
pub clkpre: CLKPRE,
pub clken: bool,
#[cfg_attr(doc, doc(cfg(any(feature = "mcp2515", feature = "mcp25625"))))]
pub osm: bool,
pub abat: bool,
pub reqop: OperationMode,
}
#[cfg(not(any(feature = "mcp2515", feature = "mcp25625")))]
#[bitfield]
#[repr(u8)]
#[derive(Copy, Clone, Debug)]
pub struct CANCTRL {
pub clkpre: CLKPRE,
pub clken: bool,
#[skip]
__: B1,
pub abat: bool,
pub reqop: OperationMode,
}
#[derive(BitfieldSpecifier, Copy, Clone, Debug)]
#[bits = 3]
pub enum OperationMode {
NormalOperation = 0b000,
Sleep = 0b001,
Loopback = 0b010,
ListenOnly = 0b011,
Configuration = 0b100,
Invalid1 = 0b101,
Invalid2 = 0b110,
Invalid3 = 0b111,
}
#[derive(BitfieldSpecifier, Copy, Clone, Debug)]
#[bits = 2]
pub enum CLKPRE {
SystemClockDiv1 = 0b000,
SystemClockDiv2 = 0b001,
SystemClockDiv4 = 0b010,
SystemClockDiv8 = 0b011,
}
impl Default for CANCTRL {
fn default() -> Self {
0b1000_0111.into()
}
}
#[bitfield]
#[repr(u8)]
#[derive(Copy, Clone, Debug)]
pub struct CANSTAT {
#[skip]
__: B1,
pub icod: InterruptFlagCode,
#[skip]
__: B1,
pub opmod: OperationMode,
}
#[derive(BitfieldSpecifier, Copy, Clone, Debug)]
#[bits = 3]
pub enum InterruptFlagCode {
NoInterrupt = 0b000,
ErrorInterrupt = 0b001,
WakeUpInterrupt = 0b010,
TXB0Interrupt = 0b011,
TXB1Interrupt = 0b100,
TXB2Interrupt = 0b101,
RXB0Interrupt = 0b110,
RXB1Interrupt = 0b111,
}
impl Default for CANSTAT {
fn default() -> Self {
0b1000_0000.into()
}
}
#[derive(Copy, Clone, Debug, Default)]
pub struct CNF {
pub cnf3: CNF3,
pub cnf2: CNF2,
pub cnf1: CNF1,
}
impl CNF {
pub const fn from_bytes(bytes: [u8; 3]) -> Self {
CNF {
cnf3: CNF3::from_bytes([bytes[0]]),
cnf2: CNF2::from_bytes([bytes[1]]),
cnf1: CNF1::from_bytes([bytes[2]]),
}
}
pub const fn into_bytes(self) -> [u8; 3] {
[
self.cnf3.into_bytes()[0],
self.cnf2.into_bytes()[0],
self.cnf1.into_bytes()[0],
]
}
}
#[bitfield]
#[repr(u8)]
#[derive(Copy, Clone, Debug, Default)]
pub struct CNF1 {
pub brp: B6,
pub sjw: B2,
}
#[bitfield]
#[repr(u8)]
#[derive(Copy, Clone, Debug, Default)]
pub struct CNF2 {
pub prseg: B3,
pub phseg1: B3,
pub sam: bool,
pub btlmode: bool,
}
#[cfg(any(feature = "mcp2515", feature = "mcp25625"))]
#[bitfield]
#[repr(u8)]
#[derive(Copy, Clone, Debug, Default)]
pub struct CNF3 {
pub phseg2: B3,
#[skip]
__: B3,
pub wakfil: bool,
#[cfg_attr(doc, doc(cfg(any(feature = "mcp2515", feature = "mcp25625"))))]
pub sof: bool,
}
#[cfg(not(any(feature = "mcp2515", feature = "mcp25625")))]
#[bitfield]
#[repr(u8)]
#[derive(Copy, Clone, Debug, Default)]
pub struct CNF3 {
pub phseg2: B3,
#[skip]
__: B3,
pub wakfil: bool,
#[skip]
__: B1,
}
#[bitfield]
#[repr(u8)]
#[derive(Copy, Clone, Debug, Default)]
pub struct DLC {
pub dlc: B4,
#[skip]
__: B2,
pub rtr: bool,
#[skip]
__: B1,
}
#[bitfield]
#[repr(u8)]
#[derive(Copy, Clone, Debug, Default)]
pub struct TXB0CTRL {
pub txp: B2,
#[skip]
__: B1,
pub txreq: bool,
pub txerr: bool,
pub mloa: bool,
pub abtf: bool,
#[skip]
__: B1,
}
#[bitfield]
#[repr(u8)]
#[derive(Copy, Clone, Debug, Default)]
pub struct TXB1CTRL {
pub txp: B2,
#[skip]
__: B1,
pub txreq: bool,
pub txerr: bool,
pub mloa: bool,
pub abtf: bool,
#[skip]
__: B1,
}
#[bitfield]
#[repr(u8)]
#[derive(Copy, Clone, Debug, Default)]
pub struct TXB2CTRL {
pub txp: B2,
#[skip]
__: B1,
pub txreq: bool,
pub txerr: bool,
pub mloa: bool,
pub abtf: bool,
#[skip]
__: B1,
}
#[bitfield]
#[repr(u8)]
#[derive(Copy, Clone, Debug, Default)]
pub struct CANINTE {
pub rx0ie: bool,
pub rx1ie: bool,
pub tx0ie: bool,
pub tx1ie: bool,
pub tx2ie: bool,
pub errie: bool,
pub wakie: bool,
pub merre: bool,
}
#[bitfield]
#[repr(u8)]
#[derive(Copy, Clone, Debug, Default)]
pub struct CANINTF {
pub rx0if: bool,
pub rx1if: bool,
pub tx0if: bool,
pub tx1if: bool,
pub tx2if: bool,
pub errif: bool,
pub wakif: bool,
pub merrf: bool,
}
#[bitfield]
#[repr(u8)]
#[derive(Copy, Clone, Debug, Default)]
pub struct EFLG {
pub ewarn: bool,
pub rxwar: bool,
pub txwar: bool,
pub rxep: bool,
pub txep: bool,
pub txbo: bool,
pub rx0ovr: bool,
pub rx1ovr: bool,
}
#[bitfield]
#[repr(u8)]
#[derive(Copy, Clone, Debug, Default)]
pub struct BFPCTRL {
pub b0bfm: bool,
pub b1bfm: bool,
pub b0bfe: bool,
pub b1bfe: bool,
pub b0bfs: bool,
pub b1bfs: bool,
#[skip]
__: B2,
}
#[bitfield]
#[repr(u8)]
#[derive(Copy, Clone, Debug, Default)]
pub struct TXRTSCTRL {
pub b0rtsm: bool,
pub b1rtsm: bool,
pub b2rtsm: bool,
pub b0rts: bool,
pub b1rts: bool,
pub b2rts: bool,
#[skip]
__: B2,
}
#[derive(Copy, Clone, Debug, Default, Ord, PartialOrd, Eq, PartialEq)]
pub struct TEC(pub u8);
impl From<u8> for TEC {
fn from(val: u8) -> Self {
TEC(val)
}
}
impl From<TEC> for u8 {
fn from(val: TEC) -> Self {
val.0
}
}
#[derive(Copy, Clone, Debug, Default, Ord, PartialOrd, Eq, PartialEq)]
pub struct REC(pub u8);
impl From<u8> for REC {
fn from(val: u8) -> Self {
REC(val)
}
}
impl From<REC> for u8 {
fn from(val: REC) -> Self {
val.0
}
}
#[bitfield]
#[repr(u8)]
#[derive(Copy, Clone, Debug, Default)]
pub struct ReadStatusResponse {
pub rx0if: bool,
pub rx1if: bool,
pub txreq0: bool,
pub tx0if: bool,
pub txreq1: bool,
pub tx1if: bool,
pub txreq2: bool,
pub tx2if: bool,
}
#[cfg(any(feature = "mcp2515", feature = "mcp25625"))]
#[cfg_attr(doc, doc(cfg(any(feature = "mcp2515", feature = "mcp25625"))))]
#[bitfield]
#[repr(u8)]
#[derive(Copy, Clone, Debug, Default)]
pub struct RxStatusResponse {
pub filter_match: FilterMatch,
pub is_remote: bool,
pub is_extended: bool,
#[skip]
__: B1,
pub rx0if: bool,
pub rx1if: bool,
}
#[cfg(any(feature = "mcp2515", feature = "mcp25625"))]
#[cfg_attr(doc, doc(cfg(any(feature = "mcp2515", feature = "mcp25625"))))]
#[derive(BitfieldSpecifier, Copy, Clone, Debug)]
#[bits = 3]
pub enum FilterMatch {
RXF0,
RXF1,
RXF2,
RXF3,
RXF4,
RXF5,
RXF0Rollover,
RXF1Rollover,
}
impl Register for RXB0CTRL {
const ADDRESS: u8 = 0x60;
}
impl Register for RXB1CTRL {
const ADDRESS: u8 = 0x70;
}
impl Register for CANCTRL {
const ADDRESS: u8 = 0x0F;
}
impl Register for CANSTAT {
const ADDRESS: u8 = 0x0E;
}
impl Register for CNF1 {
const ADDRESS: u8 = 0x2A;
}
impl Register for CNF2 {
const ADDRESS: u8 = 0x29;
}
impl Register for CNF3 {
const ADDRESS: u8 = 0x28;
}
impl Register for TXB0CTRL {
const ADDRESS: u8 = 0x30;
}
impl Register for TXB1CTRL {
const ADDRESS: u8 = 0x40;
}
impl Register for TXB2CTRL {
const ADDRESS: u8 = 0x50;
}
impl Register for CANINTE {
const ADDRESS: u8 = 0x2B;
}
impl Register for CANINTF {
const ADDRESS: u8 = 0x2C;
}
impl Register for EFLG {
const ADDRESS: u8 = 0x2D;
}
impl Register for BFPCTRL {
const ADDRESS: u8 = 0x0C;
}
impl Register for TXRTSCTRL {
const ADDRESS: u8 = 0x0D;
}
impl Register for TEC {
const ADDRESS: u8 = 0x1C;
}
impl Register for REC {
const ADDRESS: u8 = 0x1D;
}
impl Modify for CANCTRL {}
impl Modify for CNF1 {}
impl Modify for CNF2 {}
impl Modify for CNF3 {}
impl Modify for TXB0CTRL {}
impl Modify for TXB1CTRL {}
impl Modify for TXB2CTRL {}
impl Modify for RXB0CTRL {}
impl Modify for RXB1CTRL {}
impl Modify for CANINTE {}
impl Modify for CANINTF {}
impl Modify for EFLG {}
impl Modify for BFPCTRL {}
impl Modify for TXRTSCTRL {}