use core::ops;
#[allow(unused_imports)] use crate::{Can, Rx0};
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "unstable-defmt", derive(defmt::Format))]
#[non_exhaustive]
pub enum Interrupt {
TransmitMailboxEmpty = 1 << 0,
Fifo0MessagePending = 1 << 1,
Fifo0Full = 1 << 2,
Fifo0Overrun = 1 << 3,
Fifo1MessagePending = 1 << 4,
Fifo1Full = 1 << 5,
Fifo1Overrun = 1 << 6,
Error = 1 << 15,
Wakeup = 1 << 16,
Sleep = 1 << 17,
}
bitflags::bitflags! {
pub struct Interrupts: u32 {
const TRANSMIT_MAILBOX_EMPTY = 1 << 0;
const FIFO0_MESSAGE_PENDING = 1 << 1;
const FIFO0_FULL = 1 << 2;
const FIFO0_OVERRUN = 1 << 3;
const FIFO1_MESSAGE_PENDING = 1 << 4;
const FIFO1_FULL = 1 << 5;
const FIFO1_OVERRUN = 1 << 6;
const ERROR = 1 << 15;
const WAKEUP = 1 << 16;
const SLEEP = 1 << 17;
}
}
impl From<Interrupt> for Interrupts {
#[inline]
fn from(i: Interrupt) -> Self {
Self::from_bits_truncate(i as u32)
}
}
impl ops::BitOrAssign<Interrupt> for Interrupts {
#[inline]
fn bitor_assign(&mut self, rhs: Interrupt) {
*self |= Self::from(rhs);
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn interrupt_flags() {
assert_eq!(Interrupts::from(Interrupt::Sleep), Interrupts::SLEEP);
assert_eq!(
Interrupts::from(Interrupt::TransmitMailboxEmpty),
Interrupts::TRANSMIT_MAILBOX_EMPTY
);
let mut ints = Interrupts::FIFO0_FULL;
ints |= Interrupt::Fifo1Full;
assert_eq!(ints, Interrupts::FIFO0_FULL | Interrupts::FIFO1_FULL);
}
}