embassy_stm32_plus/builder/eth/
phy.rs

1use embassy_stm32::eth::{PacketQueue, PHY};
2use embassy_stm32::eth::generic_smi::GenericSMI;
3
4/// eth phy
5pub struct EthPhy<const TX: usize, const RX: usize, P: PHY> {
6    /// queue
7    pub queue: &'static mut PacketQueue<TX, RX>,
8    /// phy
9    pub phy: P,
10    /// mac addr
11    pub mac_addr: [u8; 6],
12}
13
14/// custom method
15impl<const TX: usize, const RX: usize, P: PHY> EthPhy<TX, RX, P> {
16    /// create eth phy
17    #[inline]
18    pub fn new(queue: &'static mut PacketQueue<TX, RX>, phy: P, mac_addr: [u8; 6]) -> Self {
19        Self { queue, phy, mac_addr }
20    }
21
22    /// create eth pht from queue and phy
23    #[inline]
24    pub fn from_queue_phy(queue: &'static mut PacketQueue<TX, RX>, phy: P) -> Self {
25        Self::new(queue, phy, [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF])
26    }
27
28    /// set mac addr
29    #[inline]
30    pub fn set_mac_addr(mut self, mac_addr: [u8; 6]) -> Self {
31        self.mac_addr = mac_addr;
32        self
33    }
34}
35
36/// custom method
37impl<const TX: usize, const RX: usize> EthPhy<TX, RX, GenericSMI> {
38    /// create eth phy from queue
39    #[inline]
40    pub fn from_queue(queue: &'static mut PacketQueue<TX, RX>) -> Self {
41        Self::new(queue, GenericSMI::new(0), [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF])
42    }
43}