stm32_eth/dma/
packet_id.rs

1/// A packet ID.
2///
3/// This packet ID can be used to obtain information about a specific
4/// ethernet frame (either sent or received) from the DMA.
5///
6#[cfg_attr(
7    feature = "ptp",
8    doc = "
9The main use is obtaining timestamps for frames using [`EthernetDMA::poll_timestamp`](crate::EthernetDMA::poll_timestamp)
10"
11)]
12#[cfg_attr(feature = "defmt", derive(defmt::Format))]
13#[derive(Debug, PartialEq, Clone)]
14pub struct PacketId(pub u32);
15
16impl PacketId {
17    /// The initial value for an [`Option<PacketId>`]
18    pub const INIT: Option<Self> = None;
19}
20
21impl From<u32> for PacketId {
22    fn from(value: u32) -> Self {
23        Self(value)
24    }
25}
26
27#[cfg(all(feature = "ptp", feature = "smoltcp-phy"))]
28impl From<smoltcp::phy::PacketMeta> for PacketId {
29    fn from(value: smoltcp::phy::PacketMeta) -> Self {
30        Self(value.id)
31    }
32}
33
34#[cfg(all(feature = "ptp", feature = "smoltcp-phy"))]
35impl From<PacketId> for smoltcp::phy::PacketMeta {
36    fn from(value: PacketId) -> Self {
37        let mut meta = smoltcp::phy::PacketMeta::default();
38        meta.id = value.0;
39        meta
40    }
41}