use crate::device::Speed;
use crate::setup::Direction;
use zerocopy::AsBytes;
use core::slice;
pub trait UsbDriver: ReadControl + ReadEndpoint + WriteEndpoint + UsbDriverOperations {}
pub trait UsbDriverOperations {
fn connect(&mut self, device_speed: Speed);
fn disconnect(&mut self);
fn bus_reset(&self);
fn ack(&self, endpoint_number: u8, direction: Direction);
fn set_address(&self, address: u8);
fn stall_endpoint_in(&self, endpoint_number: u8);
fn stall_endpoint_out(&self, endpoint_number: u8);
fn clear_feature_endpoint_halt(&self, endpoint_number: u8, direction: Direction);
}
pub trait UnsafeUsbDriverOperations {
unsafe fn set_tx_ack_active(&self, endpoint_number: u8);
unsafe fn clear_tx_ack_active(&self, endpoint_number: u8);
unsafe fn is_tx_ack_active(&self, endpoint_number: u8) -> bool;
}
pub trait ReadControl {
fn read_control(&self, buffer: &mut [u8]) -> usize;
}
pub trait ReadEndpoint {
fn ep_out_prime_receive(&self, endpoint_number: u8);
fn ep_out_enable(&self);
fn read(&self, endpoint_number: u8, buffer: &mut [u8]) -> usize;
}
pub trait WriteEndpoint {
fn write<I>(&self, endpoint_number: u8, iter: I) -> usize
where
I: Iterator<Item = u8>;
fn write_requested<I>(&self, endpoint_number: u8, requested_length: usize, iter: I) -> usize
where
I: Iterator<Item = u8>;
fn write_with_packet_size<I>(
&self,
endpoint_number: u8,
requested_length: Option<usize>,
iter: I,
packet_size: usize,
) -> usize
where
I: Iterator<Item = u8>;
}
pub trait AsByteSliceIterator: AsBytes {
fn as_iter(&self) -> slice::Iter<u8> {
self.as_bytes().iter()
}
}