embassy_stm32_plus/builder/eth/
mod.rs1use embassy_stm32::{bind_interrupts, eth, Peripheral};
2use embassy_stm32::eth::{CRSPin, Ethernet, RXD0Pin, PHY};
3use embassy_stm32::peripherals::ETH;
4use crate::builder::eth::pins::{EthCrs, EthRxD0, EthRxD1};
5
6pub mod pins;
7pub mod phy;
8
9bind_interrupts!(struct Irqs {
10 ETH => eth::InterruptHandler;
11});
12
13struct EthOnce<const TX: usize, const RX: usize, P: PHY> {
15 pub eth: ETH,
17 pub pin_once: pins::EthPinOnce,
19 pub phy: phy::EthPhy<TX, RX, P>,
21}
22
23pub struct EthBuilder<const TX: usize, const RX: usize, P: PHY> {
25 pub eth: ETH,
27 pub pins: pins::EthPins,
29 pub phy: phy::EthPhy<TX, RX, P>,
31}
32
33impl<const TX: usize, const RX: usize, P: PHY> EthBuilder<TX, RX, P> {
35 #[inline]
37 pub fn new(eth: ETH, pins: pins::EthPins, phy: phy::EthPhy<TX, RX, P>) -> Self {
38 Self { eth, pins, phy }
39 }
40
41 pub fn build(self) -> Ethernet<'static, ETH, P> {
43 let (crs, rx_d0, rx_d1, eth_once) = self.split();
44 match crs {
45 EthCrs::PA7(pa7) => { Self::build_rx_d0(pa7, rx_d0, rx_d1, eth_once) }
46 #[cfg(PD8)]
47 EthCrs::PD8(pa8) => { Self::build_rx_d0(pa8, rx_d0, rx_d1, eth_once) }
48 }
49 }
50
51 fn build_rx_d0(crs: impl Peripheral<P=impl CRSPin<ETH>> + 'static, rx_d0: EthRxD0, rx_d1: EthRxD1, eth_once: EthOnce<TX, RX, P>)
53 -> Ethernet<'static, ETH, P> {
54 match rx_d0 {
55 EthRxD0::PC4(pc4) => { Self::build_rx_d1(crs, pc4, rx_d1, eth_once) }
56 #[cfg(PD9)]
57 EthRxD0::PD9(pd9) => { Self::build_rx_d1(crs, pd9, rx_d1, eth_once) }
58 }
59 }
60
61 fn build_rx_d1(
63 crs: impl Peripheral<P=impl CRSPin<ETH>> + 'static,
64 rx_d0: impl Peripheral<P=impl RXD0Pin<ETH>> + 'static,
65 rx_d1: EthRxD1,
66 eth_once: EthOnce<TX, RX, P>,
67 ) -> Ethernet<'static, ETH, P> {
68 let EthOnce { eth, pin_once, phy } = eth_once;
69 match rx_d1 {
70 EthRxD1::PC5(pc5) => { Ethernet::new(phy.queue, eth, Irqs, pin_once.ref_clk, pin_once.mdio, pin_once.mdc, crs, rx_d0, pc5, pin_once.tx_d0, pin_once.tx_d1, pin_once.tx_en, phy.phy, phy.mac_addr) }
71 #[cfg(PD10)]
72 EthRxD1::PD10(pd10) => { Ethernet::new(phy.queue, eth, Irqs, pin_once.ref_clk, pin_once.mdio, pin_once.mdc, crs, rx_d0, pd10, pin_once.tx_d0, pin_once.tx_d1, pin_once.tx_en, phy.phy, phy.mac_addr) }
73 }
74 }
75
76 fn split(self) -> (EthCrs, EthRxD0, EthRxD1, EthOnce<TX, RX, P>) {
78 let (crs, rx_d0, rx_d1, pin_once) = self.pins.split();
79 (crs, rx_d0, rx_d1, EthOnce {
80 eth: self.eth,
81 pin_once,
82 phy: self.phy,
83 })
84 }
85}