use crate::timer::Timer;
use crate::usb::dwc2::{Channel, TransferError};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct IdRevision {
pub id: u16,
pub revision: u16,
}
pub trait Ethernet {
type Frames<'a>: Iterator<Item = &'a [u8]>
where
Self: 'a;
const MTU: usize;
fn id_revision(
&self,
channel: &mut Channel,
timer: &Timer,
) -> Result<IdRevision, TransferError>;
fn start(
&mut self,
channel: &mut Channel,
timer: &Timer,
mac: [u8; 6],
) -> Result<(), TransferError>;
fn is_link_up(&self, channel: &mut Channel, timer: &Timer) -> Result<bool, TransferError>;
fn is_full_duplex(&self, channel: &mut Channel, timer: &Timer) -> Result<bool, TransferError>;
fn set_all_multicast(
&mut self,
channel: &mut Channel,
timer: &Timer,
pass: bool,
) -> Result<(), TransferError>;
fn send_frame(
&mut self,
channel: &mut Channel,
timer: &Timer,
frame: &[u8],
) -> Result<(), TransferError>;
fn receive_frames(
&mut self,
channel: &mut Channel,
timer: &Timer,
) -> Result<Self::Frames<'_>, TransferError>;
}
#[cfg(feature = "async")]
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
#[allow(
async_fn_in_trait,
reason = "the futures are polled on the core that owns the host channel, so \
there is nothing for a `Send` bound to buy and adding one would \
exclude the drivers that hold a raw peripheral handle"
)]
pub trait EthernetAsync: Ethernet {
type Rx<'a>: EthernetRx
where
Self: 'a;
type Tx<'a>: EthernetTx
where
Self: 'a;
fn split(&mut self) -> (Self::Rx<'_>, Self::Tx<'_>);
async fn start_async(
&mut self,
channel: &mut Channel<'_>,
timer: &Timer,
mac: [u8; 6],
) -> Result<(), TransferError>;
async fn is_link_up_async(
&self,
channel: &mut Channel<'_>,
timer: &Timer,
) -> Result<bool, TransferError>;
async fn set_all_multicast_async(
&mut self,
channel: &mut Channel<'_>,
timer: &Timer,
pass: bool,
) -> Result<(), TransferError>;
}
#[cfg(feature = "async")]
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
#[allow(
async_fn_in_trait,
reason = "see `EthernetAsync`: no executor here moves these futures between cores"
)]
pub trait EthernetRx {
type Frames<'a>: Iterator<Item = &'a [u8]>
where
Self: 'a;
async fn receive_frames_async(
&mut self,
channel: &mut Channel<'_>,
timer: &Timer,
) -> Result<Self::Frames<'_>, TransferError>;
}
#[cfg(feature = "async")]
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
#[allow(
async_fn_in_trait,
reason = "see `EthernetAsync`: no executor here moves these futures between cores"
)]
pub trait EthernetTx {
async fn send_frame_async(
&mut self,
channel: &mut Channel<'_>,
timer: &Timer,
frame: &[u8],
) -> Result<(), TransferError>;
}