embassy_stm32_plus/builder/can/
can2.rs1use embassy_stm32::{bind_interrupts, can, Peripheral};
2use embassy_stm32::can::{Can, TxPin};
3use embassy_stm32::peripherals::{CAN2, PB12, PB13, PB5, PB6};
4
5bind_interrupts!(struct Irqs {
6 CAN2_RX0 => can::Rx0InterruptHandler<CAN2>;
7 CAN2_RX1 => can::Rx1InterruptHandler<CAN2>;
8 CAN2_SCE => can::SceInterruptHandler<CAN2>;
9 CAN2_TX => can::TxInterruptHandler<CAN2>;
10});
11
12pub enum Can2Rx {
14 PB5(PB5),
15 PB12(PB12),
16}
17
18pub enum Can2Tx {
20 PB6(PB6),
21 PB13(PB13),
22}
23
24pub struct Can2Builder {
26 pub can: CAN2,
28 pub tx: Can2Tx,
30 pub rx: Can2Rx,
32}
33
34impl Can2Builder {
36 #[inline]
38 pub fn new(can: CAN2, tx: Can2Tx, rx: Can2Rx) -> Self {
39 Self { can, tx, rx }
40 }
41
42 pub fn build(self) -> Can<'static> {
44 match self.tx {
45 Can2Tx::PB6(pb6) => { Self::build_rx(self.can, pb6, self.rx) }
46 Can2Tx::PB13(pb13) => { Self::build_rx(self.can, pb13, self.rx) }
47 }
48 }
49
50 fn build_rx(can: CAN2, tx: impl Peripheral<P=impl TxPin<CAN2>> + 'static, rx: Can2Rx) -> Can<'static> {
52 match rx {
53 Can2Rx::PB5(pb5) => { Can::new(can, pb5, tx, Irqs) }
54 Can2Rx::PB12(pb12) => { Can::new(can, pb12, tx, Irqs) }
55 }
56 }
57}